SQL SERVER 2012
我需要在使用 STIntersect
与多边形几何相交的线路后找到线的几何形状的长度。
例如,我有一条长7731米长,但随后我会在一组多边形的情况下进行STIntersect
,我需要找到该线的长度在每个多边形中。
输出表看起来像
ReferenceID PolygonID LineID Length
12324 3234 24661 1635
12325 3233 24652 663
12326 3236 24653 256
12327 3365 24634 165
当前使用此方法,但无法返回几何形状或长度
insert [VMS_OBS_LINES_INTERSECT] (CA_Reference_Key, STAT_AREA,WATERS,GNMFSAREA, Grid_ID, Length)select l.CA_Reference_Key,g.stat_area,g.waters, g.GNMFSAREA , g.Grid_ID, g.shape.STIntersection(l.shape).STLength()
FROM GRID_AREA_SQL g, VMS_OBS_COMBINE_LINES_AI l
WHERE g.shape.STIntersects(l.shape) = 1;
declare @g geometry, @l geometry;
select @g = geometry::STGeomFromText('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))', 0), --10x10 box
@l = geometry::STGeomFromText('LINESTRING( -10 -10 , 20 20 )', 0); --a line that will go through the corners of the box
select @g.STIntersection(@l).STLength();