How to find the elevation of a lon/lat polygon - google-maps

I am trying to create an application that uses terrain information about an area. I use lon/lat (4326) polygons from a kml file and store the geometries in postgis.
I need to find the elevation fluctuations of a particular area (polygon) defined by lon/lat points. How is this possible? I have read certain possible solutions like DEM but i do not how to use them.
Is there any other way of achieving it?
Thanks in advance for your replies.

Surprisingly there is a Google Elevation API :) (mainly for Android development, you need to register for a proper key):
https://developers.google.com/maps/documentation/elevation/
Maybe you could use the JavaScript API of the same service (I haven't tried this one, just found the link from the previous one):
https://developers.google.com/maps/documentation/javascript/services#Elevation
Probably you can us it, but beware of this:
Use of the Google Elevation API is subject to a limit of 2,500 requests per day.
The good thing is that in one request you can get elevation data about a Line, with arbitrary number of divider points (the dividers are sectioning the line into equal length sections).

Related

Google maps waypoints limit - show long routes accurately from raw GPS data

I am well aware that this question was asked many times and i've spent days looking through stackoverflow answers but couldn't find anything that goes behind workarounds.
The problem is pretty simple: we need to show exact routes passed by the car (so, from GPS long/lat history data) on google maps and the routes are hundreds or even thousands kms long. What that mean is that we will always exceed waypoints limits by at least an order of magnitude (8 for free or 25 for premium). My gut is telling me that batching GPS locations to batches of 8/25, sending many requests that way and then snap all of those to roads and at the end merge all together into a single route is a bit wild solution.
If we are on a highway then its not that big problem since snap and expected/calculated route will work but if some long route is a combination of highway but also in-town drive through small streets with alot of turning, then i can imagine huge discrepancy between an actual (from raw GPS data) and shown route.
I am wondering if i am missing something? Is there some 'more proper' way to approach this problem?
PS.
I don't need any code at the moment, just a proper way to architecture the idea.
Thanks
[UPDATE]
To put a few numbers into the mix:
1) average route distance is about 1800kms
2) number of raw GPS points generated is about 15000-18000 (every 100-150 meters)
3) number of points that the route must go through (waypoints) is in at least in hundreds and sometimes in thousands (when most of the route is in urban areas)
One possible solution is the Roads API.
Related questions:
draw a path from GEO locations from GPS snapped to road
Google Map Road API not interpolating path and not giving smooth route
Issues
The Roads API doesn't seem ready for prime time (reports of inconsistent results in the issue tracker)
Issue 9436: Roads-API - Snapping point defects
has a limit of 100 points at a time with a (not documented) recommended maximum separation of 400m (reference a comment under the answer to Google Map Road API not interpolating path and not giving smooth route).
You could render the routes as images yourself and load them as an overlay layer on top of google maps.
For example in my website we render weather forecast layers and add them as layers on top of the base map:
http://www.weather.gr/en/maps.aspx

Getting all streets visible in Google map's viewport

I'm trying to build a map with the following algorithm:
Wait for pan or zoom to occurs.
Query for all streets visible in the viewport (extent).
Color every visible street with a predefined color.
Example:
I want to show the numbers of businesses on each street, or the number of crimes committed at each street.
I have a DB which holds this kind of information (streetname, data), but each row doesn't have the location data.
Therefore, after each map zoom or pan, I cannot query all of it by a geographical bounding rectangle, it will be far more efficient to use Google own DB and query it by street names.
I know how to register to pan and zoom events.
I know how to calculate the viewport coordinates.
I know how to color a single street.
How can I get a list of all streets visible in the viewport?
Any other solutions or architectures are welcome.
The preferred solution will not use Google DirectionsService nor DirectionsRenderer since they slow down the map.
My understanding is that what you are asking is not possible from Google API's. Reverse geocoding inside a polygon is not a service they offer. There are some posts on other sites (e.g. https://gis.stackexchange.com/questions/22816/how-to-reverse-geocode-without-google) with the reference gisgraphy.com looking like a pretty neat reverse geocoding tool.
This still does not address your all streets in a polygon problem however. I think your only option would be to get your hands on the data (Open Street Maps) and write the code yourself. Further - if you are going to do this for a large area I would take an approach like I recommended here with grids: https://stackoverflow.com/a/18420564/1803682
I would create my grid elements, and for each street calculate all the grids to which it belongs and store in the database. Then when you search a polygon, you would calculate all the grids the polygon overlaps, and can then test the subset of road data in each of those squares to determine overlap.
I looked into this and abandoned a similar requirement a few months back and still have a desire to implement it. Most of the point/line in polygon work is happening on data created in my application (i.e. not street data) and right now that is the only data I will be including. What I am trying to say is - I hope someone gives you a better answer.
Update:
For what you are asking I still believe you will need to use a mix of your own database based on OpenStreetMap and some kind of grid analysis carried out in advance. If you have some time to commit to the project this should not be too awful to process. The database will be large, and the calculations needed will likely require a significant amount of one-time / upfront processing time. As far as highlighting routes/roads/whatever within the viewport, there are lots of way to accomplish this using the API - example here which I found useful: polyline snap to road using google maps api v3
Also useful: http://econym.org.uk/gmap/snap.htm
Note that one way streets may give some grief if using the directions api to snap to a street and you will likely have to watch for this and correct or reverse the start/end points.
Google would recommend using it's Geocoding Service in order to populate your data base with the co-ordinates. You can then use the LatLng Bounds Class method "contains" to check whether your points lie within the viewport. The advantage of this approach is you only need to geocode the information once and then store this, versus sending coding requests each time the viewport changes.
An alternate efficient way of displaying this kind of data may be to use google fusion tables. this greatly simplifies the integration of the data with the map.

Is it possible to get cities polygonal boundaries like in Google Maps?

I would like to have the possibility to tell if a GPS location is in an inhabited or uninhabited zone.
I have tried some reverse geocoding services out there, but all of them proved useless, because they select the nearest address possible. (I understand why this should be so, it is useful for the purpose of reverse geocoding)
I have noticed in Google Maps, when I search for a city, their boundaries are selected in red dotted well defined line. I would love it to use this, or something similar.
Is there any possible way that Google maps can provide such a service, or something that can solve my problem.
Are there any other web solution or databases that you know of that can give me this information ?
Or maybe I can use any of the reverse geocoding solutions with some parameters (such as restricting the size of searching) to determine if the location is or is not in a populated area?
If you will not find a public service then it gets interesting, and expensive in terms of developping effort.
Public data (world wide) is only available from OpenStreetMap, i think they have such a layer (could be named Land_use (rural, etc.)) This layer is usually used to color a map, look at openstreet map Web page if you find a suitable coloring, that coresponds to your task. (E.g look at green, or gray).
These data are stored in polygons, you would have top extract these polygons (i asume millions of them). Ten you need a fast searching spatial index, like a region Quadtree.
Then you do a "point(lat, lon) in polygon" call, and get the polygon related to your position.
Probaly not all that polygons will fit into main memory, so you must load them on demand (e.g by country).
A variant of this approach is to use a geo spatial database like postgres to store that polygons, and do a DB query.
With that approach most work will be extracting the polygons from OpenStreetMap DB file.
More acurate is data from TomTom, but these can be really expensive.

Be able to give 4 latitude/longitude points and see if the 5th is within the specified region

I have an interesting problem where I want to see if a pair of Latitude/Longitude points are within the region of 4 other specified ones. An application of this is specifying 4 intersections and seeing if the address is within that region. With the Google Maps Geocoding API (http://code.google.com/apis/maps/documentation/geocoding/) it's easy to convert the intersections into the long/lat and if the area is a perfect rectangle it's easy.... but what if the street is curvey? Does something like this already exist?
It sounds like you are looking for a point-in-polygon routine. http://en.wikipedia.org/wiki/Point_in_polygon
There are many implementations of point-in-polygon; if you are using PostGIS for your a database backend, use the ST_Intersects. There is already a question/answer on stackoverflow with code for a point-in-polygon function, see Point in Polygon Algorithm

Get countries within range of LAT/LONG coordinates

Trouble!
I'm looking for a way to find the countries within a given range of LAT/LONG coordinates.
E.g.:
When viewing an area in Africa using Google Maps, I get out which countries that are in my current view.
This is a bit ambitious, and I think the main problem will be dealing with accuracy of the needed polygons. The accuracy of these don't need to be all that great, the borders can probably be tens of miles off, or even more.
This will be needed for the entire world.
You can solve this easily using QGIS based on the assumption that you have
A GIS layer of Africa (if not you can find one using google
A point layer based on Lat long (or you can use Qgis's text delimited import)
using ftools -or- Vector menu, there is a feature called points in polygons that should solve your problem
You can try using the Yahoo WOE ID stuff... Here is a great article on it:
Yahoo Woe. Flickr has a similar service (I think it uses the Yahoo one under it...): Flickr