Skip to content
Permalink
Browse files

Move some cpp code samples to python

  • Loading branch information
DelazJ authored and nyalldawson committed Jul 21, 2020
1 parent 8383676 commit 5c83cd07cc3d3c8917017ac886f13d4edd6b6e13
@@ -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
=================
@@ -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).
@@ -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

@@ -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

@@ -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)
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -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::

@@ -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`
@@ -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
@@ -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.

@@ -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::
@@ -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
@@ -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.
@@ -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
@@ -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
@@ -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
@@ -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()
@@ -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
@@ -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
@@ -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.

0 comments on commit 5c83cd0

Please sign in to comment.
You can’t perform that action at this time.