create procedure relation_line
@Intersections varchar(500),
@StartpointX int,
@StartpointY int,
@EndpointX int,
@EndpointY int,
@Split varchar(1)=';',
@SplitXY varchar(1)=',',
@XYarea int =100,
@area decimal(18,6) =0.00001,
@Usefulline varchar(255) output
as
begin
declare @Oldintersections varchar(500)
declare @Length int
declare @CommaLocation int
declare @FirstPoint varchar(18)
declare @Longitude varchar(9)
declare @latitude varchar(9)
declare @logicalx varchar(6)
declare @logicaly varchar(6)
declare @LengthXY int
declare @LengthFirstSplit int
declare @LastLineids varchar(16)
declare @ThisLineids varchar(16)
declare @isExistLine varchar(2)
declare @Index_line int
declare @Clineid int
declare @Cpointid int
----对线路中所有路口点处理
select @OldintersectiOns=@Intersections
select @CommaLocation=CHARINDEX(@Split, @Oldintersections)
while(@CommaLocation>0) and (@Oldintersections is not null)
begin
set @isExistLine='no'
select @CommaLocation=CHARINDEX(@Split, @Oldintersections)
select @Length=DATALENGTH(@Oldintersections)
select @FirstPoint=SUBSTRING(@Oldintersections,1,@CommaLocation-1)
print @FirstPoint
if @FirstPoint is not null
begin
select @LengthXY=DATALENGTH(@FirstPoint)
select @LengthFirstSplit=CHARINDEX(@SplitXY,@FirstPoint)
end
if @LengthXY>0
begin
select @LOngitude=SUBSTRING(@FirstPoint,1,@LengthFirstSplit-1)
select @latitude=SUBSTRING(@FirstPoint,@LengthFirstSplit+1,@LengthXY-@LengthFirstSplit)
if @ThisLineids is not null
begin
select @LastLineids=@ThisLineids
set @ThisLineids=null
end
declare curPointline cursor for
select kr.lineid,kr.pointid from kangaroo_roadnet as kr,kangaroo_roadnet_point as krp where kr.pointid=krp.pointid
and krp.longitude>=cast(@Longitude as decimal(18,6))-@area and krp.longitude<=cast(@Longitude as decimal(18,6))+@area
and krp.latitude>=cast(@latitude as decimal(18,6))-@area and krp.latitude<=cast(@latitude as decimal(18,6))+@area
and krp.pointtype=1
declare @lineid int
declare @pointid int
declare @SubUsefulline varchar(255)
declare @templp varchar(255)
declare @lastpointid varchar(5)
open curPointline
fetch next from curPointline into @lineid,@pointid
while ( @@Fetch_Status=0 )
begin
if @lineid is not null
begin
select @ThisLineids=@ThisLineids+',l'+@lineid+',p'+@pointid
end
else
begin
select @ThisLineids='l'+@lineid+',p'+@pointid
end
if @LastLineids is not null
begin
select @Index_line= CHARINDEX('l'+ cast(@lineid as varchar(4)),@LastLineids)
if @Index_line>0
begin
set @isExistLine='ye'
set @templp=substring(@LastLineids,@Index_line+DATALENGTH('l'+cast(@lineid as varchar(4)))+1,DATALENGTH(@LastLineids))
set @lastpointid=substring(@templp,2,CHARINDEX(',',@templp)-1)
declare getPointXY cursor for
select krp.logicalx,krp.logicaly from kangaroo_roadnet as kr,kangaroo_roadnet_point as krp where kr.lineid=@lineid
AND (kr.ordernum BETWEEN @lastpointid AND @pointid) ORDER BY kr.ordernum DESC
open getPointXY
fetch next from getPointXY
into @logicalx, @logicaly
if @SubUsefulline is not null
begin
select @SubUsefulline=@SubUsefulline+','+@logicalx+','+@logicaly
end
else
begin
select @SubUsefulline=@logicalx+','+@logicaly
end
close getPointXY
deallocate getPointXY
end
end
end
close curPointline
deallocate curPointline
end
if(@isExistLine='ye')
begin
set @area=0.00001
select @OldintersectiOns=SUBSTRING(@Oldintersections, @CommaLocation + 1, @Length - @CommaLocation)
select @CommaLocation = CHARINDEX(@Split, @Oldintersections)
if @Usefulline is not null
begin
select @Usefulline=@Usefulline+';'+@SubUsefulline
end
else
begin
select @Usefulline=@SubUsefulline
end
end
else
begin
set @area=@area+0.00001
end
end
----对起始终止点处理
if (@StartpointX is not null) and (@EndpointX is not null) and (@StartpointY is not null) and (@EndpointY is not null)
begin
if @Usefulline is not null
declare @Subuserline varchar(255)
declare @FSubuserline varchar(255)
declare @FirstX varchar(9)
declare @FirstY varchar(9)
declare @LastX varchar(9)
declare @LastY varchar(9)
declare @Clogicalx varchar(9)
declare @Clogicaly varchar(9)
declare @LinePoints varchar(255)
declare @int int
begin
set @FirstX=left(@Usefulline, charindex(',',@Usefulline)-1)
set @Subuserline=substring(@Usefulline,charindex(',',@Usefulline)+1,len(@Usefulline))
--select substring(@Usefulline,charindex(',',@Usefulline)+1,len(@Usefulline))
set @FirstY=left(@Subuserline, charindex(',',@Subuserline)-1)
set @XYarea=100
set @int=0
while @int<3
begin
set @isExistLine='no'
declare StartFirstline cursor for
SELECT kr1.lineid,krp1.pointid
FROM kangaroo_roadnet kr1
INNER JOIN
kangaroo_roadnet_point krp1 ON kr1.pointid = krp1.pointid
where (krp1.logicalx <= @StartpointX+@XYarea and krp1.logicalx >= @StartpointX-@XYarea)
AND (krp1.logicaly <= @StartpointY+@XYarea and krp1.logicaly >= @StartpointY-@XYarea)
and kr1.lineid in(
SELECT kr.lineid
FROM kangaroo_roadnet kr INNER JOIN
kangaroo_roadnet_point krp ON kr.pointid = krp.pointid
WHERE (krp.logicalx = @FirstX) AND (krp.logicaly = @FirstY))
open StartFirstline
fetch next from StartFirstline into @Clineid,@Cpointid
while ( @@Fetch_Status=0 )
begin
if @Clineid is not null and @Cpointid is not null
begin
set @isExistLine='ye'
declare StartFirstPoints cursor for
select krp1.logicalx,krp1.logicaly from kangaroo_roadnet_point as krp1 where krp1.pointid between @Cpointid and
(select krp.pointid from kangaroo_roadnet_point as krp,kangaroo_roadnet as kr
where krp.logicalx=@FirstX and krp.logicaly=@FirstY and krp.pointid=kr.pointid
and kr.lineid=@Clineid)
open StartFirstPoints
fetch next from StartFirstPoints into @Clogicalx,@Clogicaly
while ( @@Fetch_Status=0 )
begin
if @LinePoints is not null
begin
select @LinePoints=@LinePoints+','+@Clogicalx+','+@Clogicaly
end
else
begin
select @LinePoints=@Clogicalx+','+@Clogicaly
end
end
close StartFirstPoints
deallocate StartFirstPoints
end
else
begin
set @XYarea=@XYarea+100
end
end
close StartFirstline
deallocate StartFirstline
if(@isExistLine='ye')
begin
if(@Usefulline is not null)
begin
select @Usefulline=@LinePoints+';'+@Usefulline
end
else
begin
select @Usefulline=@LinePoints
end
break
end
else
begin
set @int=@int+1
end
end
set @XYarea=100
set @int=0
while @int<3
begin
set @isExistLine='no'
set @LastY=right(@Usefulline, charindex(',',reverse(@Usefulline))-1)
set @FSubuserline=substring(@Usefulline,1,len(@Usefulline)-charindex(',',reverse(@Usefulline)))
--select substring(@s,1,len(@s)-charindex('-',reverse(@s)))
set @LastX=right(@FSubuserline, charindex(',',reverse(@FSubuserline))-1)
declare EndLastline cursor for
SELECT kr1.lineid,krp1.pointid
FROM kangaroo_roadnet kr1
INNER JOIN
kangaroo_roadnet_point krp1 ON kr1.pointid = krp1.pointid
where (krp1.logicalx <= @StartpointX+@XYarea and krp1.logicalx >= @StartpointX-@XYarea)
AND (krp1.logicaly <= @StartpointY+@XYarea and krp1.logicaly >= @StartpointY-@XYarea)
and kr1.lineid in(
SELECT kr.lineid
FROM kangaroo_roadnet kr INNER JOIN
kangaroo_roadnet_point krp ON kr.pointid = krp.pointid
WHERE (krp.logicalx = @FirstX) AND (krp.logicaly = @FirstY))
open EndLastline
fetch next from EndLastline into @Clineid,@Cpointid
while ( @@Fetch_Status=0 )
begin
if @Clineid is not null and @Cpointid is not null
begin
set @isExistLine='ye'
declare EndLastPoints cursor for
select krp1.logicalx,krp1.logicaly from kangaroo_roadnet_point as krp1 where krp1.pointid between @Cpointid and
(select krp.pointid from kangaroo_roadnet_point as krp,kangaroo_roadnet as kr
where krp.logicalx=@FirstX and krp.logicaly=@FirstY and krp.pointid=kr.pointid
and kr.lineid=@Clineid)
open EndLastPoints
fetch next from EndLastPoints into @Clogicalx,@Clogicaly
while ( @@Fetch_Status=0 )
begin
if @LinePoints is not null
begin
select @LinePoints=@LinePoints+','+@Clogicalx+','+@Clogicaly
end
else
begin
select @LinePoints=@Clogicalx+','+@Clogicaly
end
end
close EndLastPoints
deallocate EndLastPoints
end
else
begin
set @XYarea=@XYarea+100
end
end
close EndLastline
deallocate EndLastline
if(@isExistLine='ye')
begin
if(@Usefulline is not null)
begin
select @Usefulline=@Usefulline+';'+@LinePoints
end
else
begin
select @Usefulline=@LinePoints
end
break
end
else
begin
set @int=@int+1
end
end
end
end
end
GO