How does routing services for OSM determine the distance between two points - openstreetmap

I am going to design an Android application and I will be needing the distances of the pathways inside our university(pathways between buildings)
I read about OSM(OpenStreetMap) and tried it. It is a map which is editable which means anyone can contribute to that map(like a wikipedia map version).
It has many routing services that give routes and directions between two point(start and end).
There is a routing service named GraphHopper and it is very easy to use. I can just drag and drop the start and end pt and it gives the distance(km) between the two pts.
What I want to know is how did they come up with the distance?
Is the distance reliable and accurate?
Any help is greatly appreciated because I want to use the distances for my Android app and I need to know if these distances have basis.

The distance is 'accurate' in the sense that it correctly processes the existing information from OpenStreetMap and correctly adds road segments for the final route. You can just try for your local area and compare to your own knowledge.
There could be mapping errors, where a road is incorrectly mapped. And there could be also roads missing and so the router uses a detour making the path unnecessarily longer. Also there are different modes like for cars or bikes or fastest and shortest where you get a different distance between two coordinates.

Related

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

How to design multi level highway intersection

So I am trying to design a multi-level highway system with the Road Traffic library in Anylogic. The highways have multiple levels and I am having trouble with depicting the difference in the levels of the roads in my model.
I looked at the help content related to RTL specifically Library Reference Guides and Tutorials but they don't mention adding grades/inclination to a road to get a multi level system.
I apologize in advance if I missed documentation related to this. But I would like to know how to do this in Anylogic.
Also, there is a Highway Junction model available in the sample models that comes with the installation and implements an increase in the z-value of the roads but I am not sure how to do that when designing the road.
When You draw road Object in RTL, in points section of the drawn road properties panel, you can set the Z value of each point of your road. So you should use more than two points to draw your road, even if it is a straight one. This way you can easily set z value of different points of your road, and build up needed levels, grades or slope of the road.
Hope this helps you.

Framework for plotting latitude longitude in a map based on country, state and district depending on the zoom level

I need a framework which takes a set of latitude longitude points and plots on a world map, grouped by country having the count of points as a marker on each country. Grouping here is the count of latitude longitude points in a country.
And as I drill down into a country, the clustering should change to state based one. And the next level, to districts.
Leaflet marker cluster is something very similar to what I have asked for, but the grouping is based on proximity and it doesn't consider country or state boundaries. That is, they are not region aware.
Regionbound.com has tweaked in some code in the leaflet code for making it region aware,
Sample marker definition:
var marker1 = new L.marker([-37.8, 145], {regions: ["Asia-Pac", "Australia", "VIC", "Melbourne"]} );
But the sample code says, every latitude longitude must be defined along with some extra parameter containing place information.
I could get the place information using reverse geocoding, but reverse geocoding every latitude longitude is time consuming right.
Highmaps provided by Highcharts is one another solution, but there, every country has code which should be assigned a value[count of point coordinates belonging to that country].
But all I have is latitude longitude points, no country or state information.
Thus, I need something which takes only a set of latitude longitude and does clustering based on country, state, district depending on the zoom level.
You have 2 separate needs in your questions:
Map your lat/lng coordinates to appropriate administrative areas. E.g. through the reverse geocoding that you mention.
Display "clusters" on those administrative areas depending on zoom level.
As for point 1, you know that lat/lng points do not say by themselves which administrative area(s) they belong to. So "reverse geocoding every latitude longitude" is a mandatory step. Whether time consuming or not depends on the solution you choose to perform this operation.
If I understand correctly, you would like a "framework" that could do that automatically for you. But frameworks are usually data agnostic, and if they do not have data about boundaries of those administrative areas, they cannot help you.
You may rather look for "services" (like the Mapbox Geocoding API that you mention) or software that would already have such data. It is not time consuming if you can program the lookup (or perform "bulk" operations) and if you are not limited by the requests rate and your amount of points to map (which may be the case with Mapbox).
You could very well set up your own application to perform this mapping:
As for the dataset for administrative areas boundaries, you would probably be interested in links in this post: Are there any free administrative boundaries available as shapefiles? If your points are limited to a few countries, it will be easier for you to find the appropriate data source(s).
Once you have that data, many GIS software should be capable of mapping your lat/lng points to the areas they belong to. This would be mainly for a "one-shot" operation, if your set of points do not change much.
A "web-compatible" alternative would be for example to use Leaflet with point in polygon for Leaflet plugin. You would need your boundaries data converted to GeoJSON format first. Again, GIS software should be capable of doing so, or many online services as well (search for "convert geojson" for example).
A server-side solution would avoid having to manage the entire boundaries data through network and in client browser (if you need to perform the mapping dynamically). I am sure many GIS servers are capable of performing this operation, once they are fed with the boundaries data.
For point 2, once you have completed the above step, I think you would have many options available, including those you mention (RegionBound, Highmaps).
Even with standard mapping libraries (Leaflet, OpenLayers 3), you would just need to build your "clusters" (markers on administrative areas with a number saying how many points are in there), like you have to do with Highmaps anyway for example.
Computing the number of "clustered" point is as easy as filtering your points per area name / code. Then switch the clusters to the desired administrative level when the map zoom changes.
So the key is really to determine first to which areas your points belong to (point 1).
Then a small question would rise about where to place the "cluster" marker:
On centroid of the administrative area? You need the coordinates of that centroid from your data source, or a good algorithm to compute it from the boundaries (good luck on that…).
On "center" of the bounding box of the area? Leaflet can easily compute that: from your area vector shape, you would do myShape.getBounds().getCenter().
On barycentre / centroid of the clustered points? This is what Leaflet.markercluster and RegionBound do (do not know for Highmaps).
Good luck!

Translating GPS coordinates to map tile-like structure

I'm a complete illiterate when it comes to working with geographical data, so bear with me.
For our application we will be tracking a fairly large amount of rapidly changing points on a map. It would be nice to be able to cache the location of these points in some kind of map-tile structure so it would be easy to find all points currently in the same tile or neighbouring tiles, making it easier to quickly determine the nearest neigbours and have special logic for specific tiles, etc.
Although we're working for one specific (but already large) location, it would be nice if a solution would scale to other locations as well. Since we would only cache tiles that concern the system, would just tiling the enitre planet be the best option? The dimensions of a tile would then be measured in arc seconds/minutes, or is that a bad idea?
We already work with Postgres and this seems like something that could be done with PostGIS (is this what rasters are?), but jumping in to the documentation/tutorials without knowing what exactly I'm looking for is proving difficult. Any ideas?
PostGIS is all that you need. It can store your points in any coordinate reference system, but you'll probably be using longitude/latitude. Are your points coming from a GPS device?
PostGIS uses GIST indexing, making the search for points close to a given point quite efficient. One option you might want to look at, seeing that you are interested in tiling, is to "geohash" your points. Basically, this turns an (X,Y) coordinate pair into a single "string" with a length depending on the level of partitioning. Nearby points will have the same geohash value (= 1 tile) and are then easily identified with standard database search tools. See this answer and related question for some more considerations and an example in PostgreSQL.
You do not want to look at rasters. These are gridded data, think aerial photography or satellite images, weather maps, etc.
But if you want a more specific answer you should give some more details:
How many points? How are they collected?
Do you have large clusters?
Local? Regional? Global?
What other data does this relate to?
Pseudo table structure? Data layout?
etc
More info = better answer
Cheers, hope you get your face back

Calculate nearest point of KML polygon for iPhone app

I have a series of nature reserves that need to be plotted, as polygon overlays, on a map using the coordinates contained within KML data. I’ve found a tutorial on the Apple website for displaying KML overlays on map instances.
The problem is that the reserves vary in size greatly - from a small pond right up to several hundred kilometers in size. As a result I can’t use the coordinates of the center point to find the nearest reserves. Instead I need to calculate the nearest point of the reserves polygon to find the nearest one. With the data in KML - how would I go about trying to achieve this?
I've only managed to find one other person ask this and no one had replied :(
Well, there are a couple different solutions depending on your needs. The higher the accuracy required, the more work required. I like Phil's meanRadius parameter idea. That would give you a rough idea of which polygon is closest and would be pretty easy to calculate. This idea works best if the polygons are "circlish". If the polygon are very irregular in shape, this idea loses it's accuracy.
From a math standpoint, here is what you want to do. Loop through all points of all polygons. Calculate the distance from those points to your current coordinate. Then just keep track of which one is closest. There is one final wrinkle. Imagine a two points making a line segment that is very long. You are located one meter away from the midpoint of the line. Well, the distance to these two points is very large, while, in fact you are very close to the polygon. You will need to calculate the distance from your coordinate to every possible line segment which you can do in a variety of manners which are outlined here:
http://www.worsleyschool.net/science/files/linepoint/distance.html
Finally, you need to ask yourself, am I in any polygons? If you're 10 meters away from a point on a polygon, but are, in fact, inside the polygon, obviously, you need to consider that. The best way to do that is to use a ray casting algorithm:
http://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm