Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.*, b.town, 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
add comment

1 Answer 1

up vote 7 down vote accepted

Think you need a WHERE clause:

CREATE TABLE crime_test AS 
SELECT a.*, b.town
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
    
add comment

Your Answer

 
discard

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.