Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've managed to create the below statement that creates a table based on a point in polygon query. However it creates a column that gives a true/false value which I then delete out all the f values from. Is there a better way of producing this statement?

CREATE TABLE crime_test AS 
SELECT a.*,, ST_within(a.the_geom, b.the_geom) "within"
FROM crime_data a, nh_areas b;
DELETE FROM crime_test WHERE within = 'f'
share|improve this question
up vote 7 down vote accepted

Think you need a WHERE clause:

CREATE TABLE crime_test AS 
FROM crime_data a, nh_areas b
WHERE ST_Within(a.the_geom, b.the_geom);
share|improve this answer
Excellent, that worked a treat. – geosmiles Dec 5 '12 at 13:09
Does ST_Within() takes into account postgis' spatial indexes? – nickves Dec 6 '12 at 0:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.