You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been asked to create a Django app where users can manage their existing library of KML documents along with other GIS formats. Unfortunately, it seems that about half of the documents have 2D geometry while the rest are 3D. This causes issues when saving the geometry model because GeoDjango's GeometryField has a default dim value of 2, which results in errors when uploading a 3D file.
My conundrum is similar to the question here at GIS Stackexchange, just inverted. However, I would not want to not force a 2D transform, as the height values are a big part of the data.
A short term solution is to include two geometry fields within the model, one 2D and the other 3D. Depending on the dimension, the geometry will be saved to the appropriate field in the model. In order to use this within the serializer, a GeometrySerializerMethodField needs to be used, much like
class SegmentSerializer(gis_serializer.GeoFeatureModelSerializer):
trail = TrailSerializer()
geometry = gis_serializer.GeometrySerializerMethodField()
def get_geometry(self, obj):
print(obj)
if obj.two_d_geom is None:
return obj.three_d_geom
else:
return obj.two_d_geom
class Meta:
model = TrailSegment
geo_field = 'geometry'
If geo_field were to accept a tuple as a value, then the above could be functionally identical to
class SegmentSerializer(gis_serializer.GeoFeatureModelSerializer):
trail = TrailSerializer()
class Meta:
model = TrailSegment
geo_field = ('two_d_geom', 'three_d_geom', )
This would also benefit devs who find themselves doing far too many joins that impact performance and use denormalization as a solution.
The text was updated successfully, but these errors were encountered:
I don't see the benefit of including such a feature in drf-gis right now, you should be able to extend drf-gis serializers and implement what you need. You might as well publish your solution somewhere so we can better understand the use case in more detail.
I've been asked to create a Django app where users can manage their existing library of KML documents along with other GIS formats. Unfortunately, it seems that about half of the documents have 2D geometry while the rest are 3D. This causes issues when saving the geometry model because GeoDjango's
GeometryField
has a defaultdim
value of 2, which results in errors when uploading a 3D file.My conundrum is similar to the question here at GIS Stackexchange, just inverted. However, I would not want to not force a 2D transform, as the height values are a big part of the data.
A short term solution is to include two geometry fields within the model, one 2D and the other 3D. Depending on the dimension, the geometry will be saved to the appropriate field in the model. In order to use this within the serializer, a
GeometrySerializerMethodField
needs to be used, much likeIf
geo_field
were to accept a tuple as a value, then the above could be functionally identical toThis would also benefit devs who find themselves doing far too many joins that impact performance and use denormalization as a solution.
The text was updated successfully, but these errors were encountered: