[Django] #36001: error GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found' with custom CRS in spatial_ref_sys

10 views
Skip to first unread message

Django

unread,
Dec 11, 2024, 11:11:11 AM12/11/24
to django-...@googlegroups.com
#36001: error GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found' with
custom CRS in spatial_ref_sys
-------------------------------------+-------------------------------------
Reporter: Alex | Type: Bug
Status: new | Component: GIS
Version: 4.2 | Severity: Normal
Keywords: gdal, proj4, | Triage Stage:
postgis | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Hi
situation with custom CRS in geodjango.

context: Debian GNU/Linux 12 (bookworm), Postgresql 16.6, Python 3.11.2,
Postgis 3.4.2, GDAL 3.6.2, PROJ 9.1.1, Django 4.2.11

Objects with geometry in DB creates with no problem with this class
{{{
from django.contrib.gis.db import models

class Location(models.Model):
...
c_geom = models.GeometryCollectionField(srid=300001)
...
}}}
gdalsrsinfo works as expected
{{{
gdalsrsinfo 'USER:300001'
PROJ.4 : +proj=tmerc ...
}}}
projinfo also works fine
{{{
projinfo 'USER:300001'
PROJ.4 : +proj=tmerc ...
}}}
python manage.py shell `is correct`
{{{
from osgeo import osr
sk = osr.SpatialReference()
sk.SetFromUserInput('USER:300001')
0
print(sk)
PROJCS...
}}}

, but app always throws errors when fetch and create objects

{{{
def create(self, validated_data):
if "SRID=300001;" in str(self.validated_data["geom"]):
logger.info("*"*60)
logger.info(f"validated_data geom with USER:300001:
{self.validated_data['geom']}")
logger.info(f"geom srid: {self.validated_data['geom'].srid}")
from osgeo import osr
sk = osr.SpatialReference()
sk.SetFromUserInput('USER:300001') # <- here same error:
GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
logger.info(f"SpatialReference: {sk}")
logger.info("*"*60)
}}}

error.log
{{{
************************************************************
validated_data geom with USER:300001: SRID=300001;GEOMETRYCOLLECTION Z
(POINT Z (83721.138 59266.787 101.09))
geom srid: 300001
GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
SpatialReference:
************************************************************
GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
...
}}}
if request one object via api, Django send 8 email with this error. odd
--
Ticket URL: <https://code.djangoproject.com/ticket/36001>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 11, 2024, 1:41:19 PM12/11/24
to django-...@googlegroups.com
#36001: error GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found' with
custom CRS in spatial_ref_sys
-------------------------------------+-------------------------------------
Reporter: Alex | Owner: (none)
Type: Bug | Status: new
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: gdal, proj4, | Triage Stage:
postgis | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Alex:

Old description:
New description:

Hi
situation with custom CRS in geodjango.

context: Debian GNU/Linux 12 (bookworm), Postgresql 16.6, Python 3.11.2,
Postgis 3.4.2, GDAL 3.6.2, PROJ 9.1.1, Django 4.2.11, DRF 3.5.11, [DRF-
GIS]https://github.com/openwisp/django-rest-framework-gis 1.0

Objects with geometry in DB creates with no problem with this class
{{{#!python
--
Ticket URL: <https://code.djangoproject.com/ticket/36001#comment:1>

Django

unread,
Dec 11, 2024, 1:47:19 PM12/11/24
to django-...@googlegroups.com
#36001: error GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found' with
custom CRS in spatial_ref_sys
-------------------------------------+-------------------------------------
Reporter: Alex | Owner: (none)
Type: Bug | Status: new
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: gdal, proj4, | Triage Stage:
postgis | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Alex:

Old description:

> Hi
> situation with custom CRS in geodjango.
>
> context: Debian GNU/Linux 12 (bookworm), Postgresql 16.6, Python 3.11.2,
{{{#!python
from osgeo import osr
sk = osr.SpatialReference()
sk.SetFromUserInput('USER:300001')
0
print(sk)
PROJCS...
}}}

but app always throws errors when fetch and create objects via API (in
admin.site - ok)

{{{#!python
def create(self, validated_data):
if "SRID=300001;" in str(self.validated_data["geom"]):
logger.info("*"*60)
logger.info(f"validated_data geom with USER:300001:
{self.validated_data['geom']}")
logger.info(f"geom srid: {self.validated_data['geom'].srid}")
from osgeo import osr
sk = osr.SpatialReference()
sk.SetFromUserInput('USER:300001') # <- here same error:
GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
logger.info(f"SpatialReference: {sk}")
logger.info("*"*60)
}}}

error.log
{{{
************************************************************
validated_data geom with USER:300001: SRID=300001;GEOMETRYCOLLECTION Z
(POINT Z (83721.138 59266.787 101.09))
geom srid: 300001
GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
SpatialReference:
************************************************************
GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
...
}}}
if request one object via API, Django send 8 email with this error. odd

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36001#comment:2>

Django

unread,
Dec 11, 2024, 1:48:51 PM12/11/24
to django-...@googlegroups.com
admin.site - ok, no errors)
Ticket URL: <https://code.djangoproject.com/ticket/36001#comment:3>

Django

unread,
Dec 11, 2024, 2:41:45 PM12/11/24
to django-...@googlegroups.com
#36001: error GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found' with
custom CRS in spatial_ref_sys
-------------------------------------+-------------------------------------
Reporter: Alex | Owner: (none)
Type: Bug | Status: closed
Component: GIS | Version: 4.2
Severity: Normal | Resolution: invalid
Keywords: gdal, proj4, | Triage Stage:
postgis | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* resolution: => invalid
* status: new => closed

Comment:

At this stage, I think you didn't provide enough information showing that
Django is at fault. Moreover you are using osgeo `SpatialReference` while
Django has its own `SpatialReference` in gdal.srs.

I would suggest you present your issue to the Django Forum under
https://forum.djangoproject.com/c/internals/geodjango/13. You could always
reopen this ticket if you find the problem comes from Django.
--
Ticket URL: <https://code.djangoproject.com/ticket/36001#comment:4>

Django

unread,
Dec 12, 2024, 8:01:32 AM12/12/24
to django-...@googlegroups.com
#36001: error GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found' with
custom CRS in spatial_ref_sys
-------------------------------------+-------------------------------------
Reporter: Alex | Owner: (none)
Type: Bug | Status: closed
Component: GIS | Version: 4.2
Severity: Normal | Resolution: invalid
Keywords: gdal, proj4, | Triage Stage:
postgis | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Alex):

>You could always reopen this ticket if you find the problem comes from
Django.
Yes, it's Django bug

i've patch file srs.py from line 72
[https://github.com/django/django/blob/6f38697f90a14f1450a71c1e40aea0f5df7dca86/django/contrib/gis/gdal/srs.py#L72]
like that
{{{#!python
elif isinstance(srs_input, str):
try:
# If SRID is a string, e.g., '4326', then make acceptable
# as user input.
logger.info(f"DJANGO HACK: just view srs_input:
{srs_input}")
if srs_input == '300001' or srs_input == 'USER:300001' or
srs_input == 300001:
logger.info(f"DJANGO HACK: 300001")
srs_input = "USER:300001"
else:
srid = int(srs_input)
srs_input = "EPSG:%d" % srid
except ValueError:
pass
elif isinstance(srs_input, int):
# EPSG integer code was input.
logger.info(f"DJANGO HACK: just view srs_input: {srs_input}")
if srs_input == 300001:
srs_type = "user"
else:
srs_type = "epsg"
}}}

and as result - errors gone

{{{
INFO 2024-12-12 15:45:49,385 srs 2558856 139853388865600 DJANGO HACK: just
view srs_input: 4326
INFO 2024-12-12 15:45:49,386 srs 2558856 139853388865600 DJANGO HACK: just
view srs_input: 300001
INFO 2024-12-12 15:45:49,386 srs 2558856 139853388865600 DJANGO HACK: just
view srs_input: 300001
INFO 2024-12-12 15:45:49,389 srs 2558856 139853388865600 DJANGO HACK: just
view srs_input: 4326
INFO 2024-12-12 15:45:49,389 srs 2558856 139853388865600 DJANGO HACK: just
view srs_input: 4326
INFO 2024-12-12 15:45:49,389 srs 2558856 139853388865600 DJANGO HACK: just
view srs_input: 300001
INFO 2024-12-12 15:45:49,390 srs 2558856 139853388865600 DJANGO HACK: just
view srs_input: 300001
INFO 2024-12-12 15:45:49,393 srs 2558856 139853388865600 DJANGO HACK: just
view srs_input: 4326
INFO 2024-12-12 15:45:49,393 srs 2558856 139853388865600 DJANGO HACK: just
view srs_input: 4326
INFO 2024-12-12 15:45:49,393 srs 2558856 139853388865600 DJANGO HACK: just
view srs_input: 300001
INFO 2024-12-12 15:45:49,394 srs 2558856 139853388865600 DJANGO HACK: just
view srs_input: 300001
INFO 2024-12-12 15:46:25,476 srs 2558856 139853388865600 DJANGO HACK: just
view srs_input: 4326
INFO 2024-12-12 15:46:25,476 srs 2558856 139853388865600 DJANGO HACK: just
view srs_input: 3857
}}}


== conclusion
Django not allow to work with non EPSG Coordinate systems, at all (ESRI,
OGC, USER and other domains - good luck)
--
Ticket URL: <https://code.djangoproject.com/ticket/36001#comment:5>

Django

unread,
Dec 12, 2024, 8:05:47 AM12/12/24
to django-...@googlegroups.com
#36001: error GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found' with
custom CRS in spatial_ref_sys
-------------------------------------+-------------------------------------
Reporter: Alex | Owner: (none)
Type: Bug | Status: new
Component: GIS | Version: 4.2
Severity: Normal | Resolution:
Keywords: gdal, proj4, | Triage Stage:
postgis | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Alex):

* resolution: invalid =>
* status: closed => new
> admin.site - ok, no errors)
>
> {{{#!python
> def create(self, validated_data):
> if "SRID=300001;" in str(self.validated_data["geom"]):
> logger.info("*"*60)
> logger.info(f"validated_data geom with USER:300001:
> {self.validated_data['geom']}")
> logger.info(f"geom srid: {self.validated_data['geom'].srid}")
> from osgeo import osr
> sk = osr.SpatialReference()
> sk.SetFromUserInput('USER:300001') # <- here same error:
> GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
> logger.info(f"SpatialReference: {sk}")
> logger.info("*"*60)
> }}}
>
> error.log
> {{{
> ************************************************************
> validated_data geom with USER:300001: SRID=300001;GEOMETRYCOLLECTION Z
> (POINT Z (83721.138 59266.787 101.09))
> geom srid: 300001
> GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
> SpatialReference:
> ************************************************************
> GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
> GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
> ...
> }}}
> if request one object via API, Django send 8 email with this error. odd

New description:

# update in comment below
[https://code.djangoproject.com/ticket/36001#comment:5]
sk.SetFromUserInput('USER:300001') # <- here same error:
GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
logger.info(f"SpatialReference: {sk}")
logger.info("*"*60)
}}}

error.log
{{{
************************************************************
validated_data geom with USER:300001: SRID=300001;GEOMETRYCOLLECTION Z
(POINT Z (83721.138 59266.787 101.09))
geom srid: 300001
GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
SpatialReference:
************************************************************
GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
GDAL_ERROR 1: b'PROJ: proj_create_from_database: crs not found'
...
}}}
if request one object via API, Django send 8 email with this error. odd

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36001#comment:6>
Reply all
Reply to author
Forward
0 new messages