Skip to content

Commit 4e9074b

Browse files
feat : add centroid for the geom in predictions
1 parent b48e336 commit 4e9074b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

backend/core/views.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,8 +1089,14 @@ def create(self, validated_data):
10891089

10901090
def to_representation(self, instance):
10911091
ret = super().to_representation(instance)
1092-
if self.context.get("request") and self.context["request"].method == "GET":
1092+
request = self.context.get("request")
1093+
if request and request.method == "GET":
10931094
ret["user"] = UserSerializer(instance.user).data
1095+
centroid_param = request.query_params.get("centroid", "false").lower()
1096+
if centroid_param == "true":
1097+
centroid = instance.geom.centroid
1098+
centroid.srid = instance.geom.srid
1099+
ret["geom"] = GeometryField().to_representation(centroid)
10941100
return ret
10951101

10961102

0 commit comments

Comments
 (0)