# import necessary libraries from qgis.core import QgsPoint, QgsFeature, QgsGeometry # create a point point = QgsGeometry.fromPoint(QgsPoint(10, 20)) # create a feature and add the point geometry to it feature = QgsFeature() feature.setGeometry(point) # add the feature to a layer in QGIS layer = QgsVectorLayer("Point", "Point", "memory") layer.startEditing() layer.addFeature(feature) layer.commitChanges()
# import necessary libraries from qgis.core import QgsPoint, QgsFeature, QgsGeometry # create a polygon points = [QgsPoint(10, 10), QgsPoint(20, 10), QgsPoint(20, 20), QgsPoint(10, 20)] polygon = QgsGeometry.fromPolygon([points]) # calculate the area of the polygon area = polygon.area() # print the area print("Polygon area:", area)
# import necessary libraries from qgis.core import QgsPoint, QgsFeature, QgsGeometry # create a point point = QgsGeometry.fromPoint(QgsPoint(10, 20)) # buffer the point with a radius of 5 units buffered_point = point.buffer(5, 5) # print the buffered point geometry print(buffered_point)All of these examples use the Python QGIS library qgis.core.