Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting bounding-box of city

Tags:

gis

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?

like image 681
zmbq Avatar asked Nov 18 '12 12:11

zmbq


People also ask

How do you find the bounding box of a city?

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.

How do you calculate bounding box?

The area of the box is the width times height. Here, 29 times 50, or 1450. The perimeter of the box is twice the width plus height. Here, that is 2(29+50), or 158.

What is a bounding box on a map?

A bounding box (usually shortened to bbox) is an area defined by two longitudes and two latitudes, where: Latitude is a decimal number between -90.0 and 90.0. Longitude is a decimal number between -180.0 and 180.0.

How does a bounding box work?

A bounding box is an abstract rectangle that acts as a reference point for object detection and produces a collision box for that object. These rectangles are drawn over images by data annotators, who identify the X and Y coordinates of the point of interest within each image.


2 Answers

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.

like image 152
Fred Avatar answered Sep 20 '22 23:09

Fred


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
           }
        }
like image 35
Matthew Turner Avatar answered Sep 19 '22 23:09

Matthew Turner