|
|
@ -18,8 +18,8 @@ to raster (image) data.
|
|
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
|
|
Although the module is named ``gdal``, GeoDjango only supports
|
|
|
|
Although the module is named ``gdal``, GeoDjango only supports some of the
|
|
|
|
some of the capabilities of OGR and GDAL's raster features at this time.
|
|
|
|
capabilities of OGR and GDAL's raster features at this time.
|
|
|
|
|
|
|
|
|
|
|
|
__ http://www.gdal.org/
|
|
|
|
__ http://www.gdal.org/
|
|
|
|
__ http://www.gdal.org/ogr_arch.html
|
|
|
|
__ http://www.gdal.org/ogr_arch.html
|
|
|
@ -61,22 +61,20 @@ each feature in that layer.
|
|
|
|
.. class:: DataSource(ds_input, encoding='utf-8')
|
|
|
|
.. class:: DataSource(ds_input, encoding='utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
The constructor for ``DataSource`` only requires one parameter: the path of
|
|
|
|
The constructor for ``DataSource`` only requires one parameter: the path of
|
|
|
|
the file you want to read. However, OGR
|
|
|
|
the file you want to read. However, OGR also supports a variety of more
|
|
|
|
also supports a variety of more complex data sources, including
|
|
|
|
complex data sources, including databases, that may be accessed by passing
|
|
|
|
databases, that may be accessed by passing a special name string instead
|
|
|
|
a special name string instead of a path. For more information, see the
|
|
|
|
of a path. For more information, see the `OGR Vector Formats`__
|
|
|
|
`OGR Vector Formats`__ documentation. The :attr:`name` property of a
|
|
|
|
documentation. The :attr:`name` property of a ``DataSource``
|
|
|
|
``DataSource`` instance gives the OGR name of the underlying data source
|
|
|
|
instance gives the OGR name of the underlying data source that it is
|
|
|
|
that it is using.
|
|
|
|
using.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The optional ``encoding`` parameter allows you to
|
|
|
|
The optional ``encoding`` parameter allows you to specify a non-standard
|
|
|
|
specify a non-standard encoding of the strings in the source. This is
|
|
|
|
encoding of the strings in the source. This is typically useful when you
|
|
|
|
typically useful when you obtain ``DjangoUnicodeDecodeError`` exceptions
|
|
|
|
obtain ``DjangoUnicodeDecodeError`` exceptions while reading field values.
|
|
|
|
while reading field values.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Once you've created your ``DataSource``, you can find out how many
|
|
|
|
Once you've created your ``DataSource``, you can find out how many layers
|
|
|
|
layers of data it contains by accessing the :attr:`layer_count` property,
|
|
|
|
of data it contains by accessing the :attr:`layer_count` property, or
|
|
|
|
or (equivalently) by using the ``len()`` function. For information on
|
|
|
|
(equivalently) by using the ``len()`` function. For information on
|
|
|
|
accessing the layers of data themselves, see the next section::
|
|
|
|
accessing the layers of data themselves, see the next section::
|
|
|
|
|
|
|
|
|
|
|
|
>>> from django.contrib.gis.gdal import DataSource
|
|
|
|
>>> from django.contrib.gis.gdal import DataSource
|
|
|
@ -101,18 +99,17 @@ __ http://www.gdal.org/ogr_formats.html
|
|
|
|
|
|
|
|
|
|
|
|
.. class:: Layer
|
|
|
|
.. class:: Layer
|
|
|
|
|
|
|
|
|
|
|
|
``Layer`` is a wrapper for a layer of data in a ``DataSource`` object.
|
|
|
|
``Layer`` is a wrapper for a layer of data in a ``DataSource`` object. You
|
|
|
|
You never create a ``Layer`` object directly. Instead, you retrieve
|
|
|
|
never create a ``Layer`` object directly. Instead, you retrieve them from
|
|
|
|
them from a :class:`DataSource` object, which is essentially a standard
|
|
|
|
a :class:`DataSource` object, which is essentially a standard Python
|
|
|
|
Python container of ``Layer`` objects. For example, you can access a
|
|
|
|
container of ``Layer`` objects. For example, you can access a specific
|
|
|
|
specific layer by its index (e.g. ``ds[0]`` to access the first
|
|
|
|
layer by its index (e.g. ``ds[0]`` to access the first layer), or you can
|
|
|
|
layer), or you can iterate over all the layers in the container in a
|
|
|
|
iterate over all the layers in the container in a ``for`` loop. The
|
|
|
|
``for`` loop. The ``Layer`` itself acts as a container for geometric
|
|
|
|
``Layer`` itself acts as a container for geometric features.
|
|
|
|
features.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Typically, all the features in a given layer have the same geometry type.
|
|
|
|
Typically, all the features in a given layer have the same geometry type.
|
|
|
|
The :attr:`geom_type` property of a layer is an :class:`OGRGeomType`
|
|
|
|
The :attr:`geom_type` property of a layer is an :class:`OGRGeomType` that
|
|
|
|
that identifies the feature type. We can use it to print out some basic
|
|
|
|
identifies the feature type. We can use it to print out some basic
|
|
|
|
information about each layer in a :class:`DataSource`::
|
|
|
|
information about each layer in a :class:`DataSource`::
|
|
|
|
|
|
|
|
|
|
|
|
>>> for layer in ds:
|
|
|
|
>>> for layer in ds:
|
|
|
@ -143,8 +140,7 @@ __ http://www.gdal.org/ogr_formats.html
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: geom_type
|
|
|
|
.. attribute:: geom_type
|
|
|
|
|
|
|
|
|
|
|
|
Returns the geometry type of the layer, as an :class:`OGRGeomType`
|
|
|
|
Returns the geometry type of the layer, as an :class:`OGRGeomType` object::
|
|
|
|
object::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>>> layer.geom_type.name
|
|
|
|
>>> layer.geom_type.name
|
|
|
|
'Point'
|
|
|
|
'Point'
|
|
|
@ -166,41 +162,39 @@ __ http://www.gdal.org/ogr_formats.html
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute field_types
|
|
|
|
.. attribute field_types
|
|
|
|
|
|
|
|
|
|
|
|
Returns a list of the data types of each of the fields in this layer.
|
|
|
|
Returns a list of the data types of each of the fields in this layer. These
|
|
|
|
These are subclasses of ``Field``, discussed below::
|
|
|
|
are subclasses of ``Field``, discussed below::
|
|
|
|
|
|
|
|
|
|
|
|
>>> [ft.__name__ for ft in layer.field_types]
|
|
|
|
>>> [ft.__name__ for ft in layer.field_types]
|
|
|
|
['OFTString', 'OFTReal', 'OFTReal', 'OFTDate']
|
|
|
|
['OFTString', 'OFTReal', 'OFTReal', 'OFTDate']
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: field_widths
|
|
|
|
.. attribute:: field_widths
|
|
|
|
|
|
|
|
|
|
|
|
Returns a list of the maximum field widths for each of the fields in
|
|
|
|
Returns a list of the maximum field widths for each of the fields in this
|
|
|
|
this layer::
|
|
|
|
layer::
|
|
|
|
|
|
|
|
|
|
|
|
>>> layer.field_widths
|
|
|
|
>>> layer.field_widths
|
|
|
|
[80, 11, 24, 10]
|
|
|
|
[80, 11, 24, 10]
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: field_precisions
|
|
|
|
.. attribute:: field_precisions
|
|
|
|
|
|
|
|
|
|
|
|
Returns a list of the numeric precisions for each of the fields in
|
|
|
|
Returns a list of the numeric precisions for each of the fields in this
|
|
|
|
this layer. This is meaningless (and set to zero) for non-numeric
|
|
|
|
layer. This is meaningless (and set to zero) for non-numeric fields::
|
|
|
|
fields::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>>> layer.field_precisions
|
|
|
|
>>> layer.field_precisions
|
|
|
|
[0, 0, 15, 0]
|
|
|
|
[0, 0, 15, 0]
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: extent
|
|
|
|
.. attribute:: extent
|
|
|
|
|
|
|
|
|
|
|
|
Returns the spatial extent of this layer, as an :class:`Envelope`
|
|
|
|
Returns the spatial extent of this layer, as an :class:`Envelope` object::
|
|
|
|
object::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>>> layer.extent.tuple
|
|
|
|
>>> layer.extent.tuple
|
|
|
|
(-104.609252, 29.763374, -95.23506, 38.971823)
|
|
|
|
(-104.609252, 29.763374, -95.23506, 38.971823)
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: srs
|
|
|
|
.. attribute:: srs
|
|
|
|
|
|
|
|
|
|
|
|
Property that returns the :class:`SpatialReference` associated
|
|
|
|
Property that returns the :class:`SpatialReference` associated with this
|
|
|
|
with this layer::
|
|
|
|
layer::
|
|
|
|
|
|
|
|
|
|
|
|
>>> print(layer.srs)
|
|
|
|
>>> print(layer.srs)
|
|
|
|
GEOGCS["GCS_WGS_1984",
|
|
|
|
GEOGCS["GCS_WGS_1984",
|
|
|
@ -216,9 +210,9 @@ __ http://www.gdal.org/ogr_formats.html
|
|
|
|
|
|
|
|
|
|
|
|
Property that may be used to retrieve or set a spatial filter for this
|
|
|
|
Property that may be used to retrieve or set a spatial filter for this
|
|
|
|
layer. A spatial filter can only be set with an :class:`OGRGeometry`
|
|
|
|
layer. A spatial filter can only be set with an :class:`OGRGeometry`
|
|
|
|
instance, a 4-tuple extent, or ``None``. When set with something
|
|
|
|
instance, a 4-tuple extent, or ``None``. When set with something other than
|
|
|
|
other than ``None``, only features that intersect the filter will be
|
|
|
|
``None``, only features that intersect the filter will be returned when
|
|
|
|
returned when iterating over the layer::
|
|
|
|
iterating over the layer::
|
|
|
|
|
|
|
|
|
|
|
|
>>> print(layer.spatial_filter)
|
|
|
|
>>> print(layer.spatial_filter)
|
|
|
|
None
|
|
|
|
None
|
|
|
@ -246,9 +240,9 @@ __ http://www.gdal.org/ogr_formats.html
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: get_geoms(geos=False)
|
|
|
|
.. method:: get_geoms(geos=False)
|
|
|
|
|
|
|
|
|
|
|
|
A method that returns a list containing the geometry of each feature
|
|
|
|
A method that returns a list containing the geometry of each feature in the
|
|
|
|
in the layer. If the optional argument ``geos`` is set to ``True``
|
|
|
|
layer. If the optional argument ``geos`` is set to ``True`` then the
|
|
|
|
then the geometries are converted to :class:`~django.contrib.gis.geos.GEOSGeometry`
|
|
|
|
geometries are converted to :class:`~django.contrib.gis.geos.GEOSGeometry`
|
|
|
|
objects. Otherwise, they are returned as :class:`OGRGeometry` objects::
|
|
|
|
objects. Otherwise, they are returned as :class:`OGRGeometry` objects::
|
|
|
|
|
|
|
|
|
|
|
|
>>> [pt.tuple for pt in layer.get_geoms()]
|
|
|
|
>>> [pt.tuple for pt in layer.get_geoms()]
|
|
|
@ -256,9 +250,9 @@ __ http://www.gdal.org/ogr_formats.html
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: test_capability(capability)
|
|
|
|
.. method:: test_capability(capability)
|
|
|
|
|
|
|
|
|
|
|
|
Returns a boolean indicating whether this layer supports the
|
|
|
|
Returns a boolean indicating whether this layer supports the given
|
|
|
|
given capability (a string). Examples of valid capability strings
|
|
|
|
capability (a string). Examples of valid capability strings include:
|
|
|
|
include: ``'RandomRead'``, ``'SequentialWrite'``, ``'RandomWrite'``,
|
|
|
|
``'RandomRead'``, ``'SequentialWrite'``, ``'RandomWrite'``,
|
|
|
|
``'FastSpatialFilter'``, ``'FastFeatureCount'``, ``'FastGetExtent'``,
|
|
|
|
``'FastSpatialFilter'``, ``'FastFeatureCount'``, ``'FastGetExtent'``,
|
|
|
|
``'CreateField'``, ``'Transactions'``, ``'DeleteFeature'``, and
|
|
|
|
``'CreateField'``, ``'Transactions'``, ``'DeleteFeature'``, and
|
|
|
|
``'FastSetNextByIndex'``.
|
|
|
|
``'FastSetNextByIndex'``.
|
|
|
@ -268,15 +262,14 @@ __ http://www.gdal.org/ogr_formats.html
|
|
|
|
|
|
|
|
|
|
|
|
.. class:: Feature
|
|
|
|
.. class:: Feature
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
``Feature`` wraps an OGR feature. You never create a ``Feature`` object
|
|
|
|
``Feature`` wraps an OGR feature. You never create a ``Feature``
|
|
|
|
directly. Instead, you retrieve them from a :class:`Layer` object. Each
|
|
|
|
object directly. Instead, you retrieve them from a :class:`Layer` object.
|
|
|
|
feature consists of a geometry and a set of fields containing additional
|
|
|
|
Each feature consists of a geometry and a set of fields containing
|
|
|
|
properties. The geometry of a field is accessible via its ``geom`` property,
|
|
|
|
additional properties. The geometry of a field is accessible via its
|
|
|
|
which returns an :class:`OGRGeometry` object. A ``Feature`` behaves like a
|
|
|
|
``geom`` property, which returns an :class:`OGRGeometry` object. A ``Feature``
|
|
|
|
standard Python container for its fields, which it returns as :class:`Field`
|
|
|
|
behaves like a standard Python container for its fields, which it returns as
|
|
|
|
objects: you can access a field directly by its index or name, or you can
|
|
|
|
:class:`Field` objects: you can access a field directly by its index or name,
|
|
|
|
iterate over a feature's fields, e.g. in a ``for`` loop.
|
|
|
|
or you can iterate over a feature's fields, e.g. in a ``for`` loop.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: geom
|
|
|
|
.. attribute:: geom
|
|
|
|
|
|
|
|
|
|
|
@ -296,22 +289,22 @@ __ http://www.gdal.org/ogr_formats.html
|
|
|
|
.. attribute:: geom_type
|
|
|
|
.. attribute:: geom_type
|
|
|
|
|
|
|
|
|
|
|
|
Returns the type of geometry for this feature, as an :class:`OGRGeomType`
|
|
|
|
Returns the type of geometry for this feature, as an :class:`OGRGeomType`
|
|
|
|
object. This will be the same for all features in a given layer, and
|
|
|
|
object. This will be the same for all features in a given layer and is
|
|
|
|
is equivalent to the :attr:`Layer.geom_type` property of the
|
|
|
|
equivalent to the :attr:`Layer.geom_type` property of the :class:`Layer`
|
|
|
|
:class:`Layer` object the feature came from.
|
|
|
|
object the feature came from.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: num_fields
|
|
|
|
.. attribute:: num_fields
|
|
|
|
|
|
|
|
|
|
|
|
Returns the number of fields of data associated with the feature.
|
|
|
|
Returns the number of fields of data associated with the feature. This will
|
|
|
|
This will be the same for all features in a given layer, and is
|
|
|
|
be the same for all features in a given layer and is equivalent to the
|
|
|
|
equivalent to the :attr:`Layer.num_fields` property of the
|
|
|
|
:attr:`Layer.num_fields` property of the :class:`Layer` object the feature
|
|
|
|
:class:`Layer` object the feature came from.
|
|
|
|
came from.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: fields
|
|
|
|
.. attribute:: fields
|
|
|
|
|
|
|
|
|
|
|
|
Returns a list of the names of the fields of data associated with the
|
|
|
|
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
|
|
|
|
feature. This will be the same for all features in a given layer and is
|
|
|
|
is equivalent to the :attr:`Layer.fields` property of the :class:`Layer`
|
|
|
|
equivalent to the :attr:`Layer.fields` property of the :class:`Layer`
|
|
|
|
object the feature came from.
|
|
|
|
object the feature came from.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: fid
|
|
|
|
.. attribute:: fid
|
|
|
@ -323,16 +316,16 @@ __ http://www.gdal.org/ogr_formats.html
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: layer_name
|
|
|
|
.. attribute:: layer_name
|
|
|
|
|
|
|
|
|
|
|
|
Returns the name of the :class:`Layer` that the feature came from.
|
|
|
|
Returns the name of the :class:`Layer` that the feature came from. This
|
|
|
|
This will be the same for all features in a given layer::
|
|
|
|
will be the same for all features in a given layer::
|
|
|
|
|
|
|
|
|
|
|
|
>>> city.layer_name
|
|
|
|
>>> city.layer_name
|
|
|
|
'cities'
|
|
|
|
'cities'
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: index
|
|
|
|
.. attribute:: index
|
|
|
|
|
|
|
|
|
|
|
|
A method that returns the index of the given field name. This will be
|
|
|
|
A method that returns the index of the given field name. This will be the
|
|
|
|
the same for all features in a given layer::
|
|
|
|
same for all features in a given layer::
|
|
|
|
|
|
|
|
|
|
|
|
>>> city.index('Population')
|
|
|
|
>>> city.index('Population')
|
|
|
|
1
|
|
|
|
1
|
|
|
@ -351,9 +344,8 @@ __ http://www.gdal.org/ogr_formats.html
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: type
|
|
|
|
.. attribute:: type
|
|
|
|
|
|
|
|
|
|
|
|
Returns the OGR type of this field, as an integer. The
|
|
|
|
Returns the OGR type of this field, as an integer. The ``FIELD_CLASSES``
|
|
|
|
``FIELD_CLASSES`` dictionary maps these values onto
|
|
|
|
dictionary maps these values onto subclasses of ``Field``::
|
|
|
|
subclasses of ``Field``::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>>> city['Density'].type
|
|
|
|
>>> city['Density'].type
|
|
|
|
2
|
|
|
|
2
|
|
|
@ -367,9 +359,9 @@ __ http://www.gdal.org/ogr_formats.html
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: value
|
|
|
|
.. attribute:: value
|
|
|
|
|
|
|
|
|
|
|
|
Returns the value of this field. The ``Field`` class itself
|
|
|
|
Returns the value of this field. The ``Field`` class itself returns the
|
|
|
|
returns the value as a string, but each subclass returns the
|
|
|
|
value as a string, but each subclass returns the value in the most
|
|
|
|
value in the most appropriate form::
|
|
|
|
appropriate form::
|
|
|
|
|
|
|
|
|
|
|
|
>>> city['Population'].value
|
|
|
|
>>> city['Population'].value
|
|
|
|
102121
|
|
|
|
102121
|
|
|
@ -383,8 +375,8 @@ __ http://www.gdal.org/ogr_formats.html
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: precision
|
|
|
|
.. attribute:: precision
|
|
|
|
|
|
|
|
|
|
|
|
Returns the numeric precision of this field. This is meaningless (and
|
|
|
|
Returns the numeric precision of this field. This is meaningless (and set
|
|
|
|
set to zero) for non-numeric fields::
|
|
|
|
to zero) for non-numeric fields::
|
|
|
|
|
|
|
|
|
|
|
|
>>> city['Density'].precision
|
|
|
|
>>> city['Density'].precision
|
|
|
|
15
|
|
|
|
15
|
|
|
@ -422,13 +414,13 @@ __ http://www.gdal.org/ogr_formats.html
|
|
|
|
|
|
|
|
|
|
|
|
.. class:: Driver(dr_input)
|
|
|
|
.. class:: Driver(dr_input)
|
|
|
|
|
|
|
|
|
|
|
|
The ``Driver`` class is used internally to wrap an OGR :class:`DataSource` driver.
|
|
|
|
The ``Driver`` class is used internally to wrap an OGR :class:`DataSource`
|
|
|
|
|
|
|
|
driver.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: driver_count
|
|
|
|
.. attribute:: driver_count
|
|
|
|
|
|
|
|
|
|
|
|
Returns the number of OGR vector drivers currently registered.
|
|
|
|
Returns the number of OGR vector drivers currently registered.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OGR Geometries
|
|
|
|
OGR Geometries
|
|
|
|
==============
|
|
|
|
==============
|
|
|
|
|
|
|
|
|
|
|
@ -436,24 +428,23 @@ OGR Geometries
|
|
|
|
---------------
|
|
|
|
---------------
|
|
|
|
|
|
|
|
|
|
|
|
:class:`OGRGeometry` objects share similar functionality with
|
|
|
|
:class:`OGRGeometry` objects share similar functionality with
|
|
|
|
:class:`~django.contrib.gis.geos.GEOSGeometry` objects, and are thin
|
|
|
|
:class:`~django.contrib.gis.geos.GEOSGeometry` objects and are thin wrappers
|
|
|
|
wrappers around OGR's internal geometry representation. Thus,
|
|
|
|
around OGR's internal geometry representation. Thus, they allow for more
|
|
|
|
they allow for more efficient access to data when using :class:`DataSource`.
|
|
|
|
efficient access to data when using :class:`DataSource`. Unlike its GEOS
|
|
|
|
Unlike its GEOS counterpart, :class:`OGRGeometry` supports spatial reference
|
|
|
|
counterpart, :class:`OGRGeometry` supports spatial reference systems and
|
|
|
|
systems and coordinate transformation::
|
|
|
|
coordinate transformation::
|
|
|
|
|
|
|
|
|
|
|
|
>>> from django.contrib.gis.gdal import OGRGeometry
|
|
|
|
>>> from django.contrib.gis.gdal import OGRGeometry
|
|
|
|
>>> polygon = OGRGeometry('POLYGON((0 0, 5 0, 5 5, 0 5))')
|
|
|
|
>>> polygon = OGRGeometry('POLYGON((0 0, 5 0, 5 5, 0 5))')
|
|
|
|
|
|
|
|
|
|
|
|
.. class:: OGRGeometry(geom_input, srs=None)
|
|
|
|
.. class:: OGRGeometry(geom_input, srs=None)
|
|
|
|
|
|
|
|
|
|
|
|
This object is a wrapper for the `OGR Geometry`__ class.
|
|
|
|
This object is a wrapper for the `OGR Geometry`__ class. These objects are
|
|
|
|
These objects are instantiated directly from the given ``geom_input``
|
|
|
|
instantiated directly from the given ``geom_input`` parameter, which may be
|
|
|
|
parameter, which may be a string containing WKT, HEX, GeoJSON, a ``buffer``
|
|
|
|
a string containing WKT, HEX, GeoJSON, a ``buffer`` containing WKB data, or
|
|
|
|
containing WKB data, or an :class:`OGRGeomType` object. These objects
|
|
|
|
an :class:`OGRGeomType` object. These objects are also returned from the
|
|
|
|
are also returned from the :class:`Feature.geom` attribute, when
|
|
|
|
:class:`Feature.geom` attribute, when reading vector data from
|
|
|
|
reading vector data from :class:`Layer` (which is in turn a part of
|
|
|
|
:class:`Layer` (which is in turn a part of a :class:`DataSource`).
|
|
|
|
a :class:`DataSource`).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__ http://www.gdal.org/classOGRGeometry.html
|
|
|
|
__ http://www.gdal.org/classOGRGeometry.html
|
|
|
|
|
|
|
|
|
|
|
@ -463,8 +454,8 @@ systems and coordinate transformation::
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: __len__()
|
|
|
|
.. method:: __len__()
|
|
|
|
|
|
|
|
|
|
|
|
Returns the number of points in a :class:`LineString`, the
|
|
|
|
Returns the number of points in a :class:`LineString`, the number of rings
|
|
|
|
number of rings in a :class:`Polygon`, or the number of geometries in a
|
|
|
|
in a :class:`Polygon`, or the number of geometries in a
|
|
|
|
:class:`GeometryCollection`. Not applicable to other geometry types.
|
|
|
|
:class:`GeometryCollection`. Not applicable to other geometry types.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: __iter__()
|
|
|
|
.. method:: __iter__()
|
|
|
@ -490,8 +481,8 @@ systems and coordinate transformation::
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: coord_dim
|
|
|
|
.. attribute:: coord_dim
|
|
|
|
|
|
|
|
|
|
|
|
Returns or sets the coordinate dimension of this geometry. For
|
|
|
|
Returns or sets the coordinate dimension of this geometry. For example, the
|
|
|
|
example, the value would be 2 for two-dimensional geometries.
|
|
|
|
value would be 2 for two-dimensional geometries.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: geom_count
|
|
|
|
.. attribute:: geom_count
|
|
|
|
|
|
|
|
|
|
|
@ -528,8 +519,8 @@ systems and coordinate transformation::
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: area
|
|
|
|
.. attribute:: area
|
|
|
|
|
|
|
|
|
|
|
|
Returns the area of this geometry, or 0 for geometries that do not
|
|
|
|
Returns the area of this geometry, or 0 for geometries that do not contain
|
|
|
|
contain an area::
|
|
|
|
an area::
|
|
|
|
|
|
|
|
|
|
|
|
>>> polygon.area
|
|
|
|
>>> polygon.area
|
|
|
|
25.0
|
|
|
|
25.0
|
|
|
@ -590,7 +581,6 @@ systems and coordinate transformation::
|
|
|
|
>>> OGRGeometry('POINT(1 2)').json
|
|
|
|
>>> OGRGeometry('POINT(1 2)').json
|
|
|
|
'{ "type": "Point", "coordinates": [ 1.000000, 2.000000 ] }'
|
|
|
|
'{ "type": "Point", "coordinates": [ 1.000000, 2.000000 ] }'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: kml
|
|
|
|
.. attribute:: kml
|
|
|
|
|
|
|
|
|
|
|
|
Returns a string representation of this geometry in KML format.
|
|
|
|
Returns a string representation of this geometry in KML format.
|
|
|
@ -631,10 +621,11 @@ systems and coordinate transformation::
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: transform(coord_trans, clone=False)
|
|
|
|
.. method:: transform(coord_trans, clone=False)
|
|
|
|
|
|
|
|
|
|
|
|
Transforms this geometry to a different spatial reference system. May
|
|
|
|
Transforms this geometry to a different spatial reference system. May take
|
|
|
|
take a :class:`CoordTransform` object, a :class:`SpatialReference` object,
|
|
|
|
a :class:`CoordTransform` object, a :class:`SpatialReference` object, or
|
|
|
|
or any other input accepted by :class:`SpatialReference` (including
|
|
|
|
any other input accepted by :class:`SpatialReference` (including spatial
|
|
|
|
spatial reference WKT and PROJ.4 strings, or an integer SRID).
|
|
|
|
reference WKT and PROJ.4 strings, or an integer SRID).
|
|
|
|
|
|
|
|
|
|
|
|
By default nothing is returned and the geometry is transformed in-place.
|
|
|
|
By default nothing is returned and the geometry is transformed in-place.
|
|
|
|
However, if the ``clone`` keyword is set to ``True`` then a transformed
|
|
|
|
However, if the ``clone`` keyword is set to ``True`` then a transformed
|
|
|
|
clone of this geometry is returned instead.
|
|
|
|
clone of this geometry is returned instead.
|
|
|
@ -646,8 +637,8 @@ systems and coordinate transformation::
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: equals(other)
|
|
|
|
.. method:: equals(other)
|
|
|
|
|
|
|
|
|
|
|
|
Returns ``True`` if this geometry is equivalent to the other, otherwise returns
|
|
|
|
Returns ``True`` if this geometry is equivalent to the other, otherwise
|
|
|
|
``False``.
|
|
|
|
returns ``False``.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: disjoint(other)
|
|
|
|
.. method:: disjoint(other)
|
|
|
|
|
|
|
|
|
|
|
@ -666,8 +657,8 @@ systems and coordinate transformation::
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: within(other)
|
|
|
|
.. method:: within(other)
|
|
|
|
|
|
|
|
|
|
|
|
Returns ``True`` if this geometry is contained within the other, otherwise returns
|
|
|
|
Returns ``True`` if this geometry is contained within the other, otherwise
|
|
|
|
``False``.
|
|
|
|
returns ``False``.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: contains(other)
|
|
|
|
.. method:: contains(other)
|
|
|
|
|
|
|
|
|
|
|
@ -740,8 +731,8 @@ systems and coordinate transformation::
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: z
|
|
|
|
.. attribute:: z
|
|
|
|
|
|
|
|
|
|
|
|
Returns the Z coordinate of this point, or ``None`` if the
|
|
|
|
Returns the Z coordinate of this point, or ``None`` if the point does not
|
|
|
|
point does not have a Z coordinate::
|
|
|
|
have a Z coordinate::
|
|
|
|
|
|
|
|
|
|
|
|
>>> OGRGeometry('POINT (1 2 3)').z
|
|
|
|
>>> OGRGeometry('POINT (1 2 3)').z
|
|
|
|
3.0
|
|
|
|
3.0
|
|
|
@ -764,8 +755,8 @@ systems and coordinate transformation::
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: z
|
|
|
|
.. attribute:: z
|
|
|
|
|
|
|
|
|
|
|
|
Returns a list of Z coordinates in this line, or ``None`` if the
|
|
|
|
Returns a list of Z coordinates in this line, or ``None`` if the line does
|
|
|
|
line does not have Z coordinates::
|
|
|
|
not have Z coordinates::
|
|
|
|
|
|
|
|
|
|
|
|
>>> OGRGeometry('LINESTRING (1 2 3,4 5 6)').z
|
|
|
|
>>> OGRGeometry('LINESTRING (1 2 3,4 5 6)').z
|
|
|
|
[3.0, 6.0]
|
|
|
|
[3.0, 6.0]
|
|
|
@ -793,7 +784,6 @@ systems and coordinate transformation::
|
|
|
|
Adds a geometry to this geometry collection. Not applicable to other
|
|
|
|
Adds a geometry to this geometry collection. Not applicable to other
|
|
|
|
geometry types.
|
|
|
|
geometry types.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
``OGRGeomType``
|
|
|
|
``OGRGeomType``
|
|
|
|
---------------
|
|
|
|
---------------
|
|
|
|
|
|
|
|
|
|
|
@ -826,8 +816,7 @@ systems and coordinate transformation::
|
|
|
|
.. attribute:: django
|
|
|
|
.. attribute:: django
|
|
|
|
|
|
|
|
|
|
|
|
Returns the Django field type (a subclass of GeometryField) to use for
|
|
|
|
Returns the Django field type (a subclass of GeometryField) to use for
|
|
|
|
storing this OGR type, or ``None`` if there is no appropriate Django
|
|
|
|
storing this OGR type, or ``None`` if there is no appropriate Django type::
|
|
|
|
type::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>>> gt1.django
|
|
|
|
>>> gt1.django
|
|
|
|
'PolygonField'
|
|
|
|
'PolygonField'
|
|
|
@ -837,10 +826,9 @@ systems and coordinate transformation::
|
|
|
|
|
|
|
|
|
|
|
|
.. class:: Envelope(*args)
|
|
|
|
.. class:: Envelope(*args)
|
|
|
|
|
|
|
|
|
|
|
|
Represents an OGR Envelope structure that contains the
|
|
|
|
Represents an OGR Envelope structure that contains the minimum and maximum
|
|
|
|
minimum and maximum X, Y coordinates for a rectangle bounding box.
|
|
|
|
X, Y coordinates for a rectangle bounding box. The naming of the variables
|
|
|
|
The naming of the variables is compatible with the OGR Envelope
|
|
|
|
is compatible with the OGR Envelope C structure.
|
|
|
|
C structure.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: min_x
|
|
|
|
.. attribute:: min_x
|
|
|
|
|
|
|
|
|
|
|
@ -874,7 +862,6 @@ systems and coordinate transformation::
|
|
|
|
|
|
|
|
|
|
|
|
A string representing this envelope as a polygon in WKT format.
|
|
|
|
A string representing this envelope as a polygon in WKT format.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: expand_to_include(*args)
|
|
|
|
.. method:: expand_to_include(*args)
|
|
|
|
|
|
|
|
|
|
|
|
Coordinate System Objects
|
|
|
|
Coordinate System Objects
|
|
|
@ -891,7 +878,8 @@ Coordinate System Objects
|
|
|
|
* OGC Well Known Text (WKT) (a string)
|
|
|
|
* OGC Well Known Text (WKT) (a string)
|
|
|
|
* EPSG code (integer or string)
|
|
|
|
* EPSG code (integer or string)
|
|
|
|
* PROJ.4 string
|
|
|
|
* PROJ.4 string
|
|
|
|
* A shorthand string for well-known standards (``'WGS84'``, ``'WGS72'``, ``'NAD27'``, ``'NAD83'``)
|
|
|
|
* A shorthand string for well-known standards (``'WGS84'``, ``'WGS72'``,
|
|
|
|
|
|
|
|
``'NAD27'``, ``'NAD83'``)
|
|
|
|
|
|
|
|
|
|
|
|
Example::
|
|
|
|
Example::
|
|
|
|
|
|
|
|
|
|
|
@ -914,8 +902,8 @@ Coordinate System Objects
|
|
|
|
.. method:: __getitem__(target)
|
|
|
|
.. method:: __getitem__(target)
|
|
|
|
|
|
|
|
|
|
|
|
Returns the value of the given string attribute node, ``None`` if the node
|
|
|
|
Returns the value of the given string attribute node, ``None`` if the node
|
|
|
|
doesn't exist. Can also take a tuple as a parameter, (target, child),
|
|
|
|
doesn't exist. Can also take a tuple as a parameter, (target, child), where
|
|
|
|
where child is the index of the attribute in the WKT. For example::
|
|
|
|
child is the index of the attribute in the WKT. For example::
|
|
|
|
|
|
|
|
|
|
|
|
>>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]')
|
|
|
|
>>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]')
|
|
|
|
>>> srs = SpatialReference(wkt) # could also use 'WGS84', or 4326
|
|
|
|
>>> srs = SpatialReference(wkt) # could also use 'WGS84', or 4326
|
|
|
@ -953,8 +941,8 @@ Coordinate System Objects
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: identify_epsg()
|
|
|
|
.. method:: identify_epsg()
|
|
|
|
|
|
|
|
|
|
|
|
This method inspects the WKT of this SpatialReference, and will
|
|
|
|
This method inspects the WKT of this ``SpatialReference`` and will add EPSG
|
|
|
|
add EPSG authority nodes where an EPSG identifier is applicable.
|
|
|
|
authority nodes where an EPSG identifier is applicable.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: from_esri()
|
|
|
|
.. method:: from_esri()
|
|
|
|
|
|
|
|
|
|
|
@ -1013,14 +1001,13 @@ Coordinate System Objects
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: units
|
|
|
|
.. attribute:: units
|
|
|
|
|
|
|
|
|
|
|
|
Returns a 2-tuple of the units value and the units name,
|
|
|
|
Returns a 2-tuple of the units value and the units name and will
|
|
|
|
and will automatically determines whether to return the linear
|
|
|
|
automatically determines whether to return the linear or angular units.
|
|
|
|
or angular units.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ellipsoid
|
|
|
|
.. attribute:: ellipsoid
|
|
|
|
|
|
|
|
|
|
|
|
Returns a tuple of the ellipsoid parameters for this spatial
|
|
|
|
Returns a tuple of the ellipsoid parameters for this spatial reference:
|
|
|
|
reference: (semimajor axis, semiminor axis, and inverse flattening)
|
|
|
|
(semimajor axis, semiminor axis, and inverse flattening).
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: semi_major
|
|
|
|
.. attribute:: semi_major
|
|
|
|
|
|
|
|
|
|
|
@ -1036,18 +1023,18 @@ Coordinate System Objects
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: geographic
|
|
|
|
.. attribute:: geographic
|
|
|
|
|
|
|
|
|
|
|
|
Returns ``True`` if this spatial reference is geographic
|
|
|
|
Returns ``True`` if this spatial reference is geographic (root node is
|
|
|
|
(root node is ``GEOGCS``).
|
|
|
|
``GEOGCS``).
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: local
|
|
|
|
.. attribute:: local
|
|
|
|
|
|
|
|
|
|
|
|
Returns ``True`` if this spatial reference is local
|
|
|
|
Returns ``True`` if this spatial reference is local (root node is
|
|
|
|
(root node is ``LOCAL_CS``).
|
|
|
|
``LOCAL_CS``).
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: projected
|
|
|
|
.. attribute:: projected
|
|
|
|
|
|
|
|
|
|
|
|
Returns ``True`` if this spatial reference is a projected coordinate
|
|
|
|
Returns ``True`` if this spatial reference is a projected coordinate system
|
|
|
|
system (root node is ``PROJCS``).
|
|
|
|
(root node is ``PROJCS``).
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: wkt
|
|
|
|
.. attribute:: wkt
|
|
|
|
|
|
|
|
|
|
|
@ -1069,7 +1056,6 @@ Coordinate System Objects
|
|
|
|
|
|
|
|
|
|
|
|
Returns the XML representation of this spatial reference.
|
|
|
|
Returns the XML representation of this spatial reference.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
``CoordTransform``
|
|
|
|
``CoordTransform``
|
|
|
|
------------------
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
|
@ -1077,8 +1063,8 @@ Coordinate System Objects
|
|
|
|
|
|
|
|
|
|
|
|
Represents a coordinate system transform. It is initialized with two
|
|
|
|
Represents a coordinate system transform. It is initialized with two
|
|
|
|
:class:`SpatialReference`, representing the source and target coordinate
|
|
|
|
:class:`SpatialReference`, representing the source and target coordinate
|
|
|
|
systems, respectively. These objects should be used when performing
|
|
|
|
systems, respectively. These objects should be used when performing the same
|
|
|
|
the same coordinate transformation repeatedly on different geometries::
|
|
|
|
coordinate transformation repeatedly on different geometries::
|
|
|
|
|
|
|
|
|
|
|
|
>>> ct = CoordTransform(SpatialReference('WGS84'), SpatialReference('NAD83'))
|
|
|
|
>>> ct = CoordTransform(SpatialReference('WGS84'), SpatialReference('NAD83'))
|
|
|
|
>>> for feat in layer:
|
|
|
|
>>> for feat in layer:
|
|
|
|