Skip to content

Commit

Permalink
Move some cpp code samples to python
Browse files Browse the repository at this point in the history
  • Loading branch information
DelazJ authored and nyalldawson committed Jul 21, 2020
1 parent 8383676 commit 5c83cd0
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 57 deletions.
11 changes: 11 additions & 0 deletions python/core/auto_generated/expression/qgsexpression.sip.in
Expand Up @@ -18,6 +18,17 @@ Class for parsing and evaluation of expressions (formerly called "search strings
The expressions try to follow both syntax and semantics of SQL expressions.

Usage:
.. code-block:: python

exp = QgsExpression("gid*2 > 10 and type not in ('D','F')")
if exp.hasParserError():
# show error message with parserErrorString() and exit

result = exp.evaluate(feature, fields)
if exp.hasEvalError():
# show error message with evalErrorString()
else
# examine the result

Three Value Logic
=================
Expand Down
Expand Up @@ -541,8 +541,11 @@ If the gridified geometry could not be calculated ``None`` will be returned.
It may generate an invalid geometry (in some corner cases).
It can also be thought as rounding the edges and it may be useful for removing errors.

Example
-------
Example:

.. code-block:: python

geometry.snappedToGrid(1, 1)

In this case we use a 2D grid of 1x1 to gridify.
In this case, it can be thought like rounding the x and y of all the points/vertices to full units (remove all decimals).
Expand Down Expand Up @@ -702,7 +705,6 @@ Returns Java-style iterator for traversal of parts of the geometry. This iterato
can safely be used to modify parts of the geometry.

Example
-------

.. code-block:: python

Expand Down Expand Up @@ -743,7 +745,6 @@ Returns a read-only, Java-style iterator for traversal of vertices of all the ge
modified using the iterator. See :py:func:`~QgsAbstractGeometry.transformVertices` for a safe method to modify vertices "in-place".

Example
-------

.. code-block:: python

Expand Down
11 changes: 5 additions & 6 deletions python/core/auto_generated/mesh/qgsmeshlayer.sip.in
Expand Up @@ -42,17 +42,16 @@ E.g. to create mesh with one quad and one triangle

.. code-block::

QString uri(
"1.0, 2.0 \n" \
uri = "1.0, 2.0 \n" \
"2.0, 2.0 \n" \
"3.0, 2.0 \n" \
"2.0, 3.0 \n" \
"1.0, 3.0 \n" \
"---" \
"0, 1, 3, 4 \n" \
"1, 2, 3 \n"
);
QgsMeshLayer *scratchLayer = new QgsMeshLayer(uri, "My Scratch layer", "mesh_memory");

scratchLayer = QgsMeshLayer(uri, "My Scratch layer", "mesh_memory")

MDAL data provider (mdal)
~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -62,8 +61,8 @@ is the MDAL connection string. QGIS must be built with MDAL support to allow thi

.. code-block::

QString uri = "test/land.2dm";
QgsMeshLayer *scratchLayer = new QgsMeshLayer(uri, "My Scratch Layer", "mdal");
uri = "test/land.2dm"
scratchLayer = QgsMeshLayer(uri, "My Scratch Layer", "mdal")

.. note::

Expand Down
17 changes: 10 additions & 7 deletions python/core/auto_generated/qgscoordinatereferencesystem.sip.in
Expand Up @@ -100,13 +100,16 @@ on different machines or user profiles.
# Well-known text (WKT): Defined by Open Geospatial Consortium (OGC), this is another common
format to define CRS. For WGS84 the OGC WKT definition is the following:

GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]
.. code-block::

GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]



.. seealso:: :py:func:`toWkt`
Expand Down
6 changes: 6 additions & 0 deletions python/core/auto_generated/raster/qgsrasterlayer.sip.in
Expand Up @@ -25,6 +25,12 @@ corresponding to the provider type, and passes it the url. The data provider
connects to the data source.

Sample usage of the QgsRasterLayer class:

.. code-block:: python

myFileNameQString = "/path/to/file"
myBaseNameQString = "my layer"
myRasterLayer = QgsRasterLayer(myFileNameQString, myBaseNameQString)
%End

%TypeHeaderCode
Expand Down
10 changes: 9 additions & 1 deletion python/gui/auto_generated/qgsprojectionselectiondialog.sip.in
Expand Up @@ -19,6 +19,14 @@ Typically you will use this when you want to prompt the user for
a coordinate system identifier e.g. from a plugin you might do this
to get an epsg code:

.. code-block:: python

crs = QgsCoordinateReferenceSystem()
mySelector = QgsProjectionSelectionDialog( iface.mainWindow() )
mySelector.setCrs( crs )
if mySelector.exec():
mCrs = mySelector.crs()

If you wish to embed the projection selector into an existing dialog
the you probably want to look at QgsProjectionSelectionWidget instead.

Expand Down Expand Up @@ -91,7 +99,7 @@ Sets this dialog to filter the available projections to those listed
by the given Coordinate Reference Systems.

:param crsFilter: a list of OGC Coordinate Reference Systems to filter the
list of projections by. This is useful in (e.g.) WMS situations
list of projections by. This is useful in (e.g.) WMS situations
where you just want to offer what the WMS server can support.

.. warning::
Expand Down
23 changes: 9 additions & 14 deletions src/core/expression/qgsexpression.h
Expand Up @@ -50,21 +50,16 @@ Class for parsing and evaluation of expressions (formerly called "search strings
The expressions try to follow both syntax and semantics of SQL expressions.
Usage:
\code{.cpp}
QgsExpression exp("gid*2 > 10 and type not in ('D','F')");
if (exp.hasParserError())
{
// show error message with parserErrorString() and exit
}
QVariant result = exp.evaluate(feature, fields);
if (exp.hasEvalError())
{
// show error message with evalErrorString()
}
\code{.py}
exp = QgsExpression("gid*2 > 10 and type not in ('D','F')")
if exp.hasParserError():
# show error message with parserErrorString() and exit
result = exp.evaluate(feature, fields)
if exp.hasEvalError():
# show error message with evalErrorString()
else
{
// examine the result
}
# examine the result
\endcode
Three Value Logic
Expand Down
10 changes: 5 additions & 5 deletions src/core/geometry/qgsabstractgeometry.h
Expand Up @@ -546,10 +546,10 @@ class CORE_EXPORT QgsAbstractGeometry
* It may generate an invalid geometry (in some corner cases).
* It can also be thought as rounding the edges and it may be useful for removing errors.
*
* ### Example
* Example:
*
* \code{.cpp}
* geometry->snappedToGrid(1, 1);
* \code{.py}
* geometry.snappedToGrid(1, 1)
* \endcode
*
* In this case we use a 2D grid of 1x1 to gridify.
Expand Down Expand Up @@ -917,7 +917,7 @@ class CORE_EXPORT QgsAbstractGeometry
* Returns Java-style iterator for traversal of parts of the geometry. This iterator
* can safely be used to modify parts of the geometry.
*
* ### Example
* Example
*
* \code{.py}
* # print the WKT representation of each part in a multi-point geometry
Expand Down Expand Up @@ -955,7 +955,7 @@ class CORE_EXPORT QgsAbstractGeometry
* \warning The iterator returns a copy of individual vertices, and accordingly geometries cannot be
* modified using the iterator. See transformVertices() for a safe method to modify vertices "in-place".
*
* ### Example
* Example
*
* \code{.py}
* # print the x and y coordinate for each vertex in a LineString
Expand Down
15 changes: 7 additions & 8 deletions src/core/mesh/qgsmeshlayer.h
Expand Up @@ -64,28 +64,27 @@ class QgsMeshDatasetGroupStore;
* vertices and faces is comma separated coordinates and connections for mesh.
* E.g. to create mesh with one quad and one triangle
*
* \code
* QString uri(
* "1.0, 2.0 \n" \
* \code{py}
* uri = "1.0, 2.0 \n" \
* "2.0, 2.0 \n" \
* "3.0, 2.0 \n" \
* "2.0, 3.0 \n" \
* "1.0, 3.0 \n" \
* "---" \
* "0, 1, 3, 4 \n" \
* "1, 2, 3 \n"
* );
* QgsMeshLayer *scratchLayer = new QgsMeshLayer(uri, "My Scratch layer", "mesh_memory");
*
* scratchLayer = QgsMeshLayer(uri, "My Scratch layer", "mesh_memory")
* \endcode
*
* \subsection mdal MDAL data provider (mdal)
*
* Accesses data using the MDAL drivers (https://github.com/lutraconsulting/MDAL). The url
* is the MDAL connection string. QGIS must be built with MDAL support to allow this provider.
* \code
* QString uri = "test/land.2dm";
* QgsMeshLayer *scratchLayer = new QgsMeshLayer(uri, "My Scratch Layer", "mdal");
* \code{py}
* uri = "test/land.2dm"
* scratchLayer = QgsMeshLayer(uri, "My Scratch Layer", "mdal")
* \endcode
*
* \note The API is considered EXPERIMENTAL and can be changed without a notice
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgscoordinatereferencesystem.h
Expand Up @@ -141,13 +141,15 @@ typedef void ( *CUSTOM_CRS_VALIDATION )( QgsCoordinateReferenceSystem & ) SIP_SK
* # Well-known text (WKT): Defined by Open Geospatial Consortium (OGC), this is another common
* format to define CRS. For WGS84 the OGC WKT definition is the following:
*
* \code
* GEOGCS["WGS 84",
* DATUM["WGS_1984",
* SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],
* AUTHORITY["EPSG","6326"]],
* PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],
* UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],
* AUTHORITY["EPSG","4326"]]
* \endcode
*
* \see toWkt()
* \see createFromWkt()
Expand Down
8 changes: 4 additions & 4 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -63,10 +63,10 @@ typedef QList < QPair< QString, QColor > > QgsLegendColorList;
*
* Sample usage of the QgsRasterLayer class:
*
* \code{.cpp}
* QString myFileNameQString = "/path/to/file";
* QString myBaseNameQString = "my layer";
* QgsRasterLayer *myRasterLayer = new QgsRasterLayer(myFileNameQString, myBaseNameQString);
* \code{.py}
* myFileNameQString = "/path/to/file"
* myBaseNameQString = "my layer"
* myRasterLayer = QgsRasterLayer(myFileNameQString, myBaseNameQString)
* \endcode
*/
class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
Expand Down
16 changes: 8 additions & 8 deletions src/gui/qgsprojectionselectiondialog.h
Expand Up @@ -34,13 +34,13 @@
* Typically you will use this when you want to prompt the user for
* a coordinate system identifier e.g. from a plugin you might do this
* to get an epsg code:
* \code{.cpp}
* QgsProjectionSelectionDialog mySelector( mQGisIface->mainWindow() );
* mySelector.setCrs( crs );
* if ( mySelector.exec() )
* {
* mCrs = mySelector.crs();
* }
*
* \code{.py}
* crs = QgsCoordinateReferenceSystem()
* mySelector = QgsProjectionSelectionDialog( iface.mainWindow() )
* mySelector.setCrs( crs )
* if mySelector.exec():
* mCrs = mySelector.crs()
* \endcode
*
* If you wish to embed the projection selector into an existing dialog
Expand Down Expand Up @@ -105,7 +105,7 @@ class GUI_EXPORT QgsProjectionSelectionDialog : public QDialog, private Ui::QgsG
* by the given Coordinate Reference Systems.
*
* \param crsFilter a list of OGC Coordinate Reference Systems to filter the
* list of projections by. This is useful in (e.g.) WMS situations
* list of projections by. This is useful in (e.g.) WMS situations
* where you just want to offer what the WMS server can support.
*
* \warning This function's behavior is undefined if it is called after the dialog is shown.
Expand Down

0 comments on commit 5c83cd0

Please sign in to comment.