Meanwhile here is the solution I wrote using pyqgis, it works for me :
my_lines = QgsVectorLayer('/path/to/my_lines.shp', 'my_lines', 'ogr')
my_polygons = QgsVectorLayer('/path/to/my_polygons.shp', 'my_polygons', 'ogr')
diff = processing.runalg("qgis:difference", my_lines, my_polygons, False, None)
result = processing.getObject(diff['OUTPUT'])
_writer = QgsVectorFileWriter.writeAsVectorFormat(result,"/path/to/result.shp","utf-8",None,"ESRI Shapefile")
my_lines_diff_my_polygons = gpd.read_file('/path/to/result.shp')
for this to work, one has to import processing:
import processing
Since the orientation of the exterior ring doesn't matter, you could use the shapely.geometry.polygon.orient
function, which will orient the interiors colckwise or counterclockwise.
Simple example:
from shapely.geometry import Polygon
from shapely.geometry import polygon
pol = Polygon([(0,0),(1,0),(1,1),(0,1)],[[(0.1,0.1),(0.1,0.2),(0.2,0.2)]])
[[*p.coords] for p in polygon.orient(pol,-1).interiors]
#Out[]: [[(0.1, 0.1), (0.2, 0.2), (0.1, 0.2), (0.1, 0.1)]]
[[*p.coords] for p in polygon.orient(pol,1).interiors]
#Out[]: [[(0.1, 0.1), (0.1, 0.2), (0.2, 0.2), (0.1, 0.1)]]
In geopandas you will map the function over the gemetry column with:
new_geometry_series = dataframe.geometry.apply(polygon.orient,args=(1)) #or -1
Best Answer
You just access the
c.geometry
attribute.Poly 1
Poly 2
Symmetric difference