4

I am curious to know on how to implement NNJoin into the python code. I have created a point shapefile using shapely. I have another shapefile which is a centerline and is used as a reference line. Now I want to find the shortest distance from each point to the centerline. The way which I have done so far is converted the centerline shapefile into points and used NNJoin to find the shortest distance and the nearest coordinates of the point on the centerline. I want to know as to how I can implement the NNJoin using python.

Is there a way to import NNJoin as a library and use it?

If not are there any alternatives to it which I can use?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
webapp
  • 209
  • 1
  • 9

1 Answers1

4

NNjoin joins two vector layers based on nearest neighbour relationships and it use GEOS as Shapely.

In Python it is quicker to use a Spatial Index as Rtree (Nearest Neighbours). There are many examples of the use of this module with Shapely and Fiona on the Web and GIS SE.

A solution with Shapely (without a Spatial Index) is given in Nearest neighbor between point layer and line layer?

And a comparison of all the Python solutions is proposed in Benchmarking Nearest Neighbor Searches in Python

gene
  • 54,868
  • 3
  • 110
  • 187
  • Thanks for the help gene, I was able to get the nearest neighbor based on your recommendation. I also tried and was able to find the nearest point using interpolation. This also gave me the coordinates of the nearest neighbor on the centerline. – webapp Mar 14 '16 at 00:30