zmbq
zmbq

Reputation: 39013

Getting bounding-box of city

I want to know how far a specific geographic coordinate is from a list of cities ('far' meaning the euclidean distance between the coordinate and the city, not taking roads into account). For this I need to find a bounding-box for each of the cities - all located in Israel.

This post discusses country bounding-boxes, but I need them at the city level.

Is there any way to get this information for a long list of cities, other than drawing rectangles by hand on a map and extracting the coordinates?

Upvotes: 16

Views: 25583

Answers (4)

Matthew Turner
Matthew Turner

Reputation: 3740

For a long list of cities, use the Google Geocoding service. Once you get set up, you can use any language to access the REST API. For example you could use the popular standard requests library for Python.

Or, you could use Google's own Google Maps Java API, Python API, or JavaScript API. Any of these contain the Google Geocoding service.

See some simple examples of the Python and Java library here: https://developers.google.com/maps/documentation/webservices/client-library.

Here's the schema for the Geocoding results:

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   postcode_localities[]: string,
   types[]: string
 },
 partial_match: boolean,
 place_id: string,
 postcode_localities[]: string,
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}

The bounding box is located in the geometry>viewport variable and looks like this

"viewport" : {
           "northeast" : {
              "lat" : 37.4238253802915,
              "lng" : -122.0829009197085
           },
           "southwest" : {
              "lat" : 37.4211274197085,
              "lng" : -122.0855988802915
           }
        }

Upvotes: 6

quit
quit

Reputation: 282

You can find the bounding box of those cities at http://boundingbox.klokantech.com/ Entering a city/country will display a box on a map and give the latitude and longitude of each side. But accuracy is higher then at http://www.mapdevelopers.com/geocode_bounding_box.php (thx to @Fred for his answer)

Upvotes: 4

Fred
Fred

Reputation: 220

You can find the bounding box of those cities at www.mapdevelopers.com/geocode_bounding_box.php. Entering a city will display a box on a map and give the latitude and longitude of each side. Hopefully that will give you the information you need.

Upvotes: 12

nadya
nadya

Reputation: 240

I think, you need not bounding boxes, but city boundaries. Because with bounding boxes your analysis will be very rough, and to get a bounding box you anyway firstly need a boundary.

If you have now just list of cities, you need to get spatial data, the boundaries of all your cities. To find this data you can try this links. I would suggest to check Open Street Maps. Then you can use any GIS software (for example, open-source Quantum GIS) and calculate there the euclidean distances between your point and the city boundaries.

Hope this helps.

Upvotes: 1

Related Questions