Fix code exemples in:

qgsgeometry
qgsabstractgeometry
qgsgeometryutils
qgsalgorithmbatchgeocode
This commit is contained in:
Valentin Buira 2025-08-29 18:44:01 +02:00
parent 1b0c079390
commit 5793f3fe1c
12 changed files with 42 additions and 39 deletions

View File

@ -27,6 +27,7 @@ Example
def geocodeString(self, string, context, feedback):
# calculate and return results...
pass
my_geocoder = MyGeocoder()

View File

@ -868,22 +868,22 @@ Example
.. code-block:: python
# print the WKT representation of each part in a multi-point geometry
geometry = QgsMultiPoint.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
for part in geometry.parts():
print(part.asWkt())
# single part geometries only have one part - this loop will iterate once only
geometry = QgsLineString.fromWkt( 'LineString( 0 0, 10 10 )' )
geometry = QgsGeometry.fromWkt( 'LineString( 0 0, 10 10 )' )
for part in geometry.parts():
print(part.asWkt())
# parts can be modified during the iteration
geometry = QgsMultiPoint.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
for part in geometry.parts():
part.transform(ct)
part.transform(ct=QgsCoordinateTransform()) # Dummy transform
# part iteration can also be combined with vertex iteration
geometry = QgsMultiPolygon.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )
geometry = QgsGeometry.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )
for part in geometry.parts():
for v in part.vertices():
print(v.x(), v.y())
@ -909,12 +909,12 @@ Example
.. code-block:: python
# print the x and y coordinate for each vertex in a LineString
geometry = QgsLineString.fromWkt( 'LineString( 0 0, 1 1, 2 2)' )
geometry = QgsGeometry.fromWkt( 'LineString( 0 0, 1 1, 2 2)' )
for v in geometry.vertices():
print(v.x(), v.y())
# vertex iteration includes all parts and rings
geometry = QgsMultiPolygon.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )
geometry = QgsGeometry.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )
for v in geometry.vertices():
print(v.x(), v.y())

View File

@ -260,7 +260,7 @@ Example
.. code-block:: python
# Create a polygon geometry with a single exterior ring (a triangle)
polygon = QgsGeometry.fromPolygonXY([[QgsPointXY(1, 2), QgsPointXY(5, 2), QgsPointXY(5, 10), QgsPointXY(1, 2)]]))
polygon = QgsGeometry.fromPolygonXY([[QgsPointXY(1, 2), QgsPointXY(5, 2), QgsPointXY(5, 10), QgsPointXY(1, 2)]])
# Create a donut shaped polygon geometry with an interior ring
polygon = QgsGeometry.fromPolygonXY([[QgsPointXY(1, 2), QgsPointXY(5, 2), QgsPointXY(5, 10), QgsPointXY(1, 10), QgsPointXY(1, 2)],
@ -539,7 +539,7 @@ Example
# parts can be modified during the iteration
geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
for part in geometry.parts():
part.transform(ct)
part.transform(ct=QgsCoordinateTransform()) # Dummy transform
# part iteration can also be combined with vertex iteration
geometry = QgsGeometry.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )

View File

@ -311,13 +311,13 @@ Example
.. code-block:: python
p = QgsPoint( 4, 6 ) # 2D point
pr = midpoint ( p, QgsPoint( 2, 2 ) )
pr = QgsGeometryUtils.midpoint ( p, QgsPoint( 2, 2 ) )
# pr is a 2D point: 'Point (3 4)'
pr = midpoint ( p, QgsPoint( QgsWkbTypes.PointZ, 2, 2, 2 ) )
pr = QgsGeometryUtils.midpoint ( p, QgsPoint( QgsWkbTypes.PointZ, 2, 2, 2 ) )
# pr is a 3D point: 'PointZ (3 4 1)'
pr = midpoint ( p, QgsPoint( QgsWkbTypes.PointM, 2, 2, 0, 2 ) )
pr = QgsGeometryUtils.midpoint ( p, QgsPoint( QgsWkbTypes.PointM, 2, 2, 0, 2 ) )
# pr is a 3D point: 'PointM (3 4 1)'
pr = midpoint ( p, QgsPoint( QgsWkbTypes.PointZM, 2, 2, 2, 2 ) )
pr = QgsGeometryUtils.midpoint ( p, QgsPoint( QgsWkbTypes.PointZM, 2, 2, 2, 2 ) )
# pr is a 3D point: 'PointZM (3 4 1 1)'
%End

View File

@ -27,6 +27,7 @@ Example
def geocodeString(self, string, context, feedback):
# calculate and return results...
pass
my_geocoder = MyGeocoder()

View File

@ -868,22 +868,22 @@ Example
.. code-block:: python
# print the WKT representation of each part in a multi-point geometry
geometry = QgsMultiPoint.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
for part in geometry.parts():
print(part.asWkt())
# single part geometries only have one part - this loop will iterate once only
geometry = QgsLineString.fromWkt( 'LineString( 0 0, 10 10 )' )
geometry = QgsGeometry.fromWkt( 'LineString( 0 0, 10 10 )' )
for part in geometry.parts():
print(part.asWkt())
# parts can be modified during the iteration
geometry = QgsMultiPoint.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
for part in geometry.parts():
part.transform(ct)
part.transform(ct=QgsCoordinateTransform()) # Dummy transform
# part iteration can also be combined with vertex iteration
geometry = QgsMultiPolygon.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )
geometry = QgsGeometry.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )
for part in geometry.parts():
for v in part.vertices():
print(v.x(), v.y())
@ -909,12 +909,12 @@ Example
.. code-block:: python
# print the x and y coordinate for each vertex in a LineString
geometry = QgsLineString.fromWkt( 'LineString( 0 0, 1 1, 2 2)' )
geometry = QgsGeometry.fromWkt( 'LineString( 0 0, 1 1, 2 2)' )
for v in geometry.vertices():
print(v.x(), v.y())
# vertex iteration includes all parts and rings
geometry = QgsMultiPolygon.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )
geometry = QgsGeometry.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )
for v in geometry.vertices():
print(v.x(), v.y())

View File

@ -260,7 +260,7 @@ Example
.. code-block:: python
# Create a polygon geometry with a single exterior ring (a triangle)
polygon = QgsGeometry.fromPolygonXY([[QgsPointXY(1, 2), QgsPointXY(5, 2), QgsPointXY(5, 10), QgsPointXY(1, 2)]]))
polygon = QgsGeometry.fromPolygonXY([[QgsPointXY(1, 2), QgsPointXY(5, 2), QgsPointXY(5, 10), QgsPointXY(1, 2)]])
# Create a donut shaped polygon geometry with an interior ring
polygon = QgsGeometry.fromPolygonXY([[QgsPointXY(1, 2), QgsPointXY(5, 2), QgsPointXY(5, 10), QgsPointXY(1, 10), QgsPointXY(1, 2)],
@ -539,7 +539,7 @@ Example
# parts can be modified during the iteration
geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
for part in geometry.parts():
part.transform(ct)
part.transform(ct=QgsCoordinateTransform()) # Dummy transform
# part iteration can also be combined with vertex iteration
geometry = QgsGeometry.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )

View File

@ -311,13 +311,13 @@ Example
.. code-block:: python
p = QgsPoint( 4, 6 ) # 2D point
pr = midpoint ( p, QgsPoint( 2, 2 ) )
pr = QgsGeometryUtils.midpoint ( p, QgsPoint( 2, 2 ) )
# pr is a 2D point: 'Point (3 4)'
pr = midpoint ( p, QgsPoint( QgsWkbTypes.PointZ, 2, 2, 2 ) )
pr = QgsGeometryUtils.midpoint ( p, QgsPoint( QgsWkbTypes.PointZ, 2, 2, 2 ) )
# pr is a 3D point: 'PointZ (3 4 1)'
pr = midpoint ( p, QgsPoint( QgsWkbTypes.PointM, 2, 2, 0, 2 ) )
pr = QgsGeometryUtils.midpoint ( p, QgsPoint( QgsWkbTypes.PointM, 2, 2, 0, 2 ) )
# pr is a 3D point: 'PointM (3 4 1)'
pr = midpoint ( p, QgsPoint( QgsWkbTypes.PointZM, 2, 2, 2, 2 ) )
pr = QgsGeometryUtils.midpoint ( p, QgsPoint( QgsWkbTypes.PointZM, 2, 2, 2, 2 ) )
# pr is a 3D point: 'PointZM (3 4 1 1)'
%End

View File

@ -38,6 +38,7 @@ class QgsGeocoderInterface;
*
* def geocodeString(self, string, context, feedback):
* # calculate and return results...
* pass
*
* my_geocoder = MyGeocoder()
*

View File

@ -1052,22 +1052,22 @@ class CORE_EXPORT QgsAbstractGeometry
*
* \code{.py}
* # print the WKT representation of each part in a multi-point geometry
* geometry = QgsMultiPoint.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
* geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
* for part in geometry.parts():
* print(part.asWkt())
*
* # single part geometries only have one part - this loop will iterate once only
* geometry = QgsLineString.fromWkt( 'LineString( 0 0, 10 10 )' )
* geometry = QgsGeometry.fromWkt( 'LineString( 0 0, 10 10 )' )
* for part in geometry.parts():
* print(part.asWkt())
*
* # parts can be modified during the iteration
* geometry = QgsMultiPoint.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
* geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
* for part in geometry.parts():
* part.transform(ct)
* part.transform(ct=QgsCoordinateTransform()) # Dummy transform
*
* # part iteration can also be combined with vertex iteration
* geometry = QgsMultiPolygon.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )
* geometry = QgsGeometry.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )
* for part in geometry.parts():
* for v in part.vertices():
* print(v.x(), v.y())
@ -1090,12 +1090,12 @@ class CORE_EXPORT QgsAbstractGeometry
*
* \code{.py}
* # print the x and y coordinate for each vertex in a LineString
* geometry = QgsLineString.fromWkt( 'LineString( 0 0, 1 1, 2 2)' )
* geometry = QgsGeometry.fromWkt( 'LineString( 0 0, 1 1, 2 2)' )
* for v in geometry.vertices():
* print(v.x(), v.y())
*
* # vertex iteration includes all parts and rings
* geometry = QgsMultiPolygon.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )
* geometry = QgsGeometry.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )
* for v in geometry.vertices():
* print(v.x(), v.y())
* \endcode

View File

@ -316,7 +316,7 @@ class CORE_EXPORT QgsGeometry
*
* \code{.py}
* # Create a polygon geometry with a single exterior ring (a triangle)
* polygon = QgsGeometry.fromPolygonXY([[QgsPointXY(1, 2), QgsPointXY(5, 2), QgsPointXY(5, 10), QgsPointXY(1, 2)]]))
* polygon = QgsGeometry.fromPolygonXY([[QgsPointXY(1, 2), QgsPointXY(5, 2), QgsPointXY(5, 10), QgsPointXY(1, 2)]])
*
* # Create a donut shaped polygon geometry with an interior ring
* polygon = QgsGeometry.fromPolygonXY([[QgsPointXY(1, 2), QgsPointXY(5, 2), QgsPointXY(5, 10), QgsPointXY(1, 10), QgsPointXY(1, 2)],
@ -623,7 +623,7 @@ class CORE_EXPORT QgsGeometry
* # parts can be modified during the iteration
* geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
* for part in geometry.parts():
* part.transform(ct)
* part.transform(ct=QgsCoordinateTransform()) # Dummy transform
*
* # part iteration can also be combined with vertex iteration
* geometry = QgsGeometry.fromWkt( 'MultiPolygon((( 0 0, 0 10, 10 10, 10 0, 0 0 ),( 5 5, 5 6, 6 6, 6 5, 5 5)),((20 2, 22 2, 22 4, 20 4, 20 2)))' )

View File

@ -360,13 +360,13 @@ class CORE_EXPORT QgsGeometryUtils
*
* \code{.py}
* p = QgsPoint( 4, 6 ) # 2D point
* pr = midpoint ( p, QgsPoint( 2, 2 ) )
* pr = QgsGeometryUtils.midpoint ( p, QgsPoint( 2, 2 ) )
* # pr is a 2D point: 'Point (3 4)'
* pr = midpoint ( p, QgsPoint( QgsWkbTypes.PointZ, 2, 2, 2 ) )
* pr = QgsGeometryUtils.midpoint ( p, QgsPoint( QgsWkbTypes.PointZ, 2, 2, 2 ) )
* # pr is a 3D point: 'PointZ (3 4 1)'
* pr = midpoint ( p, QgsPoint( QgsWkbTypes.PointM, 2, 2, 0, 2 ) )
* pr = QgsGeometryUtils.midpoint ( p, QgsPoint( QgsWkbTypes.PointM, 2, 2, 0, 2 ) )
* # pr is a 3D point: 'PointM (3 4 1)'
* pr = midpoint ( p, QgsPoint( QgsWkbTypes.PointZM, 2, 2, 2, 2 ) )
* pr = QgsGeometryUtils.midpoint ( p, QgsPoint( QgsWkbTypes.PointZM, 2, 2, 2, 2 ) )
* # pr is a 3D point: 'PointZM (3 4 1 1)'
* \endcode
*/