【发布时间】:2020-08-04 15:56:43
【问题描述】:
让我解释一下附图Yellow line termed as Construction Planning identified by Planning Id and all other colors termed as Construction Segment identified by SegmentId。我正在尝试使用地理点的STDistance 函数通过传递PlanningID=25801 来查找SegmentId=12689 和SegmentId=12687。我的程序应该返回值12689 和12687,因为这两个值完全位于PlanningID=25801 中。但是,它应该排除值SegmentId=12688,因为该段不完全位于或该段的大部分不在施工规划内。
我在 SQL Server 中创建了以下脚本
declare @Planningid INT
declare @agencyID int
set @Planningid=25801
set @agencyID=79
DECLARE @finalresult int
DECLARE @result TABLE (id INT, starting sys.geography, ending sys.geography,
chachedroute sys.geography)
DECLARE @tablevar TABLE(id INT)
insert into @result select id,
starting,Ending,CachedRoute from Route R where AgencyId=@agencyID and LayerId=1
and CachedRoute.STDistance((select CachedRoute from route
where id=@Planningid))<0.5
select * from @result
/* the above part of the code is working fine as it should */
/* the next part of the logic is not working and it is excluding all the Segment Id when it
should not and should only exclude SegmentId=12688 */
insert into @tablevar
select id from @result where
chachedroute.STDistance((select starting from route where id=@Planningid))<700
and
chachedroute.STDistance((select ending from route where id=@Planningid))<700
intersect
select id from @result
select * from @tablevar
我猜这个问题是因为代码第二部分中的and 逻辑,它计算值是否在 700 米之内。这段代码最初是根据每个PlanningId 应该只有一个SegmentID 的概念创建的,这就是我通过匹配段的开始和结束来编码它的原因。但现在的修改是单个PlanningId 可以有多个SegmentID,我猜这就是问题所在。
任何有关如何修改代码的帮助将不胜感激。
表Route 包含以下属性:
- ID(整数)
- 起点(地理点)
- 结局(地理点)
- 缓存路线(地理点)
- LayerId (int)
- AgencyId(int)
值LayerId=1指的是Construction Segment,LayerId=4指的是Construction Planning
【问题讨论】: