Has anyone worked how to do geospatial queries in SQL Server? In particular, I'm interested in Geo Joins between point data (addresses). A Geo Polygons. (Counties and the Like)
The idea is to be able to do a join where you can tell by Lat and Lon if a particular address is in a particular county, or school district, or political jurisdiction.
Anyone having info please reach out. I'd like to learn from you. We have a reporting situation that could really benefit from such an approach.
Thanks.
--Tom
I would like to hear more about this also. Thx!
Hi Tom -
There's a decent tip here that explains how to find the nearest neighbor, which I hope might get you started: docs.microsoft.com/.../query-spatial-data-for-nearest-neighbor
Here's the query I worked out on our Tessitura system. We don't have much of anything in the 'geo_location' field but if you do, this might get you started as well. It finds the top 7 closest matches - I imagine you'll want to tinker with that.
USE [impresario]GO
DECLARE @g geography = 'POINT(-71.057083 42.361145)'; -- Boston MA coordinates
SELECT TOP(7) geo_location.ToString(), city FROM t_Address WHERE geo_location.STDistance(@g) IS NOT NULL ORDER BY geo_location.STDistance(@g);
Hi Tom --
I'm very interested in whatever you may find. I've taken a different approach to these kinds of projects. For various projects previously, I've batch geocoded addresses using the free geocoder provided by the US Census Bureau (https://www.census.gov/geo/maps-data/data/geocoder.html), then have either used publicly available lookup tables (census tract/block to City District in NYC) or -- at your suggestion -- have used QGIS to join an imported list/table with GIS geo-shapes to query Miami-Dade County districts and similar datasets.
Currently (still) in development, is a Service Interceptor that will geocode addresses using Google's Maps API (which is included as part of the non-profit Google Grant) whenever an address is added or updated. We can then send that geocoded lat/long to any of the publicly available GIS datasets (typically available from your county or city). The Service Interceptor will facilitate those lookups and then write back lat/long to the [geo_location] field in [T_ADDRESS] and the data we're interested in to specific keywords/attributes. I'm hoping to have that ready to demo by TLCC 2019 and happily share.
DGomez
Heather Sheridan (Past Member)
Cool! I'm actually interested in working with geography Points for addresses of schools. I can see putting this information in the T_Address.geo_location. Then I want to Join to geography polygons for counties and political districts.
It appears that SQL Server provides a .STWithin() function. I'm trying to figure out:
Thoughts?
Anyone else interested in working on these experiments with me?
In what language did you code your geocoder of Tessitura Data?
Are you willing to share?