I'm writing a program that reads two MultiLineString
shapefiles and intersects them, then processes the result in various ways. The intersection normally will give me a GeoSeries of points, like this:
n1 = geopandas.read_file('file1.shp')
n2 = geopandas.read_file('file2.shp')
internodes = n1.intersection(n2)
inex = internodes.explode(index_parts=True).droplevel(0)
>>>inex
0 POINT (-49.09646 -13.26470)
1 POINT (-57.73859 -10.66091)
2 POINT (-61.73795 -8.95471)
dtype: geometry
<class 'geopandas.geoseries.GeoSeries'>
But sometimes two or more segments from the MultiLineString
s will overlap in their totality, and this will give me a GeoSeries with both Point
s and LineString
s:
>>>inex
0 LINESTRING (-53.17200 -8.94200, -45.42200 -17.162)
1 POINT (-59.89331 -11.36051)
dtype: geometry
<class 'geopandas.geoseries.GeoSeries'>
This leads to errors in my program since it expects a GeoSeries with only points.
What's the best method to get a new GeoSeries (or maybe a GeoDataFrame) that contains only the points and coordinates of this GeoSeries? Using the example above, I want to obtain something like this:
>>>inex
0 POINT (-53.17200 -8.94200)
1 POINT (-57.73859 -10.66091)
2 POINT (-59.89331 -11.36051)
dtype: geometry
<class 'geopandas.geoseries.GeoSeries'>
I've tried using GeoSeries.extract_unique_points()
and GeoSeries.get_coordinates()
as mentioned here and here, but then I get an error message that says 'GeoSeries' object has no attribute 'extract_unique_points'
or 'GeoSeries' object has no attribute 'get_coordinates'
.
I've also tried converting the GeoSeries to a GeoDataFrame and using extract_xy()
from the GemGIS package, but as stated here, currently GeoDataFrames with multiple types of geometries are not supported.