Add Christchurch Zone model and shapefile ingestion
This commit is contained in:
parent
77135650cf
commit
8f63a917e0
5 changed files with 55 additions and 1 deletions
11
README.md
11
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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.'))
|
||||
|
|
23
backend/right_tree/api/migrations/0010_christchurchzone.py
Normal file
23
backend/right_tree/api/migrations/0010_christchurchzone.py
Normal file
|
@ -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)),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue