[postgis-users] Finding a polygon containing a specified point
krill
ibkrill at gmail.com
Tue Nov 2 15:27:27 PDT 2010
Hi all,
I am attempting to import and use the Federal Electoral Districts, a
shapefile provided by Elections Canada (http://geobase.ca/geobase/en/
data/admin/index.html). I converted and loaded the shapefile as
follows:
&dol; shp2pgsql -c -W ISO-8859-1 -s 4617 -DI FED_CA_1_0_0_ENG.shp
federal_ridings > federal_ridings_import.sql
&dol; psql -U username -d dbname -f federal_ridings_import.sql
The resulting structure of the table is:
Column | Type |
Modifiers
------------+------------------------
+---------------------------------------------------------------
gid | integer | not null default
nextval('federal_ridings_gid_seq'::regclass)
nid | character varying(36) |
fednum | integer |
enname | character varying(100) |
frname | character varying(100) |
provcode | character varying(2) |
creadt | character varying(8) |
revdt | character varying(8) |
reporder | character varying(8) |
decpopcnt | integer |
quipopcnt | integer |
enlegaldsc | character varying(200) |
frlegaldsc | character varying(200) |
shape_area | numeric |
shape_len | numeric |
the_geom | geometry |
Indexes:
"federal_ridings_pkey" PRIMARY KEY, btree (gid)
"federal_ridings_the_geom_gist" gist (the_geom)
Check constraints:
"enforce_dims_the_geom" CHECK (st_ndims(the_geom) = 2)
"enforce_geotype_the_geom" CHECK (geometrytype(the_geom) =
'MULTIPOLYGON'::text OR the_geom IS NULL)
"enforce_srid_the_geom" CHECK (st_srid(the_geom) = 4617)
The other table I'm using has some postal codes:
id | city_name | postal_code | city_type | province_name |
province_abbr | latitude | longitude
----+-------------+-------------+-----------+------------------
+---------------+-----------+-------------
8 | Fredericton | E3A 1A4 | D | New Brunswick |
NB | 45.977710 | -66.678430
9 | Montreal | H1E 6M9 | D | Quebec |
QC | 45.641710 | -73.577240
10 | Ottawa | K1K 2K3 | D | Ontario |
ON | 45.433880 | -75.635240
11 | Toronto | M4M 1X2 | D | Ontario |
ON | 43.665720 | -79.346550
12 | Vancouver | V5N 1X1 | D | British Columbia |
BC | 49.262270 | -123.056050
I am trying to determine which electoral district a postal code is
in. For this I used the following query:
mydb=# select gid from federal_ridings fr where
ST_Contains(fr.the_geom, ST_GeomFromText('POINT(' || -123.056050 || '
' || 49.262270 || ')', 4617));
But the query returns no records.
I have confirmed that the lon/lat is converted to a spacial geometry
point:
mydb=# select ST_GeomFromText('POINT(' || -123.056050 || ' ' ||
49.262270 || ')', 4617);
st_geomfromtext
----------------------------------------------------
010100002009120000363CBD5296C35EC0685C381092A14840
(1 row)
Do you see anything I am doing wrong?
More information about the postgis-users
mailing list