from qgis.core import QgsGeometry poly1 = QgsGeometry.fromWkt('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))') poly2 = QgsGeometry.fromWkt('POLYGON((0.5 0.5, 0.5 1.5, 1.5 1.5, 1.5 0.5, 0.5 0.5))') intersection = poly1.intersection(poly2) print(intersection.asWkt())
from qgis.core import QgsPointXY, QgsLineString, QgsGeometry point = QgsGeometry.fromPointXY(QgsPointXY(1, 1)) line = QgsGeometry.fromPolyline([QgsPointXY(0, 0), QgsPointXY(1, 1.5), QgsPointXY(2, 0)]) intersection = point.intersection(line) print(intersection.asPoint())In this example, we created a QgsPointXY object called `point` with coordinates (1, 1) and a QgsLineString object called `line` with three points. We then called the `intersection` method on `point` with `line` as an argument to find the intersection between the point and line. Finally, we printed the resulting intersection as a point. The package library for this function is qgis.core.