loadgisdata working, removed old addgeo
This commit is contained in:
@@ -12,6 +12,14 @@ from django.contrib.gis.gdal import DataSource
|
||||
from geo.models import Country, Region, Province, City
|
||||
|
||||
|
||||
logging.basicConfig(
|
||||
filename='logs/loadgisdata.log',
|
||||
filemode='w',
|
||||
format='%(levelname)s:%(message)s',
|
||||
level=logging.INFO,
|
||||
)
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
help = 'Load GIS data into database'
|
||||
@@ -52,8 +60,8 @@ class Command(BaseCommand):
|
||||
country_counter += 1
|
||||
logging.info(f"Country instance created for: {name}")
|
||||
except Exception as e:
|
||||
logging.error(f"[{type(e)}] {str(e)}")
|
||||
import ipdb; ipdb.set_trace()
|
||||
logging.error(f"[{name}][{type(e)}] {str(e)}")
|
||||
# import ipdb; ipdb.set_trace()
|
||||
|
||||
# region instances
|
||||
logging.info("loading region instances")
|
||||
@@ -74,8 +82,8 @@ class Command(BaseCommand):
|
||||
region_counter += 1
|
||||
logging.info(f"Region instance created for: {name}")
|
||||
except Exception as e:
|
||||
logging.error(f"[{type(e)}] {str(e)}")
|
||||
import ipdb; ipdb.set_trace()
|
||||
logging.error(f"[{name}][{type(e)}] {str(e)}")
|
||||
# import ipdb; ipdb.set_trace()
|
||||
|
||||
# province instances
|
||||
logging.info("loading province instances")
|
||||
@@ -90,14 +98,14 @@ class Command(BaseCommand):
|
||||
polygon_list.append(polygon)
|
||||
geom_geos = MultiPolygon(polygon_list)
|
||||
# get name and parent
|
||||
name = feature['properties']['NAME_2']
|
||||
name = feature.get('NAME_2')
|
||||
parent_region = Region.objects.get(name=feature.get('NAME_1'))
|
||||
# create instance
|
||||
Province.objects.create(name=name, geo=geom_geos, region=parent_region)
|
||||
province_counter += 1
|
||||
logging.info(f"Province instance created for: {name}")
|
||||
except Exception as e:
|
||||
logging.error(f"[{type(e)}] {str(e)}")
|
||||
logging.error(f"[{name}][{type(e)}] {str(e)}")
|
||||
import ipdb; ipdb.set_trace()
|
||||
|
||||
# city instances
|
||||
@@ -114,16 +122,16 @@ class Command(BaseCommand):
|
||||
geom_geos = MultiPolygon(polygon_list)
|
||||
|
||||
# get name and parent
|
||||
name = feature['properties']['NAME_3']
|
||||
parent_province = Region.objects.get(name=feature.get('NAME_2'))
|
||||
name = feature.get('NAME_3')
|
||||
parent_province = Province.objects.get(name=feature.get('NAME_2'))
|
||||
City.objects.create(name=name, geo=geom_geos, province=parent_province)
|
||||
city_counter += 1
|
||||
logging.debug(f"City instance created for: {name}")
|
||||
except Exception as e:
|
||||
logging.error(f"[{type(e)}] {str(e)}")
|
||||
import ipdb; ipdb.set_trace()
|
||||
# import ipdb; ipdb.set_trace()
|
||||
|
||||
logging.info(f"Country instances created: {country_counter}")
|
||||
logging.info(f"Region instances created: {region_counter}")
|
||||
logging.info(f"Province instances created: {[province_counter]}")
|
||||
logging.info(f"Province instances created: {province_counter}")
|
||||
logging.info(f"City instances created: {city_counter}")
|
||||
|
||||
Reference in New Issue
Block a user