Update ChristchurchZone model name to ChristchurchRegion

This commit is contained in:
Dana Lambert 2021-12-07 10:39:30 +13:00 committed by Alistair McIntyre
parent 3f251e4c68
commit 36746729ec
5 changed files with 12 additions and 12 deletions

View file

@ -22,4 +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)
admin.site.register(models.ChristchurchRegion)

View file

@ -3,7 +3,7 @@ import json
from django.http import Http404
from django.db.models import Q
from .models import Plant, EcologicalRegion, EcologicalDistrictLayer, ChristchurchZone, SoilOrder, SoilVariant
from .models import Plant, EcologicalRegion, EcologicalDistrictLayer, ChristchurchRegion, SoilOrder, SoilVariant
from .wms_utils import get_point_from_coordinates
@ -67,7 +67,7 @@ def is_in_auckland(coordinates):
def is_in_christchurch(coordinates):
pnt = get_point_from_coordinates(coordinates)
in_chch = ChristchurchZone.objects.filter(geom__intersects=pnt).first()
in_chch = ChristchurchRegion.objects.filter(geom__intersects=pnt).first()
return in_chch is not None;
def get_filtered_plants(request):

View file

@ -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, ChristchurchZone
from right_tree.api.models import SoilLayer, EcologicalDistrictLayer, ChristchurchRegion
# Auto-generated `LayerMapping` dictionary for SoilLayers model
soillayer_mapping = {
@ -25,8 +25,8 @@ ecologicaldistrictlayer_mapping = {
'geom': 'POLYGON',
}
# Auto-generated `LayerMapping` dictionary for ChristchurchZone model
christchurchzone_mapping = {
# Auto-generated `LayerMapping` dictionary for ChristchurchRegion model
christchurchregion_mapping = {
'objectid': 'OBJECTID',
'name': 'NAME',
'geom': 'MULTIPOLYGON',
@ -35,7 +35,7 @@ christchurchzone_mapping = {
# 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'
christchurchregion_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.'
@ -52,6 +52,6 @@ class Command(BaseCommand):
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)
christchurchregionlayer_lm = LayerMapping(ChristchurchRegion, christchurchregion_shp, christchurchregion_mapping, transform=False)
christchurchregionlayer_lm.save(strict=True)
self.stdout.write(self.style.SUCCESS(' Christchurch zone layer loaded succesfully.'))

View file

@ -1,4 +1,4 @@
# Generated by Django 3.2.8 on 2021-11-30 00:40
# Generated by Django 3.2.8 on 2021-12-06 21:36
import django.contrib.gis.db.models.fields
from django.db import migrations, models
@ -12,7 +12,7 @@ class Migration(migrations.Migration):
operations = [
migrations.CreateModel(
name='ChristchurchZone',
name='ChristchurchRegion',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('objectid', models.IntegerField()),

View file

@ -46,7 +46,7 @@ class EcologicalDistrictLayer(models.Model):
return f"{self.ecologic_1} ({self.ecologic_2})"
class ChristchurchZone(models.Model):
class ChristchurchRegion(models.Model):
objectid = models.IntegerField()
name = models.CharField(max_length=25)
geom = models.MultiPolygonField(srid=2193)