Geodjango layermapping utility

27 views
Skip to first unread message

jban...@deltageo.ca

unread,
Jan 22, 2017, 8:45:33 PM1/22/17
to Django users
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
load.py
models.py
watersheds_test.dbf
watersheds_test.prj
watersheds_test.qpj
watersheds_test.shp
watersheds_test.shx

jban...@deltageo.ca

unread,
Jan 23, 2017, 10:52:01 AM1/23/17
to Django users
It seems like layermapping.py is not seeing the data as an instance of six.string_types and therefore doesn't build a GDAL Datasource from it.  

Line 92-96 of contrib\gis\utils\layermaping.py

if isinstance(data, six.string_types):
 
self.ds = DataSource(data, encoding=encoding)
else:
 
self.ds = data
self.layer = self.ds[layer]


jban...@deltageo.ca

unread,
Jan 23, 2017, 11:27:50 AM1/23/17
to Django users
Replacing lines 92-96 in layermapping.py with 

if isinstance(data[0], six.string_types):
    self.ds = DataSource(data[0], encoding=encoding)
else:
    self.ds = data
self.layer = self.ds[layer]

worked for me.
Reply all
Reply to author
Forward
0 new messages