summaryrefslogtreecommitdiff
path: root/docs/ref/contrib
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-10-25 12:27:27 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-10-25 12:27:56 +0200
commit415ef34c4c2d4e9416ecf04ddf8cfb33585f1934 (patch)
tree12194fbcd557df1cd3ea5099307da032ad360812 /docs/ref/contrib
parent8b18e0bb3ba8bb1f51e15487a6d5402853e637ae (diff)
[5.0.x] Added missing pycon directives in various docs.
Backport of 718b32c6918037cfc746d7867333d79a3c887a8c from main
Diffstat (limited to 'docs/ref/contrib')
-rw-r--r--docs/ref/contrib/gis/gdal.txt160
-rw-r--r--docs/ref/contrib/postgres/search.txt16
2 files changed, 122 insertions, 54 deletions
diff --git a/docs/ref/contrib/gis/gdal.txt b/docs/ref/contrib/gis/gdal.txt
index 2eeb3818c6..9011aa6e2b 100644
--- a/docs/ref/contrib/gis/gdal.txt
+++ b/docs/ref/contrib/gis/gdal.txt
@@ -1246,25 +1246,31 @@ blue.
sources (using the sample data from the GeoDjango tests; see also the
:ref:`gdal_sample_data` section).
+ .. code-block:: pycon
+
>>> from django.contrib.gis.gdal import GDALRaster
- >>> rst = GDALRaster('/path/to/your/raster.tif', write=False)
+ >>> rst = GDALRaster("/path/to/your/raster.tif", write=False)
>>> rst.name
'/path/to/your/raster.tif'
>>> rst.width, rst.height # This file has 163 x 174 pixels
(163, 174)
- >>> rst = GDALRaster({ # Creates an in-memory raster
- ... 'srid': 4326,
- ... 'width': 4,
- ... 'height': 4,
- ... 'datatype': 1,
- ... 'bands': [{
- ... 'data': (2, 3),
- ... 'offset': (1, 1),
- ... 'size': (2, 2),
- ... 'shape': (2, 1),
- ... 'nodata_value': 5,
- ... }]
- ... })
+ >>> rst = GDALRaster(
+ ... { # Creates an in-memory raster
+ ... "srid": 4326,
+ ... "width": 4,
+ ... "height": 4,
+ ... "datatype": 1,
+ ... "bands": [
+ ... {
+ ... "data": (2, 3),
+ ... "offset": (1, 1),
+ ... "size": (2, 2),
+ ... "shape": (2, 1),
+ ... "nodata_value": 5,
+ ... }
+ ... ],
+ ... }
+ ... )
>>> rst.srs.srid
4326
>>> rst.width, rst.height
@@ -1274,7 +1280,7 @@ blue.
[5, 2, 3, 5],
[5, 2, 3, 5],
[5, 5, 5, 5]], dtype=uint8)
- >>> rst_file = open('/path/to/your/raster.tif', 'rb')
+ >>> rst_file = open("/path/to/your/raster.tif", "rb")
>>> rst_bytes = rst_file.read()
>>> rst = GDALRaster(rst_bytes)
>>> rst.is_vsi_based
@@ -1291,7 +1297,9 @@ blue.
The name of the source which is equivalent to the input file path or the name
provided upon instantiation.
- >>> GDALRaster({'width': 10, 'height': 10, 'name': 'myraster', 'srid': 4326}).name
+ .. code-block:: pycon
+
+ >>> GDALRaster({"width": 10, "height": 10, "name": "myraster", "srid": 4326}).name
'myraster'
.. attribute:: driver
@@ -1306,15 +1314,27 @@ blue.
An in-memory raster is created through the following example:
- >>> GDALRaster({'width': 10, 'height': 10, 'srid': 4326}).driver.name
+ .. code-block:: pycon
+
+ >>> GDALRaster({"width": 10, "height": 10, "srid": 4326}).driver.name
'MEM'
A file based GeoTiff raster is created through the following example:
+ .. code-block:: pycon
+
>>> import tempfile
- >>> rstfile = tempfile.NamedTemporaryFile(suffix='.tif')
- >>> rst = GDALRaster({'driver': 'GTiff', 'name': rstfile.name, 'srid': 4326,
- ... 'width': 255, 'height': 255, 'nr_of_bands': 1})
+ >>> rstfile = tempfile.NamedTemporaryFile(suffix=".tif")
+ >>> rst = GDALRaster(
+ ... {
+ ... "driver": "GTiff",
+ ... "name": rstfile.name,
+ ... "srid": 4326,
+ ... "width": 255,
+ ... "height": 255,
+ ... "nr_of_bands": 1,
+ ... }
+ ... )
>>> rst.name
'/tmp/tmp7x9H4J.tif' # The exact filename will be different on your computer
>>> rst.driver.name
@@ -1324,14 +1344,18 @@ blue.
The width of the source in pixels (X-axis).
- >>> GDALRaster({'width': 10, 'height': 20, 'srid': 4326}).width
+ .. code-block:: pycon
+
+ >>> GDALRaster({"width": 10, "height": 20, "srid": 4326}).width
10
.. attribute:: height
The height of the source in pixels (Y-axis).
- >>> GDALRaster({'width': 10, 'height': 20, 'srid': 4326}).height
+ .. code-block:: pycon
+
+ >>> GDALRaster({"width": 10, "height": 20, "srid": 4326}).height
20
.. attribute:: srs
@@ -1341,7 +1365,9 @@ blue.
setting it to an other :class:`SpatialReference` or providing any input
that is accepted by the :class:`SpatialReference` constructor.
- >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
+ .. code-block:: pycon
+
+ >>> rst = GDALRaster({"width": 10, "height": 20, "srid": 4326})
>>> rst.srs.srid
4326
>>> rst.srs = 3086
@@ -1354,7 +1380,9 @@ blue.
property is a shortcut to getting or setting the SRID through the
:attr:`srs` attribute.
- >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
+ .. code-block:: pycon
+
+ >>> rst = GDALRaster({"width": 10, "height": 20, "srid": 4326})
>>> rst.srid
4326
>>> rst.srid = 3086
@@ -1378,7 +1406,9 @@ blue.
The default is ``[0.0, 1.0, 0.0, 0.0, 0.0, -1.0]``.
- >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
+ .. code-block:: pycon
+
+ >>> rst = GDALRaster({"width": 10, "height": 20, "srid": 4326})
>>> rst.geotransform
[0.0, 1.0, 0.0, 0.0, 0.0, -1.0]
@@ -1388,7 +1418,9 @@ blue.
reference system of the source, as a point object with ``x`` and ``y``
members.
- >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
+ .. code-block:: pycon
+
+ >>> rst = GDALRaster({"width": 10, "height": 20, "srid": 4326})
>>> rst.origin
[0.0, 0.0]
>>> rst.origin.x = 1
@@ -1401,7 +1433,9 @@ blue.
object with ``x`` and ``y`` members. See :attr:`geotransform` for more
information.
- >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
+ .. code-block:: pycon
+
+ >>> rst = GDALRaster({"width": 10, "height": 20, "srid": 4326})
>>> rst.scale
[1.0, -1.0]
>>> rst.scale.x = 2
@@ -1414,7 +1448,9 @@ blue.
with ``x`` and ``y`` members. In case of north up images, these
coefficients are both ``0``.
- >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
+ .. code-block:: pycon
+
+ >>> rst = GDALRaster({"width": 10, "height": 20, "srid": 4326})
>>> rst.skew
[0.0, 0.0]
>>> rst.skew.x = 3
@@ -1427,7 +1463,9 @@ blue.
``(xmin, ymin, xmax, ymax)`` in the spatial reference system of the
source.
- >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
+ .. code-block:: pycon
+
+ >>> rst = GDALRaster({"width": 10, "height": 20, "srid": 4326})
>>> rst.extent
(0.0, -20.0, 10.0, 0.0)
>>> rst.origin.x = 100
@@ -1438,8 +1476,16 @@ blue.
List of all bands of the source, as :class:`GDALBand` instances.
- >>> rst = GDALRaster({"width": 1, "height": 2, 'srid': 4326,
- ... "bands": [{"data": [0, 1]}, {"data": [2, 3]}]})
+ .. code-block:: pycon
+
+ >>> rst = GDALRaster(
+ ... {
+ ... "width": 1,
+ ... "height": 2,
+ ... "srid": 4326,
+ ... "bands": [{"data": [0, 1]}, {"data": [2, 3]}],
+ ... }
+ ... )
>>> len(rst.bands)
2
>>> rst.bands[1].data()
@@ -1482,12 +1528,18 @@ blue.
For example, the warp function can be used for aggregating a raster to
the double of its original pixel scale:
- >>> rst = GDALRaster({
- ... "width": 6, "height": 6, "srid": 3086,
- ... "origin": [500000, 400000],
- ... "scale": [100, -100],
- ... "bands": [{"data": range(36), "nodata_value": 99}]
- ... })
+ .. code-block:: pycon
+
+ >>> rst = GDALRaster(
+ ... {
+ ... "width": 6,
+ ... "height": 6,
+ ... "srid": 3086,
+ ... "origin": [500000, 400000],
+ ... "scale": [100, -100],
+ ... "bands": [{"data": range(36), "nodata_value": 99}],
+ ... }
+ ... )
>>> target = rst.warp({"scale": [200, -200], "width": 3, "height": 3})
>>> target.bands[0].data()
array([[ 7., 9., 11.],
@@ -1516,12 +1568,18 @@ blue.
argument. Consult the :attr:`~GDALRaster.warp` documentation for detail
on those arguments.
- >>> rst = GDALRaster({
- ... "width": 6, "height": 6, "srid": 3086,
- ... "origin": [500000, 400000],
- ... "scale": [100, -100],
- ... "bands": [{"data": range(36), "nodata_value": 99}]
- ... })
+ .. code-block:: pycon
+
+ >>> rst = GDALRaster(
+ ... {
+ ... "width": 6,
+ ... "height": 6,
+ ... "srid": 3086,
+ ... "origin": [500000, 400000],
+ ... "scale": [100, -100],
+ ... "bands": [{"data": range(36), "nodata_value": 99}],
+ ... }
+ ... )
>>> target_srs = SpatialReference(4326)
>>> target = rst.transform(target_srs)
>>> target.origin
@@ -1547,13 +1605,15 @@ blue.
To remove a metadata item, use ``None`` as the metadata value.
- >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
+ .. code-block:: pycon
+
+ >>> rst = GDALRaster({"width": 10, "height": 20, "srid": 4326})
>>> rst.metadata
{}
- >>> rst.metadata = {'DEFAULT': {'OWNER': 'Django', 'VERSION': '1.0'}}
+ >>> rst.metadata = {"DEFAULT": {"OWNER": "Django", "VERSION": "1.0"}}
>>> rst.metadata
{'DEFAULT': {'OWNER': 'Django', 'VERSION': '1.0'}}
- >>> rst.metadata = {'DEFAULT': {'OWNER': None, 'VERSION': '2.0'}}
+ >>> rst.metadata = {"DEFAULT": {"OWNER": None, "VERSION": "2.0"}}
>>> rst.metadata
{'DEFAULT': {'VERSION': '2.0'}}
@@ -1691,7 +1751,11 @@ blue.
For example:
- >>> rst = GDALRaster({'width': 4, 'height': 4, 'srid': 4326, 'datatype': 1, 'nr_of_bands': 1})
+ .. code-block:: pycon
+
+ >>> rst = GDALRaster(
+ ... {"width": 4, "height": 4, "srid": 4326, "datatype": 1, "nr_of_bands": 1}
+ ... )
>>> bnd = rst.bands[0]
>>> bnd.data(range(16))
>>> bnd.data()
@@ -1708,7 +1772,7 @@ blue.
[ 4, -1, -2, 7],
[ 8, -3, -4, 11],
[12, 13, 14, 15]], dtype=int8)
- >>> bnd.data(data='\x9d\xa8\xb3\xbe', offset=(1, 1), size=(2, 2))
+ >>> bnd.data(data="\x9d\xa8\xb3\xbe", offset=(1, 1), size=(2, 2))
>>> bnd.data()
array([[ 0, 1, 2, 3],
[ 4, -99, -88, 7],
diff --git a/docs/ref/contrib/postgres/search.txt b/docs/ref/contrib/postgres/search.txt
index 699f81bd11..af9d3ee357 100644
--- a/docs/ref/contrib/postgres/search.txt
+++ b/docs/ref/contrib/postgres/search.txt
@@ -94,13 +94,17 @@ Examples:
.. _Full Text Search docs: https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
+.. code-block:: pycon
+
>>> from django.contrib.postgres.search import SearchQuery
- >>> SearchQuery('red tomato') # two keywords
- >>> SearchQuery('tomato red') # same results as above
- >>> SearchQuery('red tomato', search_type='phrase') # a phrase
- >>> SearchQuery('tomato red', search_type='phrase') # a different phrase
- >>> SearchQuery("'tomato' & ('red' | 'green')", search_type='raw') # boolean operators
- >>> SearchQuery("'tomato' ('red' OR 'green')", search_type='websearch') # websearch operators
+ >>> SearchQuery("red tomato") # two keywords
+ >>> SearchQuery("tomato red") # same results as above
+ >>> SearchQuery("red tomato", search_type="phrase") # a phrase
+ >>> SearchQuery("tomato red", search_type="phrase") # a different phrase
+ >>> SearchQuery("'tomato' & ('red' | 'green')", search_type="raw") # boolean operators
+ >>> SearchQuery(
+ ... "'tomato' ('red' OR 'green')", search_type="websearch"
+ ... ) # websearch operators
``SearchQuery`` terms can be combined logically to provide more flexibility: