PolylineAnalyzer (from the FME Store)
you can type 'PolylineAnalyzer' on the workbench worksheet and download from there.
Takes polylines and polygons and analyzes relationships between their
components - vertices and segments.
FME Store link
https://store.safe.com/transformers/polylineanalyzer
usage:
You can work the angle out and then use a tester transformer for 45 degrees or less
I have been always doing this kind of things using unary_union
. So, as an intersection of two linestring layers you would get a multipoint geometry which I then iterate through.
import matplotlib.pyplot as plt
import geopandas as gpd
import shapely
import fiona
from shapely.geometry import Point, mapping
from fiona import collection
from fiona.crs import from_epsg
print(gpd.__version__)
print(shapely.__version__)
print(fiona.__version__)
0.2.1
1.5.17.post1
1.7.8
Reading data from shapefiles and creating MultiPoint
:
roads = gpd.read_file(r"C:\GIS\Temp\Gpd\Roads.shp")
streams = gpd.read_file(r"C:\GIS\Temp\Gpd\Streams.shp")
points = roads.unary_union.intersection(streams.unary_union)
points
MULTIPOINT Z (316672.9970907159 4141706.877471883 0, 317324.4303508335 4141602.277340039 0, 317738.9541803655 4141848.779893903 0, 318102.8218661814 4141740.856982633 0)
Writing Multipoint
to a new shapefile:
schema = { 'geometry': 'Point', 'properties': { } }
with collection(
r"C:\GIS\Temp\Gpd\IntersectPoints.shp", "w", "ESRI Shapefile",
schema, crs=from_epsg(26912)) as output:
for i in points.geoms:
output.write({'properties': {},
'geometry': mapping(Point(i.x, i.y))})
Plotting all data on the same figure:
fig, ax = plt.subplots()
roads.plot(ax=ax, color='black')
streams.plot(ax=ax, color='red')
points_df = gpd.read_file(r"C:\GIS\Temp\Gpd\IntersectPoints.shp")
points_df.plot(ax=ax, markersize=10, color='blue')
fig.savefig(r'C:\GIS\Temp\outMap.png')
Best Answer
The nodes:
You want two things, the end points of the polylines (without intermediate nodes) and the intersection points. There are an additional problem, some polylines end points are also intersection points:
A solution is to use Python and the modules Shapely and Fiona
1) Read the shapefile:
2) Find the end Points of the lines (how would one get the end points of a polyline?):
3) Compute the intersections (iterating through pairs of geometries in the layer with the itertools module). The result of some intersections are MultiPoints and we want a list of points:
4) Eliminate duplicates between end points and intersection points (as you can see in the figures)
5) Save the resulting shapefile
Final result:
The line segments
If you want also the segments between the nodes, you need to "planarize" (Planar Graph, no edges cross each other) your shapefile. This can be done by the unary_union function of Shapely