-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
municipalities loading vue + overwriting save() method on observations and making municipality a computed field here
- Loading branch information
1 parent
3cb3f72
commit b624d42
Showing
19 changed files
with
333 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ services: | |
tty: true | ||
volumes: | ||
- .:/workspaces/vespadb/ | ||
|
||
app: | ||
build: | ||
context: . | ||
|
@@ -37,6 +36,16 @@ services: | |
volumes: | ||
- postgres_data:/var/lib/postgresql/data | ||
|
||
pgadmin: | ||
image: dpage/pgadmin4 | ||
environment: | ||
PGADMIN_DEFAULT_EMAIL: "[email protected]" | ||
PGADMIN_DEFAULT_PASSWORD: "root" | ||
ports: | ||
- "5050:80" | ||
depends_on: | ||
- db | ||
|
||
volumes: | ||
postgres_data: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
"""Test vespadb.""" | ||
""".""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
"""Pytest configuration.""" | ||
""".""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
"""Test vespadb.""" | ||
""".""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROJCS["Belge_Lambert_1972",GEOGCS["GCS_Belge_1972",DATUM["D_Belge_1972",SPHEROID["International_1924",6378388.0,297.0]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",150000.01256],PARAMETER["False_Northing",5400088.4378],PARAMETER["Central_Meridian",4.367486666666666],PARAMETER["Standard_Parallel_1",49.8333339],PARAMETER["Standard_Parallel_2",51.16666723333333],PARAMETER["Latitude_Of_Origin",90.0],UNIT["Meter",1.0]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,44 @@ | ||
"""Handle the load_municipalities command.""" | ||
"""Handlers.""" | ||
|
||
from pathlib import Path | ||
from typing import Any | ||
|
||
import geopandas as gpd | ||
from django.contrib.gis.geos import GEOSGeometry, MultiPolygon, Polygon | ||
from django.contrib.gis.utils import LayerMapping | ||
from django.core.management.base import BaseCommand | ||
|
||
from vespadb.observations.models import Municipality | ||
|
||
# A mapping dictionary to map field names from the Shapefile to the Municipality model fields. | ||
municipality_mapping = { | ||
"oidn": "OIDN", | ||
"uidn": "UIDN", | ||
"terrid": "TERRID", | ||
"nis_code": "NISCODE", | ||
"name": "NAAM", | ||
"datpublbs": "DATPUBLBS", | ||
"numac": "NUMAC", | ||
"length": "LENGTE", | ||
"surface": "OPPERVL", | ||
"polygon": "MULTIPOLYGON", | ||
} | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Load municipalities from a Shapefile into the database.""" | ||
"""A custom management command that loads a ShapeFile containing municipality boundaries into the database. | ||
help = "Load municipalities from a Shapefile into the database" | ||
This command uses the LayerMapping utility from Django's GIS framework to perform the data import. | ||
""" | ||
|
||
def handle(self, *args: Any, **kwargs: Any) -> None: | ||
""" | ||
Load the municipalities from the Shapefile into the database. | ||
help: str = "Laadt een ShapeFile met gemeentegrenzen in de database." | ||
|
||
Args: | ||
*args (Any): Variable length argument list. | ||
**kwargs (Any): Arbitrary keyword arguments. | ||
def handle(self, *args: Any, **options: Any) -> None: | ||
""" | ||
Handle municipality data loading. | ||
Returns | ||
------- | ||
None | ||
:param args: Variable length argument list. | ||
:param options: Arbitrary keyword arguments. | ||
""" | ||
# Load the GeoDataFrame from the Shapefile | ||
script_dir = Path(__file__).parent | ||
shp_path = script_dir / "data/Refgem.shp" | ||
|
||
gdf = gpd.read_file(str(shp_path)) | ||
for _, row in gdf.iterrows(): | ||
nis_code = row["NISCODE"] | ||
name = row["NAAM"] | ||
geometry = GEOSGeometry(row["geometry"].wkt) | ||
|
||
if isinstance(geometry, Polygon): | ||
geometry = MultiPolygon(geometry) | ||
|
||
municipality, created = Municipality.objects.get_or_create( | ||
name=name, nis_code=nis_code, defaults={"polygon": geometry} | ||
) | ||
|
||
if created: | ||
self.stdout.write(self.style.SUCCESS(f'Municipality "{name}" successfully saved.')) | ||
else: | ||
# Update the polygon geometry if the municipality exists | ||
municipality.polygon = geometry | ||
municipality.save() | ||
self.stdout.write(self.style.SUCCESS(f'Municipality "{name}" updated.')) | ||
shapefile_path: str = str((Path(__file__).parent / "data" / "Refgem.shp").resolve()) | ||
|
||
lm = LayerMapping(Municipality, shapefile_path, municipality_mapping, transform=False, encoding="iso-8859-1") | ||
lm.save(strict=True, verbose=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
""".""" | ||
|
||
default_app_config = "vespadb.observations.apps.ObservationsConfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.