1

I need to load point data in SQL Server Spatial.

Similar to this post but I really don't know how to get XY data to be accessible by SQL

I want to do what was done in the initial part of this post (Identify points that plot inside the polygon):

How do I find points that are NOT within a list of polygons using MS SQL?

SELECT points.name, polygons.name
    FROM points CROSS JOIN
    polygons
    WHERE  (polygons.shape.STContains(points.shape) = 1) 

How do you get the points loaded into your table and SQL to recognize the points with out having to define them like the below?

insert into @points values 
(geometry::Point(1,1,0)), 
(geometry::Point(2,3,0)), 
(geometry::Point(5,4,0)), 
(geometry::Point(4,2,0))

I am having a hard time defining points without doing it manually like above.

Ideally I could build a table like this by selecting the xy data I have in a table already.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Tom
  • 33
  • 5
  • 2
    It's important to understand that "SQL" and "Microsoft SQL Server" are different things, and referring to them both by just "SQL" can be confusing. – Vince Jan 18 '21 at 21:23
  • Understood, I am working in a SQL only environment, running SQL scripts that I execute in the query window of SQL Management studio. Does this help clarify? I am sort of over my head here at the moment. The post I referenced seemed to be about using SQL only but I really am not sure. – Tom Jan 18 '21 at 21:34
  • What is your source data? (csv, shapefile etc.?) – Mapperz Jan 19 '21 at 01:37
  • I am loading it from a csv into SQL Management. Studio. I am having a hard time applying the spatial functions to anything more than a singularly declared point. How can I load these functions with specific results, like from a query? – Tom Jan 19 '21 at 01:46
  • Are you trying to understand how you load lat long data in a csv file into a sql server table? – jport Jun 20 '22 at 18:33
  • jport, No, I can get data into tables fine. It is applying the spatial functionality of MSSQL that I am struggling with. I am unsure if I am attempting something that doesn't work the way that I envision it does or if I am just going about it incorrectly. – Tom Jun 21 '22 at 21:21

0 Answers0