#138 WIP Validity

* adds geometry validity checks for SimpleGeomForm is_valid()
    * shows validity problems on the form if a feature is invalid
* optimizes merging of different features into one MultiPolygon
* further enhances tests
* adds as_feature_collection() method on Geometry model for converting geom MultiPolygon attribute into FeatureCollection json holding each polygon as an own feature -> makes each polygon selectable in new netgis map client
This commit is contained in:
2022-04-20 13:52:52 +02:00
parent c60afb0391
commit 253b509122
4 changed files with 61 additions and 18 deletions

View File

@@ -5,11 +5,15 @@ Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 15.11.21
"""
import json
from django.contrib.gis.db.models import MultiPolygonField
from django.contrib.gis.geos import Polygon
from django.db import models, transaction
from django.utils import timezone
from konova.models import BaseResource, UuidModel
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
from konova.utils.wfs.spatial import ParcelWFSFetcher
@@ -179,6 +183,34 @@ class Geometry(BaseResource):
return parcels
def as_feature_collection(self, srid=DEFAULT_SRID_RLP):
""" Returns a FeatureCollection structure holding all polygons of the MultiPolygon as single features
This method is used to convert a single MultiPolygon into multiple Polygons, which can be used as separated
features in the NETGIS map client.
Args:
srid (int): The spatial reference system identifier to be transformed to
Returns:
geojson (dict): The FeatureCollection json (as dict)
"""
geom = self.geom
geom.transform(ct=srid)
polygons = []
for coords in geom.coords:
p = Polygon(coords[0], srid=geom.srid)
polygons.append(p)
geojson = {
"type": "FeatureCollection",
"features": [
json.loads(x.geojson) for x in polygons
]
}
return geojson
class GeometryConflict(UuidModel):
"""