states added

parent c185dd49
......@@ -13,13 +13,13 @@ class Command(BaseCommand):
state_parser = {
'01': "Aguascalientes", '02': "Baja California", '03': "Baja California Sur", '04': "Campeche",
'05': "Coahuila", '06': "Colima", '07': "Chiapas", '08': "Chihuahua",
'09': "Ciudad de México",'10': "Durango", '11': "Guanajuato", '12': "Guerrero",
'13': "Hidalgo", '14': "Jalisco", '15': "México", '16': "Michoacán",
'05': "Coahuila de Zaragoza", '06': "Colima", '07': "Chiapas", '08': "Chihuahua",
'09': "Ciudad de México", '10': "Durango", '11': "Guanajuato", '12': "Guerrero",
'13': "Hidalgo", '14': "Jalisco", '15': "México", '16': "Michoacán de Ocampo",
'17': "Morelos", '18': "Nayarit", '19': "Nuevo León", '20': "Oaxaca",
'21': "Puebla", '22': "Querétaro", '23': "Quintana Roo", '24': "San Luis Potosí",
'25': "Sinaloa", '26': "Sonora", '27': "Tabasco", '28': "Tamaulipas",
'29': "Tlaxcala", '30': "Veracruz", '31': "Yucatán", '32': "Zacatecas"
'29': "Tlaxcala", '30': "Veracruz de Ignacio de la Llave", '31': "Yucatán", '32': "Zacatecas"
}
for p in pList:
......
......@@ -16,6 +16,7 @@
from django.core.management.base import BaseCommand, CommandError
from catalog.models import Polygon
import json, unicodedata
from shapely.geometry import shape
class Command(BaseCommand):
......@@ -29,6 +30,17 @@ class Command(BaseCommand):
## base geojson files path
base_path = options['geojson_path'][0]
states_names = {
'01': "Aguascalientes", '02': "Baja California", '03': "Baja California Sur", '04': "Campeche",
'05': "Coahuila de Zaragoza", '06': "Colima", '07': "Chiapas", '08': "Chihuahua",
'09': "Ciudad de México", '10': "Durango", '11': "Guanajuato", '12': "Guerrero",
'13': "Hidalgo", '14': "Jalisco", '15': "México", '16': "Michoacán de Ocampo",
'17': "Morelos", '18': "Nayarit", '19': "Nuevo León", '20': "Oaxaca",
'21': "Puebla", '22': "Querétaro", '23': "Quintana Roo", '24': "San Luis Potosí",
'25': "Sinaloa", '26': "Sonora", '27': "Tabasco", '28': "Tamaulipas",
'29': "Tlaxcala", '30': "Veracruz de Ignacio de la Llave", '31': "Yucatán", '32': "Zacatecas"
}
## =========================================================================================
## =========================================================================================
"""
......@@ -37,16 +49,38 @@ class Command(BaseCommand):
"""
## loading files
for index in range(1,33):
print ("Index: ", index)
with open(base_path + str(index) + ".geojson") as f:
# load data
data = json.load(f)
print ("Index: ", index)
for feat in data['features']:
feature = data['features'][0]
# update name
feature['properties']['NOMGEO'] = states_names[feature['properties']['CVE_ENT']]
# data to save
geometry = shape(feature['geometry'])
# create polygon
polygon = Polygon(
name = self.strip_accents(feat['properties']['NOMGEO'].lower()),
json_info = json.dumps(feat, ensure_ascii=True)
name = self.strip_accents(feature['properties']['NOMGEO'].lower()),
json_info = json.dumps(feature, ensure_ascii=True),
wkt_polygon = geometry.wkt,
CVE_ENT = feature['properties']['CVE_ENT']
)
# save to db
polygon.save()
# for feat in data['features']:
# polygon = Polygon(
# name = self.strip_accents(feat['properties']['NOMGEO'].lower()),
# json_info = json.dumps(feat, ensure_ascii=True)
# )
#
# polygon.save()
## =========================================================================================
## =========================================================================================
......
......@@ -223,10 +223,15 @@ class SearchSubmitView(View):
for polygon in polygonList:
polygonInfo = json.loads(polygon.json_info)
if 'ENT_NAME' in polygonInfo['properties']:
state_name = polygonInfo['properties']['ENT_NAME']
else:
state_name = ""
data_list.append({
'id': str(polygon.id),
'city': polygonInfo['properties']['NOMGEO'],
'state': polygonInfo['properties']['ENT_NAME'],
'state': state_name,
'geojson': polygonInfo,
'wkt_polygon': polygon.wkt_polygon,
'description': polygon.description,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment