Is anyone having an idea about how to get attribute data of a polygon layer by giving Coordinates with in that polygon. Here i have tried with these codes..

SELECT * FROM kar_bbmp_198 WHERE ST_Contains(geom, ST_GeomFromEWKT('SRID=4326;POINT(779322 1440590)'))

SELECT * FROM public.kar_bbmp_198 WHERE ST_Within(geom,ST_PointFromText('POINT(779322 1440590)',32643));

But I am getting an error message like

ERROR: Operation on mixed SRID geometries ********** Error ********** ERROR: Operation on mixed SRID geometries SQL state: XX000

Any idea... I am using PostGIS 2.0 and PostgreSQL 9.1

  • What do you get from: SELECT ST_SRID(geom) FROM kar_bbmp_198; ?? – Micha Jul 23 '12 at 16:23
  • @Micha, Actually i need to get attributes of the polygon, in which the point will falls. (kar_bbmp_198 is a polygon shapefile. If a user specifies a X-Y point; then the query have to run and user have to get the result).. – Kishor Jul 24 '12 at 4:07
  • From the error you posted above, it seems that the kar_bbmp_198 layer is in some other CRS, NOT UTM 43N. Let's determine what CRS we're dealing with first (using the SELECT ST_SRID() I mentioned above). Then you can use the answer posted by rec.thegeom below to construct the exact query you need. – Micha Jul 24 '12 at 7:07
  • @Micha, As u told, the problem is with the CRS only. So i again created another db and uploaded new shapefile, now its working fine. Thanks for ur valuable suggestions.. – Kishor Jul 24 '12 at 9:01

Based on the point-pair values I'll assume the coordinates are meant to be projected in EPSG:32643. Given your error message I'll assume your stored geometry is EPSG:4326. You can transform the point projection, like:

SELECT * FROM kar_bbmp_198
ST_Transform(ST_GeomFromText('POINT(779322 1440590)',32643),4326), geom
) = TRUE;

You might check out the docs for ST_PointFromText, ST_GeomFromText, ST_Contains, and ST_Within for future reference.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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