SQL Server Geography Query works but Geometry Query Does Not - Different Tables, Similar Schemas -
i trying geometry query work. similar geography query works fine must work table uses geometry type. although geography version returns lots of records expected, cannot geometry version return records. both tables have same latitude , longitude records .
this geography query works fine:
declare @home geography set @home = geography::stpointfromtext('point(-0.7799193 51.3083162 )', 4326); select outwardcode, inwardcode, latitude, longitude dbo.postcodedata geolocation.stdistance(@home) <= (5 * 1609) -- 1609 = approx metres in 1 mile the table schema is:
+-------------+--------------+ | field | type | +-------------+--------------+ | outwardcode | varchar(4) | | inwardcode | varchar(3) | | latitude | decimal(9,6) | | longitude | decimal(9,6) | | geolocation | geography | +-------------+--------------+ example table data:
+-------------+------------+------------+----------+------------------------------------------------+ | outwardcode | inwardcode | longitude | latitude | geolocation | +-------------+------------+------------+----------+------------------------------------------------+ | gu14 | 9hl | -0.7803759 | 51.30818 | 0xe6100000010c01a4367172a7494027c522e1d6f8e8bf | +-------------+------------+------------+----------+------------------------------------------------+ this geometry query returns no records (i have same latitude , longitude records in database have geometry centre point street , postcode joined version of outwardcode , inwardcode):
declare @home geometry set @home = geometry::stpointfromtext('point(51.3083162 -0.7799193)', 0); select postcode, latitude, longitude dbo.os_locator centre.stdistance(@home) <= (5 * 1609) -- 1609 = approx metres in 1 mile the table schema is:
+-----------+--------------+ | field | type | +-----------+--------------+ | postcode | nvarchar(10) | | latitude | decimal(9,6) | | longitude | decimal(9,6) | | centre | geometry | +-----------+--------------+ example table data:
+----------+-----------+-----------+------------------------------------------------+ | postcode | latitude | longitude | centre | +----------+-----------+-----------+------------------------------------------------+ | gu14 9hl | 51.308304 | -0.779928 | 0x346c0000010c00000000549c1d410000000018330341 | +----------+-----------+-----------+------------------------------------------------+ where going wrong?
there's reason there 2 distinct geospatial types. geography when coordinates represent degrees of latitude , longitude points on earth (a three-dimensional object singularities in coordinate system). geometry when points represent arbitrary x & y positions on infinite plane. can't "i'll take 51.3 degrees , make x coordinate" , have work out. high school physics teacher said "units important".
Comments
Post a Comment