from django.contrib.gis.utils import LayerMapping
from .models import Watersheds
watersheds_spatial = os.path.join(os.path.dirname(__file__), 'data', 'watersheds_test.shp'),
watersheds_mapping = {
'provcd_1' : 'PROVCD_1',
'provcd_2' : 'PROVCD_2',
'provcd_3' : 'PROVCD_3',
'provcd_4' : 'PROVCD_4',
'valdate' : 'VALDATE',
'edition' : 'EDITION',
'datasetnam' : 'DATASETNAM',
'version' : 'VERSION',
'complevel' : 'COMPLEVEL',
'wscmda' : 'WSCMDA',
'wscsda' : 'WSCSDA',
'wscssda' : 'WSCSSDA',
'fda' : 'FDA',
'ocean' : 'OCEAN',
'wscmdaname' : 'WSCMDANAME',
'wscsdaname' : 'WSCSDANAME',
'wscssdanam' : 'WSCSSDANAM',
'cont_ws' : 'Cont_WS',
'reg_ws' : 'Reg_WS',
'riv_basin' : 'Riv_Basin',
'council' : 'Council',
'area' : 'Area',
'geom' : 'MULTIPOLYGON',
}
def run(verbose=True):
lm = LayerMapping(
Watersheds, watersheds_spatial, watersheds_mapping
)
lm.save(strict=True, verbose=verbose)
from django.contrib.gis.db import models
class Watersheds(models.Model):
provcd_1 = models.CharField(max_length=100, blank=True, null=True)
provcd_2 = models.CharField(max_length=100, blank=True, null=True)
provcd_3 = models.CharField(max_length=100, blank=True, null=True)
provcd_4 = models.CharField(max_length=100, blank=True, null=True)
valdate = models.CharField(max_length=8, blank=True, null=True)
edition = models.CharField(max_length=2, blank=True, null=True)
datasetnam = models.CharField(max_length=50, blank=True, null=True)
version = models.CharField(max_length=2, blank=True, null=True)
complevel = models.CharField(max_length=20, blank=True, null=True)
wscmda = models.CharField(max_length=2, blank=True, null=True)
wscsda = models.CharField(max_length=3, blank=True, null=True)
wscssda = models.CharField(max_length=4, blank=True, null=True)
fda = models.CharField(max_length=5, blank=True, null=True)
ocean = models.CharField(max_length=20, blank=True, null=True)
wscmdaname = models.CharField(max_length=100, blank=True, null=True)
wscsdaname = models.CharField(max_length=100, blank=True, null=True)
wscssdanam = models.CharField(max_length=100, blank=True, null=True)
cont_ws = models.CharField(max_length=100, blank=True, null=True)
reg_ws = models.CharField(max_length=50, blank=True, null=True)
riv_basin = models.CharField(max_length=50, blank=True, null=True)
council = models.CharField(max_length=50, blank=True, null=True)
area = models.FloatField()
geom = models.MultiPolygonField(srid=4326)
objects = models.GeoManager()
def __str__(self):
return self.wscssdaname
Hi all, I think i've found a bug but want to confirm before i submit a ticket. I'm trying to load some spatial data using the layermapping utility and keep getting this error Traceback (most recent call last): File "<input>", line 1, in <module> File "D:\Projects\Bluegeo\bluegeo_api\bluegeo_api\water\watersheds\load.py", line 34, in run Watersheds, watersheds_shp, watersheds_mapping File "C:\Users\James-Laptop\Anaconda2\envs\bluegeo_api\lib\site-packages\django\contrib\gis\utils\layermapping.py", line 107, in __init__ self.check_layer() File "C:\Users\James-Laptop\Anaconda2\envs\bluegeo_api\lib\site-packages\django\contrib\gis\utils\layermapping.py", line 179, in check_layer ogr_fields = self.layer.fields AttributeError: 'str' object has no attribute 'fields' I'm using the following: Windows 10 Python 3.4.5 (Anaconda 4.2.13) Django 1.10.4 Postgres 9.6 and postgis 2.3 GDAL 1.11 GEOS 3.4.2 Ive attached a model, a load data script, and some data as well So is this a bug or am I doing this wrong? Thanks,
James
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/45d6f12f-9d97-401e-8cd3-aed05987cb5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment