VBAHole
VBAHole

Reputation: 1518

Get intersecting lines in sql spatial

I'm using Entity Framework 5.0 and sql server geometry type. I'm trying to take a point and find the lines that intersect a buffer of that point and meet certain attribute requirements. Is this possible?

I know of the STIntersect method but those appear to work as a comparison between two features. I have a line dataset and a single point. so i don't know how many results i could get.

Upvotes: 1

Views: 2407

Answers (1)

Ben Thul
Ben Thul

Reputation: 32687

You can use the STBuffer geometry method to get an area around a point and store that in a variable (or wherever!). From there, you can use STIntersects to find out if your lines. Like so:

DECLARE @g geometry, @l geometry;
SELECT @g = geometry::STGeomFromText('POINT(0 0)', 0),
@l = geometry::STGeomFromText('LINESTRING(0 1, 4 0)', 0);

SELECT @g, @l, @g.STBuffer(1), @l.STIntersects(@g.STBuffer(1));

Also, my standard caveat of using the right data type (geography vs geometry) applies if you're doing geospatial.

Upvotes: 1

Related Questions