-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Determine project country from extent geometry using world country boundary data. - Set up country boundary data during provisioning.
- Loading branch information
Ian Ross
committed
Apr 18, 2016
1 parent
15a742e
commit 1b602ae
Showing
16 changed files
with
182 additions
and
3 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 |
---|---|---|
|
@@ -36,3 +36,5 @@ vagrant.retry | |
/.tox/ | ||
/cadasta_platform.egg-info/ | ||
/pytest.txt | ||
|
||
/cadasta/geography/data |
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 |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
'corsheaders', | ||
|
||
'core', | ||
'geography', | ||
'accounts', | ||
'organization', | ||
|
||
|
Empty file.
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,30 @@ | ||
import os | ||
from django.contrib.gis.utils import LayerMapping | ||
from .models import WorldBorder | ||
|
||
|
||
world_mapping = { | ||
'fips': 'FIPS', | ||
'iso2': 'ISO2', | ||
'iso3': 'ISO3', | ||
'un': 'UN', | ||
'name': 'NAME', | ||
'area': 'AREA', | ||
'pop2005': 'POP2005', | ||
'region': 'REGION', | ||
'subregion': 'SUBREGION', | ||
'lon': 'LON', | ||
'lat': 'LAT', | ||
'mpoly': 'MULTIPOLYGON', | ||
} | ||
|
||
world_shp = os.path.abspath(os.path.join(os.path.dirname(__file__), | ||
'data', 'TM_WORLD_BORDERS-0.3.shp')) | ||
|
||
|
||
def run(verbose=True): | ||
WorldBorder.objects.all().delete() | ||
lm = LayerMapping(WorldBorder, world_shp, world_mapping, | ||
transform=False, encoding='iso-8859-1') | ||
|
||
lm.save(strict=True, verbose=verbose) |
Empty file.
Empty file.
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,10 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from ... import load | ||
|
||
|
||
class Command(BaseCommand): | ||
help = """Loads country boundary data.""" | ||
|
||
def handle(self, *args, **options): | ||
load.run() |
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,35 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.4 on 2016-04-18 20:24 | ||
from __future__ import unicode_literals | ||
|
||
import django.contrib.gis.db.models.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='WorldBorder', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=50)), | ||
('area', models.IntegerField()), | ||
('pop2005', models.IntegerField(verbose_name='Population 2005')), | ||
('fips', models.CharField(max_length=2, verbose_name='FIPS Code')), | ||
('iso2', models.CharField(max_length=2, verbose_name='2 Digit ISO')), | ||
('iso3', models.CharField(max_length=3, verbose_name='3 Digit ISO')), | ||
('un', models.IntegerField(verbose_name='United Nations Code')), | ||
('region', models.IntegerField(verbose_name='Region Code')), | ||
('subregion', models.IntegerField(verbose_name='Sub-Region Code')), | ||
('lon', models.FloatField()), | ||
('lat', models.FloatField()), | ||
('mpoly', django.contrib.gis.db.models.fields.MultiPolygonField(srid=4326)), | ||
], | ||
), | ||
] |
Empty file.
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 @@ | ||
from django.contrib.gis.db import models | ||
|
||
|
||
class WorldBorder(models.Model): | ||
name = models.CharField(max_length=50) | ||
area = models.IntegerField() | ||
pop2005 = models.IntegerField('Population 2005') | ||
fips = models.CharField('FIPS Code', max_length=2) | ||
iso2 = models.CharField('2 Digit ISO', max_length=2) | ||
iso3 = models.CharField('3 Digit ISO', max_length=3) | ||
un = models.IntegerField('United Nations Code') | ||
region = models.IntegerField('Region Code') | ||
subregion = models.IntegerField('Sub-Region Code') | ||
lon = models.FloatField() | ||
lat = models.FloatField() | ||
mpoly = models.MultiPolygonField() | ||
|
||
def __str__(self): | ||
return self.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,13 @@ | ||
from django.test import TestCase | ||
|
||
from geography.models import WorldBorder | ||
|
||
|
||
class WorldBorderTest(TestCase): | ||
def test_str(self): | ||
border = WorldBorder.objects.create( | ||
name='Narnia', area=1, pop2005=1, un=1, region=1, subregion=1, | ||
lat=0, lon=0, | ||
mpoly='MULTIPOLYGON(((10 10, 10 20, 20 20, 20 15, 10 10)))' | ||
) | ||
assert str(border) == 'Narnia' |
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
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