tags:

views:

160

answers:

3

We are purchasing a database of zip codes and their corresponding Lat/Long. I want to store cities in a separate table with a lat/long point representing the center of the city. Can I calculate that based on taking all of the zips that belong to that city, getting the min/max points for each direction, and taking the center point of the resulting rectangle?

Is there a more accurate method? I want to avoid purchasing another DB. We haven't purchased the full DB yet so I can't just try it and compare the results to Google Maps.

+1  A: 

Would that be very helpful? That might give you something that approximates the geographic center, but normally when you talk about the center of the city, you are talking about the town square, or the commercial center, or the historical center.

Go to google maps for example. If you search for New York, it will take you directly to Times Square. Isn't that really what you expect if you search for the center of that City.

Pete
I'm not going to display these points anywhere, it's more for "there are X miles between this city and that city". After talking with a coworker, I'm probably over-thinking this and don't need a 100% accurate value.
AndyMcKenna
+1  A: 

Well, the center of a city is impossible to calculate exactly, as there are probably as many views on what the center is as there are people...

Instead of using just the min/max points of the zip code areas, you could get the average of all positions, that would give you a more weighted position.

If you have an approximate number of people for each zip code you could use that as weight for the points, that would give you a "gravital center" of the population.

Guffa
+1  A: 

Well actually ZIP codes do not always encompass cities. Zip codes are arbitrary regions used to defined postal addresses.

Edit: Not always your assumption that the sum of all ZIP Codes will correspond to the city boundary or will retrieve you the correct centroid.

Your best bet is to get a countys table with spatial data in it.

In PostGIS a simple ST_Centroid(GeometryField) would suffice to get you the centroid of a polygon. That works out for any type of polygons.

If you are in the US, probably exists a public county/cities/states dataset availuable on the internet. Consider GIS tools for doing this work.

George