diff --git a/README.md b/README.md index 2bd940d..1b4cdad 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,17 @@ backend/right_tree/api/data/resources/fundamental_soil_layers/ - fundamental-soil-layers-new-zealand-soil-classification.shp - fundamental-soil-layers-new-zealand-soil-classification.shx - fundamental-soil-layers-new-zealand-soil-classification.xml +``` + +**Christchurch Zone Shapefile:** +``` +backend/right_tree/api/data/resources/chch_zone/ +- Greater_Christchurch_Area.cpg +- Greater_Christchurch_Area.shp +- Greater_Christchurch_Area.dbf +- Greater_Christchurch_Area.shx +- Greater_Christchurch_Area.prj + ``` ### Add spreadsheet data for database population diff --git a/backend/right_tree/api/admin.py b/backend/right_tree/api/admin.py index bd8b267..03d100d 100644 --- a/backend/right_tree/api/admin.py +++ b/backend/right_tree/api/admin.py @@ -22,3 +22,4 @@ admin.site.register(models.HabitatImage) admin.site.register(models.Habitat) admin.site.register(models.Zone, ZoneAdmin) admin.site.register(models.ZoneImageSegment, ZoneImageSegmentAdmin) +admin.site.register(models.ChristchurchZone) diff --git a/backend/right_tree/api/management/commands/loadshapefiles.py b/backend/right_tree/api/management/commands/loadshapefiles.py index 4fa9f96..250fc81 100644 --- a/backend/right_tree/api/management/commands/loadshapefiles.py +++ b/backend/right_tree/api/management/commands/loadshapefiles.py @@ -4,7 +4,7 @@ from django.contrib.gis.utils import LayerMapping from pathlib import Path import right_tree.api.data -from right_tree.api.models import SoilLayer, EcologicalDistrictLayer +from right_tree.api.models import SoilLayer, EcologicalDistrictLayer, ChristchurchZone # Auto-generated `LayerMapping` dictionary for SoilLayers model soillayer_mapping = { @@ -25,9 +25,17 @@ ecologicaldistrictlayer_mapping = { 'geom': 'POLYGON', } +# Auto-generated `LayerMapping` dictionary for ChristchurchZone model +christchurchzone_mapping = { + 'objectid': 'OBJECTID', + 'name': 'NAME', + 'geom': 'MULTIPOLYGON', +} + # Shapefiles soillayer_shp = Path(right_tree.api.data.__file__).resolve().parent / 'resources' / 'fundamental_soil_layers' / 'fundamental-soil-layers-new-zealand-soil-classification.shp' ecologicaldistrictlayer_shp = Path(right_tree.api.data.__file__).resolve().parent / 'resources' / 'ecological_districts' / 'DOC_EcologicalDistricts_2021_08_02.shp' +christchurchzone_shp = Path(right_tree.api.data.__file__).resolve().parent / 'resources' / 'chch_zone' / 'Greater_Christchurch_Area.shp' class Command(BaseCommand): help = 'Ingests the shapefile data for ecological regions and soil layers.' @@ -42,3 +50,8 @@ class Command(BaseCommand): ecologicaldistrictlayer_lm = LayerMapping(EcologicalDistrictLayer, ecologicaldistrictlayer_shp, ecologicaldistrictlayer_mapping, transform=False) ecologicaldistrictlayer_lm.save(strict=True) self.stdout.write(self.style.SUCCESS('Ecological district layers loaded succesfully.')) + + self.stdout.write('Loading christchurch zone layer...') + christchurchzonelayer_lm = LayerMapping(ChristchurchZone, christchurchzone_shp, christchurchzone_mapping, transform=False) + christchurchzonelayer_lm.save(strict=True) + self.stdout.write(self.style.SUCCESS(' Christchurch zone layer loaded succesfully.')) diff --git a/backend/right_tree/api/migrations/0010_christchurchzone.py b/backend/right_tree/api/migrations/0010_christchurchzone.py new file mode 100644 index 0000000..04e165a --- /dev/null +++ b/backend/right_tree/api/migrations/0010_christchurchzone.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.8 on 2021-11-30 00:40 + +import django.contrib.gis.db.models.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0009_alter_plant_options'), + ] + + operations = [ + migrations.CreateModel( + name='ChristchurchZone', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('objectid', models.IntegerField()), + ('name', models.CharField(max_length=25)), + ('geom', django.contrib.gis.db.models.fields.MultiPolygonField(srid=2193)), + ], + ), + ] diff --git a/backend/right_tree/api/models.py b/backend/right_tree/api/models.py index 38572b3..d50d182 100644 --- a/backend/right_tree/api/models.py +++ b/backend/right_tree/api/models.py @@ -46,6 +46,12 @@ class EcologicalDistrictLayer(models.Model): return f"{self.ecologic_1} ({self.ecologic_2})" +class ChristchurchZone(models.Model): + objectid = models.IntegerField() + name = models.CharField(max_length=25) + geom = models.MultiPolygonField(srid=2193) + + class ToleranceLevel(models.Model): level = models.CharField(max_length=1)