TLDR: How do I save/read a LineStringZM / MultiLineStringZM type of geometry to PostGIS through GeoDjango?
I was following a tutorial to ingest shapefiles into GeoDjango & PostGIS and I encountered an error in the LayerMapping ingestion step when trying to ingest a shapefile with linear referencing.
The shapefile has a field type of MultiLineStringZM
, and since it does not exist, I tried to use a MultiLineStringField(dim=4)
instead since it simply is a MultiLineString with 4 dimensions, outputting this error:
>>> load.run()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/git/web-gis/linear_referencing/backend_django/django_gis/django_gis/roadnetwork/load.py", line 30, in run
lm = LayerMapping(RoadNetwork, roadnetwork_shp, roadnetwork_mapping, transform=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ken/.cache/pypoetry/virtualenvs/django-gis-a4oOe18h-py3.11/lib/python3.11/site-packages/django/contrib/gis/utils/layermapping.py", line 132, in __init__
self.check_layer()
File "/home/ken/.cache/pypoetry/virtualenvs/django-gis-a4oOe18h-py3.11/lib/python3.11/site-packages/django/contrib/gis/utils/layermapping.py", line 259, in check_layer
raise LayerMapError(
django.contrib.gis.utils.layermapping.LayerMapError: Invalid mapping geometry; model has MultiLineStringField, layer geometry type is LineStringZM.
Should I create a custom field and save function for this, then process the LineStringZM field there? Is there any documentation, code snippet or GitHub repo I can use as a reference for this endeavor?
PostGIS supports geometry(LINESTRINGZM)
according to this: Chapter 4. Data Management
And LineStringZM / MultiLineStringZM is listed in geomtypes here: django/django/contrib/gis/gdal/geomtype.py at stable/5.1.x · django/django · GitHub
But I currently have no idea how to utilize this from a Django model field.