sql - Query table records with points (geometry) within area -



sql - Query table records with points (geometry) within area -

i have table (locations) has field called point (geometry). wrote query passes top , bottom latitude coordinates , bottom , top longitude coordinates. want retrieve records within area of coordinates pass stored procedure. when run returns 0 records though know there record matches criteria. ideas might doing wrong?

declare @categoryid int,@leftlong float,@rightlong float,@toplat float,@bottomlat float declare @searcharea geometry, @polygon varchar(500); set @leftlong = -85.605469 set @toplat = 42.303468 set @rightlong = -85.594912 set @bottomlat = 42.297564 set @polygon = cast(@leftlong varchar(20)) + ' ' + cast(@toplat varchar(20)) + ',' + cast(@leftlong varchar(20)) + ' ' + cast(@bottomlat varchar(20)) + ',' + cast(@rightlong varchar(20)) + ' ' + cast(@bottomlat varchar(20)) + ',' + cast(@rightlong varchar(20)) + ' ' + cast(@toplat varchar(20)) + ',' + cast(@leftlong varchar(20)) + ' ' + cast(@toplat varchar(20)) set @searcharea = geometry::stgeomfromtext('polygon ((' + @polygon + '))', 0); select * locations l l.point.stwithin(@searcharea) = 1

there 2 potential sources of problem:

usage of geometry instead of geography type. when working latitude , longitude data, want utilize geography type in order calculations on ellipsoid instead of on plane. these calculations can different considerably - lot of info available on distinction in various articles such whitepaper.

mismatching srids - srid of info in locations table 0 rows? if these not match between info , @searcharea, no results returned.

sql sql-server tsql sql-server-2008 geospatial

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -