I setup 2 test Polygons geo
and geo2
. One using Parse
method and the other using STPolyFromText
method.
declare @geo geography
= geography::STPolyFromText('POLYGON ((73.250684 34.198599, 73.250598 34.199324, 73.250343 34.200021, 73.249927 34.200663, 73.249369 34.201226, 73.248688 34.201688, 73.247912 34.202031, 73.247069 34.202243, 73.246193 34.202314, 73.245317 34.202243, 73.244474 34.202031, 73.243698 34.201688, 73.243017 34.201226, 73.242458 34.200663, 73.242043 34.200021, 73.241788 34.199324, 73.241701 34.198599, 73.241788 34.197874, 73.242043 34.197177, 73.242458 34.196535, 73.243017 34.195972, 73.243698 34.19551, 73.244474 34.195167, 73.245317 34.194956, 73.246193 34.194884, 73.247069 34.194956, 73.247912 34.195167, 73.248688 34.19551, 73.249369 34.195972, 73.249927 34.196535, 73.250343 34.197177, 73.250598 34.197874, 73.250684 34.198599, 73.250684 34.198599))', 4326)
declare @geo2 geography
= geography::Parse('POLYGON ((73.250684 34.198599, 73.250598 34.199324, 73.250343 34.200021, 73.249927 34.200663, 73.249369 34.201226, 73.248688 34.201688, 73.247912 34.202031, 73.247069 34.202243, 73.246193 34.202314, 73.245317 34.202243, 73.244474 34.202031, 73.243698 34.201688, 73.243017 34.201226, 73.242458 34.200663, 73.242043 34.200021, 73.241788 34.199324, 73.241701 34.198599, 73.241788 34.197874, 73.242043 34.197177, 73.242458 34.196535, 73.243017 34.195972, 73.243698 34.19551, 73.244474 34.195167, 73.245317 34.194956, 73.246193 34.194884, 73.247069 34.194956, 73.247912 34.195167, 73.248688 34.19551, 73.249369 34.195972, 73.249927 34.196535, 73.250343 34.197177, 73.250598 34.197874, 73.250684 34.198599, 73.250684 34.198599))')
declare @outsidePoint geography
= geography::STPointFromText('POINT(-122.34900 47.65100)', 4326),
@insidePoint geography
= geography::STPointFromText('POINT(73.2438096 34.1989505)', 4326)
select
geo = @geo,
geoString = @geo.ToString(),
IsValid = @geo.STIsValid(),
doesContainOutsidePoint = @geo.STContains(@outsidePoint),
doesIntersectOutsidePoint = @geo.STIntersects(@outsidePoint),
doesContainInsidePoint = @geo.STContains(@insidePoint),
doesIntersectInsidePoint = @geo.STIntersects(@insidePoint)
select
geo = @geo2,
geoString = @geo2.ToString(),
IsValid = @geo2.STIsValid(),
doesContainOutsidePoint = @geo2.STContains(@outsidePoint),
doesIntersectOutsidePoint = @geo2.STIntersects(@outsidePoint),
doesContainInsidePoint = @geo2.STContains(@insidePoint),
doesIntersectInsidePoint = @geo2.STIntersects(@insidePoint)
Both of them seem to work for me - with the following results:

I can query from my Polygon table in the DB using both the STContains
and STIntersects
methods of the geography type.
So if .STContains
is returning 0
for you that means the Point is not inside the box. Maybe you could post a sample Polygon and Point where it is returning 0
but should return 1
that might help.
