Alessandro Chiarotto Alessandro Chiarotto - 1 month ago 13
reST (reStructuredText) Question

MapBox - How the get Points of Building Shape/Edge

I would like to get the points of the shape of a building using mapbox. Is it possible?
For example I would like to get the red point of a building like in the image below:

Red points of building

I'm going to use Swift, but maybe these kind of data can be retrieved using some end-point exposed by mapbox rest API.

Answer

Not programmatically you can do the following: Based on the overpass API you can take use of the overpass API turbo engine. With that engine it's possible to extract all the data from the OpenStreetMap database including geometries of buildings and their coordinates. If you want to query ALL buildings in a specific boundary box just do:

 (
  way[building]({{bbox}});
  >;

 );
  out skel; 

Here goes the EXAMPLE in the engine.

If you want to set search conditions based on buildings, you may want do the following:

(
  way[building][key=value]({{bbox}});
  >;

 );
  out skel;

Here is an EXAMPLE to get a building in a given bounding box with the name "Istituto Professionale Servizi Commerciale".

Programmatically just do a POST request with your progamming language of choice. An example URL could like the following, where the coordinates are the bounding box of the request:

https://www.overpass-api.de/api/interpreter?data=(way[building][name~%22Istituto%20Professionale%20Servizi%20Commerciale%22](41.89217881581378,12.488332986831665,41.89511780763163,12.492608428001404);%3E;);out;

The returned result is as default an XML.

If you want to return you result in a geoJSON just do:

https://www.overpass-api.de/api/interpreter?data=[out:json];(way[building][name~%22Istituto%20Professionale%20Servizi%20Commerciale%22](41.89217881581378,12.488332986831665,41.89511780763163,12.492608428001404);%3E;);out;

Accessing the "elements" key of each polygon will give you the attributes of your corner edges of the polygon in geographical coordinates (lat, lon).