#34302: SpatialReference.srid incorrectly assumes first AUTHORITY value to be projection SRID ------------------------------+---------------------------------------- Reporter: Stefan Brand | Owner: Stefan Brand Type: Bug | Status: assigned Component: GIS | Version: dev Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 ------------------------------+---------------------------------------- Changes (by Stefan Brand):
* owner: nobody => Stefan Brand * status: new => assigned Comment: While applying the change, I got a failing test. It turns out that GeoDjango has a different behaviour than the GDAL Python bindings. Compare: {{{ #!python from django.contrib.gis.gdal import SpatialReference from osgeo import ogr WEB_MERCATOR = """PROJCS["WGS 84 / Pseudo-Mercator", GEOGCS["WGS 84", DATUM["WGS_1984", SPHEROID["WGS 84",6378137,298.257223563, AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich",0, AUTHORITY["EPSG","8901"]], UNIT["degree",0.0174532925199433, AUTHORITY["EPSG","9122"]], AUTHORITY["EPSG","4326"]], PROJECTION["Mercator_1SP"], PARAMETER["central_meridian",0], PARAMETER["scale_factor",1], PARAMETER["false_easting",0], PARAMETER["false_northing",0], UNIT["metre",1, AUTHORITY["EPSG","9001"]], AXIS["Easting",EAST], AXIS["Northing",NORTH], EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs"], AUTHORITY["EPSG","3857"]]""" geodjango_srs = SpatialReference(WEB_MERCATOR) geodjango_srs.validate() # raises for invalid SRS print(geodjango_srs.attr_value("AUTHORITY", 1)) print(geodjango_srs.auth_code(target=None)) ogr_srs = ogr.osr.SpatialReference(WEB_MERCATOR) if ogr_srs.Validate(): raise print(ogr_srs.GetAttrValue("AUTHORITY", 1)) print(ogr_srs.GetAuthorityCode(None)) }}} > 3857 > None > 3857 > 3857 The reason is that [https://github.com/django/django/blob/fd21f82aa82b0d75a161f618ef944ebe0923e0ab/django/utils/encoding.py#L91-L108 `django/utils/force_bytes`] turns `None` into the byte string `b'None'`. Since `ctypes.c_char_p` also accepts `None`, we can bypass `force_bytes` if `target is None`. I will do some more testing and push a patch tomorrow. -- Ticket URL: <https://code.djangoproject.com/ticket/34302#comment:3> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018631ae42f0-e18c30fa-0007-44e1-abd5-e314e9b7e28f-000000%40eu-central-1.amazonses.com.