I am learning postgis 2.1. I created a postgis table from a shapefile and imported it into the DB. It made a table like this:
db=# \d districts ... geog | geography(MultiPolygon,4326) |
I also created a table "callsforservice" importing tabular data from a CSV, which I then converted into points with a SRID = 4326.
db=# update callsforservice set latlongpointdetails = ST_SetSRID(latlongpoint, 4326);
I want to know which
callsforservice.latlongpointdetails are included in which
I tried with this query, which takes very, very, very long time. The limit 1 is only to shorten the time the query is running. After 2 min or so I kill it:
select * from callsforservice, districts where ST_Within(geometry(districts.geog), callsforservice.latlongpointdetails) limit 1;
If I add an additional condition to the where clause (
where districts.district='1-1') -- this query returns immediately with 0 rows, even though districts does have a row with this ID.
Do I have the syntax right for finding out which calls came in what districts?
The docs for ST_within say "the source geometries must both be of the same coordinate projection, having the same SRID." If I examine the two tables with the
\dt command then the geog column in districts shows type
geography(MultiPolygon,4326) but the
latlongpointdetails column in callsforservices only shows type geometry -- without parenthesis like in the districts table. Maybe this is the reason for the failures of ST_Within? Where am I going wrong?