Open henhuy opened 3 years ago
Try this (using GeometrySerializerMethodField
):
class InSituCommentSerializer(GeoFeatureModelSerializer):
geometry_4326 = GeometrySerializerMethodField()
def get_geometry_4326(self, state) -> Polygon:
return state.geom.transform(4326, clone=True)
class Meta:
model = Instance
geo_field = "geometry_4326"
fields = ("name", )
Other solution that is cleaner in my opinion because it uses db for transformation:
class StatesSerializer(GeoFeatureModelSerializer):
geom_4326 = GeometryField()
class Meta:
model = State
geo_field = "geom_4326"
fields = [
"id",
"name",
"geom_4326"
]
I have a model with a geom (srid=3035) and I want to serialize it as geom (srid=4326). Did not found a solution to do this with django-restframework-gis? My approach was:
but this gives me:
django.core.exceptions.ImproperlyConfigured: Field name
geom_4326is not valid for model
State.
Also found this: https://stackoverflow.com/questions/22449406/how-to-transform-geometry-in-django-rest-framework-gis/22537247#22537247 But couldn't get it to work... (see my comment on that answer)
Any help? thx