I'm trying to generate a list of GPS coordinates within 5 meters radius of a location. My latitude and longitude are stored as FLOAT, but after research, I have noticed that I need to work with GEORGRAPHY datatype? So what I'm doing is creating an additional column of that type, and then working with that. I have learned of a few functions (ST_Within, ST_SetSRID, etc). The problem I'm facing is that any function I use returns a 'function not recognized error'. Am I on the right track?
Any help you could provide would be greatly appreciated. My table is called 'gpstemp'. Fields are 'latitude', 'longitude', and gps (my created field of geography datatype).
is this for Microsoft SQL Server? if so could you please provide some sample data and the sql code that is causing the error. We cant just guess what your code is. Well we could and give you the wrong solution
I'm currently creating a temporary table with a subset of data from a view just to get the process down. I can't alter the view as it's a third-party database.
select latitude,longitude into gpstemp from avl.vwsc_DeviceLatLongHistory
where perno = 'ECSO02PER000093'
--Then create the geography field
alter table gpstemp add gps geography
--Calculate the field
update gpstemp set gps = ST_SetSRID(ST_MakePoint(Longitude,Latitude), 4326)
--Execute query to get all coordinates within 5 meters radius
SELECT *
FROM gpstemp
WHERE ST_DWithin(gps, ST_SetSRID(ST_MakePoint(-72.657, 42.0657), 4326), 5)
so in order to help you we need sample data from you or give us access to your SQL Server so we can see what is in gpstemp
no to the latter of course so please provide sample data like this
create table #sample( perno varchar(50), long geography, lat geography)
insert into #sample
select 'ECSO02PER000093', 87.66.77.8, 56.56.66
please provide the data type of three columns. latitude longitude gps
and now please provide the code that is causing the error. is it tsql code? you are almost there!