[postgis-users] Point in Poly just not working
Paul Ramsey
pramsey at opengeo.org
Thu Dec 23 13:50:04 PST 2010
Jason,
You're inappropriately mixing coordinate reference systems.
As an aside, you don't need to add a spatial_ref_sys entry, if you've
loaded the default PostGIS spatial_ref_sys table, the entry for 29610
is NAD823/UTM10N.
The key problem in your query is this part:
ST_GeomFromText('POINT(-123.097172 49.284562)', 1)
Having defined SRID 1 as UTM10N, you then say, "here's a point, treat
the coordinates as if they are UTM10N". But those coordinates are not
UTM10N, they are geographic coordinates from Google Maps,
longitude/latitude on a WGS83 spheroid... SRID 4326 in the standard
PostGIS spatial ref sys table.
Ah! So, can you just replace '1' with '4326' in your
ST_GeomFromText()? Not quite. Because then you'll be doing an
ST_Contains() test with a different SRID for each argument, and that's
not legal! So you need to transform one side into a matching SRID. The
final, working query, will look like this:
select ST_Contains(c.the_geom,
ST_Transform(ST_GeomFromText('POINT(-123.097172 49.284562)', 4326),1))
from city_boundary c;
Happy holidays,
Paul
On Thu, Dec 23, 2010 at 11:09 AM, Jason Leach <jason.leach at gmail.com> wrote:
> Hi:
> I'm just not having any luck determining if a point is in a polygon.
> 1. I add my SRID for NAD_1983_UTM_Zone_10N to the spatial ref.
> 2. Importing the City of Vancouver's boundary (MULTILINESTRING) with -s 1
> (SRID=1) and load the SQL file.
> 3. Pick a point within the city from google map: 49.284562,-123.097172
> 4. Check if the point is in the boundary:
> covciv=# select ST_Contains(c.the_geom, ST_GeomFromText('POINT(49.284562
> -123.097172)', 1)) from city_boundary c;
> st_contains
> -------------
> f
> (1 row)
> covciv=# select ST_Contains(c.the_geom, ST_GeomFromText('POINT(-123.097172
> 49.284562)', 1)) from city_boundary c;
> st_contains
> -------------
> f
> (1 row)
> I've also tried this with MULTIPOLYGON data in case MULTILINESTRING was the
> problem.
>
> Any tips would be appreciated.
>
> The shape file's proj:
> PROJCS["NAD_1983_UTM_Zone_10N",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000],PARAMETER["False_Northing",0],PARAMETER["Central_Meridian",-123],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0],UNIT["Meter",1]]
> My proj with SRID = 1;
> INSERT INTO spatial_ref_sys VALUES
> (1,NULL,NULL,'PROJCS[''NAD_1983_UTM_Zone_10N'',
> GEOGCS[''GCS_North_American_1983'', DATUM[''D_North_American_1983'',
> SPHEROID[''GRS_1980'',6378137,298.257222101]], PRIMEM[''Greenwich'',0],
> UNIT[''Degree'',0.0174532925199433]], PROJECTION[''Transverse_Mercator''],
> PARAMETER[''False_Easting'',500000.0], PARAMETER[''False_Northing'',0.0],
> PARAMETER[''Central_Meridian'',-123.0], PARAMETER[''Scale_Factor'',0.9996],
> PARAMETER[''Latitude_of_Origin'',0.0], UNIT[''Meter'',1.0]]');
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
>
More information about the postgis-users
mailing list