# Unit tests for konova geometry
* adds further unit tests for konova app geometry model
This commit is contained in:
parent
e443c5f8be
commit
1773463e86
@ -317,7 +317,7 @@ class Geometry(BaseResource):
|
||||
"""
|
||||
geom = self.geom
|
||||
if geom.srid != srid:
|
||||
geom.transform(ct=srid)
|
||||
geom.transform(srid)
|
||||
polygons = [p for p in geom]
|
||||
geojson = {
|
||||
"type": "FeatureCollection",
|
||||
|
@ -15,7 +15,7 @@ DEFAULT_SRID_RLP = 25832
|
||||
|
||||
# Needed to redirect to LANIS
|
||||
## Values to be inserted are [zoom_level, x_coord, y_coord]
|
||||
LANIS_LINK_TEMPLATE = "https://geodaten.naturschutz.rlp.de/kartendienste_naturschutz/index.php?lang=de&zl={}&x={}&y={}&bl=tk_rlp_tms_grau&bo=1&lo=0.8,0.8,0.8,0.6,0.8,0.8,0.8,0.8,0.8&layers=eiv_recorded,eiv_unrecorded,kom_recorded,kom_unrecorded,oek_recorded,oek_unrecorded,ema_recorded,ema_unrecorded,mae&service=kartendienste_naturschutz"
|
||||
LANIS_LINK_TEMPLATE = "https://geodaten.naturschutz.rlp.de/kartendienste_naturschutz/index.php?lang=de&zl={}&x={}&y={}&bl=tk_rlp_tms_grau&bo=1&lo=0.8,0.8,0.8,0.6,0.8,0.8,0.8,0.8,0.8&layers=eiv_recorded,eiv_unrecorded,eiv_unrecorded_old_entries,kom_recorded,kom_unrecorded,kom_unrecorded_old_entries,oek_recorded,oek_unrecorded,ema_recorded,ema_unrecorded,mae&service=kartendienste_naturschutz"
|
||||
## This look up table (LUT) defines different zoom levels on the size of the calculate area of a geometry.
|
||||
LANIS_ZOOM_LUT = {
|
||||
1000000000: 6,
|
||||
|
@ -5,9 +5,12 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 15.12.21
|
||||
|
||||
"""
|
||||
import json
|
||||
|
||||
from django.contrib.gis.db.models.functions import Translate
|
||||
|
||||
from konova.models import Geometry, GeometryConflict
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID
|
||||
from konova.tests.test_views import BaseTestCase
|
||||
from konova.utils.schneider.fetcher import ParcelFetcher
|
||||
|
||||
@ -74,3 +77,66 @@ class GeometryTestCase(BaseTestCase):
|
||||
fetcher = ParcelFetcher(geometry=self.geom_1)
|
||||
features = fetcher.get_parcels()
|
||||
self.assertNotEqual(0, len(features), msg="Spatial fetcher get feature did not work!")
|
||||
|
||||
def test_str(self):
|
||||
self.assertEqual(
|
||||
str(self.geom_1),
|
||||
str(self.geom_1.id)
|
||||
)
|
||||
|
||||
def test_get_data_objects(self):
|
||||
num_objs_with_geom = 0
|
||||
self.assertEqual(
|
||||
len(self.geom_1.get_data_objects()),
|
||||
num_objs_with_geom
|
||||
)
|
||||
|
||||
objs = [
|
||||
self.intervention,
|
||||
self.compensation,
|
||||
self.eco_account,
|
||||
self.ema,
|
||||
]
|
||||
for obj in objs:
|
||||
obj.geometry = self.geom_1
|
||||
obj.save()
|
||||
|
||||
num_objs_with_geom += 1
|
||||
geom_objs = self.geom_1.get_data_objects()
|
||||
self.assertEqual(
|
||||
len(geom_objs),
|
||||
num_objs_with_geom
|
||||
)
|
||||
self.assertIn(obj, geom_objs)
|
||||
|
||||
def test_as_feature_collection(self):
|
||||
geometry = self.geom_1.geom
|
||||
polygons = [p for p in geometry]
|
||||
expected_result = {
|
||||
"type": "FeatureCollection",
|
||||
"crs": {
|
||||
"type": "name",
|
||||
"properties": {
|
||||
"name": f"urn:ogc:def:crs:EPSG::{geometry.srid}"
|
||||
}
|
||||
},
|
||||
"features": [
|
||||
{
|
||||
"type": "Feature",
|
||||
"geometry": json.loads(p.json),
|
||||
}
|
||||
for p in polygons
|
||||
]
|
||||
}
|
||||
result = self.geom_1.as_feature_collection()
|
||||
result = json.dumps(result)
|
||||
expected_result = json.dumps(expected_result)
|
||||
|
||||
self.assertEqual(expected_result, result)
|
||||
|
||||
# Transform geometry into non-default-rlp srid to trigger retransforming in later steps
|
||||
geometry.transform(DEFAULT_SRID)
|
||||
different_result = self.geom_1.as_feature_collection()
|
||||
different_result = json.dumps(result)
|
||||
self.assertNotEqual(different_result, result)
|
||||
|
||||
|
@ -333,7 +333,7 @@ class BaseTestCase(TestCase):
|
||||
"""
|
||||
polygon = Polygon.from_bbox((7.592449, 50.359385, 7.593382, 50.359874))
|
||||
polygon.srid = 4326
|
||||
polygon = polygon.transform(DEFAULT_SRID_RLP, clone=True)
|
||||
polygon.transform(DEFAULT_SRID_RLP)
|
||||
return MultiPolygon(polygon, srid=DEFAULT_SRID_RLP)
|
||||
|
||||
def create_geojson(self, geometry):
|
||||
|
Loading…
Reference in New Issue
Block a user