When using the Django Geospatial API together with Postgis Raster, I tried setting the SRID of RasterField to None, which seems to work:
rast = django.contrib.gis.db.models.RasterField(srid=None)
But then adding a Raster WITH SRID results in the following Error:
psycopg2.errors.UndefinedColumn: column “none” does not exist
LINE 1: …000000000000000000000000000000000000000’::raster, None), 54)…
This Error comes from the function get_geom_placeholder from the module contrib/gis/db/backends/postgis/operations.py:
# Adding Transform() to the SQL placeholder if the value srid
# is not equal to the field srid.
if value_srid is None or value_srid == f.srid:
placeholder = "%s"
else:
placeholder = "%s(%%s, %s)" % (transform_func, f.srid)
The error then occurs because it then wants to transform it to the fields SRID, which is None. Here is the resulting SQL-query made from Django which then fails:
'INSERT INTO "test_raster" ("name", "rast",) VALUES (%s, ST_Transform(%s, None)) RETURNING "test_raster"."id"'
Shouldn’t we be able to specify no srid for a field and then not beeing forced to transform the new rasters?
Possible fix:
Adding FORCE_RASTER_TRANSFORM in the settings (defaults to True) and then not forcing a transform:
if value_srid is None or value_srid == f.srid or f.srid is None and not FORCE_RASTER_TRANSFORM:
placeholder = "%s"
else:
placeholder = "%s(%%s, %s)" % (transform_func, f.srid)