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
9e009c5a
Commit
9e009c5a
authored
Jul 16, 2018
by
Renán Sosa Guillen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db population
parent
b0133c01
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
29 deletions
+48
-29
populate_db.py
catalog/management/commands/populate_db.py
+48
-29
No files found.
catalog/management/commands/populate_db.py
View file @
9e009c5a
# -*- coding: utf-8 -*-
"""
This script saves in DB the info from geojson files.
Receives as parameter the path where geojson files are located.
Usage:
$ cd GeoInt_SIDT
$ python manage.py populate_db [path/of/geojson/files]
Example:
$ cd GeoInt_SIDT
$ python manage.py populate_db /home/emmanuelhp/Documentos/geojson/
"""
from
django.core.management.base
import
BaseCommand
,
CommandError
from
catalog.models
import
Polygon
import
json
,
unicodedata
class
Command
(
BaseCommand
):
def
add_arguments
(
self
,
parser
):
## positional arguments
parser
.
add_argument
(
'geojson_path'
,
nargs
=
1
,
type
=
str
)
def
handle
(
self
,
*
args
,
**
options
):
#base
path
base_path
=
'/home/emmanuelhp/Documentos/geojson/'
## base geojson files
path
base_path
=
options
[
'geojson_path'
][
0
]
# loads
files
# loading
files
for
index
in
range
(
1
,
33
):
with
open
(
base_path
+
str
(
index
)
+
'.geojson'
)
as
f
:
with
open
(
base_path
+
str
(
index
)
+
".geojson"
)
as
f
:
data
=
json
.
load
(
f
)
print
(
"Index: "
,
index
)
for
feat
in
data
[
'features'
]:
...
...
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