Get buildings polygons points from mapbox with fetch API only - mapbox

I try to get the buildings geometry coordinates polygons from features, but i cant seem to find a way for this to work without the javascript method queryRenderedFeatures or SourceFeatures.
This question Getting building information from mapbox api uses the javascript method, but i want something to work with a link, that i can fetch a json from.
I have managed to come close with something like this:
https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/tilequery/27.598505,47.162098.json?radius=30&layers=road,poi_label,building,geometry&access_token=ACCESS_TOKEN_HERE.
But this has a major flaw:
It only returns geometry as a point:
{"type":"FeatureCollection","features":[{"type":"Feature","id":235028771,"geometry":{"type":"Point","coordinates":[27.598497434198464,47.16209573500234],"type":"building"...}}
You can observe that it returns a point even though it is a building.
Is there a way to do this?
The queryRenderedFeatures method DOES return a polygon. Somehow the information reaches the Map object that i query but how can i fetch through an api that info?

What you're trying to do is not possible. Mapbox doesn't provide complete polygon datasets. At best, there are ways of retrieving polygons from vector tilesets (such as query-remote-tiles, which does something similar to TileQuery). But these will only retrieve the part of the polygon within a given vector tile, which may not be what you want. (queryRenderedFeatures has the same issue).

Related

How to compute bounding boxes of specific roads from Overpass api

I have a high volume dataset with keys like this:
lat:6.897585,
long:52.785805,
speed:12,
bearing:144
Basically it is a dataset of records of various trips on cars. The data was stored every few seconds during each trip. The main goal of this project is to be able to visualize only u-turns (turn arounds) on a map. But for now, I am trying to at least show the data on specifc roads. For that, I am using Overpass API
With the help of Overpass Turbo, I can get a dataset with all the roads I need.
However, in the dataset, the road's geometry is represented with LineString type.
My question is, How can I get a bounding box(es) of the roads from Overpass API, so later on, I can display events that happened only on the given roads? Or maybe you have a better solution on how to achieve this?
A bounding box wouldn't be very helpful here, as using it to filter your points would show everything that falls within the box (which could include other nearby roads)
It sounds like getting a buffer around a linestring might get you closer, but could still include points that are within the buffer but not on the road you are inspecting.
The smarter way to do this would be to assign each event to a road segment using some logic based on their attributes/properties, so you don't have to depend on a spatial filter.

How do I use the snap to road function using OSRM?

I am currently working with OSRM and used some GPS data for testing which i generated using googles Interactive Polyline Encoder Utility
https://developers.google.com/maps/documentation/utilities/polylineutility
The concept im going for is that a car is driving along a street sending every 20 seconds its GPS location. I want to display the path and the kilometers it drove at the end of its trip.
I set up a Client in C# performing a GET request with the match algorithm to communicate with the api on the open demoserver backend http://router.project-osrm.org
The problem is that i cannot use the match algorithm because it only takes two GPS points instead of a polyline consisting of several GPS locations. To me this does not make sense.
I tried this and it worked not that bad but it lost track and somehow ended at a point i didn't define, probably because of the quite long distance between the two points but i need it to work for more than two though:
here's the picture of it where it went wrong
http://router.project-osrm.org/match/v1/driving/13.682632,47.393753;13.6849281,47.3935649?overview=full&radiuses=49;49
I also found some decent blogs and websites telling me that I should use the OSRM matching algorithm as a Snap to road tool. One of them is this one: https://www.jamesrcroft.com/2015/06/snapping-gps-tracks-to-roads/
I also tried the route method which according to the OSRM wiki finds the fastest route between coordinates in the supplied order. Thats not exactly what I want. At least it could take a polyline of GPS locations but it was always extremely inacurate and faulty.
This is the GET Request for the method route I used:
Pic of how it looked before OSRM, it is slightly inacurate so i want it snapped to the road:
string polyline = #"kz~dHclrbBbAfAn#iBb#{Cf#aBXkA_#s#m#i#_A}#c#c#Fu#Tq#ZWXT";
string.Format("http://router.project-osrm.org/route/v1/driving/polyline({0})?overview=full", polyline);
As response i got this polyline in the attribute geometry:
mz~dHalrbB`#b#XZFFFHBK#CBI#E\\uA\\mA?[?SH[Ru#Nm#XkAFOg#a#m#g#AA}#_Ac#c#IIPk#Tq#Nc#?A??
This is what i got when I decoded it through the google polyline encoder: a complete mess..
Could someone explain what I am doing wrong? Thank you in advance!
I am sure the problem is that you do not send the timestamp of each geolocation in unix time.
Take a look at the official documentation: http://project-osrm.org/docs/v5.5.1/api/#match-service
This is how your request should look like:
http://router.project-osrm.org/match/v1/driving/13.682632,47.393753;13.6849281,47.3935649?overview=full&radiuses=49;49&timestamps=1563459949;1563460007

Leaflet.js and complex polygons

For a small project I am allowing users to add areas to the database. Their query is sent to http://nominatim.openstreetmap.org and I store the latitude and longitude. If available, I also store the geoJSON polygon outline data.
Example output: http://nominatim.openstreetmap.org/search?q=wyoming&format=xml&polygon_geojson=1&addressdetails=1
This outlined area is then displayed on a map using leaflet.js. For a lot of polygons this works out just fine, but it seems that there is a limit to the amount of data the library can process. Some rather complex areas (that require a longtext to store in mysql) simply do not get displayed at all, without an error being thrown.
I guess my question has two parts:
1 - Am I right to assume that the large datasets are the root of the problem or should leaflet.js be able to handle those?
2 - What would be the best way of simplifying such datasets? Leaflet has such an algorithm for displaying areas, but that seems to be the failing point already.
And while we are on the topic: Right now I'm converting Nominatim's lnglat polygons to leaflet's latlng by splitting up the data and patching it back together in javascript. Is there an easier/safer way to do that? Should I rather move that task to the server and use some php library/function?
I appreciate your help!
Edit: Forgot to mention: on the occasion that the polygon fails to render, my console gives me this error: TypeError: t is null
are the large datasets the root of the problem or should leaflet.js be able to handle those?
Leaflet.js will handle whatever you throw at it. There is, however, a limit on what your web browser can handle without slowing down.
Remember that every modern web browser has performance analysis tools that you can use to see what parts of the Leaflet code (or of the browser's internals) is taking up most of your time.
What would be the best way of simplifying such datasets?
You probably want to look at the Douglas-Peucker algorithm for a starting point in these algorithms.
Keep in mind that Leaflet uses this algorithm internally to simplify polygons on each zoom level, up to a pixel.
For some big complex polygons, slicing them up with something like Leaflet.VectorGrid might improve the performance.
There is no silver bullet for simplifying datasets, however. The best way will depend on the specific data you are using.
on the occasion that the polygon fails to render, my console gives me this error: TypeError: t is null
This is a different matter, and might be a symptom of malformed data.
In order to display prettier error messages, use the leaflet-src.js file instead of the leaflet.js file. Starting with Leaflet 1.0.0-beta2, leaflet-src.js has a sourcemap, which can point to the individual original files, allowing for better debugging.

Polyline changes the order of points

I would like leaflet to connect points in polyline in the same order as they were passed into constructor (L.polyline(route, routeOptions).addTo(map) where route is an array of points), but it seems to me that polyline does not care about order at all. Any suggestions would be highly appreciated.
What makes you think that Leaflet polyline does not care at all about the order in the array of points (coordinates)?
L.polyline(arrayOfLatLngs) should draw a segmented line passing by all the specified coordinates in arrayOfLatLngs, in the order they are set in the array.
Demo: http://jsfiddle.net/ve2huzxw/91/
If it does not behave that way for you, please provide your code and if possible reproduce your issue online (e.g. on jsfiddle) so that people can investigate.

MongoDB storing a circle

Is it possible to store a circle on MongoDB? I want to store circles as collections, and be able to index them for searching. I know that the $geoWithin query is possible where one specifies a circle and retrieves points or now GeoJSON objects, but I want to be able to do the opposite. Somehow drawing a giant polygon with multiple points on a plane doesn't seem very attractive as a workaround, so I'm hoping that someone has something better.
I've searched on Google, but can't find anything. I know about storing polygons and linestring, which were introduced in MongoDB 2.3>, there are also some suggestions on the GeoJSON spec for defining circles.
I have also seen this question on SO,but the OP never came back to link to jira, or to update the answer if they found a solution.