4
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;
4

1 回答 1

4
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();
于 2012-12-31T18:28:23.373 回答