Loading django/contrib/gis/gdal/raster/source.py +5 −1 Original line number Diff line number Diff line Loading @@ -90,6 +90,10 @@ class GDALRaster(GDALBase): if 'width' not in ds_input or 'height' not in ds_input: raise GDALException('Specify width and height attributes for JSON or dict input.') # Check if srid was specified if 'srid' not in ds_input: raise GDALException('Specify srid for JSON or dict input.') # Create GDAL Raster self._ptr = capi.create_ds( driver._ptr, Loading @@ -108,7 +112,7 @@ class GDALRaster(GDALBase): self.bands[i].nodata_value = band_input['nodata_value'] # Set SRID, default to 0 (this assures SRS is always instanciated) self.srs = ds_input.get('srid', 0) self.srs = ds_input.get('srid') # Set additional properties if provided if 'origin' in ds_input: Loading docs/ref/contrib/gis/gdal.txt +24 −23 Original line number Diff line number Diff line Loading @@ -1118,9 +1118,10 @@ blue. defines the raster source, it is either a path to a file or spatial data with values defining the properties of a new raster (such as size and name). If the input is a file path, the second parameter specifies if the raster should be opened with write access. The following example shows how rasters can be created from different input sources (using the sample data from the GeoDjango tests, see the :ref:`gdal_sample_data` section):: be opened with write access. If the input is raw data, the parameters ``width``, ``heigth``, and ``srid`` are required. The following example shows how rasters can be created from different input sources (using the sample data from the GeoDjango tests, see also the :ref:`gdal_sample_data` section):: >>> from django.contrib.gis.gdal.raster.source import GDALRaster >>> rst = GDALRaster('/path/to/your/raster.tif', write=False) Loading Loading @@ -1148,7 +1149,7 @@ 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'}).name >>> GDALRaster({'width': 10, 'height': 10, 'name': 'myraster', 'srid': 4326}).name 'myraster' .. attribute:: driver Loading @@ -1163,14 +1164,14 @@ blue. An in-memory raster is created through the following example: >>> GDALRaster({'width': 10, 'height': 10}).driver.name >>> GDALRaster({'width': 10, 'height': 10, 'srid': 4326}).driver.name 'MEM' A file based GeoTiff raster is created through the following example: >>> import tempfile >>> rstfile = tempfile.NamedTemporaryFile(suffix='.tif') >>> rst = GDALRaster({'driver': 'GTiff', 'name': rstfile.name, >>> 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 Loading @@ -1181,14 +1182,14 @@ blue. The width of the source in pixels (X-axis). >>> GDALRaster({'width': 10, 'height': 20}).width >>> 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}).height >>> GDALRaster({'width': 10, 'height': 20, 'srid': 4326}).height 20 .. attribute:: srs Loading @@ -1198,12 +1199,12 @@ 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}) >>> rst.srs None >>> rst.srs = 4326 >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.srs.srid 4326 >>> rst.srs = 3086 >>> rst.srs.srid 3086 .. attribute:: geotransform Loading @@ -1220,7 +1221,7 @@ blue. The default is ``[0.0, 1.0, 0.0, 0.0, 0.0, -1.0]``. >>> rst = GDALRaster({'width': 10, 'height': 20}) >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.geotransform [0.0, 1.0, 0.0, 0.0, 0.0, -1.0] Loading @@ -1230,7 +1231,7 @@ blue. reference system of the source, as a point object with ``x`` and ``y`` members. >>> rst = GDALRaster({'width': 10, 'height': 20}) >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.origin [0.0, 0.0] >>> rst.origin.x = 1 Loading @@ -1243,7 +1244,7 @@ blue. point object with ``x`` and ``y`` members. See :attr:`geotransform` for more information. >>> rst = GDALRaster({'width': 10, 'height': 20}) >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.scale [1.0, -1.0] >>> rst.scale.x = 2 Loading @@ -1256,7 +1257,7 @@ blue. with ``x`` and ``y`` members. In case of north up images, these coefficients are both ``0``. >>> rst = GDALRaster({'width': 10, 'height': 20}) >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.skew [0.0, 0.0] >>> rst.skew.x = 3 Loading @@ -1269,7 +1270,7 @@ blue. ``(xmin, ymin, xmax, ymax)`` in the spatial reference system of the source. >>> rst = GDALRaster({'width': 10, 'height': 20}) >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.extent (0.0, -20.0, 10.0, 0.0) >>> rst.origin.x = 100 Loading @@ -1280,8 +1281,8 @@ blue. List of all bands of the source, as :class:`GDALBand` instances. >>> rst = GDALRaster({"width": 1, "height": 2, "bands": [{"data": [0, 1]}, ... {"data": [2, 3]}]}) >>> rst = GDALRaster({"width": 1, "height": 2, 'srid': 4326, ... "bands": [{"data": [0, 1]}, {"data": [2, 3]}]}) >>> len(rst.bands) 2 >>> rst.bands[1].data() Loading Loading @@ -1360,7 +1361,7 @@ blue. For example: >>> rst = GDALRaster({'width': 4, 'height': 4, 'datatype': 1, 'nr_of_bands': 1}) >>> rst = GDALRaster({'width': 4, 'height': 4, 'srid': 4326, 'datatype': 1, 'nr_of_bands': 1}) >>> bnd = rst.bands[0] >>> bnd.data(range(16)) >>> bnd.data() Loading tests/gis_tests/gdal_tests/test_raster.py +2 −1 Original line number Diff line number Diff line Loading @@ -190,7 +190,8 @@ class GDALBandTests(unittest.TestCase): 'name': 'mem_rst', 'width': 10, 'height': 10, 'nr_of_bands': 1 'nr_of_bands': 1, 'srid': 4326, }) bandmem = rsmem.bands[0] Loading Loading
django/contrib/gis/gdal/raster/source.py +5 −1 Original line number Diff line number Diff line Loading @@ -90,6 +90,10 @@ class GDALRaster(GDALBase): if 'width' not in ds_input or 'height' not in ds_input: raise GDALException('Specify width and height attributes for JSON or dict input.') # Check if srid was specified if 'srid' not in ds_input: raise GDALException('Specify srid for JSON or dict input.') # Create GDAL Raster self._ptr = capi.create_ds( driver._ptr, Loading @@ -108,7 +112,7 @@ class GDALRaster(GDALBase): self.bands[i].nodata_value = band_input['nodata_value'] # Set SRID, default to 0 (this assures SRS is always instanciated) self.srs = ds_input.get('srid', 0) self.srs = ds_input.get('srid') # Set additional properties if provided if 'origin' in ds_input: Loading
docs/ref/contrib/gis/gdal.txt +24 −23 Original line number Diff line number Diff line Loading @@ -1118,9 +1118,10 @@ blue. defines the raster source, it is either a path to a file or spatial data with values defining the properties of a new raster (such as size and name). If the input is a file path, the second parameter specifies if the raster should be opened with write access. The following example shows how rasters can be created from different input sources (using the sample data from the GeoDjango tests, see the :ref:`gdal_sample_data` section):: be opened with write access. If the input is raw data, the parameters ``width``, ``heigth``, and ``srid`` are required. The following example shows how rasters can be created from different input sources (using the sample data from the GeoDjango tests, see also the :ref:`gdal_sample_data` section):: >>> from django.contrib.gis.gdal.raster.source import GDALRaster >>> rst = GDALRaster('/path/to/your/raster.tif', write=False) Loading Loading @@ -1148,7 +1149,7 @@ 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'}).name >>> GDALRaster({'width': 10, 'height': 10, 'name': 'myraster', 'srid': 4326}).name 'myraster' .. attribute:: driver Loading @@ -1163,14 +1164,14 @@ blue. An in-memory raster is created through the following example: >>> GDALRaster({'width': 10, 'height': 10}).driver.name >>> GDALRaster({'width': 10, 'height': 10, 'srid': 4326}).driver.name 'MEM' A file based GeoTiff raster is created through the following example: >>> import tempfile >>> rstfile = tempfile.NamedTemporaryFile(suffix='.tif') >>> rst = GDALRaster({'driver': 'GTiff', 'name': rstfile.name, >>> 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 Loading @@ -1181,14 +1182,14 @@ blue. The width of the source in pixels (X-axis). >>> GDALRaster({'width': 10, 'height': 20}).width >>> 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}).height >>> GDALRaster({'width': 10, 'height': 20, 'srid': 4326}).height 20 .. attribute:: srs Loading @@ -1198,12 +1199,12 @@ 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}) >>> rst.srs None >>> rst.srs = 4326 >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.srs.srid 4326 >>> rst.srs = 3086 >>> rst.srs.srid 3086 .. attribute:: geotransform Loading @@ -1220,7 +1221,7 @@ blue. The default is ``[0.0, 1.0, 0.0, 0.0, 0.0, -1.0]``. >>> rst = GDALRaster({'width': 10, 'height': 20}) >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.geotransform [0.0, 1.0, 0.0, 0.0, 0.0, -1.0] Loading @@ -1230,7 +1231,7 @@ blue. reference system of the source, as a point object with ``x`` and ``y`` members. >>> rst = GDALRaster({'width': 10, 'height': 20}) >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.origin [0.0, 0.0] >>> rst.origin.x = 1 Loading @@ -1243,7 +1244,7 @@ blue. point object with ``x`` and ``y`` members. See :attr:`geotransform` for more information. >>> rst = GDALRaster({'width': 10, 'height': 20}) >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.scale [1.0, -1.0] >>> rst.scale.x = 2 Loading @@ -1256,7 +1257,7 @@ blue. with ``x`` and ``y`` members. In case of north up images, these coefficients are both ``0``. >>> rst = GDALRaster({'width': 10, 'height': 20}) >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.skew [0.0, 0.0] >>> rst.skew.x = 3 Loading @@ -1269,7 +1270,7 @@ blue. ``(xmin, ymin, xmax, ymax)`` in the spatial reference system of the source. >>> rst = GDALRaster({'width': 10, 'height': 20}) >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.extent (0.0, -20.0, 10.0, 0.0) >>> rst.origin.x = 100 Loading @@ -1280,8 +1281,8 @@ blue. List of all bands of the source, as :class:`GDALBand` instances. >>> rst = GDALRaster({"width": 1, "height": 2, "bands": [{"data": [0, 1]}, ... {"data": [2, 3]}]}) >>> rst = GDALRaster({"width": 1, "height": 2, 'srid': 4326, ... "bands": [{"data": [0, 1]}, {"data": [2, 3]}]}) >>> len(rst.bands) 2 >>> rst.bands[1].data() Loading Loading @@ -1360,7 +1361,7 @@ blue. For example: >>> rst = GDALRaster({'width': 4, 'height': 4, 'datatype': 1, 'nr_of_bands': 1}) >>> rst = GDALRaster({'width': 4, 'height': 4, 'srid': 4326, 'datatype': 1, 'nr_of_bands': 1}) >>> bnd = rst.bands[0] >>> bnd.data(range(16)) >>> bnd.data() Loading
tests/gis_tests/gdal_tests/test_raster.py +2 −1 Original line number Diff line number Diff line Loading @@ -190,7 +190,8 @@ class GDALBandTests(unittest.TestCase): 'name': 'mem_rst', 'width': 10, 'height': 10, 'nr_of_bands': 1 'nr_of_bands': 1, 'srid': 4326, }) bandmem = rsmem.bands[0] Loading