You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This would be a cool feature - calculate the Hausdorf Distance of two GeoJSON LineStrings. This allows you to compare the similarity between two lines to find the most similar in a Collection or Set of lines.
This could also potentially be exposed in a similar way as Points with the @turf/nearest-point package. This could be packaged as @turf/line-similarity and @turf/line-most-similar.
Another JavaScript implementation that appears to support this is Sketchy.JS.
defhausdorffDistance(geom1,geom2):
''' Hausdorff Distance calculator, somewhat based on https://github.com/anitagraser/QGIS-Processing-tools/blob/master/1.1/scripts/find_similar_line_feature.py Uses pure pyqgis instead of numpy Inputs geom1 and geom2 should be QgsGeometry of type 'QGis.Line' '''dist=lambdax1, y1, x2, y2: float((x2-x1)**2+(y2-y1)**2)**(0.5) #Euclidean distance between two coordinates##Get all possible combinations between coordinates on the first line and second linecombins= [dist(a[0], a[1], b[0], b[1]) foraingeom1.asPolyline() forbingeom2.asPolyline()]
##Find array dimensionscombinSz=len(list(combins))
xArrSize=len(geom1.asPolyline())
yArrSize=combinSz/xArrSize#print "{0}x{1} array".format(xArrSize, yArrSize)##Turn 1-dimensional list of distances into 2-dimensional list/arraydistAryOne= [[0]*yArrSizeforiinrange(xArrSize)] #initialize empty 2-dimensional distance array firstforxinrange(xArrSize):
foryinrange(yArrSize):
distAryOne[x][y]=combins[(x*yArrSize)+y]
distAryTwo= [[0]*xArrSizeforiinrange(yArrSize)] #flipped order of distAryOneforyinrange(yArrSize):
forxinrange(xArrSize):
#print y, x, (y*xArrSize)+xdistAryTwo[y][x]=combins[(y*xArrSize)+x]
##Finally calculates Hausdorff Distance#Calculate distances between origin and target featureH1=max([min([distAryOne[i][j] foriinrange(xArrSize)]) forjinrange(yArrSize)]) #get the highest minimum (supremum infimum) travelling along axis 1 (y-axis)H2=max([min([distAryOne[i][j] forjinrange(yArrSize)]) foriinrange(xArrSize)]) #get the highest minimum (supremum infimum) travelling along axis 0 (x-axis)#print H1, H2#Repeat the calculation in reverse orderH3=max([min([distAryTwo[j][i] foriinrange(xArrSize)]) forjinrange(yArrSize)]) #get the highest minimum (supremum infimum) travelling along axis 1 (y-axis)H4=max([min([distAryTwo[j][i] forjinrange(yArrSize)]) foriinrange(xArrSize)]) #get the highest minimum (supremum infimum) travelling along axis 0 (x-axis)#print H3, H4hausdorff=max([H1, H2]+[H3, H4])
#print hausdorffreturnhausdorffhDist=hausdorffDistance(featureOne.geometry(), featureTwo.geometry()) #gets Hausdorff Distance between two QgsGeometry
This would be a cool feature - calculate the Hausdorf Distance of two GeoJSON
LineStrings
. This allows you to compare the similarity between two lines to find the most similar in a Collection or Set of lines.This could also potentially be exposed in a similar way as Points with the @turf/nearest-point package. This could be packaged as
@turf/line-similarity
and@turf/line-most-similar
.Another JavaScript implementation that appears to support this is Sketchy.JS.
From: https://gis.stackexchange.com/questions/204361/find-a-linestring-closest-to-a-given-linestring
The text was updated successfully, but these errors were encountered: