Esempio n. 1
0
 def handle(self, *args, **options):
     
     """ 
     Adds the necessary SRS 32633 (UTM 33N) and 4326 (WGS84) to
     the postgis DB
     """
     add_postgis_srs(32633)
     add_postgis_srs(4326)
Esempio n. 2
0
    def handle(self, *args, **options):
        srid = args[0]
        try:
            add_postgis_srs(srid)
        except:
            raise CommandError('Problem adding SRID: %s' % srid)

        self.stdout.write('Successfully added SRID "%s"' % srid)
Esempio n. 3
0
    def handle(self, *args, **options):
        srid = args[0]
        try:
            add_postgis_srs(srid)
        except:
            raise CommandError('Problem adding SRID: %s' % srid)


        self.stdout.write('Successfully added SRID "%s"' % srid)
Esempio n. 4
0
    def handle_noargs(self, **options):
        
        add_postgis_srs(102671)
        
        management.call_command('syncdb')

    	lm = LayerMapping(models.CpdBeats, 'data/maps/cpd_beats/cpd_beats.shp', models.cpdbeats_mapping,transform=True, encoding='iso-8859-1')

    	lm.save(verbose=True)
Esempio n. 5
0
def run():
    import os
    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

    from psycopg2 import IntegrityError
    from django.contrib.gis.utils import mapping, LayerMapping, add_postgis_srs

    from world.models import WorldBorders

    try:
        add_postgis_srs(900913)
    except IntegrityError:
        print "The Google Spherical Mercator projection, or a projection with srid 900913, already exists, skipping insert"

    WORLD_SHP = 'apps/world/data/TM_WORLD_BORDERS-0.3.shp'
    layer = LayerMapping(WorldBorders,
                          WORLD_SHP,
                          mapping(WORLD_SHP,geom_name='mpoly',multi_geom=True),
                          transform=False,
                          encoding='iso-8859-1')

    layer.save(verbose=True,strict=True,progress=True)


    print 'Fixing invalid polygons...'
    num = len(WorldBorders.objects.extra(where=['NOT ST_IsValid(mpoly)']))
    for item in WorldBorders.objects.extra(where=['NOT ST_IsValid(mpoly)']):
        corrected = item.mpoly.buffer(0)
        item.mpoly = corrected
        item.save()

    print '....'
    num = len(WorldBorders.objects.extra(where=['NOT ST_IsValid(mpoly)']))
    if num:
      print '%s invalid polygons remain' % num
      print WorldBorders.objects.extra(where=['NOT ST_IsValid(mpoly)'])
Esempio n. 6
0
#!/usr/local/venv/locus/bin/python

# Add world mollweide
# <54009> +proj=moll +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs <>
import os

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "settings"

from django.contrib.gis.utils import add_postgis_srs
add_postgis_srs(54009)
Esempio n. 7
0
from django.core.management import setup_environ
import settings
setup_environ(settings)
from django.contrib.gis.geos import GEOSGeometry, fromstr
from django.contrib.gis.utils import add_postgis_srs
from django.db import transaction
from clustr.models import AlphaShapes

# Download this data from:
# http://www.flickr.com/services/shapefiles/1.0/
FLICKR_SHAPES_XML_FILE = "clustr/flickr_shapefiles_public_dataset_1.0.xml"

# why not try to toss in the gmerc projection while we are here...
try:
    add_postgis_srs(900913)
except IntegrityError:
    print "The Google Spherical Mercator projection, or a projection with srid 900913, already exists, skipping insert"

logging.basicConfig(
    level=logging.ERROR,
    datefmt="%Y-%m-%d %H:%M:%S",
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")


def sort_list_by_obj_attr(seq, attr):
    """
    Borrowed from ActiveState recipe #52230, adjusted for using lxml elements
    """
    intermed = [(seq[i].get(attr), i, seq[i]) for i in xrange(len(seq))]
    intermed.sort()
Esempio n. 8
0
#!/usr/bin/env python

from manage import *

from django.core.management import setup_environ
import settings

setup_environ(settings)

from django.contrib.gis.utils import add_postgis_srs

if __name__ == "__main__":
    add_postgis_srs(900913)
    

Esempio n. 9
0
 def handle(self, *fixtures, **options):
     from django.contrib.gis.gdal import SpatialReference
     from django.contrib.gis.utils import add_postgis_srs
     # adding the Google Projection Merkator
     add_postgis_srs(SpatialReference(900913))
Esempio n. 10
0
 def handle(self, *args, **options):
     add_postgis_srs(54009)
Esempio n. 11
0
 def handle(self, *args, **options):
     add_postgis_srs(54009)
Esempio n. 12
0
from django.db import models
from django.contrib.gis.db import models
from django.contrib.gis.utils import add_postgis_srs
from django.contrib.auth.models import User

add_postgis_srs(102671)


class CpdBeats(models.Model):
    objectid = models.IntegerField()
    district = models.CharField(max_length=2)
    sector = models.CharField(max_length=1)
    beat = models.CharField(max_length=1)
    beat_num = models.CharField(max_length=4)
    shape_area = models.FloatField()
    shape_len = models.FloatField()
    geom = models.PolygonField(srid=102671)
    objects = models.GeoManager()


# Auto-generated `LayerMapping` dictionary for CpdBeats model
cpdbeats_mapping = {
    "objectid": "OBJECTID",
    "district": "DISTRICT",
    "sector": "SECTOR",
    "beat": "BEAT",
    "beat_num": "BEAT_NUM",
    "shape_area": "SHAPE_AREA",
    "shape_len": "SHAPE_LEN",
    "geom": "POLYGON",
}
Esempio n. 13
0
 def handle(self, *fixtures, **options):
     from django.contrib.gis.gdal import SpatialReference
     from django.contrib.gis.utils import add_postgis_srs
     # adding the Google Projection Merkator
     add_postgis_srs(SpatialReference(900913))
Esempio n. 14
0
 def setUp(self):
     add_postgis_srs(900913)
     self.dummy_obj = DummyModel(name="foo")
     self.dummy_obj.save()
     self.dummy_model_contenttype = ContentType.objects.get(name="dummy model")