Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoInt_SIDT
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoInt_SIDT
Commits
10c2be2e
Commit
10c2be2e
authored
Sep 19, 2019
by
Emmanuel René Huchim Puc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
states added
parent
c185dd49
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
25 deletions
+64
-25
addState.py
catalog/management/commands/addState.py
+9
-9
populate_db.py
catalog/management/commands/populate_db.py
+42
-8
views.py
catalog/views.py
+13
-8
No files found.
catalog/management/commands/addState.py
View file @
10c2be2e
...
...
@@ -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
:
...
...
catalog/management/commands/populate_db.py
View file @
10c2be2e
...
...
@@ -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()
## =========================================================================================
## =========================================================================================
...
...
catalog/views.py
View file @
10c2be2e
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment