Is it possible to get cities polygonal boundaries like in Google Maps? - 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.

Related

Is it possible to extract coordinates from a static map picture?

I was wondering if it were possible to extract coordinates from a static map picture like this:
Is it possible to extract the coordinates of the routes? The only idea I can come up with, other than manually getting them by hand, is by overlaying the map and extracting the exact coordinates that way.
The process that you are looking for is called georeferencing in a GIS context.
In order to determine the latitude/longitude coordinates of a point (or series of points in a line), you need to first establish coordinates of other known points. These are reference points of known locations (such as a distinctive coastline, or a city). Applying these to the raster image that you have, you can then overlay it on a map in a GIS application and then query other unknown locations on the image (such as the routes) to establish their latitude/longitude.
You could attempt this in a graphics program by looking at the x/y coordinates of the route pixels and compare to a known reference point pixel; however, the math on that is going to be tedious and you also wouldn't account for the map projection. Both of those are taken care of by georeferencing.
I would note that you should consider the results you get, even in a well-referenced GIS, to be approximate. The map deals with a very large spatial area, and the routes cover long distances. But since it dates from 2012 it was presumably made in a GIS application and so at least the source data is likely to be accurate :)
Additional resources:
Help Page for ArcGIS (both overview and instructions)
Help Page for QGIS (tutorial)

Plotting huge number of locations on a map

Is there any good library that will enable to see the coarse location distribution.
I have some million data points to plot on a map. Doing it on google maps is going to be heavy. I want this to be like a dot plot.
The closest I can think to the functionality you are looking for would be to implement a heatmap layer : https://developers.google.com/maps/documentation/javascript/examples/layer-heatmap.
This would allow you to see the distribution of points without plotting them individually and thus saving you some client-side work.
How well this will work with a million+ points however I am not sure. You might be best off looking into a fusion tables combination.

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.

How do I discern a country from X/Y Coordinates (or Long/Lat)?

I have a number of XY coordinates and am looking to discern which country each of these are in, who knows a good service/way of doing this?
I am working with MySQL & PHP, not that its really relevant, I am o fey with consuming web services/pages and assume there must be a web-service/page somewhere which will do this, if someone can point me in the right direction that would be awesome.
How do I take: 306458,383136 and turn it into: United Kingdom (for example.)
Appreciate your responses in advance.
What you're looking for is called reverse geocoding, and e.g. Google Maps has this functionality: http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding
It works from a Lat/Lon coordinate, and could return even a more precise information than only a country; note that this is only an estimate - in some places, country boundaries are somewhat tangled.
If you're looking to do this offline, or if Google's/Bing's/whoever's licensing is too strict for you (e.g. you need to do a gazillion of requests per day, or need to present the result in an unorthodox format), it's possible to run your own instance of Nominatim, feed it a data extract from OpenStreetMap (under ODbL, a much more permissive license), and query that.
For example, there's a set of boundaries available at https://wambachers-osm.website/boundaries/ - just the national boundaries, so you wouldn't need to download the entire planet map.

Can I get terrain data from anywhere for use in simulations?

Is there a way I can build terrain data in a simple way from sources like Google Maps. I am not interested in heights but a simple 2D representation will be good enough.
For instance, I am trying to represent a terrain using the roads and buildings inside a map to model a traffic simulation. Representing objects like buildings is necessary so that when my cars are moving on a road, they should know when to take a turn etc. Are there any standards for representing these?
There are dozens of map standards. also map data tends to be very expensive, although there are some low cost and open source map sources. Eg. OpenStreetMap, and for the US, Tiger/Line.
I would also read up on, at least, some introductory GIS - I think you'll find the field is much bigger and more complex that you are initially thinking.