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;
答案 0 :(得分:3)
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();