Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cities Geojson polygons database/library or API

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?

like image 847
Diolor Avatar asked Dec 19 '22 20:12

Diolor


2 Answers

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.

like image 109
user3146587 Avatar answered Jan 11 '23 06:01

user3146587


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

like image 26
ak2040 Avatar answered Jan 11 '23 06:01

ak2040