fix(backend): utilise une version compatible avec Django de GDAL
Parent
0e68e8c984
révision
dd23ea8046
|
@ -33,12 +33,12 @@ Then visit [http://127.0.0.1:8000/](http://127.0.0.1:8000/) in your web browser.
|
|||
|
||||
On a Debian-based host, you will need the following packages:
|
||||
- `python3`
|
||||
- GDAL < 3.0 (e.g. `libgdal20` in Debian Buster)
|
||||
- `python3-psycopg2` (in case of PostgreSQL database with PostGIS extension)
|
||||
- `libsqlite3-mod-spatialite` (in case of SQLite database)
|
||||
- `virtualenv`
|
||||
- `make`
|
||||
- GDAL library (e.g. `libgdal20` in Debian Buster)
|
||||
- `git` (recommended for getting the source)
|
||||
- `python3-psycopg2` (optional, in case of a PostgreSQL database wich must have
|
||||
PostGIS extension)
|
||||
|
||||
### Quick start
|
||||
|
||||
|
|
|
@ -4,3 +4,6 @@ from django.apps import AppConfig
|
|||
class CoreConfig(AppConfig):
|
||||
name = 'danse.core'
|
||||
verbose_name = "Core"
|
||||
|
||||
def ready(self):
|
||||
from . import checks # noqa: F401
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
from django.contrib.gis.gdal import GDAL_VERSION
|
||||
from django.core.checks import Error, Tags, register
|
||||
|
||||
|
||||
@register(Tags.compatibility)
|
||||
def check_gdal_version(**kwargs):
|
||||
return (
|
||||
[
|
||||
Error(
|
||||
"GDAL library version must be lower than 3.0", id='danse.E001',
|
||||
)
|
||||
]
|
||||
if GDAL_VERSION[0] >= 3
|
||||
else []
|
||||
) # pragma: no cover
|
|
@ -32,10 +32,9 @@ class GeomMixin:
|
|||
def coordinates(self):
|
||||
if self.geom is None:
|
||||
return None
|
||||
# le système WGS84 stocke les coordonnées en [lat, lon]
|
||||
return {
|
||||
'lon': self.geom.y,
|
||||
'lat': self.geom.x,
|
||||
'lon': self.geom.x,
|
||||
'lat': self.geom.y,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ def libreville():
|
|||
return VilleFactory(
|
||||
nom="Libreville",
|
||||
code_postal="01234",
|
||||
geom=Point(x=50.68, y=2.8, srid=4326),
|
||||
geom=Point(x=2.8, y=50.68, srid=4326),
|
||||
url_wikipedia="https://fr.wikipedia.org/wiki/Libreville",
|
||||
)
|
||||
|
||||
|
@ -27,7 +27,7 @@ def olieux(libreville):
|
|||
nom="Olieux",
|
||||
rue="13 rue des marguerites",
|
||||
ville=libreville,
|
||||
geom=Point(x=50.68, y=2.9, srid=4326),
|
||||
geom=Point(x=2.9, y=50.68, srid=4326),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -8,15 +8,6 @@ from django.core.serializers.python import Serializer as PythonSerializer
|
|||
GEOJSON_SRID = 4326
|
||||
|
||||
|
||||
def swap_geometry_axis(geometry):
|
||||
if geometry['type'] == 'Point':
|
||||
geometry['coordinates'].reverse()
|
||||
else:
|
||||
for point in geometry['coordinates']:
|
||||
point.reverse()
|
||||
return geometry
|
||||
|
||||
|
||||
class Serializer(PythonSerializer):
|
||||
"""
|
||||
Sérialise des objets au format GeoJSON, en suivant la RFC7946.
|
||||
|
@ -83,9 +74,6 @@ class Serializer(PythonSerializer):
|
|||
)
|
||||
self._geometry.transform(self._cts[self._geometry.srid])
|
||||
data['geometry'] = eval(self._geometry.geojson)
|
||||
# inverse les coordonnées afin d'avoir [lon, lat] comme le
|
||||
# spécifie la RFC7946, contrairement au système WGS84
|
||||
swap_geometry_axis(data['geometry'])
|
||||
else:
|
||||
data['geometry'] = None
|
||||
return data
|
||||
|
|
|
@ -7,8 +7,6 @@ import pytest
|
|||
|
||||
from danse.core.models import Ville
|
||||
|
||||
from ..serializers.geojson import swap_geometry_axis
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ville1():
|
||||
|
@ -24,21 +22,6 @@ def ville2():
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'geometry, coordinates',
|
||||
[
|
||||
({'type': 'Point', 'coordinates': [1.0, 2.0]}, [2.0, 1.0]),
|
||||
(
|
||||
{'type': 'LineString', 'coordinates': [[1.0, 2.0], [3.0, 4.0]]},
|
||||
[[2.0, 1.0], [4.0, 3.0]],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_swap_geometry_axis(geometry, coordinates):
|
||||
assert swap_geometry_axis(geometry)['coordinates'] == coordinates
|
||||
assert geometry['coordinates'] == coordinates
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestGeoJSONSerializer:
|
||||
def serialize(self, queryset=None, **kwargs):
|
||||
|
@ -53,7 +36,7 @@ class TestGeoJSONSerializer:
|
|||
{
|
||||
'type': 'Feature',
|
||||
'id': '1',
|
||||
'geometry': {'type': 'Point', 'coordinates': [1.0, 0.0]},
|
||||
'geometry': {'type': 'Point', 'coordinates': [0.0, 1.0]},
|
||||
'properties': {
|
||||
'nom': 'Ville 1',
|
||||
'code_postal': '01234',
|
||||
|
@ -63,7 +46,7 @@ class TestGeoJSONSerializer:
|
|||
{
|
||||
'type': 'Feature',
|
||||
'id': '2',
|
||||
'geometry': {'type': 'Point', 'coordinates': [2.0, 1.0]},
|
||||
'geometry': {'type': 'Point', 'coordinates': [1.0, 2.0]},
|
||||
'properties': {
|
||||
'nom': 'Ville 2',
|
||||
'code_postal': '01235',
|
||||
|
@ -108,18 +91,18 @@ class TestGeoJSONSerializer:
|
|||
|
||||
def test_transform_srid(self, ville1, ville2):
|
||||
ville1.geom.transform(3857)
|
||||
assert ville1.geom.wkt == 'POINT (111319.4907932736 0)'
|
||||
assert ville1.geom.wkt == 'POINT (0 111325.1428663849)'
|
||||
ville2.geom.transform(3857)
|
||||
assert ville2.geom.wkt == 'POINT (222638.9815865471 111325.1428663849)'
|
||||
assert ville2.geom.wkt == 'POINT (111319.4907932736 222684.2085055445)'
|
||||
|
||||
serialized = self.serialize(queryset=[ville1, ville2], to_json=False)
|
||||
assert serialized['features'][0]['geometry']['coordinates'] == [
|
||||
1.0,
|
||||
0.0,
|
||||
1.0,
|
||||
]
|
||||
assert serialized['features'][1]['geometry']['coordinates'] == [
|
||||
2.0,
|
||||
1.0,
|
||||
2.0,
|
||||
]
|
||||
|
||||
def test_deserialize(self):
|
||||
|
|
Chargement…
Référencer dans un nouveau ticket