Skip to content

Commit

Permalink
Test to ingest regions and footprints into database.
Browse files Browse the repository at this point in the history
  • Loading branch information
amaurs committed Dec 5, 2017
1 parent 3ca13d3 commit 5d7e847
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 4 deletions.
2 changes: 0 additions & 2 deletions madmex/management/commands/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ def handle(self, **options):

segmentation = bis.Model()

sgementation = slic.Model()


shapes, transform, meta = segmentation.predict(stack)

Expand Down
53 changes: 53 additions & 0 deletions madmex/management/commands/shape.py
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()

24 changes: 24 additions & 0 deletions madmex/migrations/0009_region.py
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)),
],
),
]
29 changes: 29 additions & 0 deletions madmex/migrations/0010_auto_20171205_0405.py
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',
),
]
20 changes: 20 additions & 0 deletions madmex/migrations/0011_auto_20171205_0445.py
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',
),
]
19 changes: 19 additions & 0 deletions madmex/migrations/0012_auto_20171205_0446.py
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',
),
]
21 changes: 21 additions & 0 deletions madmex/migrations/0013_auto_20171205_0452.py
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),
),
]
10 changes: 9 additions & 1 deletion madmex/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@

class Segment(models.Model):
segment_id = models.IntegerField('Region Code')
mpoly = models.PolygonField()
the_geom = models.PolygonField()

class Region(models.Model):
name = models.CharField(max_length=50)
the_geom = models.MultiPolygonField()

class Footprint(models.Model):
name = models.CharField(max_length=50)
the_geom = models.PolygonField()

class WorldBorder(models.Model):
# Regular Django fields corresponding to the attributes in the
Expand Down
1 change: 0 additions & 1 deletion web/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
USE_TZ = True

USGS_USER = os.environ.get('USGS_USER')

USGS_PASSWORD = os.environ.get('USGS_PASSWORD')
BIS_LICENSE = os.environ.get('BIS_LICENSE')
TEMP_FOLDER = os.environ.get('TEMP_FOLDER')
Expand Down

0 comments on commit 5d7e847

Please sign in to comment.