Question

Hi Stackoverflow people,

I am working on an organisation registration, in which orgs can register their project areas (like all Nevada, entire US, or simply a city e.g. Boston) and users should find all organisations which are covered by the organisation according to their lat & lng.

What is the best way to connect the organisation information with the user searches?

Is the following process ok or do you have any suggestions:

  1. I load the shapefiles of all necessary states, counties , etc. in my postgis database
  2. If an organisation adds "New York state" to their coverage area, I would look up the polygon shape for the state (or the id to the shape) and save it in my coverage table
  3. When I search for the org coverage, I would find all projects where the user lat & lng is part of

Is that process above ok to connect the user information to the shapefile information?

How can I look up polygons in the shape files? Can I reference them with an ID?

How would the lookup work with cities, since most lists with city name, lat, lng only list the center point of the city? Or is there a table for even city boundaries?

Thank you for your help and suggestions!

Was it helpful?

Solution

When you import a shp file to postgis with shp2pgsql, all the other columns (state name, city name, etc) are imported too, so you can search by name or any other property that the shp file has, or you can search by geometry, if you have a point and you want to search polygons or points(citys in your case) near that point, the query to the database is very simple:

SELECT * from myTable where ST_DWithin(users_point, the_geom, 0.002);

//the distance units of ST_DWithin are in the geometry units.

PS shp2pgsql automatically creates a serial column(unique id)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top