doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
class Translate(expression, x, y, z=0.0, **extra)
django.ref.contrib.gis.functions#django.contrib.gis.db.models.functions.Translate
class Union(expr1, expr2, **extra)
django.ref.contrib.gis.functions#django.contrib.gis.db.models.functions.Union
class GeometryCollectionField
django.ref.contrib.gis.model-api#django.contrib.gis.db.models.GeometryCollectionField
class GeometryField
django.ref.contrib.gis.model-api#django.contrib.gis.db.models.GeometryField
GeometryField.dim
django.ref.contrib.gis.model-api#django.contrib.gis.db.models.GeometryField.dim
GeometryField.geography
django.ref.contrib.gis.model-api#django.contrib.gis.db.models.GeometryField.geography
class LineStringField
django.ref.contrib.gis.model-api#django.contrib.gis.db.models.LineStringField
class MakeLine(geo_field)
django.ref.contrib.gis.geoquerysets#django.contrib.gis.db.models.MakeLine
class MultiLineStringField
django.ref.contrib.gis.model-api#django.contrib.gis.db.models.MultiLineStringField
class MultiPointField
django.ref.contrib.gis.model-api#django.contrib.gis.db.models.MultiPointField
class MultiPolygonField
django.ref.contrib.gis.model-api#django.contrib.gis.db.models.MultiPolygonField
class PointField
django.ref.contrib.gis.model-api#django.contrib.gis.db.models.PointField
class PolygonField
django.ref.contrib.gis.model-api#django.contrib.gis.db.models.PolygonField
class RasterField
django.ref.contrib.gis.model-api#django.contrib.gis.db.models.RasterField
class Union(geo_field)
django.ref.contrib.gis.geoquerysets#django.contrib.gis.db.models.Union
class Feed In addition to methods provided by the django.contrib.syndication.views.Feed base class, GeoDjango’s Feed class provides the following overrides. Note that these overrides may be done in multiple ways: from django.contrib.gis.feeds import Feed class MyFeed(Feed): # First, as a class attribute. geometry = ... item_geometry = ... # Also a function with no arguments def geometry(self): ... def item_geometry(self): ... # And as a function with a single argument def geometry(self, obj): ... def item_geometry(self, item): ... geometry(obj) Takes the object returned by get_object() and returns the feed’s geometry. Typically this is a GEOSGeometry instance, or can be a tuple to represent a point or a box. For example: class ZipcodeFeed(Feed): def geometry(self, obj): # Can also return: `obj.poly`, and `obj.poly.centroid`. return obj.poly.extent # tuple like: (X0, Y0, X1, Y1). item_geometry(item) Set this to return the geometry for each item in the feed. This can be a GEOSGeometry instance, or a tuple that represents a point coordinate or bounding box. For example: class ZipcodeFeed(Feed): def item_geometry(self, obj): # Returns the polygon. return obj.poly
django.ref.contrib.gis.feeds#django.contrib.gis.feeds.Feed
geometry(obj)
django.ref.contrib.gis.feeds#django.contrib.gis.feeds.Feed.geometry
item_geometry(item)
django.ref.contrib.gis.feeds#django.contrib.gis.feeds.Feed.item_geometry
class GeoAtom1Feed
django.ref.contrib.gis.feeds#django.contrib.gis.feeds.GeoAtom1Feed
class GeoRSSFeed
django.ref.contrib.gis.feeds#django.contrib.gis.feeds.GeoRSSFeed
class W3CGeoFeed
django.ref.contrib.gis.feeds#django.contrib.gis.feeds.W3CGeoFeed
Field.geom_type You generally shouldn’t have to set or change that attribute which should be set up depending on the field class. It matches the OpenGIS standard geometry name.
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.Field.geom_type
Field.srid This is the SRID code that the field value should be transformed to. For example, if the map widget SRID is different from the SRID more generally used by your application or database, the field will automatically convert input values into that SRID.
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.Field.srid
class GeometryCollectionField
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.GeometryCollectionField
class GeometryField
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.GeometryField
class LineStringField
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.LineStringField
class MultiLineStringField
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.MultiLineStringField
class MultiPointField
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.MultiPointField
class MultiPolygonField
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.MultiPolygonField
class PointField
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.PointField
class PolygonField
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.PolygonField
class BaseGeometryWidget This is an abstract base widget containing the logic needed by subclasses. You cannot directly use this widget for a geometry field. Note that the rendering of GeoDjango widgets is based on a template, identified by the template_name class attribute.
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.BaseGeometryWidget
BaseGeometryWidget.display_raw Boolean value specifying if a textarea input showing the serialized representation of the current geometry is visible, mainly for debugging purposes (default is False).
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.BaseGeometryWidget.display_raw
BaseGeometryWidget.geom_type The OpenGIS geometry type, generally set by the form field.
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.BaseGeometryWidget.geom_type
BaseGeometryWidget.map_height
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.BaseGeometryWidget.map_height
BaseGeometryWidget.map_srid SRID code used by the map (default is 4326).
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.BaseGeometryWidget.map_srid
BaseGeometryWidget.map_width Height and width of the widget map (default is 400x600).
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.BaseGeometryWidget.map_width
BaseGeometryWidget.supports_3d Indicates if the widget supports edition of 3D data (default is False).
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.BaseGeometryWidget.supports_3d
BaseGeometryWidget.template_name The template used to render the map widget.
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.BaseGeometryWidget.template_name
class OpenLayersWidget This is the default widget used by all GeoDjango form fields. template_name is gis/openlayers.html. OpenLayersWidget and OSMWidget use the openlayers.js file hosted on the cdnjs.cloudflare.com content-delivery network. You can subclass these widgets in order to specify your own version of the OpenLayers.js file in the js property of the inner Media class (see Assets as a static definition).
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.OpenLayersWidget
class OSMWidget This widget uses an OpenStreetMap base layer to display geographic objects on. Attributes are: template_name gis/openlayers-osm.html default_lat default_lon The default center latitude and longitude are 47 and 5, respectively, which is a location in eastern France. default_zoom The default map zoom is 12. The OpenLayersWidget note about JavaScript file hosting above also applies here. See also this FAQ answer about https access to map tiles.
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.OSMWidget
default_lat
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.OSMWidget.default_lat
default_lon The default center latitude and longitude are 47 and 5, respectively, which is a location in eastern France.
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.OSMWidget.default_lon
default_zoom The default map zoom is 12.
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.OSMWidget.default_zoom
template_name gis/openlayers-osm.html
django.ref.contrib.gis.forms-api#django.contrib.gis.forms.widgets.OSMWidget.template_name
class CoordTransform(source, target)
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.CoordTransform
class DataSource(ds_input, encoding='utf-8') The constructor for DataSource only requires one parameter: the path of the file you want to read. However, OGR also supports a variety of more complex data sources, including databases, that may be accessed by passing a special name string instead of a path. For more information, see the OGR Vector Formats documentation. The name property of a DataSource instance gives the OGR name of the underlying data source that it is using. The optional encoding parameter allows you to specify a non-standard encoding of the strings in the source. This is typically useful when you obtain DjangoUnicodeDecodeError exceptions while reading field values. Once you’ve created your DataSource, you can find out how many layers of data it contains by accessing the layer_count property, or (equivalently) by using the len() function. For information on accessing the layers of data themselves, see the next section: >>> from django.contrib.gis.gdal import DataSource >>> ds = DataSource('/path/to/your/cities.shp') >>> ds.name '/path/to/your/cities.shp' >>> ds.layer_count # This file only contains one layer 1 layer_count Returns the number of layers in the data source. name Returns the name of the data source. Changed in Django 3.2: Support for pathlib.Path ds_input was added.
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.DataSource
layer_count
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.DataSource.layer_count
name
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.DataSource.name
class Driver(dr_input) The Driver class is used internally to wrap an OGR DataSource driver. driver_count Returns the number of OGR vector drivers currently registered.
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Driver
driver_count
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Driver.driver_count
class Envelope(*args) Represents an OGR Envelope structure that contains the minimum and maximum X, Y coordinates for a rectangle bounding box. The naming of the variables is compatible with the OGR Envelope C structure. min_x The value of the minimum X coordinate. min_y The value of the maximum X coordinate. max_x The value of the minimum Y coordinate. max_y The value of the maximum Y coordinate. ur The upper-right coordinate, as a tuple. ll The lower-left coordinate, as a tuple. tuple A tuple representing the envelope. wkt A string representing this envelope as a polygon in WKT format. expand_to_include(*args)
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Envelope
expand_to_include(*args)
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Envelope.expand_to_include
ll
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Envelope.ll
max_x
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Envelope.max_x
max_y
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Envelope.max_y
min_x
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Envelope.min_x
min_y
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Envelope.min_y
tuple
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Envelope.tuple
ur
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Envelope.ur
wkt
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Envelope.wkt
class Feature Feature wraps an OGR feature. You never create a Feature object directly. Instead, you retrieve them from a Layer object. Each feature consists of a geometry and a set of fields containing additional properties. The geometry of a field is accessible via its geom property, which returns an OGRGeometry object. A Feature behaves like a standard Python container for its fields, which it returns as Field objects: you can access a field directly by its index or name, or you can iterate over a feature’s fields, e.g. in a for loop. geom Returns the geometry for this feature, as an OGRGeometry object: >>> city.geom.tuple (-104.609252, 38.255001) get A method that returns the value of the given field (specified by name) for this feature, not a Field wrapper object: >>> city.get('Population') 102121 geom_type Returns the type of geometry for this feature, as an OGRGeomType object. This will be the same for all features in a given layer and is equivalent to the Layer.geom_type property of the Layer object the feature came from. num_fields Returns the number of fields of data associated with the feature. This will be the same for all features in a given layer and is equivalent to the Layer.num_fields property of the Layer object the feature came from. fields Returns a list of the names of the fields of data associated with the feature. This will be the same for all features in a given layer and is equivalent to the Layer.fields property of the Layer object the feature came from. fid Returns the feature identifier within the layer: >>> city.fid 0 layer_name Returns the name of the Layer that the feature came from. This will be the same for all features in a given layer: >>> city.layer_name 'cities' index A method that returns the index of the given field name. This will be the same for all features in a given layer: >>> city.index('Population') 1
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Feature
fid
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Feature.fid
fields
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Feature.fields
geom
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Feature.geom
geom_type
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Feature.geom_type
get
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Feature.get
index
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Feature.index
layer_name
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Feature.layer_name
num_fields
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Feature.num_fields
class Field name Returns the name of this field: >>> city['Name'].name 'Name' type Returns the OGR type of this field, as an integer. The FIELD_CLASSES dictionary maps these values onto subclasses of Field: >>> city['Density'].type 2 type_name Returns a string with the name of the data type of this field: >>> city['Name'].type_name 'String' value Returns the value of this field. The Field class itself returns the value as a string, but each subclass returns the value in the most appropriate form: >>> city['Population'].value 102121 width Returns the width of this field: >>> city['Name'].width 80 precision Returns the numeric precision of this field. This is meaningless (and set to zero) for non-numeric fields: >>> city['Density'].precision 15 as_double() Returns the value of the field as a double (float): >>> city['Density'].as_double() 874.7 as_int() Returns the value of the field as an integer: >>> city['Population'].as_int() 102121 as_string() Returns the value of the field as a string: >>> city['Name'].as_string() 'Pueblo' as_datetime() Returns the value of the field as a tuple of date and time components: >>> city['Created'].as_datetime() (c_long(1999), c_long(5), c_long(23), c_long(0), c_long(0), c_long(0), c_long(0))
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Field
as_datetime()
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Field.as_datetime
as_double()
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Field.as_double
as_int()
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Field.as_int
as_string()
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Field.as_string
name
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Field.name
precision
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Field.precision
type
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Field.type
type_name
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Field.type_name
value
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Field.value
width
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.Field.width
class GDALBand GDALBand instances are not created explicitly, but rather obtained from a GDALRaster object, through its bands attribute. The GDALBands contain the actual pixel values of the raster. description The name or description of the band, if any. width The width of the band in pixels (X-axis). height The height of the band in pixels (Y-axis). pixel_count The total number of pixels in this band. Is equal to width * height. statistics(refresh=False, approximate=False) Compute statistics on the pixel values of this band. The return value is a tuple with the following structure: (minimum, maximum, mean, standard deviation). If the approximate argument is set to True, the statistics may be computed based on overviews or a subset of image tiles. If the refresh argument is set to True, the statistics will be computed from the data directly, and the cache will be updated with the result. If a persistent cache value is found, that value is returned. For raster formats using Persistent Auxiliary Metadata (PAM) services, the statistics might be cached in an auxiliary file. In some cases this metadata might be out of sync with the pixel values or cause values from a previous call to be returned which don’t reflect the value of the approximate argument. In such cases, use the refresh argument to get updated values and store them in the cache. For empty bands (where all pixel values are “no data”), all statistics are returned as None. The statistics can also be retrieved directly by accessing the min, max, mean, and std properties. min The minimum pixel value of the band (excluding the “no data” value). max The maximum pixel value of the band (excluding the “no data” value). mean The mean of all pixel values of the band (excluding the “no data” value). std The standard deviation of all pixel values of the band (excluding the “no data” value). nodata_value The “no data” value for a band is generally a special marker value used to mark pixels that are not valid data. Such pixels should generally not be displayed, nor contribute to analysis operations. To delete an existing “no data” value, set this property to None (requires GDAL ≥ 2.1). datatype(as_string=False) The data type contained in the band, as an integer constant between 0 (Unknown) and 11. If as_string is True, the data type is returned as a string with the following possible values: GDT_Unknown, GDT_Byte, GDT_UInt16, GDT_Int16, GDT_UInt32, GDT_Int32, GDT_Float32, GDT_Float64, GDT_CInt16, GDT_CInt32, GDT_CFloat32, and GDT_CFloat64. color_interp(as_string=False) The color interpretation for the band, as an integer between 0and 16. If as_string is True, the data type is returned as a string with the following possible values: GCI_Undefined, GCI_GrayIndex, GCI_PaletteIndex, GCI_RedBand, GCI_GreenBand, GCI_BlueBand, GCI_AlphaBand, GCI_HueBand, GCI_SaturationBand, GCI_LightnessBand, GCI_CyanBand, GCI_MagentaBand, GCI_YellowBand, GCI_BlackBand, GCI_YCbCr_YBand, GCI_YCbCr_CbBand, and GCI_YCbCr_CrBand. GCI_YCbCr_CrBand also represents GCI_Max because both correspond to the integer 16, but only GCI_YCbCr_CrBand is returned as a string. data(data=None, offset=None, size=None, shape=None) The accessor to the pixel values of the GDALBand. Returns the complete data array if no parameters are provided. A subset of the pixel array can be requested by specifying an offset and block size as tuples. If NumPy is available, the data is returned as NumPy array. For performance reasons, it is highly recommended to use NumPy. Data is written to the GDALBand if the data parameter is provided. The input can be of one of the following types - packed string, buffer, list, array, and NumPy array. The number of items in the input should normally correspond to the total number of pixels in the band, or to the number of pixels for a specific block of pixel values if the offset and size parameters are provided. If the number of items in the input is different from the target pixel block, the shape parameter must be specified. The shape is a tuple that specifies the width and height of the input data in pixels. The data is then replicated to update the pixel values of the selected block. This is useful to fill an entire band with a single value, for instance. For example: >>> rst = GDALRaster({'width': 4, 'height': 4, 'srid': 4326, 'datatype': 1, 'nr_of_bands': 1}) >>> bnd = rst.bands[0] >>> bnd.data(range(16)) >>> bnd.data() array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]], dtype=int8) >>> bnd.data(offset=(1, 1), size=(2, 2)) array([[ 5, 6], [ 9, 10]], dtype=int8) >>> bnd.data(data=[-1, -2, -3, -4], offset=(1, 1), size=(2, 2)) >>> bnd.data() array([[ 0, 1, 2, 3], [ 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() array([[ 0, 1, 2, 3], [ 4, -99, -88, 7], [ 8, -77, -66, 11], [ 12, 13, 14, 15]], dtype=int8) >>> bnd.data([1], shape=(1, 1)) >>> bnd.data() array([[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], dtype=uint8) >>> bnd.data(range(4), shape=(1, 4)) array([[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]], dtype=uint8) metadata The metadata of this band. The functionality is identical to GDALRaster.metadata.
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand
color_interp(as_string=False) The color interpretation for the band, as an integer between 0and 16. If as_string is True, the data type is returned as a string with the following possible values: GCI_Undefined, GCI_GrayIndex, GCI_PaletteIndex, GCI_RedBand, GCI_GreenBand, GCI_BlueBand, GCI_AlphaBand, GCI_HueBand, GCI_SaturationBand, GCI_LightnessBand, GCI_CyanBand, GCI_MagentaBand, GCI_YellowBand, GCI_BlackBand, GCI_YCbCr_YBand, GCI_YCbCr_CbBand, and GCI_YCbCr_CrBand. GCI_YCbCr_CrBand also represents GCI_Max because both correspond to the integer 16, but only GCI_YCbCr_CrBand is returned as a string.
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.color_interp
data(data=None, offset=None, size=None, shape=None) The accessor to the pixel values of the GDALBand. Returns the complete data array if no parameters are provided. A subset of the pixel array can be requested by specifying an offset and block size as tuples. If NumPy is available, the data is returned as NumPy array. For performance reasons, it is highly recommended to use NumPy. Data is written to the GDALBand if the data parameter is provided. The input can be of one of the following types - packed string, buffer, list, array, and NumPy array. The number of items in the input should normally correspond to the total number of pixels in the band, or to the number of pixels for a specific block of pixel values if the offset and size parameters are provided. If the number of items in the input is different from the target pixel block, the shape parameter must be specified. The shape is a tuple that specifies the width and height of the input data in pixels. The data is then replicated to update the pixel values of the selected block. This is useful to fill an entire band with a single value, for instance. For example: >>> rst = GDALRaster({'width': 4, 'height': 4, 'srid': 4326, 'datatype': 1, 'nr_of_bands': 1}) >>> bnd = rst.bands[0] >>> bnd.data(range(16)) >>> bnd.data() array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]], dtype=int8) >>> bnd.data(offset=(1, 1), size=(2, 2)) array([[ 5, 6], [ 9, 10]], dtype=int8) >>> bnd.data(data=[-1, -2, -3, -4], offset=(1, 1), size=(2, 2)) >>> bnd.data() array([[ 0, 1, 2, 3], [ 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() array([[ 0, 1, 2, 3], [ 4, -99, -88, 7], [ 8, -77, -66, 11], [ 12, 13, 14, 15]], dtype=int8) >>> bnd.data([1], shape=(1, 1)) >>> bnd.data() array([[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], dtype=uint8) >>> bnd.data(range(4), shape=(1, 4)) array([[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]], dtype=uint8)
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.data
datatype(as_string=False) The data type contained in the band, as an integer constant between 0 (Unknown) and 11. If as_string is True, the data type is returned as a string with the following possible values: GDT_Unknown, GDT_Byte, GDT_UInt16, GDT_Int16, GDT_UInt32, GDT_Int32, GDT_Float32, GDT_Float64, GDT_CInt16, GDT_CInt32, GDT_CFloat32, and GDT_CFloat64.
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.datatype
description The name or description of the band, if any.
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.description
height The height of the band in pixels (Y-axis).
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.height
max The maximum pixel value of the band (excluding the “no data” value).
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.max
mean The mean of all pixel values of the band (excluding the “no data” value).
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.mean
metadata The metadata of this band. The functionality is identical to GDALRaster.metadata.
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.metadata
min The minimum pixel value of the band (excluding the “no data” value).
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.min
nodata_value The “no data” value for a band is generally a special marker value used to mark pixels that are not valid data. Such pixels should generally not be displayed, nor contribute to analysis operations. To delete an existing “no data” value, set this property to None (requires GDAL ≥ 2.1).
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.nodata_value
pixel_count The total number of pixels in this band. Is equal to width * height.
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.pixel_count
statistics(refresh=False, approximate=False) Compute statistics on the pixel values of this band. The return value is a tuple with the following structure: (minimum, maximum, mean, standard deviation). If the approximate argument is set to True, the statistics may be computed based on overviews or a subset of image tiles. If the refresh argument is set to True, the statistics will be computed from the data directly, and the cache will be updated with the result. If a persistent cache value is found, that value is returned. For raster formats using Persistent Auxiliary Metadata (PAM) services, the statistics might be cached in an auxiliary file. In some cases this metadata might be out of sync with the pixel values or cause values from a previous call to be returned which don’t reflect the value of the approximate argument. In such cases, use the refresh argument to get updated values and store them in the cache. For empty bands (where all pixel values are “no data”), all statistics are returned as None. The statistics can also be retrieved directly by accessing the min, max, mean, and std properties.
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.statistics
std The standard deviation of all pixel values of the band (excluding the “no data” value).
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.std
width The width of the band in pixels (X-axis).
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALBand.width
class GDALRaster(ds_input, write=False) The constructor for GDALRaster accepts two parameters. The first parameter defines the raster source, and the second parameter defines if a raster should be opened in write mode. For newly-created rasters, the second parameter is ignored and the new raster is always created in write mode. The first parameter can take three forms: a string representing a file path (filesystem or GDAL virtual filesystem), a dictionary with values defining a new raster, or a bytes object representing a raster file. If the input is a file path, the raster is opened from there. If the input is raw data in a dictionary, the parameters width, height, and srid are required. If the input is a bytes object, it will be opened using a GDAL virtual filesystem. For a detailed description of how to create rasters using dictionary input, see Creating rasters from data. For a detailed description of how to create rasters in the virtual filesystem, see Using GDAL’s Virtual Filesystem. The following example shows how rasters can be created from different input sources (using the sample data from the GeoDjango tests; see also the Sample Data section). >>> from django.contrib.gis.gdal import GDALRaster >>> 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.srs.srid 4326 >>> rst.width, rst.height (4, 4) >>> rst.bands[0].data() array([[5, 5, 5, 5], [5, 2, 3, 5], [5, 2, 3, 5], [5, 5, 5, 5]], dtype=uint8) >>> rst_file = open('/path/to/your/raster.tif', 'rb') >>> rst_bytes = rst_file.read() >>> rst = GDALRaster(rst_bytes) >>> rst.is_vsi_based True >>> rst.name # Stored in a random path in the vsimem filesystem. '/vsimem/da300bdb-129d-49a8-b336-e410a9428dad' Changed in Django 4.0: Creating rasters in any GDAL virtual filesystem was allowed. name 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 'myraster' driver The name of the GDAL driver used to handle the input file. For GDALRasters created from a file, the driver type is detected automatically. The creation of rasters from scratch is an in-memory raster by default ('MEM'), but can be altered as needed. For instance, use GTiff for a GeoTiff file. For a list of file types, see also the GDAL Raster Formats list. An in-memory raster is created through the following example: >>> 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, '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 'GTiff' width The width of the source in pixels (X-axis). >>> GDALRaster({'width': 10, 'height': 20, 'srid': 4326}).width 10 height The height of the source in pixels (Y-axis). >>> GDALRaster({'width': 10, 'height': 20, 'srid': 4326}).height 20 srs The spatial reference system of the raster, as a SpatialReference instance. The SRS can be changed by setting it to an other SpatialReference or providing any input that is accepted by the SpatialReference constructor. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.srs.srid 4326 >>> rst.srs = 3086 >>> rst.srs.srid 3086 srid The Spatial Reference System Identifier (SRID) of the raster. This property is a shortcut to getting or setting the SRID through the srs attribute. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.srid 4326 >>> rst.srid = 3086 >>> rst.srid 3086 >>> rst.srs.srid # This is equivalent 3086 geotransform The affine transformation matrix used to georeference the source, as a tuple of six coefficients which map pixel/line coordinates into georeferenced space using the following relationship: Xgeo = GT(0) + Xpixel*GT(1) + Yline*GT(2) Ygeo = GT(3) + Xpixel*GT(4) + Yline*GT(5) The same values can be retrieved by accessing the origin (indices 0 and 3), scale (indices 1 and 5) and skew (indices 2 and 4) properties. The default is [0.0, 1.0, 0.0, 0.0, 0.0, -1.0]. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.geotransform [0.0, 1.0, 0.0, 0.0, 0.0, -1.0] origin Coordinates of the top left origin of the raster in the spatial reference system of the source, as a point object with x and y members. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.origin [0.0, 0.0] >>> rst.origin.x = 1 >>> rst.origin [1.0, 0.0] scale Pixel width and height used for georeferencing the raster, as a point object with x and y members. See geotransform for more information. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.scale [1.0, -1.0] >>> rst.scale.x = 2 >>> rst.scale [2.0, -1.0] skew Skew coefficients used to georeference the raster, as a point object with x and y members. In case of north up images, these coefficients are both 0. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.skew [0.0, 0.0] >>> rst.skew.x = 3 >>> rst.skew [3.0, 0.0] extent Extent (boundary values) of the raster source, as a 4-tuple (xmin, ymin, xmax, ymax) in the spatial reference system of the source. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.extent (0.0, -20.0, 10.0, 0.0) >>> rst.origin.x = 100 >>> rst.extent (100.0, -20.0, 110.0, 0.0) bands List of all bands of the source, as GDALBand instances. >>> rst = GDALRaster({"width": 1, "height": 2, 'srid': 4326, ... "bands": [{"data": [0, 1]}, {"data": [2, 3]}]}) >>> len(rst.bands) 2 >>> rst.bands[1].data() array([[ 2., 3.]], dtype=float32) warp(ds_input, resampling='NearestNeighbour', max_error=0.0) Returns a warped version of this raster. The warping parameters can be specified through the ds_input argument. The use of ds_input is analogous to the corresponding argument of the class constructor. It is a dictionary with the characteristics of the target raster. Allowed dictionary key values are width, height, SRID, origin, scale, skew, datatype, driver, and name (filename). By default, the warp functions keeps most parameters equal to the values of the original source raster, so only parameters that should be changed need to be specified. Note that this includes the driver, so for file-based rasters the warp function will create a new raster on disk. The only parameter that is set differently from the source raster is the name. The default value of the raster name is the name of the source raster appended with '_copy' + source_driver_name. For file-based rasters it is recommended to provide the file path of the target raster. The resampling algorithm used for warping can be specified with the resampling argument. The default is NearestNeighbor, and the other allowed values are Bilinear, Cubic, CubicSpline, Lanczos, Average, and Mode. The max_error argument can be used to specify the maximum error measured in input pixels that is allowed in approximating the transformation. The default is 0.0 for exact calculations. For users familiar with GDAL, this function has a similar functionality to the gdalwarp command-line utility. 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}] ... }) >>> target = rst.warp({"scale": [200, -200], "width": 3, "height": 3}) >>> target.bands[0].data() array([[ 7., 9., 11.], [ 19., 21., 23.], [ 31., 33., 35.]], dtype=float32) transform(srs, driver=None, name=None, resampling='NearestNeighbour', max_error=0.0) Transforms this raster to a different spatial reference system (srs), which may be a SpatialReference object, or any other input accepted by SpatialReference (including spatial reference WKT and PROJ strings, or an integer SRID). It calculates the bounds and scale of the current raster in the new spatial reference system and warps the raster using the warp function. By default, the driver of the source raster is used and the name of the raster is the original name appended with '_copy' + source_driver_name. A different driver or name can be specified with the driver and name arguments. The default resampling algorithm is NearestNeighbour but can be changed using the resampling argument. The default maximum allowed error for resampling is 0.0 and can be changed using the max_error argument. Consult the 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}] ... }) >>> target_srs = SpatialReference(4326) >>> target = rst.transform(target_srs) >>> target.origin [-82.98492744885776, 27.601924753080144] Changed in Django 3.2: Support for SpatialReference srs was added info Returns a string with a summary of the raster. This is equivalent to the gdalinfo command line utility. metadata The metadata of this raster, represented as a nested dictionary. The first-level key is the metadata domain. The second-level contains the metadata item names and values from each domain. To set or update a metadata item, pass the corresponding metadata item to the method using the nested structure described above. Only keys that are in the specified dictionary are updated; the rest of the metadata remains unchanged. To remove a metadata item, use None as the metadata value. >>> 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': None, 'VERSION': '2.0'}} >>> rst.metadata {'DEFAULT': {'VERSION': '2.0'}} vsi_buffer A bytes representation of this raster. Returns None for rasters that are not stored in GDAL’s virtual filesystem. is_vsi_based A boolean indicating if this raster is stored in GDAL’s virtual filesystem.
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALRaster
bands List of all bands of the source, as GDALBand instances. >>> rst = GDALRaster({"width": 1, "height": 2, 'srid': 4326, ... "bands": [{"data": [0, 1]}, {"data": [2, 3]}]}) >>> len(rst.bands) 2 >>> rst.bands[1].data() array([[ 2., 3.]], dtype=float32)
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALRaster.bands
driver The name of the GDAL driver used to handle the input file. For GDALRasters created from a file, the driver type is detected automatically. The creation of rasters from scratch is an in-memory raster by default ('MEM'), but can be altered as needed. For instance, use GTiff for a GeoTiff file. For a list of file types, see also the GDAL Raster Formats list. An in-memory raster is created through the following example: >>> 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, '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 'GTiff'
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALRaster.driver
extent Extent (boundary values) of the raster source, as a 4-tuple (xmin, ymin, xmax, ymax) in the spatial reference system of the source. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.extent (0.0, -20.0, 10.0, 0.0) >>> rst.origin.x = 100 >>> rst.extent (100.0, -20.0, 110.0, 0.0)
django.ref.contrib.gis.gdal#django.contrib.gis.gdal.GDALRaster.extent