5

I have a MongoDB database of markers with lat/long and I need another database (or other solution) containing cities, or area level boundaries. If in Geojson polygons it would have been optimal.

I have a field named city (e.g. 'city' : 'New York') but I want to narrow down to a city's area/neighborhood level e.g. "Soho". The idea to solve the problem this way is based on Google's new maps. If we type area or zip code we see the red-dotted polygon of that area.

enter image description here

I saw Maxmind's database but it does not have boundaries per city.

My best solution so far is to use Google's Geocoding API which returns a box's bounds:

e.g. for: http://maps.googleapis.com/maps/api/geocode/json?address=soho&sensor=false

Result:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "SoHo",
               "short_name" : "SoHo",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Manhattan",
               "short_name" : "Manhattan",
               "types" : [ "sublocality", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "New York",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "New York",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "SoHo, New York, NY, USA",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 40.7283442,
                  "lng" : -73.9953929
               },
               "southwest" : {
                  "lat" : 40.7184446,
                  "lng" : -74.0054619
               }
            },
            "location" : {
               "lat" : 40.723384,
               "lng" : -74.001704
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.7283442,
                  "lng" : -73.9953929
               },
               "southwest" : {
                  "lat" : 40.7184446,
                  "lng" : -74.0054619
               }
            }
         },
         "types" : [ "neighborhood", "political" ]
      }
   ],
   "status" : "OK"
}

Any better approach than using Google's geocoding API's bounding box?

Diolor
  • 13,181
  • 30
  • 111
  • 179
  • did you manage to find a solution to this? I'm looking to find a source for this information. If the google api has it that would be very helpful. – Huw Davies Nov 08 '16 at 12:10

2 Answers2

6

This answer gives a link to polygonal city boundaries from TIGER data (so U.S. only): https://stackoverflow.com/a/10821465/3146587. The format is shapefile, but you can easily convert it to GeoJSON using ogr2ogr for instance.

Community
  • 1
  • 1
user3146587
  • 4,250
  • 1
  • 16
  • 25
  • 2
    Upvoted, however I need a global solution and not only the US. – Diolor Jan 02 '14 at 16:02
  • 2
    [GADM](http://gadm.org/) is a global data set of administrative boundaries (shapefile format available among others) and _should_ include city boundaries. Else I also found this (rather involved) attempt at extracting city boundaries from OSM via their Overpass API: https://github.com/pgkelley4/city-boundaries-google-maps – user3146587 Jan 04 '14 at 23:54
6

This blew my mind: all cities, states, countries for the planet in one big geojson file: https://mapzen.com/data/borders/

ak2040
  • 71
  • 2
  • 5
  • Mapzen is shutting down their services on February 1st 2018 and this file is hosted on their S3 account, which means this download may also cease to exist in the future. Better grab it as long as you can :) – snrlx Jan 15 '18 at 13:03
  • 3
    The service is shut down. Anybody has a mirror for the Giant file? – Sajjad Bay Apr 12 '18 at 20:16
  • 2
    Anyone have a copy of this file somewhere? – Brian Voelker Oct 28 '18 at 02:04