2021-10-15 14:39:03 +13:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from django.contrib.gis.utils import LayerMapping
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import right_tree.api.data
|
2021-12-01 09:46:17 +13:00
|
|
|
from right_tree.api.models import SoilLayer, EcologicalDistrictLayer, ChristchurchZone
|
2021-10-15 14:39:03 +13:00
|
|
|
|
|
|
|
# Auto-generated `LayerMapping` dictionary for SoilLayers model
|
|
|
|
soillayer_mapping = {
|
|
|
|
'nzsc_class': 'nzsc_class',
|
|
|
|
'nzsc_group': 'nzsc_group',
|
|
|
|
'nzsc_order': {'code': 'nzsc_order'},
|
|
|
|
'shape_leng': 'SHAPE_Leng',
|
|
|
|
'geom': 'POLYGON',
|
|
|
|
}
|
|
|
|
|
|
|
|
# Auto-generated `LayerMapping` dictionary for ecologicaldistrictlayer model
|
|
|
|
ecologicaldistrictlayer_mapping = {
|
|
|
|
'ecological': 'ECOLOGICAL',
|
|
|
|
'ecologic_1': 'ECOLOGIC_1',
|
|
|
|
'ecologic_2': {'name': 'ECOLOGIC_2'},
|
|
|
|
'shape_leng': 'SHAPE_Leng',
|
|
|
|
'shape_area': 'SHAPE_Area',
|
|
|
|
'geom': 'POLYGON',
|
|
|
|
}
|
|
|
|
|
2021-12-01 09:46:17 +13:00
|
|
|
# Auto-generated `LayerMapping` dictionary for ChristchurchZone model
|
|
|
|
christchurchzone_mapping = {
|
|
|
|
'objectid': 'OBJECTID',
|
|
|
|
'name': 'NAME',
|
|
|
|
'geom': 'MULTIPOLYGON',
|
|
|
|
}
|
|
|
|
|
2021-10-15 14:39:03 +13:00
|
|
|
# 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'
|
2021-12-01 09:46:17 +13:00
|
|
|
christchurchzone_shp = Path(right_tree.api.data.__file__).resolve().parent / 'resources' / 'chch_zone' / 'Greater_Christchurch_Area.shp'
|
2021-10-15 14:39:03 +13:00
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = 'Ingests the shapefile data for ecological regions and soil layers.'
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
self.stdout.write('Loading soil layers...')
|
|
|
|
soil_lm = LayerMapping(SoilLayer, soillayer_shp, soillayer_mapping, transform=False)
|
|
|
|
soil_lm.save(strict=True)
|
|
|
|
self.stdout.write(self.style.SUCCESS('Soil layers loaded succesfully.'))
|
|
|
|
|
|
|
|
self.stdout.write('Loading ecological district layers...')
|
|
|
|
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.'))
|
2021-12-01 09:46:17 +13:00
|
|
|
|
|
|
|
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.'))
|