Geographic Information Systems Asked by ahmathelte on August 24, 2020
I have an output of getContourLines()
from contoureR package. The data frame output was modified and some points in the contour path were removed according to some masks, due to that: the distance between the points in the contour paths became longer as you can see in the leaflet map.
I used the function here to connect points to lines.
head of the data frame :
> head(output_df)
LID GID PID Group x y z
249 1 1 220 1-1 165.0000 -4.010842 0
250 1 1 221 1-1 164.6938 -4.500000 0
251 1 1 222 1-1 164.3503 -5.350302 0
252 1 1 223 1-1 163.8953 -6.000000 0
1543 1 18 203 1-18 201.0000 -10.075164 0
1552 1 18 212 1-18 207.0000 -10.937481 0
I would like to separate any line that has a big gap between its points to smaller lines for example line 1-18 in the attached map, Constructing lines from x,y coordinations without ID or sorting didn’t work.
Another approach is running loops over all points and filter lines to keep only lines coordinates that pass the threshold, this is done before converting to spatial lines. It removes too many points and can be run endlessly to reach the goal.
Loop code is :
#Filter points that are really far from their line group
end_of_loop<-nrow(output_df)-1
filter_of_far_points<-vector(length = end_of_loop)
for( j in 1:end_of_loop){
distance_to_next_point <-sqrt((output_df$x[j]-output_df$x[j+1])^2+(output_df$y[j+1]-output_df$y[j+1])^2)
if(output_df$Group[j]==output_df$Group[j+1]){
if(distance_to_next_point< 4.5){
filter_of_far_points[j]<-1
#print(c(j,"yes"))
}else{
#print(c(j,"NO",distance_to_next_point))
filter_of_far_points[j]<-0
}
}
}
#remove points which did not pass filter
nop<-which(filter_of_far_points==0)
output_df<-output_df[-nop,]
EDIT:
Can I transform it into Spatiallines and then cut lines to segments, where the distance between line coordinations exceeds the minimum distance threshold?
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP