[postgis-users] Polygon from point query

pcreso at pcreso.com pcreso at pcreso.com
Tue Dec 28 12:03:28 PST 2010


Hi,

You need to have your points already in a table, then you can run a single query to identify the county each lies within. 

SELECT p.point, c.county_nam 
FROM county c, 
             points p
WHERE  ST_Within(p.the_geom, c.the_geom);

You can also wrap this in an update statement to have a column in the point table with the id of the county to implement a foreign key to join the two tables on.

HTH,

  Brent Wood

--- On Wed, 12/29/10, Poynter, David <POYNTER at adeq.state.ar.us> wrote:

From: Poynter, David <POYNTER at adeq.state.ar.us>
Subject: [postgis-users] Polygon from point query
To: "postgis-users" <postgis-users at postgis.refractions.net>
Date: Wednesday, December 29, 2010, 8:49 AM




 


 







This is probably an easy one, but being a PostGIS newb I've
been spinning my wheels and haven't the google fu to locate an answer, so here
goes...

 

I have a table of counties from the state (county) and I'm
creating a point to insert in another table and I would like to find the county
the point falls in.

I think I should be able to do it in one query rather than
looping thru county by county, but I can't seem to put it together.

 

SELECT county_nam FROM county WHERE ?

 

I've been looking at ST_Within() and think the answer lies
with it somehow, thanks for any clues...



 


-----Inline Attachment Follows-----

_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20101228/3262b54b/attachment.html>


More information about the postgis-users mailing list