gdal.txt 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029
  1. ========
  2. GDAL API
  3. ========
  4. .. module:: django.contrib.gis.gdal
  5. :synopsis: GeoDjango's high-level interface to the GDAL library.
  6. `GDAL`__ stands for **Geospatial Data Abstraction Library**,
  7. and is a veritable "Swiss army knife" of GIS data functionality. A subset
  8. of GDAL is the `OGR`__ Simple Features Library, which specializes
  9. in reading and writing vector geographic data in a variety of standard
  10. formats.
  11. GeoDjango provides a high-level Python interface for some of the
  12. capabilities of OGR, including the reading and coordinate transformation
  13. of vector spatial data and minimal support for GDAL's features with respect
  14. to raster (image) data.
  15. .. note::
  16. Although the module is named ``gdal``, GeoDjango only supports some of the
  17. capabilities of OGR and GDAL's raster features at this time.
  18. __ https://gdal.org/
  19. __ https://gdal.org/user/vector_data_model.html
  20. Overview
  21. ========
  22. .. _gdal_sample_data:
  23. Sample Data
  24. -----------
  25. The GDAL/OGR tools described here are designed to help you read in
  26. your geospatial data, in order for most of them to be useful you have
  27. to have some data to work with. If you're starting out and don't yet
  28. have any data of your own to use, GeoDjango tests contain a number of
  29. data sets that you can use for testing. You can download them here:
  30. .. code-block:: shell
  31. $ wget https://raw.githubusercontent.com/django/django/main/tests/gis_tests/data/cities/cities.{shp,prj,shx,dbf}
  32. $ wget https://raw.githubusercontent.com/django/django/main/tests/gis_tests/data/rasters/raster.tif
  33. Vector Data Source Objects
  34. ==========================
  35. ``DataSource``
  36. --------------
  37. :class:`DataSource` is a wrapper for the OGR data source object that
  38. supports reading data from a variety of OGR-supported geospatial file
  39. formats and data sources using a consistent interface. Each
  40. data source is represented by a :class:`DataSource` object which contains
  41. one or more layers of data. Each layer, represented by a :class:`Layer`
  42. object, contains some number of geographic features (:class:`Feature`),
  43. information about the type of features contained in that layer (e.g.
  44. points, polygons, etc.), as well as the names and types of any
  45. additional fields (:class:`Field`) of data that may be associated with
  46. each feature in that layer.
  47. .. class:: DataSource(ds_input, encoding='utf-8')
  48. The constructor for ``DataSource`` only requires one parameter: the path of
  49. the file you want to read. However, OGR also supports a variety of more
  50. complex data sources, including databases, that may be accessed by passing
  51. a special name string instead of a path. For more information, see the
  52. `OGR Vector Formats`__ documentation. The :attr:`name` property of a
  53. ``DataSource`` instance gives the OGR name of the underlying data source
  54. that it is using.
  55. The optional ``encoding`` parameter allows you to specify a non-standard
  56. encoding of the strings in the source. This is typically useful when you
  57. obtain ``DjangoUnicodeDecodeError`` exceptions while reading field values.
  58. Once you've created your ``DataSource``, you can find out how many layers
  59. of data it contains by accessing the :attr:`layer_count` property, or
  60. (equivalently) by using the ``len()`` function. For information on
  61. accessing the layers of data themselves, see the next section:
  62. .. code-block:: pycon
  63. >>> from django.contrib.gis.gdal import DataSource
  64. >>> ds = DataSource("/path/to/your/cities.shp")
  65. >>> ds.name
  66. '/path/to/your/cities.shp'
  67. >>> ds.layer_count # This file only contains one layer
  68. 1
  69. .. attribute:: layer_count
  70. Returns the number of layers in the data source.
  71. .. attribute:: name
  72. Returns the name of the data source.
  73. __ https://gdal.org/drivers/vector/
  74. ``Layer``
  75. ---------
  76. .. class:: Layer
  77. ``Layer`` is a wrapper for a layer of data in a ``DataSource`` object. You
  78. never create a ``Layer`` object directly. Instead, you retrieve them from
  79. a :class:`DataSource` object, which is essentially a standard Python
  80. container of ``Layer`` objects. For example, you can access a specific
  81. layer by its index (e.g. ``ds[0]`` to access the first layer), or you can
  82. iterate over all the layers in the container in a ``for`` loop. The
  83. ``Layer`` itself acts as a container for geometric features.
  84. Typically, all the features in a given layer have the same geometry type.
  85. The :attr:`geom_type` property of a layer is an :class:`OGRGeomType` that
  86. identifies the feature type. We can use it to print out some basic
  87. information about each layer in a :class:`DataSource`:
  88. .. code-block:: pycon
  89. >>> for layer in ds:
  90. ... print('Layer "%s": %i %ss' % (layer.name, len(layer), layer.geom_type.name))
  91. ...
  92. Layer "cities": 3 Points
  93. The example output is from the cities data source, loaded above, which
  94. evidently contains one layer, called ``"cities"``, which contains three
  95. point features. For simplicity, the examples below assume that you've
  96. stored that layer in the variable ``layer``:
  97. .. code-block:: pycon
  98. >>> layer = ds[0]
  99. .. attribute:: name
  100. Returns the name of this layer in the data source.
  101. .. code-block:: pycon
  102. >>> layer.name
  103. 'cities'
  104. .. attribute:: num_feat
  105. Returns the number of features in the layer. Same as ``len(layer)``:
  106. .. code-block:: pycon
  107. >>> layer.num_feat
  108. 3
  109. .. attribute:: geom_type
  110. Returns the geometry type of the layer, as an :class:`OGRGeomType` object:
  111. .. code-block:: pycon
  112. >>> layer.geom_type.name
  113. 'Point'
  114. .. attribute:: num_fields
  115. Returns the number of fields in the layer, i.e the number of fields of
  116. data associated with each feature in the layer:
  117. .. code-block:: pycon
  118. >>> layer.num_fields
  119. 4
  120. .. attribute:: fields
  121. Returns a list of the names of each of the fields in this layer:
  122. .. code-block:: pycon
  123. >>> layer.fields
  124. ['Name', 'Population', 'Density', 'Created']
  125. .. attribute field_types
  126. Returns a list of the data types of each of the fields in this layer. These
  127. are subclasses of ``Field``, discussed below:
  128. .. code-block:: pycon
  129. >>> [ft.__name__ for ft in layer.field_types]
  130. ['OFTString', 'OFTReal', 'OFTReal', 'OFTDate']
  131. .. attribute:: field_widths
  132. Returns a list of the maximum field widths for each of the fields in this
  133. layer:
  134. .. code-block:: pycon
  135. >>> layer.field_widths
  136. [80, 11, 24, 10]
  137. .. attribute:: field_precisions
  138. Returns a list of the numeric precisions for each of the fields in this
  139. layer. This is meaningless (and set to zero) for non-numeric fields:
  140. .. code-block:: pycon
  141. >>> layer.field_precisions
  142. [0, 0, 15, 0]
  143. .. attribute:: extent
  144. Returns the spatial extent of this layer, as an :class:`Envelope` object:
  145. .. code-block:: pycon
  146. >>> layer.extent.tuple
  147. (-104.609252, 29.763374, -95.23506, 38.971823)
  148. .. attribute:: srs
  149. Property that returns the :class:`SpatialReference` associated with this
  150. layer:
  151. .. code-block:: pycon
  152. >>> print(layer.srs)
  153. GEOGCS["GCS_WGS_1984",
  154. DATUM["WGS_1984",
  155. SPHEROID["WGS_1984",6378137,298.257223563]],
  156. PRIMEM["Greenwich",0],
  157. UNIT["Degree",0.017453292519943295]]
  158. If the :class:`Layer` has no spatial reference information associated
  159. with it, ``None`` is returned.
  160. .. attribute:: spatial_filter
  161. Property that may be used to retrieve or set a spatial filter for this
  162. layer. A spatial filter can only be set with an :class:`OGRGeometry`
  163. instance, a 4-tuple extent, or ``None``. When set with something other than
  164. ``None``, only features that intersect the filter will be returned when
  165. iterating over the layer:
  166. .. code-block:: pycon
  167. >>> print(layer.spatial_filter)
  168. None
  169. >>> print(len(layer))
  170. 3
  171. >>> [feat.get("Name") for feat in layer]
  172. ['Pueblo', 'Lawrence', 'Houston']
  173. >>> ks_extent = (-102.051, 36.99, -94.59, 40.00) # Extent for state of Kansas
  174. >>> layer.spatial_filter = ks_extent
  175. >>> len(layer)
  176. 1
  177. >>> [feat.get("Name") for feat in layer]
  178. ['Lawrence']
  179. >>> layer.spatial_filter = None
  180. >>> len(layer)
  181. 3
  182. .. method:: get_fields()
  183. A method that returns a list of the values of a given field for each
  184. feature in the layer:
  185. .. code-block:: pycon
  186. >>> layer.get_fields("Name")
  187. ['Pueblo', 'Lawrence', 'Houston']
  188. .. method:: get_geoms(geos=False)
  189. A method that returns a list containing the geometry of each feature in the
  190. layer. If the optional argument ``geos`` is set to ``True`` then the
  191. geometries are converted to :class:`~django.contrib.gis.geos.GEOSGeometry`
  192. objects. Otherwise, they are returned as :class:`OGRGeometry` objects:
  193. .. code-block:: pycon
  194. >>> [pt.tuple for pt in layer.get_geoms()]
  195. [(-104.609252, 38.255001), (-95.23506, 38.971823), (-95.363151, 29.763374)]
  196. .. method:: test_capability(capability)
  197. Returns a boolean indicating whether this layer supports the given
  198. capability (a string). Examples of valid capability strings include:
  199. ``'RandomRead'``, ``'SequentialWrite'``, ``'RandomWrite'``,
  200. ``'FastSpatialFilter'``, ``'FastFeatureCount'``, ``'FastGetExtent'``,
  201. ``'CreateField'``, ``'Transactions'``, ``'DeleteFeature'``, and
  202. ``'FastSetNextByIndex'``.
  203. ``Feature``
  204. -----------
  205. .. class:: Feature
  206. ``Feature`` wraps an OGR feature. You never create a ``Feature`` object
  207. directly. Instead, you retrieve them from a :class:`Layer` object. Each
  208. feature consists of a geometry and a set of fields containing additional
  209. properties. The geometry of a field is accessible via its ``geom`` property,
  210. which returns an :class:`OGRGeometry` object. A ``Feature`` behaves like a
  211. standard Python container for its fields, which it returns as :class:`Field`
  212. objects: you can access a field directly by its index or name, or you can
  213. iterate over a feature's fields, e.g. in a ``for`` loop.
  214. .. attribute:: geom
  215. Returns the geometry for this feature, as an ``OGRGeometry`` object:
  216. .. code-block:: pycon
  217. >>> city.geom.tuple
  218. (-104.609252, 38.255001)
  219. .. attribute:: get
  220. A method that returns the value of the given field (specified by name)
  221. for this feature, **not** a ``Field`` wrapper object:
  222. .. code-block:: pycon
  223. >>> city.get("Population")
  224. 102121
  225. .. attribute:: geom_type
  226. Returns the type of geometry for this feature, as an :class:`OGRGeomType`
  227. object. This will be the same for all features in a given layer and is
  228. equivalent to the :attr:`Layer.geom_type` property of the :class:`Layer`
  229. object the feature came from.
  230. .. attribute:: num_fields
  231. Returns the number of fields of data associated with the feature. This will
  232. be the same for all features in a given layer and is equivalent to the
  233. :attr:`Layer.num_fields` property of the :class:`Layer` object the feature
  234. came from.
  235. .. attribute:: fields
  236. Returns a list of the names of the fields of data associated with the
  237. feature. This will be the same for all features in a given layer and is
  238. equivalent to the :attr:`Layer.fields` property of the :class:`Layer`
  239. object the feature came from.
  240. .. attribute:: fid
  241. Returns the feature identifier within the layer:
  242. .. code-block:: pycon
  243. >>> city.fid
  244. 0
  245. .. attribute:: layer_name
  246. Returns the name of the :class:`Layer` that the feature came from. This
  247. will be the same for all features in a given layer:
  248. .. code-block:: pycon
  249. >>> city.layer_name
  250. 'cities'
  251. .. attribute:: index
  252. A method that returns the index of the given field name. This will be the
  253. same for all features in a given layer:
  254. .. code-block:: pycon
  255. >>> city.index("Population")
  256. 1
  257. ``Field``
  258. ---------
  259. .. class:: Field
  260. .. attribute:: name
  261. Returns the name of this field:
  262. .. code-block:: pycon
  263. >>> city["Name"].name
  264. 'Name'
  265. .. attribute:: type
  266. Returns the OGR type of this field, as an integer. The ``FIELD_CLASSES``
  267. dictionary maps these values onto subclasses of ``Field``:
  268. .. code-block:: pycon
  269. >>> city["Density"].type
  270. 2
  271. .. attribute:: type_name
  272. Returns a string with the name of the data type of this field:
  273. .. code-block:: pycon
  274. >>> city["Name"].type_name
  275. 'String'
  276. .. attribute:: value
  277. Returns the value of this field. The ``Field`` class itself returns the
  278. value as a string, but each subclass returns the value in the most
  279. appropriate form:
  280. .. code-block:: pycon
  281. >>> city["Population"].value
  282. 102121
  283. .. attribute:: width
  284. Returns the width of this field:
  285. .. code-block:: pycon
  286. >>> city["Name"].width
  287. 80
  288. .. attribute:: precision
  289. Returns the numeric precision of this field. This is meaningless (and set
  290. to zero) for non-numeric fields:
  291. .. code-block:: pycon
  292. >>> city["Density"].precision
  293. 15
  294. .. method:: as_double()
  295. Returns the value of the field as a double (float):
  296. .. code-block:: pycon
  297. >>> city["Density"].as_double()
  298. 874.7
  299. .. method:: as_int()
  300. Returns the value of the field as an integer:
  301. .. code-block:: pycon
  302. >>> city["Population"].as_int()
  303. 102121
  304. .. method:: as_string()
  305. Returns the value of the field as a string:
  306. .. code-block:: pycon
  307. >>> city["Name"].as_string()
  308. 'Pueblo'
  309. .. method:: as_datetime()
  310. Returns the value of the field as a tuple of date and time components:
  311. .. code-block:: pycon
  312. >>> city["Created"].as_datetime()
  313. (c_long(1999), c_long(5), c_long(23), c_long(0), c_long(0), c_long(0), c_long(0))
  314. ``Driver``
  315. ----------
  316. .. class:: Driver(dr_input)
  317. The ``Driver`` class is used internally to wrap an OGR :class:`DataSource`
  318. driver.
  319. .. attribute:: driver_count
  320. Returns the number of OGR vector drivers currently registered.
  321. OGR Geometries
  322. ==============
  323. ``OGRGeometry``
  324. ---------------
  325. :class:`OGRGeometry` objects share similar functionality with
  326. :class:`~django.contrib.gis.geos.GEOSGeometry` objects and are thin wrappers
  327. around OGR's internal geometry representation. Thus, they allow for more
  328. efficient access to data when using :class:`DataSource`. Unlike its GEOS
  329. counterpart, :class:`OGRGeometry` supports spatial reference systems and
  330. coordinate transformation:
  331. .. code-block:: pycon
  332. >>> from django.contrib.gis.gdal import OGRGeometry
  333. >>> polygon = OGRGeometry("POLYGON((0 0, 5 0, 5 5, 0 5))")
  334. .. class:: OGRGeometry(geom_input, srs=None)
  335. This object is a wrapper for the `OGR Geometry`__ class. These objects are
  336. instantiated directly from the given ``geom_input`` parameter, which may be
  337. a string containing WKT, HEX, GeoJSON, a ``buffer`` containing WKB data, or
  338. an :class:`OGRGeomType` object. These objects are also returned from the
  339. :class:`Feature.geom` attribute, when reading vector data from
  340. :class:`Layer` (which is in turn a part of a :class:`DataSource`).
  341. __ https://gdal.org/api/ogrgeometry_cpp.html#ogrgeometry-class
  342. .. classmethod:: from_gml(gml_string)
  343. Constructs an :class:`OGRGeometry` from the given GML string.
  344. .. classmethod:: from_bbox(bbox)
  345. Constructs a :class:`Polygon` from the given bounding-box (a 4-tuple).
  346. .. method:: __len__()
  347. Returns the number of points in a :class:`LineString`, the number of rings
  348. in a :class:`Polygon`, or the number of geometries in a
  349. :class:`GeometryCollection`. Not applicable to other geometry types.
  350. .. method:: __iter__()
  351. Iterates over the points in a :class:`LineString`, the rings in a
  352. :class:`Polygon`, or the geometries in a :class:`GeometryCollection`.
  353. Not applicable to other geometry types.
  354. .. method:: __getitem__()
  355. Returns the point at the specified index for a :class:`LineString`, the
  356. interior ring at the specified index for a :class:`Polygon`, or the geometry
  357. at the specified index in a :class:`GeometryCollection`. Not applicable to
  358. other geometry types.
  359. .. attribute:: dimension
  360. Returns the number of coordinated dimensions of the geometry, i.e. 0
  361. for points, 1 for lines, and so forth:
  362. .. code-block:: pycon
  363. >>> polygon.dimension
  364. 2
  365. .. attribute:: coord_dim
  366. Returns or sets the coordinate dimension of this geometry. For example, the
  367. value would be 2 for two-dimensional geometries.
  368. .. attribute:: geom_count
  369. Returns the number of elements in this geometry:
  370. .. code-block:: pycon
  371. >>> polygon.geom_count
  372. 1
  373. .. attribute:: point_count
  374. Returns the number of points used to describe this geometry:
  375. .. code-block:: pycon
  376. >>> polygon.point_count
  377. 4
  378. .. attribute:: num_points
  379. Alias for :attr:`point_count`.
  380. .. attribute:: num_coords
  381. Alias for :attr:`point_count`.
  382. .. attribute:: geom_type
  383. Returns the type of this geometry, as an :class:`OGRGeomType` object.
  384. .. attribute:: geom_name
  385. Returns the name of the type of this geometry:
  386. .. code-block:: pycon
  387. >>> polygon.geom_name
  388. 'POLYGON'
  389. .. attribute:: area
  390. Returns the area of this geometry, or 0 for geometries that do not contain
  391. an area:
  392. .. code-block:: pycon
  393. >>> polygon.area
  394. 25.0
  395. .. attribute:: envelope
  396. Returns the envelope of this geometry, as an :class:`Envelope` object.
  397. .. attribute:: extent
  398. Returns the envelope of this geometry as a 4-tuple, instead of as an
  399. :class:`Envelope` object:
  400. .. code-block:: pycon
  401. >>> point.extent
  402. (0.0, 0.0, 5.0, 5.0)
  403. .. attribute:: srs
  404. This property controls the spatial reference for this geometry, or
  405. ``None`` if no spatial reference system has been assigned to it.
  406. If assigned, accessing this property returns a :class:`SpatialReference`
  407. object. It may be set with another :class:`SpatialReference` object,
  408. or any input that :class:`SpatialReference` accepts. Example:
  409. .. code-block:: pycon
  410. >>> city.geom.srs.name
  411. 'GCS_WGS_1984'
  412. .. attribute:: srid
  413. Returns or sets the spatial reference identifier corresponding to
  414. :class:`SpatialReference` of this geometry. Returns ``None`` if
  415. there is no spatial reference information associated with this
  416. geometry, or if an SRID cannot be determined.
  417. .. attribute:: geos
  418. Returns a :class:`~django.contrib.gis.geos.GEOSGeometry` object
  419. corresponding to this geometry.
  420. .. attribute:: gml
  421. Returns a string representation of this geometry in GML format:
  422. .. code-block:: pycon
  423. >>> OGRGeometry("POINT(1 2)").gml
  424. '<gml:Point><gml:coordinates>1,2</gml:coordinates></gml:Point>'
  425. .. attribute:: hex
  426. Returns a string representation of this geometry in HEX WKB format:
  427. .. code-block:: pycon
  428. >>> OGRGeometry("POINT(1 2)").hex
  429. '0101000000000000000000F03F0000000000000040'
  430. .. attribute:: json
  431. Returns a string representation of this geometry in JSON format:
  432. .. code-block:: pycon
  433. >>> OGRGeometry("POINT(1 2)").json
  434. '{ "type": "Point", "coordinates": [ 1.000000, 2.000000 ] }'
  435. .. attribute:: kml
  436. Returns a string representation of this geometry in KML format.
  437. .. attribute:: wkb_size
  438. Returns the size of the WKB buffer needed to hold a WKB representation
  439. of this geometry:
  440. .. code-block:: pycon
  441. >>> OGRGeometry("POINT(1 2)").wkb_size
  442. 21
  443. .. attribute:: wkb
  444. Returns a ``buffer`` containing a WKB representation of this geometry.
  445. .. attribute:: wkt
  446. Returns a string representation of this geometry in WKT format.
  447. .. attribute:: ewkt
  448. Returns the EWKT representation of this geometry.
  449. .. method:: clone()
  450. Returns a new :class:`OGRGeometry` clone of this geometry object.
  451. .. method:: close_rings()
  452. If there are any rings within this geometry that have not been closed,
  453. this routine will do so by adding the starting point to the end:
  454. .. code-block:: pycon
  455. >>> triangle = OGRGeometry("LINEARRING (0 0,0 1,1 0)")
  456. >>> triangle.close_rings()
  457. >>> triangle.wkt
  458. 'LINEARRING (0 0,0 1,1 0,0 0)'
  459. .. method:: transform(coord_trans, clone=False)
  460. Transforms this geometry to a different spatial reference system. May take
  461. a :class:`CoordTransform` object, a :class:`SpatialReference` object, or
  462. any other input accepted by :class:`SpatialReference` (including spatial
  463. reference WKT and PROJ strings, or an integer SRID).
  464. By default nothing is returned and the geometry is transformed in-place.
  465. However, if the ``clone`` keyword is set to ``True`` then a transformed
  466. clone of this geometry is returned instead.
  467. .. method:: intersects(other)
  468. Returns ``True`` if this geometry intersects the other, otherwise returns
  469. ``False``.
  470. .. method:: equals(other)
  471. Returns ``True`` if this geometry is equivalent to the other, otherwise
  472. returns ``False``.
  473. .. method:: disjoint(other)
  474. Returns ``True`` if this geometry is spatially disjoint to (i.e. does
  475. not intersect) the other, otherwise returns ``False``.
  476. .. method:: touches(other)
  477. Returns ``True`` if this geometry touches the other, otherwise returns
  478. ``False``.
  479. .. method:: crosses(other)
  480. Returns ``True`` if this geometry crosses the other, otherwise returns
  481. ``False``.
  482. .. method:: within(other)
  483. Returns ``True`` if this geometry is contained within the other, otherwise
  484. returns ``False``.
  485. .. method:: contains(other)
  486. Returns ``True`` if this geometry contains the other, otherwise returns
  487. ``False``.
  488. .. method:: overlaps(other)
  489. Returns ``True`` if this geometry overlaps the other, otherwise returns
  490. ``False``.
  491. .. method:: boundary()
  492. The boundary of this geometry, as a new :class:`OGRGeometry` object.
  493. .. attribute:: convex_hull
  494. The smallest convex polygon that contains this geometry, as a new
  495. :class:`OGRGeometry` object.
  496. .. method:: difference()
  497. Returns the region consisting of the difference of this geometry and
  498. the other, as a new :class:`OGRGeometry` object.
  499. .. method:: intersection()
  500. Returns the region consisting of the intersection of this geometry and
  501. the other, as a new :class:`OGRGeometry` object.
  502. .. method:: sym_difference()
  503. Returns the region consisting of the symmetric difference of this
  504. geometry and the other, as a new :class:`OGRGeometry` object.
  505. .. method:: union()
  506. Returns the region consisting of the union of this geometry and
  507. the other, as a new :class:`OGRGeometry` object.
  508. .. attribute:: tuple
  509. Returns the coordinates of a point geometry as a tuple, the
  510. coordinates of a line geometry as a tuple of tuples, and so forth:
  511. .. code-block:: pycon
  512. >>> OGRGeometry("POINT (1 2)").tuple
  513. (1.0, 2.0)
  514. >>> OGRGeometry("LINESTRING (1 2,3 4)").tuple
  515. ((1.0, 2.0), (3.0, 4.0))
  516. .. attribute:: coords
  517. An alias for :attr:`tuple`.
  518. .. class:: Point
  519. .. attribute:: x
  520. Returns the X coordinate of this point:
  521. .. code-block:: pycon
  522. >>> OGRGeometry("POINT (1 2)").x
  523. 1.0
  524. .. attribute:: y
  525. Returns the Y coordinate of this point:
  526. .. code-block:: pycon
  527. >>> OGRGeometry("POINT (1 2)").y
  528. 2.0
  529. .. attribute:: z
  530. Returns the Z coordinate of this point, or ``None`` if the point does not
  531. have a Z coordinate:
  532. .. code-block:: pycon
  533. >>> OGRGeometry("POINT (1 2 3)").z
  534. 3.0
  535. .. class:: LineString
  536. .. attribute:: x
  537. Returns a list of X coordinates in this line:
  538. .. code-block:: pycon
  539. >>> OGRGeometry("LINESTRING (1 2,3 4)").x
  540. [1.0, 3.0]
  541. .. attribute:: y
  542. Returns a list of Y coordinates in this line:
  543. .. code-block:: pycon
  544. >>> OGRGeometry("LINESTRING (1 2,3 4)").y
  545. [2.0, 4.0]
  546. .. attribute:: z
  547. Returns a list of Z coordinates in this line, or ``None`` if the line does
  548. not have Z coordinates:
  549. .. code-block:: pycon
  550. >>> OGRGeometry("LINESTRING (1 2 3,4 5 6)").z
  551. [3.0, 6.0]
  552. .. class:: Polygon
  553. .. attribute:: shell
  554. Returns the shell or exterior ring of this polygon, as a ``LinearRing``
  555. geometry.
  556. .. attribute:: exterior_ring
  557. An alias for :attr:`shell`.
  558. .. attribute:: centroid
  559. Returns a :class:`Point` representing the centroid of this polygon.
  560. .. class:: GeometryCollection
  561. .. method:: add(geom)
  562. Adds a geometry to this geometry collection. Not applicable to other
  563. geometry types.
  564. ``OGRGeomType``
  565. ---------------
  566. .. class:: OGRGeomType(type_input)
  567. This class allows for the representation of an OGR geometry type
  568. in any of several ways:
  569. .. code-block:: pycon
  570. >>> from django.contrib.gis.gdal import OGRGeomType
  571. >>> gt1 = OGRGeomType(3) # Using an integer for the type
  572. >>> gt2 = OGRGeomType("Polygon") # Using a string
  573. >>> gt3 = OGRGeomType("POLYGON") # It's case-insensitive
  574. >>> print(gt1 == 3, gt1 == "Polygon") # Equivalence works w/non-OGRGeomType objects
  575. True True
  576. .. attribute:: name
  577. Returns a short-hand string form of the OGR Geometry type:
  578. .. code-block:: pycon
  579. >>> gt1.name
  580. 'Polygon'
  581. .. attribute:: num
  582. Returns the number corresponding to the OGR geometry type:
  583. .. code-block:: pycon
  584. >>> gt1.num
  585. 3
  586. .. attribute:: django
  587. Returns the Django field type (a subclass of GeometryField) to use for
  588. storing this OGR type, or ``None`` if there is no appropriate Django type:
  589. .. code-block:: pycon
  590. >>> gt1.django
  591. 'PolygonField'
  592. ``Envelope``
  593. ------------
  594. .. class:: Envelope(*args)
  595. Represents an OGR Envelope structure that contains the minimum and maximum
  596. X, Y coordinates for a rectangle bounding box. The naming of the variables
  597. is compatible with the OGR Envelope C structure.
  598. .. attribute:: min_x
  599. The value of the minimum X coordinate.
  600. .. attribute:: min_y
  601. The value of the maximum X coordinate.
  602. .. attribute:: max_x
  603. The value of the minimum Y coordinate.
  604. .. attribute:: max_y
  605. The value of the maximum Y coordinate.
  606. .. attribute:: ur
  607. The upper-right coordinate, as a tuple.
  608. .. attribute:: ll
  609. The lower-left coordinate, as a tuple.
  610. .. attribute:: tuple
  611. A tuple representing the envelope.
  612. .. attribute:: wkt
  613. A string representing this envelope as a polygon in WKT format.
  614. .. method:: expand_to_include(*args)
  615. Coordinate System Objects
  616. =========================
  617. ``SpatialReference``
  618. --------------------
  619. .. class:: SpatialReference(srs_input)
  620. Spatial reference objects are initialized on the given ``srs_input``,
  621. which may be one of the following:
  622. * OGC Well Known Text (WKT) (a string)
  623. * EPSG code (integer or string)
  624. * PROJ string
  625. * A shorthand string for well-known standards (``'WGS84'``, ``'WGS72'``,
  626. ``'NAD27'``, ``'NAD83'``)
  627. Example:
  628. .. code-block:: pycon
  629. >>> wgs84 = SpatialReference("WGS84") # shorthand string
  630. >>> wgs84 = SpatialReference(4326) # EPSG code
  631. >>> wgs84 = SpatialReference("EPSG:4326") # EPSG string
  632. >>> proj = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs "
  633. >>> wgs84 = SpatialReference(proj) # PROJ string
  634. >>> wgs84 = SpatialReference(
  635. ... """GEOGCS["WGS 84",
  636. ... DATUM["WGS_1984",
  637. ... SPHEROID["WGS 84",6378137,298.257223563,
  638. ... AUTHORITY["EPSG","7030"]],
  639. ... AUTHORITY["EPSG","6326"]],
  640. ... PRIMEM["Greenwich",0,
  641. ... AUTHORITY["EPSG","8901"]],
  642. ... UNIT["degree",0.01745329251994328,
  643. ... AUTHORITY["EPSG","9122"]],
  644. ... AUTHORITY["EPSG","4326"]]"""
  645. ... ) # OGC WKT
  646. .. method:: __getitem__(target)
  647. Returns the value of the given string attribute node, ``None`` if the node
  648. doesn't exist. Can also take a tuple as a parameter, (target, child), where
  649. child is the index of the attribute in the WKT. For example:
  650. .. code-block:: pycon
  651. >>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]'
  652. >>> srs = SpatialReference(wkt) # could also use 'WGS84', or 4326
  653. >>> print(srs["GEOGCS"])
  654. WGS 84
  655. >>> print(srs["DATUM"])
  656. WGS_1984
  657. >>> print(srs["AUTHORITY"])
  658. EPSG
  659. >>> print(srs["AUTHORITY", 1]) # The authority value
  660. 4326
  661. >>> print(srs["TOWGS84", 4]) # the fourth value in this wkt
  662. 0
  663. >>> print(srs["UNIT|AUTHORITY"]) # For the units authority, have to use the pipe symbol.
  664. EPSG
  665. >>> print(srs["UNIT|AUTHORITY", 1]) # The authority value for the units
  666. 9122
  667. .. method:: attr_value(target, index=0)
  668. The attribute value for the given target node (e.g. ``'PROJCS'``).
  669. The index keyword specifies an index of the child node to return.
  670. .. method:: auth_name(target)
  671. Returns the authority name for the given string target node.
  672. .. method:: auth_code(target)
  673. Returns the authority code for the given string target node.
  674. .. method:: clone()
  675. Returns a clone of this spatial reference object.
  676. .. method:: identify_epsg()
  677. This method inspects the WKT of this ``SpatialReference`` and will add EPSG
  678. authority nodes where an EPSG identifier is applicable.
  679. .. method:: from_esri()
  680. Morphs this SpatialReference from ESRI's format to EPSG
  681. .. method:: to_esri()
  682. Morphs this SpatialReference to ESRI's format.
  683. .. method:: validate()
  684. Checks to see if the given spatial reference is valid, if not
  685. an exception will be raised.
  686. .. method:: import_epsg(epsg)
  687. Import spatial reference from EPSG code.
  688. .. method:: import_proj(proj)
  689. Import spatial reference from PROJ string.
  690. .. method:: import_user_input(user_input)
  691. .. method:: import_wkt(wkt)
  692. Import spatial reference from WKT.
  693. .. method:: import_xml(xml)
  694. Import spatial reference from XML.
  695. .. attribute:: name
  696. Returns the name of this Spatial Reference.
  697. .. attribute:: srid
  698. Returns the SRID of top-level authority, or ``None`` if undefined.
  699. .. attribute:: linear_name
  700. Returns the name of the linear units.
  701. .. attribute:: linear_units
  702. Returns the value of the linear units.
  703. .. attribute:: angular_name
  704. Returns the name of the angular units."
  705. .. attribute:: angular_units
  706. Returns the value of the angular units.
  707. .. attribute:: units
  708. Returns a 2-tuple of the units value and the units name and will
  709. automatically determines whether to return the linear or angular units.
  710. .. attribute:: ellipsoid
  711. Returns a tuple of the ellipsoid parameters for this spatial reference:
  712. (semimajor axis, semiminor axis, and inverse flattening).
  713. .. attribute:: semi_major
  714. Returns the semi major axis of the ellipsoid for this spatial reference.
  715. .. attribute:: semi_minor
  716. Returns the semi minor axis of the ellipsoid for this spatial reference.
  717. .. attribute:: inverse_flattening
  718. Returns the inverse flattening of the ellipsoid for this spatial reference.
  719. .. attribute:: geographic
  720. Returns ``True`` if this spatial reference is geographic (root node is
  721. ``GEOGCS``).
  722. .. attribute:: local
  723. Returns ``True`` if this spatial reference is local (root node is
  724. ``LOCAL_CS``).
  725. .. attribute:: projected
  726. Returns ``True`` if this spatial reference is a projected coordinate system
  727. (root node is ``PROJCS``).
  728. .. attribute:: wkt
  729. Returns the WKT representation of this spatial reference.
  730. .. attribute:: pretty_wkt
  731. Returns the 'pretty' representation of the WKT.
  732. .. attribute:: proj
  733. Returns the PROJ representation for this spatial reference.
  734. .. attribute:: proj4
  735. Alias for :attr:`SpatialReference.proj`.
  736. .. attribute:: xml
  737. Returns the XML representation of this spatial reference.
  738. ``CoordTransform``
  739. ------------------
  740. .. class:: CoordTransform(source, target)
  741. Represents a coordinate system transform. It is initialized with two
  742. :class:`SpatialReference`, representing the source and target coordinate
  743. systems, respectively. These objects should be used when performing the same
  744. coordinate transformation repeatedly on different geometries:
  745. .. code-block:: pycon
  746. >>> ct = CoordTransform(SpatialReference("WGS84"), SpatialReference("NAD83"))
  747. >>> for feat in layer:
  748. ... geom = feat.geom # getting clone of feature geometry
  749. ... geom.transform(ct) # transforming
  750. ...
  751. .. _raster-data-source-objects:
  752. Raster Data Objects
  753. ===================
  754. ``GDALRaster``
  755. ----------------
  756. :class:`GDALRaster` is a wrapper for the GDAL raster source object that
  757. supports reading data from a variety of GDAL-supported geospatial file
  758. formats and data sources using a consistent interface. Each
  759. data source is represented by a :class:`GDALRaster` object which contains
  760. one or more layers of data named bands. Each band, represented by a
  761. :class:`GDALBand` object, contains georeferenced image data. For example, an RGB
  762. image is represented as three bands: one for red, one for green, and one for
  763. blue.
  764. .. note::
  765. For raster data there is no difference between a raster instance and its
  766. data source. Unlike for the Geometry objects, :class:`GDALRaster` objects are
  767. always a data source. Temporary rasters can be instantiated in memory
  768. using the corresponding driver, but they will be of the same class as file-based
  769. raster sources.
  770. .. class:: GDALRaster(ds_input, write=False)
  771. The constructor for ``GDALRaster`` accepts two parameters. The first
  772. parameter defines the raster source, and the second parameter defines if a
  773. raster should be opened in write mode. For newly-created rasters, the second
  774. parameter is ignored and the new raster is always created in write mode.
  775. The first parameter can take three forms: a string or
  776. :class:`~pathlib.Path` representing a file path (filesystem or GDAL virtual
  777. filesystem), a dictionary with values defining a new raster, or a bytes
  778. object representing a raster file.
  779. If the input is a file path, the raster is opened from there. If the input
  780. is raw data in a dictionary, the parameters ``width``, ``height``, and
  781. ``srid`` are required. If the input is a bytes object, it will be opened
  782. using a GDAL virtual filesystem.
  783. For a detailed description of how to create rasters using dictionary input,
  784. see :ref:`gdal-raster-ds-input`. For a detailed description of how to
  785. create rasters in the virtual filesystem, see :ref:`gdal-raster-vsimem`.
  786. The following example shows how rasters can be created from different input
  787. sources (using the sample data from the GeoDjango tests; see also the
  788. :ref:`gdal_sample_data` section).
  789. >>> from django.contrib.gis.gdal import GDALRaster
  790. >>> rst = GDALRaster('/path/to/your/raster.tif', write=False)
  791. >>> rst.name
  792. '/path/to/your/raster.tif'
  793. >>> rst.width, rst.height # This file has 163 x 174 pixels
  794. (163, 174)
  795. >>> rst = GDALRaster({ # Creates an in-memory raster
  796. ... 'srid': 4326,
  797. ... 'width': 4,
  798. ... 'height': 4,
  799. ... 'datatype': 1,
  800. ... 'bands': [{
  801. ... 'data': (2, 3),
  802. ... 'offset': (1, 1),
  803. ... 'size': (2, 2),
  804. ... 'shape': (2, 1),
  805. ... 'nodata_value': 5,
  806. ... }]
  807. ... })
  808. >>> rst.srs.srid
  809. 4326
  810. >>> rst.width, rst.height
  811. (4, 4)
  812. >>> rst.bands[0].data()
  813. array([[5, 5, 5, 5],
  814. [5, 2, 3, 5],
  815. [5, 2, 3, 5],
  816. [5, 5, 5, 5]], dtype=uint8)
  817. >>> rst_file = open('/path/to/your/raster.tif', 'rb')
  818. >>> rst_bytes = rst_file.read()
  819. >>> rst = GDALRaster(rst_bytes)
  820. >>> rst.is_vsi_based
  821. True
  822. >>> rst.name # Stored in a random path in the vsimem filesystem.
  823. '/vsimem/da300bdb-129d-49a8-b336-e410a9428dad'
  824. .. versionchanged:: 4.2
  825. Support for :class:`pathlib.Path` ``ds_input`` was added.
  826. .. attribute:: name
  827. The name of the source which is equivalent to the input file path or the name
  828. provided upon instantiation.
  829. >>> GDALRaster({'width': 10, 'height': 10, 'name': 'myraster', 'srid': 4326}).name
  830. 'myraster'
  831. .. attribute:: driver
  832. The name of the GDAL driver used to handle the input file. For ``GDALRaster``\s created
  833. from a file, the driver type is detected automatically. The creation of rasters from
  834. scratch is an in-memory raster by default (``'MEM'``), but can be
  835. altered as needed. For instance, use ``GTiff`` for a ``GeoTiff`` file.
  836. For a list of file types, see also the `GDAL Raster Formats`__ list.
  837. __ https://gdal.org/drivers/raster/
  838. An in-memory raster is created through the following example:
  839. >>> GDALRaster({'width': 10, 'height': 10, 'srid': 4326}).driver.name
  840. 'MEM'
  841. A file based GeoTiff raster is created through the following example:
  842. >>> import tempfile
  843. >>> rstfile = tempfile.NamedTemporaryFile(suffix='.tif')
  844. >>> rst = GDALRaster({'driver': 'GTiff', 'name': rstfile.name, 'srid': 4326,
  845. ... 'width': 255, 'height': 255, 'nr_of_bands': 1})
  846. >>> rst.name
  847. '/tmp/tmp7x9H4J.tif' # The exact filename will be different on your computer
  848. >>> rst.driver.name
  849. 'GTiff'
  850. .. attribute:: width
  851. The width of the source in pixels (X-axis).
  852. >>> GDALRaster({'width': 10, 'height': 20, 'srid': 4326}).width
  853. 10
  854. .. attribute:: height
  855. The height of the source in pixels (Y-axis).
  856. >>> GDALRaster({'width': 10, 'height': 20, 'srid': 4326}).height
  857. 20
  858. .. attribute:: srs
  859. The spatial reference system of the raster, as a
  860. :class:`SpatialReference` instance. The SRS can be changed by
  861. setting it to an other :class:`SpatialReference` or providing any input
  862. that is accepted by the :class:`SpatialReference` constructor.
  863. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
  864. >>> rst.srs.srid
  865. 4326
  866. >>> rst.srs = 3086
  867. >>> rst.srs.srid
  868. 3086
  869. .. attribute:: srid
  870. The Spatial Reference System Identifier (SRID) of the raster. This
  871. property is a shortcut to getting or setting the SRID through the
  872. :attr:`srs` attribute.
  873. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
  874. >>> rst.srid
  875. 4326
  876. >>> rst.srid = 3086
  877. >>> rst.srid
  878. 3086
  879. >>> rst.srs.srid # This is equivalent
  880. 3086
  881. .. attribute:: geotransform
  882. The affine transformation matrix used to georeference the source, as a
  883. tuple of six coefficients which map pixel/line coordinates into
  884. georeferenced space using the following relationship::
  885. Xgeo = GT(0) + Xpixel * GT(1) + Yline * GT(2)
  886. Ygeo = GT(3) + Xpixel * GT(4) + Yline * GT(5)
  887. The same values can be retrieved by accessing the :attr:`origin`
  888. (indices 0 and 3), :attr:`scale` (indices 1 and 5) and :attr:`skew`
  889. (indices 2 and 4) properties.
  890. The default is ``[0.0, 1.0, 0.0, 0.0, 0.0, -1.0]``.
  891. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
  892. >>> rst.geotransform
  893. [0.0, 1.0, 0.0, 0.0, 0.0, -1.0]
  894. .. attribute:: origin
  895. Coordinates of the top left origin of the raster in the spatial
  896. reference system of the source, as a point object with ``x`` and ``y``
  897. members.
  898. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
  899. >>> rst.origin
  900. [0.0, 0.0]
  901. >>> rst.origin.x = 1
  902. >>> rst.origin
  903. [1.0, 0.0]
  904. .. attribute:: scale
  905. Pixel width and height used for georeferencing the raster, as a point
  906. object with ``x`` and ``y`` members. See :attr:`geotransform` for more
  907. information.
  908. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
  909. >>> rst.scale
  910. [1.0, -1.0]
  911. >>> rst.scale.x = 2
  912. >>> rst.scale
  913. [2.0, -1.0]
  914. .. attribute:: skew
  915. Skew coefficients used to georeference the raster, as a point object
  916. with ``x`` and ``y`` members. In case of north up images, these
  917. coefficients are both ``0``.
  918. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
  919. >>> rst.skew
  920. [0.0, 0.0]
  921. >>> rst.skew.x = 3
  922. >>> rst.skew
  923. [3.0, 0.0]
  924. .. attribute:: extent
  925. Extent (boundary values) of the raster source, as a 4-tuple
  926. ``(xmin, ymin, xmax, ymax)`` in the spatial reference system of the
  927. source.
  928. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
  929. >>> rst.extent
  930. (0.0, -20.0, 10.0, 0.0)
  931. >>> rst.origin.x = 100
  932. >>> rst.extent
  933. (100.0, -20.0, 110.0, 0.0)
  934. .. attribute:: bands
  935. List of all bands of the source, as :class:`GDALBand` instances.
  936. >>> rst = GDALRaster({"width": 1, "height": 2, 'srid': 4326,
  937. ... "bands": [{"data": [0, 1]}, {"data": [2, 3]}]})
  938. >>> len(rst.bands)
  939. 2
  940. >>> rst.bands[1].data()
  941. array([[ 2., 3.]], dtype=float32)
  942. .. method:: warp(ds_input, resampling='NearestNeighbour', max_error=0.0)
  943. Returns a warped version of this raster.
  944. The warping parameters can be specified through the ``ds_input``
  945. argument. The use of ``ds_input`` is analogous to the corresponding
  946. argument of the class constructor. It is a dictionary with the
  947. characteristics of the target raster. Allowed dictionary key values are
  948. width, height, SRID, origin, scale, skew, datatype, driver, and name
  949. (filename).
  950. By default, the warp functions keeps most parameters equal to the
  951. values of the original source raster, so only parameters that should be
  952. changed need to be specified. Note that this includes the driver, so
  953. for file-based rasters the warp function will create a new raster on
  954. disk.
  955. The only parameter that is set differently from the source raster is the
  956. name. The default value of the raster name is the name of the source
  957. raster appended with ``'_copy' + source_driver_name``. For file-based
  958. rasters it is recommended to provide the file path of the target raster.
  959. The resampling algorithm used for warping can be specified with the
  960. ``resampling`` argument. The default is ``NearestNeighbor``, and the
  961. other allowed values are ``Bilinear``, ``Cubic``, ``CubicSpline``,
  962. ``Lanczos``, ``Average``, and ``Mode``.
  963. The ``max_error`` argument can be used to specify the maximum error
  964. measured in input pixels that is allowed in approximating the
  965. transformation. The default is 0.0 for exact calculations.
  966. For users familiar with ``GDAL``, this function has a similar
  967. functionality to the ``gdalwarp`` command-line utility.
  968. For example, the warp function can be used for aggregating a raster to
  969. the double of its original pixel scale:
  970. >>> rst = GDALRaster({
  971. ... "width": 6, "height": 6, "srid": 3086,
  972. ... "origin": [500000, 400000],
  973. ... "scale": [100, -100],
  974. ... "bands": [{"data": range(36), "nodata_value": 99}]
  975. ... })
  976. >>> target = rst.warp({"scale": [200, -200], "width": 3, "height": 3})
  977. >>> target.bands[0].data()
  978. array([[ 7., 9., 11.],
  979. [ 19., 21., 23.],
  980. [ 31., 33., 35.]], dtype=float32)
  981. .. method:: transform(srs, driver=None, name=None, resampling='NearestNeighbour', max_error=0.0)
  982. Transforms this raster to a different spatial reference system
  983. (``srs``), which may be a :class:`SpatialReference` object, or any
  984. other input accepted by :class:`SpatialReference` (including spatial
  985. reference WKT and PROJ strings, or an integer SRID).
  986. It calculates the bounds and scale of the current raster in the new
  987. spatial reference system and warps the raster using the
  988. :attr:`~GDALRaster.warp` function.
  989. By default, the driver of the source raster is used and the name of the
  990. raster is the original name appended with
  991. ``'_copy' + source_driver_name``. A different driver or name can be
  992. specified with the ``driver`` and ``name`` arguments.
  993. The default resampling algorithm is ``NearestNeighbour`` but can be
  994. changed using the ``resampling`` argument. The default maximum allowed
  995. error for resampling is 0.0 and can be changed using the ``max_error``
  996. argument. Consult the :attr:`~GDALRaster.warp` documentation for detail
  997. on those arguments.
  998. >>> rst = GDALRaster({
  999. ... "width": 6, "height": 6, "srid": 3086,
  1000. ... "origin": [500000, 400000],
  1001. ... "scale": [100, -100],
  1002. ... "bands": [{"data": range(36), "nodata_value": 99}]
  1003. ... })
  1004. >>> target_srs = SpatialReference(4326)
  1005. >>> target = rst.transform(target_srs)
  1006. >>> target.origin
  1007. [-82.98492744885776, 27.601924753080144]
  1008. .. attribute:: info
  1009. Returns a string with a summary of the raster. This is equivalent to
  1010. the `gdalinfo`__ command line utility.
  1011. __ https://gdal.org/programs/gdalinfo.html
  1012. .. attribute:: metadata
  1013. The metadata of this raster, represented as a nested dictionary. The
  1014. first-level key is the metadata domain. The second-level contains the
  1015. metadata item names and values from each domain.
  1016. To set or update a metadata item, pass the corresponding metadata item
  1017. to the method using the nested structure described above. Only keys
  1018. that are in the specified dictionary are updated; the rest of the
  1019. metadata remains unchanged.
  1020. To remove a metadata item, use ``None`` as the metadata value.
  1021. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326})
  1022. >>> rst.metadata
  1023. {}
  1024. >>> rst.metadata = {'DEFAULT': {'OWNER': 'Django', 'VERSION': '1.0'}}
  1025. >>> rst.metadata
  1026. {'DEFAULT': {'OWNER': 'Django', 'VERSION': '1.0'}}
  1027. >>> rst.metadata = {'DEFAULT': {'OWNER': None, 'VERSION': '2.0'}}
  1028. >>> rst.metadata
  1029. {'DEFAULT': {'VERSION': '2.0'}}
  1030. .. attribute:: vsi_buffer
  1031. A ``bytes`` representation of this raster. Returns ``None`` for rasters
  1032. that are not stored in GDAL's virtual filesystem.
  1033. .. attribute:: is_vsi_based
  1034. A boolean indicating if this raster is stored in GDAL's virtual
  1035. filesystem.
  1036. ``GDALBand``
  1037. ------------
  1038. .. class:: GDALBand
  1039. ``GDALBand`` instances are not created explicitly, but rather obtained
  1040. from a :class:`GDALRaster` object, through its :attr:`~GDALRaster.bands`
  1041. attribute. The GDALBands contain the actual pixel values of the raster.
  1042. .. attribute:: description
  1043. The name or description of the band, if any.
  1044. .. attribute:: width
  1045. The width of the band in pixels (X-axis).
  1046. .. attribute:: height
  1047. The height of the band in pixels (Y-axis).
  1048. .. attribute:: pixel_count
  1049. The total number of pixels in this band. Is equal to ``width * height``.
  1050. .. method:: statistics(refresh=False, approximate=False)
  1051. Compute statistics on the pixel values of this band. The return value
  1052. is a tuple with the following structure:
  1053. ``(minimum, maximum, mean, standard deviation)``.
  1054. If the ``approximate`` argument is set to ``True``, the statistics may
  1055. be computed based on overviews or a subset of image tiles.
  1056. If the ``refresh`` argument is set to ``True``, the statistics will be
  1057. computed from the data directly, and the cache will be updated with the
  1058. result.
  1059. If a persistent cache value is found, that value is returned. For
  1060. raster formats using Persistent Auxiliary Metadata (PAM) services, the
  1061. statistics might be cached in an auxiliary file. In some cases this
  1062. metadata might be out of sync with the pixel values or cause values
  1063. from a previous call to be returned which don't reflect the value of
  1064. the ``approximate`` argument. In such cases, use the ``refresh``
  1065. argument to get updated values and store them in the cache.
  1066. For empty bands (where all pixel values are "no data"), all statistics
  1067. are returned as ``None``.
  1068. The statistics can also be retrieved directly by accessing the
  1069. :attr:`min`, :attr:`max`, :attr:`mean`, and :attr:`std` properties.
  1070. .. attribute:: min
  1071. The minimum pixel value of the band (excluding the "no data" value).
  1072. .. attribute:: max
  1073. The maximum pixel value of the band (excluding the "no data" value).
  1074. .. attribute:: mean
  1075. The mean of all pixel values of the band (excluding the "no data"
  1076. value).
  1077. .. attribute:: std
  1078. The standard deviation of all pixel values of the band (excluding the
  1079. "no data" value).
  1080. .. attribute:: nodata_value
  1081. The "no data" value for a band is generally a special marker value used
  1082. to mark pixels that are not valid data. Such pixels should generally not
  1083. be displayed, nor contribute to analysis operations.
  1084. To delete an existing "no data" value, set this property to ``None``.
  1085. .. method:: datatype(as_string=False)
  1086. The data type contained in the band, as an integer constant between 0
  1087. (Unknown) and 14. If ``as_string`` is ``True``, the data type is
  1088. returned as a string. Check out the "GDAL Pixel Type" column in the
  1089. :ref:`datatype value table <gdal-raster-datatype>` for possible values.
  1090. .. method:: color_interp(as_string=False)
  1091. The color interpretation for the band, as an integer between 0and 16.
  1092. If ``as_string`` is ``True``, the data type is returned as a string
  1093. with the following possible values:
  1094. ``GCI_Undefined``, ``GCI_GrayIndex``, ``GCI_PaletteIndex``,
  1095. ``GCI_RedBand``, ``GCI_GreenBand``, ``GCI_BlueBand``, ``GCI_AlphaBand``,
  1096. ``GCI_HueBand``, ``GCI_SaturationBand``, ``GCI_LightnessBand``,
  1097. ``GCI_CyanBand``, ``GCI_MagentaBand``, ``GCI_YellowBand``,
  1098. ``GCI_BlackBand``, ``GCI_YCbCr_YBand``, ``GCI_YCbCr_CbBand``, and
  1099. ``GCI_YCbCr_CrBand``. ``GCI_YCbCr_CrBand`` also represents ``GCI_Max``
  1100. because both correspond to the integer 16, but only ``GCI_YCbCr_CrBand``
  1101. is returned as a string.
  1102. .. method:: data(data=None, offset=None, size=None, shape=None)
  1103. The accessor to the pixel values of the ``GDALBand``. Returns the complete
  1104. data array if no parameters are provided. A subset of the pixel array can
  1105. be requested by specifying an offset and block size as tuples.
  1106. If NumPy is available, the data is returned as NumPy array. For performance
  1107. reasons, it is highly recommended to use NumPy.
  1108. Data is written to the ``GDALBand`` if the ``data`` parameter is provided.
  1109. The input can be of one of the following types - packed string, buffer, list,
  1110. array, and NumPy array. The number of items in the input should normally
  1111. correspond to the total number of pixels in the band, or to the number
  1112. of pixels for a specific block of pixel values if the ``offset`` and
  1113. ``size`` parameters are provided.
  1114. If the number of items in the input is different from the target pixel
  1115. block, the ``shape`` parameter must be specified. The shape is a tuple
  1116. that specifies the width and height of the input data in pixels. The
  1117. data is then replicated to update the pixel values of the selected
  1118. block. This is useful to fill an entire band with a single value, for
  1119. instance.
  1120. For example:
  1121. >>> rst = GDALRaster({'width': 4, 'height': 4, 'srid': 4326, 'datatype': 1, 'nr_of_bands': 1})
  1122. >>> bnd = rst.bands[0]
  1123. >>> bnd.data(range(16))
  1124. >>> bnd.data()
  1125. array([[ 0, 1, 2, 3],
  1126. [ 4, 5, 6, 7],
  1127. [ 8, 9, 10, 11],
  1128. [12, 13, 14, 15]], dtype=int8)
  1129. >>> bnd.data(offset=(1, 1), size=(2, 2))
  1130. array([[ 5, 6],
  1131. [ 9, 10]], dtype=int8)
  1132. >>> bnd.data(data=[-1, -2, -3, -4], offset=(1, 1), size=(2, 2))
  1133. >>> bnd.data()
  1134. array([[ 0, 1, 2, 3],
  1135. [ 4, -1, -2, 7],
  1136. [ 8, -3, -4, 11],
  1137. [12, 13, 14, 15]], dtype=int8)
  1138. >>> bnd.data(data='\x9d\xa8\xb3\xbe', offset=(1, 1), size=(2, 2))
  1139. >>> bnd.data()
  1140. array([[ 0, 1, 2, 3],
  1141. [ 4, -99, -88, 7],
  1142. [ 8, -77, -66, 11],
  1143. [ 12, 13, 14, 15]], dtype=int8)
  1144. >>> bnd.data([1], shape=(1, 1))
  1145. >>> bnd.data()
  1146. array([[1, 1, 1, 1],
  1147. [1, 1, 1, 1],
  1148. [1, 1, 1, 1],
  1149. [1, 1, 1, 1]], dtype=uint8)
  1150. >>> bnd.data(range(4), shape=(1, 4))
  1151. array([[0, 0, 0, 0],
  1152. [1, 1, 1, 1],
  1153. [2, 2, 2, 2],
  1154. [3, 3, 3, 3]], dtype=uint8)
  1155. .. attribute:: metadata
  1156. The metadata of this band. The functionality is identical to
  1157. :attr:`GDALRaster.metadata`.
  1158. .. _gdal-raster-ds-input:
  1159. Creating rasters from data
  1160. --------------------------
  1161. This section describes how to create rasters from scratch using the
  1162. ``ds_input`` parameter.
  1163. A new raster is created when a ``dict`` is passed to the :class:`GDALRaster`
  1164. constructor. The dictionary contains defining parameters of the new raster,
  1165. such as the origin, size, or spatial reference system. The dictionary can also
  1166. contain pixel data and information about the format of the new raster. The
  1167. resulting raster can therefore be file-based or memory-based, depending on the
  1168. driver specified.
  1169. There's no standard for describing raster data in a dictionary or JSON flavor.
  1170. The definition of the dictionary input to the :class:`GDALRaster` class is
  1171. therefore specific to Django. It's inspired by the `geojson`__ format, but the
  1172. ``geojson`` standard is currently limited to vector formats.
  1173. Examples of using the different keys when creating rasters can be found in the
  1174. documentation of the corresponding attributes and methods of the
  1175. :class:`GDALRaster` and :class:`GDALBand` classes.
  1176. __ https://geojson.org/
  1177. The ``ds_input`` dictionary
  1178. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1179. Only a few keys are required in the ``ds_input`` dictionary to create a raster:
  1180. ``width``, ``height``, and ``srid``. All other parameters have default values
  1181. (see the table below). The list of keys that can be passed in the ``ds_input``
  1182. dictionary is closely related but not identical to the :class:`GDALRaster`
  1183. properties. Many of the parameters are mapped directly to those properties;
  1184. the others are described below.
  1185. The following table describes all keys that can be set in the ``ds_input``
  1186. dictionary.
  1187. ================= ======== ==================================================
  1188. Key Default Usage
  1189. ================= ======== ==================================================
  1190. ``srid`` required Mapped to the :attr:`~GDALRaster.srid` attribute
  1191. ``width`` required Mapped to the :attr:`~GDALRaster.width` attribute
  1192. ``height`` required Mapped to the :attr:`~GDALRaster.height` attribute
  1193. ``driver`` ``MEM`` Mapped to the :attr:`~GDALRaster.driver` attribute
  1194. ``name`` ``''`` See below
  1195. ``origin`` ``0`` Mapped to the :attr:`~GDALRaster.origin` attribute
  1196. ``scale`` ``0`` Mapped to the :attr:`~GDALRaster.scale` attribute
  1197. ``skew`` ``0`` Mapped to the :attr:`~GDALRaster.width` attribute
  1198. ``bands`` ``[]`` See below
  1199. ``nr_of_bands`` ``0`` See below
  1200. ``datatype`` ``6`` See below
  1201. ``papsz_options`` ``{}`` See below
  1202. ================= ======== ==================================================
  1203. .. object:: name
  1204. String representing the name of the raster. When creating a file-based
  1205. raster, this parameter must be the file path for the new raster. If the
  1206. name starts with ``/vsimem/``, the raster is created in GDAL's virtual
  1207. filesystem.
  1208. .. _gdal-raster-datatype:
  1209. .. object:: datatype
  1210. Integer representing the data type for all the bands. Defaults to ``6``
  1211. (Float32). All bands of a new raster are required to have the same datatype.
  1212. The value mapping is:
  1213. ===== =============== ===================================
  1214. Value GDAL Pixel Type Description
  1215. ===== =============== ===================================
  1216. 1 GDT_Byte 8 bit unsigned integer
  1217. 2 GDT_UInt16 16 bit unsigned integer
  1218. 3 GDT_Int16 16 bit signed integer
  1219. 4 GDT_UInt32 32 bit unsigned integer
  1220. 5 GDT_Int32 32 bit signed integer
  1221. 6 GDT_Float32 32 bit floating point
  1222. 7 GDT_Float64 64 bit floating point
  1223. 12 GDT_UInt64 64 bit unsigned integer (GDAL 3.5+)
  1224. 13 GDT_Int64 64 bit signed integer (GDAL 3.5+)
  1225. 14 GDT_Int8 8 bit signed integer (GDAL 3.7+)
  1226. ===== =============== ===================================
  1227. .. object:: nr_of_bands
  1228. Integer representing the number of bands of the raster. A raster can be
  1229. created without passing band data upon creation. If the number of bands
  1230. isn't specified, it's automatically calculated from the length of the
  1231. ``bands`` input. The number of bands can't be changed after creation.
  1232. .. object:: bands
  1233. A list of ``band_input`` dictionaries with band input data. The resulting
  1234. band indices are the same as in the list provided. The definition of the
  1235. band input dictionary is given below. If band data isn't provided, the
  1236. raster bands values are instantiated as an array of zeros and the "no
  1237. data" value is set to ``None``.
  1238. .. object:: papsz_options
  1239. A dictionary with raster creation options. The key-value pairs of the
  1240. input dictionary are passed to the driver on creation of the raster.
  1241. The available options are driver-specific and are described in the
  1242. documentation of each driver.
  1243. The values in the dictionary are not case-sensitive and are automatically
  1244. converted to the correct string format upon creation.
  1245. The following example uses some of the options available for the
  1246. `GTiff driver`__. The result is a compressed raster with an internal tiling
  1247. scheme. The internal tiles have a block size of 23 by 23:
  1248. .. code-block:: pycon
  1249. >>> GDALRaster(
  1250. ... {
  1251. ... "driver": "GTiff",
  1252. ... "name": "/path/to/new/file.tif",
  1253. ... "srid": 4326,
  1254. ... "width": 255,
  1255. ... "height": 255,
  1256. ... "nr_of_bands": 1,
  1257. ... "papsz_options": {
  1258. ... "compress": "packbits",
  1259. ... "tiled": "yes",
  1260. ... "blockxsize": 23,
  1261. ... "blockysize": 23,
  1262. ... },
  1263. ... }
  1264. ... )
  1265. __ https://gdal.org/drivers/raster/gtiff.html
  1266. The ``band_input`` dictionary
  1267. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1268. The ``bands`` key in the ``ds_input`` dictionary is a list of ``band_input``
  1269. dictionaries. Each ``band_input`` dictionary can contain pixel values and the
  1270. "no data" value to be set on the bands of the new raster. The data array can
  1271. have the full size of the new raster or be smaller. For arrays that are smaller
  1272. than the full raster, the ``size``, ``shape``, and ``offset`` keys control the
  1273. pixel values. The corresponding keys are passed to the :meth:`~GDALBand.data`
  1274. method. Their functionality is the same as setting the band data with that
  1275. method. The following table describes the keys that can be used.
  1276. ================ ================================= ======================================================
  1277. Key Default Usage
  1278. ================ ================================= ======================================================
  1279. ``nodata_value`` ``None`` Mapped to the :attr:`~GDALBand.nodata_value` attribute
  1280. ``data`` Same as ``nodata_value`` or ``0`` Passed to the :meth:`~GDALBand.data` method
  1281. ``size`` ``(with, height)`` of raster Passed to the :meth:`~GDALBand.data` method
  1282. ``shape`` Same as size Passed to the :meth:`~GDALBand.data` method
  1283. ``offset`` ``(0, 0)`` Passed to the :meth:`~GDALBand.data` method
  1284. ================ ================================= ======================================================
  1285. .. _gdal-raster-vsimem:
  1286. Using GDAL's Virtual Filesystem
  1287. -------------------------------
  1288. GDAL can access files stored in the filesystem, but also supports virtual
  1289. filesystems to abstract accessing other kind of files, such as compressed,
  1290. encrypted, or remote files.
  1291. Using memory-based Virtual Filesystem
  1292. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1293. GDAL has an internal memory-based filesystem, which allows treating blocks of
  1294. memory as files. It can be used to read and write :class:`GDALRaster` objects
  1295. to and from binary file buffers.
  1296. This is useful in web contexts where rasters might be obtained as a buffer
  1297. from a remote storage or returned from a view without being written to disk.
  1298. :class:`GDALRaster` objects are created in the virtual filesystem when a
  1299. ``bytes`` object is provided as input, or when the file path starts with
  1300. ``/vsimem/``.
  1301. Input provided as ``bytes`` has to be a full binary representation of a file.
  1302. For instance:
  1303. .. code-block:: pycon
  1304. # Read a raster as a file object from a remote source.
  1305. >>> from urllib.request import urlopen
  1306. >>> dat = urlopen("http://example.com/raster.tif").read()
  1307. # Instantiate a raster from the bytes object.
  1308. >>> rst = GDALRaster(dat)
  1309. # The name starts with /vsimem/, indicating that the raster lives in the
  1310. # virtual filesystem.
  1311. >>> rst.name
  1312. '/vsimem/da300bdb-129d-49a8-b336-e410a9428dad'
  1313. To create a new virtual file-based raster from scratch, use the ``ds_input``
  1314. dictionary representation and provide a ``name`` argument that starts with
  1315. ``/vsimem/`` (for detail of the dictionary representation, see
  1316. :ref:`gdal-raster-ds-input`). For virtual file-based rasters, the
  1317. :attr:`~GDALRaster.vsi_buffer` attribute returns the ``bytes`` representation
  1318. of the raster.
  1319. Here's how to create a raster and return it as a file in an
  1320. :class:`~django.http.HttpResponse`:
  1321. .. code-block:: pycon
  1322. >>> from django.http import HttpResponse
  1323. >>> rst = GDALRaster(
  1324. ... {
  1325. ... "name": "/vsimem/temporarymemfile",
  1326. ... "driver": "tif",
  1327. ... "width": 6,
  1328. ... "height": 6,
  1329. ... "srid": 3086,
  1330. ... "origin": [500000, 400000],
  1331. ... "scale": [100, -100],
  1332. ... "bands": [{"data": range(36), "nodata_value": 99}],
  1333. ... }
  1334. ... )
  1335. >>> HttpResponse(rast.vsi_buffer, "image/tiff")
  1336. Using other Virtual Filesystems
  1337. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1338. Depending on the local build of GDAL other virtual filesystems may be
  1339. supported. You can use them by prepending the provided path with the
  1340. appropriate ``/vsi*/`` prefix. See the `GDAL Virtual Filesystems
  1341. documentation`_ for more details.
  1342. .. warning:
  1343. Rasters with names starting with `/vsi*/` will be treated as rasters from
  1344. the GDAL virtual filesystems. Django doesn't perform any extra validation.
  1345. Compressed rasters
  1346. ^^^^^^^^^^^^^^^^^^
  1347. Instead decompressing the file and instantiating the resulting raster, GDAL can
  1348. directly access compressed files using the ``/vsizip/``, ``/vsigzip/``, or
  1349. ``/vsitar/`` virtual filesystems:
  1350. .. code-block:: pycon
  1351. >>> from django.contrib.gis.gdal import GDALRaster
  1352. >>> rst = GDALRaster("/vsizip/path/to/your/file.zip/path/to/raster.tif")
  1353. >>> rst = GDALRaster("/vsigzip/path/to/your/file.gz")
  1354. >>> rst = GDALRaster("/vsitar/path/to/your/file.tar/path/to/raster.tif")
  1355. Network rasters
  1356. ^^^^^^^^^^^^^^^
  1357. GDAL can support online resources and storage providers transparently. As long
  1358. as it's built with such capabilities.
  1359. To access a public raster file with no authentication, you can use
  1360. ``/vsicurl/``:
  1361. .. code-block:: pycon
  1362. >>> from django.contrib.gis.gdal import GDALRaster
  1363. >>> rst = GDALRaster("/vsicurl/https://example.com/raster.tif")
  1364. >>> rst.name
  1365. '/vsicurl/https://example.com/raster.tif'
  1366. For commercial storage providers (e.g. ``/vsis3/``) the system should be
  1367. previously configured for authentication and possibly other settings (see the
  1368. `GDAL Virtual Filesystems documentation`_ for available options).
  1369. .. _`GDAL Virtual Filesystems documentation`: https://gdal.org/user/virtual_file_systems.html
  1370. Settings
  1371. ========
  1372. .. setting:: GDAL_LIBRARY_PATH
  1373. ``GDAL_LIBRARY_PATH``
  1374. ---------------------
  1375. A string specifying the location of the GDAL library. Typically,
  1376. this setting is only used if the GDAL library is in a non-standard
  1377. location (e.g., ``/home/john/lib/libgdal.so``).
  1378. Exceptions
  1379. ==========
  1380. .. exception:: GDALException
  1381. The base GDAL exception, indicating a GDAL-related error.
  1382. .. exception:: SRSException
  1383. An exception raised when an error occurs when constructing or using a
  1384. spatial reference system object.