Hello,
Could anyone tell me what the difference is between the resulting building bag ids from this javascript fetch request and this sparql query? They don’t seem to match correctly.
js fetch:
export async function fetchBuildingsByCoordinates(coords: { latitude: number; longitude: number }) {
const url = 'https://bag.basisregistraties.overheid.nl/api/v1/panden'
return fetch(url, {
method: 'POST',
headers: {
'X-Api-Key': 'my-api-key',
'Content-Type': 'application/json',
},
body: JSON.stringify({
geometrie: { contains: { type: 'Point', coordinates: [coords.latitude, coords.longitude] } },
}),
})
.then((r) => r.json())
.then((r) => {
return r
})
}
sparql query:
def get_address_and_building_bag_ids(postal_code: nil, house_number: nil)
query = %Q{
prefix bag: <http://bag.basisregistraties.overheid.nl/def/bag#>
SELECT ?addressBagId ?buildingBagId WHERE {
?object a bag:Verblijfsobject .
?object bag:hoofdadres ?nummer .
?object bag:identificatiecode ?addressBagId .
?nummer bag:postcode ?postcode .
?nummer bag:huisnummer ?huisnummer .
?object bag:pandrelatering ?pand .
?pand bag:identificatiecode ?buildingBagId .
FILTER (?postcode = "#{postal_code}" && ?huisnummer = #{house_number.to_i})
}
}
results = bag_sparql_get(query)
results.map do |result|
{
address_bag_id: result["addressBagId"]["value"],
building_bag_id: result["buildingBagId"]["value"]
}
end
end
def bag_sparql_get(query)
url = URI("https://bag.basisregistraties.overheid.nl/sparql")
response = HTTParty.post(url, headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/sparql-results+json'
},
body: URI.encode_www_form({ query: query }))
begin
JSON.parse(response.body)["results"]["bindings"]
rescue => e
raise "Could not fetch BAG SPARQL #{e.message}, query: #{query}"
end
end