I am using 'intersection' function from Shapely to find junctions of a road network. As i found, intersection returns GeometryCollection. In my case it could be Point, LineString or perhaps MultiLineString. I want to segregate these objects based on their geometry. I only want Point objects for further use. I found similar post here
It suggests to use as.GeometryCollection however, in my case it gives:
p = l1.intersection(l2).asGeometryCollection()
AttributeError: 'GeometryCollection' object has no attribute 'asGeometryCollection'
here is the sample code: (I expect to get points in junctions[])
with open('./lines.geojson') as f:
routes = json.load(f)
junctions =[]
for i in range(len(routes['features'])-1):
j =i+1
while (j < len(routes['features'])):
l1 = LineString(routes['features'][i]['geometry']['coordinates'])
l2 = LineString(routes['features'][j]['geometry']['coordinates'])
p = l1.intersection(l2).asGeometryCollection()
junctions.append(p[0])
j = j+1