有趣的。我从未使用过几何数据类型。但这是我的第一个猜测。
您可以使用Point几何字段的几何方法STWithin并传入Area几何对象以查看该点是否在该区域“内”
declare @Areas table ( AreaID int identity(1,1), Description varchar(50), Area geometry)
declare @Points table ( PointID int identity(1,1), Description varchar(50), Point geometry )
insert @Areas ( Description, Area )
select 'Area 1', geometry::STGeomFromText('POLYGON((0 0, 0 3, 3 3, 3 0, 0 0))', 0)
insert @Areas ( Description, Area )
select 'Area 2', geometry::STGeomFromText('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))', 0)
insert @Points ( Description, Point )
select 'Point 1', geometry::STPointFromText('POINT(2 2)', 0)
insert @Points ( Description, Point )
select 'Point 2', geometry::STPointFromText('POINT(4 4)', 0)
insert @Points ( Description, Point )
select 'Point 3', geometry::STPointFromText('POINT(12 13)', 0)
select a.Description, p.Description, case when p.Point.STWithin(a.Area) = 1 then 'Yes' else 'No' end as PointWithin
from @Areas a, @Points p
结果:
Description Description PointWithin
----------- ----------- -----------
Area 1 Point 1 Yes
Area 2 Point 1 No
Area 1 Point 2 No
Area 2 Point 2 No
Area 1 Point 3 No
Area 2 Point 3 Yes
希望这可以帮助