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