4

I am very new to MS SQL 2008. I got a task to select a polygon from the polygon layer by giving the X-Y coordinates. I already got the script for PostgreSQL for the same thing, but I need it for MS SQL 2008. the code in PostgreSQL is:

SELECT * 
FROM "Kar_bbmp_198" 
WHERE ST_Within 
  ((ST_GeomFromText('POINT(773824 1442012)',32643)), the_geom) = TRUE;` 

Can anybody help me from this?

  • Is your data stored in the GEOMETRY or GEOGRAPHY data type? – CatchingMonkey Jul 25 '12 at 8:40
  • may i know, is any difference will be there if the data stored in Geometry or Geography. Actually i dont know about the storage of data.. – Kishor Jul 25 '12 at 8:48
1
SELECT * FROM 
[TABLE_NAME]
WHERE 
[TABLES_SPATIAL_COLUMN].STIntersects(GEOGRAPHY::STGeomFromText('POINT(773824 1442012)',[SRID - e.g. 4326])) = 1

You can change the GEOGRAPHY:: to GEOMETRY:: depending on the data type you are using. Also, you could also use .STWithin(), .STContain() to do this.

2

ASPMapper probably has the right approach, but I think you do not want STIntersects (that would imply that the point is on the boundary) or STWithin (which would imply that the polygon is within the point). STContains is probably what you need.

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.