#34302: SpatialReference.srid incorrectly assumes first AUTHORITY value to be
projection SRID
----------------------------------------+------------------------
Reporter: Stefan Brand | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 4.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
== Problem
When reading data into our PostGIS database, we noticed strange locations
for our geometries. The data was supposed to be `EPSG:31287`, but
investigation showed that Django was assuming `EPSG:6312`. This led to
wrong EWKTs when saving geometries to PostGIS.
It turns out that the dataset did not have any SRID stored for the
projection, just for the DATUM. Django assumed the DATUM's AUTHORITY value
to be the SRID of the dataset's projection. This '''contradicts the
[https://docs.djangoproject.com/en/4.1/ref/contrib/gis/gdal/#django.contrib.gis.gdal.SpatialReference.srid
documentation]''' for `SpatialReference.srid`:
> Returns the SRID of top-level authority, or None if undefined.
Since the layer's `srid` cannot be set to a different value, the only
workaround is to set the `srid` for each `OGRGeometry` individually.
== Current Result
[https://github.com/django/django/blob/0265b1b49ba10f957abfd1311d0bae0ecefc3111/django/contrib/gis/gdal/srs.py#L208
`SpatialReference.srid`] calls `int(self.attr_value("AUTHORITY", 1))`,
which returns `6312` (wrong SRID).
== Expected Result
`SpatialReference.srid` should call `auth_code(target=None)` to get the
top-level SRID.
Django should not assume a wrong SRID if the projection does not have a
SRID. For example, QGIS reads the whole spatial reference information,
correctly projects the data, but displays "Unknown CRS" because it does
not assume any AUTHORITY value to be the dataset SRID.
== Steps to reproduce
{{{
#!python
from django.contrib.gis.gdal import SpatialReference
WKT = """PROJCRS["MGI / Austria Lambert",
BASEGEOGCRS["MGI",
DATUM["Militar-Geographische Institut",
ELLIPSOID["Bessel 1841",6377397.155,299.1528128,
LENGTHUNIT["metre",1]],
ID["EPSG",6312]],
PRIMEM["Greenwich",0,
ANGLEUNIT["Degree",0.0174532925199433]]],
CONVERSION["unnamed",
METHOD["Lambert Conic Conformal (2SP)",
ID["EPSG",9802]],
PARAMETER["Latitude of false origin",47.5,
ANGLEUNIT["Degree",0.0174532925199433],
ID["EPSG",8821]],
PARAMETER["Longitude of false origin",13.3333333333333,
ANGLEUNIT["Degree",0.0174532925199433],
ID["EPSG",8822]],
PARAMETER["Latitude of 1st standard parallel",49,
ANGLEUNIT["Degree",0.0174532925199433],
ID["EPSG",8823]],
PARAMETER["Latitude of 2nd standard parallel",46,
ANGLEUNIT["Degree",0.0174532925199433],
ID["EPSG",8824]],
PARAMETER["Easting at false origin",400000,
LENGTHUNIT["metre",1],
ID["EPSG",8826]],
PARAMETER["Northing at false origin",400000,
LENGTHUNIT["metre",1],
ID["EPSG",8827]]],
CS[Cartesian,2],
AXIS["easting",east,
ORDER[1],
LENGTHUNIT["metre",1,
ID["EPSG",9001]]],
AXIS["northing",north,
ORDER[2],
LENGTHUNIT["metre",1,
ID["EPSG",9001]]]]"""
geodjango_srs = SpatialReference(WKT)
geodjango_srs.validate() # raises for invalid SRS
print(geodjango_srs.attr_value("AUTHORITY", 1))
print(geodjango_srs.auth_code(target=None))
}}}
> 6312
> None
--
Ticket URL: <https://code.djangoproject.com/ticket/34302>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018601fe57ee-68ef32f8-2cd0-4f52-98b0-efe322806cb3-000000%40eu-central-1.amazonses.com.