I want to get splitGeometry working example in qgis where i can find it. Official documentation have define here but this is not enough. Where i can get its working example in order to understand it and use in my project.
By using Official Documentation for 'splitGeometry' of QgsGeometry and shapefiles at next image:
I tried out my own code based in Maplus link:
mapcanvas = iface.mapCanvas()
layers = mapcanvas.layers()
feat_1 = layers[0].getFeatures().next()
feat_2 = layers[1].getFeatures().next()
if feat_1.geometry().intersects(feat_2.geometry()):
success, splits, topo = feat_1.geometry().splitGeometry(feat_2.geometry().asPolygon()[0], True)
if success == 0:
print splits[0].exportToWkt()
geom = QgsGeometry()
print geom.fromPolyline(topo).exportToWkt()
First argument of 'splitGeometry' is a QgsPoint list, 'splits' is a geometry list and 'topo' is also a QgsPoint list. Results printed at Python Console of QGIS were:
So, I used QuickWKT plugin for visualizing these results:
Try GitHub search. Here is link: GitHub splitGeometry search
For some reason link is not working. Please just visit github page and write splitGeometry. Then click on Code on the left panel and choose python. There are 25 examples.
There are some examples how people use this method in python. It is very good way how to get info about using other methods in pyqgis because of small numbers of pyqgis examples.
Here are specific project using this method: Mapplus
geom_b = QgsGeometry(feat_b.geometry())
if geom_b.intersects(geom_a):
success, splits, topo = geom_a.splitGeometry(geom_b.asPolyline(), True) # split polygon by line
if success == 0:
#if it success you can make other operations