-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test to ingest regions and footprints into database.
- Loading branch information
Showing
9 changed files
with
175 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
''' | ||
Created on Dec 4, 2017 | ||
@author: agutierrez | ||
''' | ||
import json | ||
from pydoc import locate | ||
|
||
from django.contrib.gis.geos.geometry import GEOSGeometry | ||
import fiona | ||
import geojson | ||
from shapely.geometry.geo import shape | ||
from shapely.geometry.multipolygon import MultiPolygon | ||
|
||
from madmex.management.base import AntaresBaseCommand | ||
import madmex.models | ||
|
||
|
||
class Command(AntaresBaseCommand): | ||
''' | ||
classdocs | ||
''' | ||
def add_arguments(self, parser): | ||
''' | ||
Adds the sum argument for this command, of course this will change in | ||
the final implementation. | ||
''' | ||
parser.add_argument('--path', nargs='*', help='The file to be segmented.') | ||
parser.add_argument('--column', nargs='*', help='The file to be segmented.') | ||
parser.add_argument('--model', nargs='*', help='The file to be segmented.') | ||
|
||
def handle(self, **options): | ||
path = options['path'][0] | ||
column = options['column'][0] | ||
model = options['model'][0] | ||
|
||
|
||
|
||
with fiona.open(path) as src: | ||
print json.dumps(src.schema, indent=4) | ||
print src.crs | ||
for feat in src: | ||
|
||
#print feat['geometry']['type'] | ||
s = shape(feat['geometry']) | ||
if feat['geometry']['type'] == 'Polygon': | ||
s = MultiPolygon([s]) | ||
print json.dumps(feat['geometry']) | ||
klass = locate('madmex.models.%s' % model) | ||
|
||
f = klass(name=feat['properties'][column], the_geom=GEOSGeometry(s.wkt)) | ||
f.save() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.6 on 2017-12-05 03:48 | ||
from __future__ import unicode_literals | ||
|
||
import django.contrib.gis.db.models.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('madmex', '0008_auto_20171201_2150'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Region', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=50)), | ||
('the_geom', django.contrib.gis.db.models.fields.PolygonField(srid=4326)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.6 on 2017-12-05 04:05 | ||
from __future__ import unicode_literals | ||
|
||
import django.contrib.gis.db.models.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('madmex', '0009_region'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Footprints', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('footprint_id', models.CharField(max_length=50)), | ||
('the_geom', django.contrib.gis.db.models.fields.PolygonField(srid=4326)), | ||
], | ||
), | ||
migrations.RenameField( | ||
model_name='segment', | ||
old_name='mpoly', | ||
new_name='the_geom', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.6 on 2017-12-05 04:45 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('madmex', '0010_auto_20171205_0405'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='footprints', | ||
old_name='footprint_id', | ||
new_name='name', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.6 on 2017-12-05 04:46 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('madmex', '0011_auto_20171205_0445'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameModel( | ||
old_name='Footprints', | ||
new_name='Footprint', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.6 on 2017-12-05 04:52 | ||
from __future__ import unicode_literals | ||
|
||
import django.contrib.gis.db.models.fields | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('madmex', '0012_auto_20171205_0446'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='region', | ||
name='the_geom', | ||
field=django.contrib.gis.db.models.fields.MultiPolygonField(srid=4326), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters