Mapbox: Making a line given two OSM Node IDs - leaflet

I have two Open Street Map node IDs. Is there any API provided by Mapbox or Leaflet which could draw a PolyLine or LineString given the two node IDs?
I am not able to find any reference to OSM IDs anywhere in Mapbox documentation, apart from here and it does not detail how to use the OSM IDs for ourselves to draw lines on the map.
What I want to do is given 2 OSM IDs, I want to highlight the road segment connecting those OSM IDs. I can't go for things like Leaflet routing machine since the number of such lines are too many, with small distances. I can't run routing for all the edges.

Since you say "I can't go for things like Leaflet routing machine since the number of such lines are too many, with small distances. I can't run routing for all the edges." I'm excluding all solutions calling an external routing API, instead you can do your own internal routing.
Use the OSM Overpass API to get the long,lat points for those nodes
In Mapbox GL JS fitBounds to those two nodes and do map.querySourceFeatures to get the roads as GeoJSON LineStrings
then compute a network graph from this and use Dijkstra's algorithm to get the shortest path between your two OSM nodes.

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 to get a polygon (for buildings) with one known inside node?

I'm now using OSMnx to extract data for buildings. What I need is to get building polygons through addresses. The question I met is about some of the buildings have multiple addresses, thus there are no address data for that building's polygon.
For example, the building 'Furutorpsgatan 49A' (in Helsingborg, Sweden) has three nodes you can search for, which are:
Furutorpsgatan 49A; Furutorpsgatan 49B; Gustav Adolfs Gata 23
But if you export the geometry data (polygon), there's no address data at all! In another word, there's no way to get the building polygon except for three nodes inside.
I was trying to use OSMid for polygons to match the position, but I can't find the building with OSMid 'w483244917'
Then I'm thinking is there any method I can extract the polygon data through one or several nodes inside?
Or could you suggest me some methods to get any building footprint polygons through building addresses?
Or is there a plugin for grasshopper to get building footprints by addresses?
Thank you!

Visualising road segments as heatmap in Leaflet efficiently

I have data consisting of parts of road segments of a city, with different number of visits. I want to plot the data on a Map and visualise it in the form of a heatmap.
I have two related questions:
I have the data from Open Street Maps (OSM) in the form of pairs of node ID's, where node ID correspond to the unique ID being assigned to a point by OSM. I also have a mapping for each node Id to its corresponding coordinates. Is there any Leaflet or Mapbox utility or plugin, which can plot a trip / highlight the road segment using 2 node ID's. I can always do it manually (by using the coordinate mapping and converting it into GeoJSON), but the problem occurs with the line width -- I have to make it exactly overlap with the width of the road, so that it seems that I am highlighting a road segment.
Is there any plugin / utility for Leaflet or Mapbox, which can be used for plotting polylines or geojson as heatmap efficiently? My current approach is calculating the color for each polyline and encoding that as a geojson property. But the problem is that with the increase in the number of lines (> 1K) the rendering becomes a pain and the method is not feasible. There are some plugins for Leaflet out there for plotting heatmap, but all of them are for points only and not lines. Any approach using WebGL would be really great.
An approach which I thought of could be converting my data into a shape file, upload to Mapbox Studio and use as a layer directly. But I have no idea how to go about doing that i.e. creating a shapes file, encoding the information in such a way that the complete road segment gets highlighted in the correct color.

Calculate distance between two points in an OpenStreetMap file

I need to calculate the distance between two points in a map in the same way as Google Maps' distance matrix and get direction APIs.
Since I have to use offline more, I have to work with OpenStreetMap data.
I have downloaded the planet.osm file for the map data. How do I calculate the distance between two points with the OpenStreetMap file?
There are already several routing solutions for OpenStreetMap (OSM), including various web services, standalone programs, and libraries. You are probably interested in one of the many offline routers.

Openlayers: baselayer overlay - projection

The issue is:
I have vector/topo/image tiled maps for some places in north america which were published as ArcGIS Server REST service. These maps (A) are based in EPSG26912 projection. Now I wanna use these as basemap for my openlayer web app; besides, I also want to consume other base map sources (B), e.g., OpenStreetmap, Google Maps, ESRI, etc. Since most of these maps are in EPSG900913 which is sphericalMercator projection to my knowledge, if I just add these base map layers into openlayer map component, the group A and group B won't overlay correctly, which means they are displayed as seperate maps. I know this is something related to projection, and might need some code with proj4js, however, as a newbie, I dont really know how to start with.
Basically, I want to put OSM/Google maps as the base map for the whole world in tier 1, then put EPSG26912 base maps for some places in north america in tier 2, and put other WMS or WFS in the top tier.
do I need to transform EPSG26912 to EPSG900913 or opposite? I guess I should use EPSG900913 as the base projection.
Appreciate any replies!
Unfortunately the only solution here is to reproject data from one projection to another. Most logical would be of course to reproject EPSG:26912 to EPSG:900913.
Geoserver can help you out with this as it can reproject both WMS and WFS