[Tutor] RuntimeError: file does not exist
Susana Iraiis Delgado Rodriguez
susana.delgado_s at utzmg.edu.mx
Tue May 17 19:10:04 CEST 2011
Hello list!!
I'm using a python dll to create images out from shapefiles. I import a
python module and its functions, when I want to use this library, I get a
message which tells me the file I want to work with doesn't exist, but it
does. I'm running the script from Windows. This is the code:
import mapnik
import os,fnmatc
file_list = []
folders = None
for root, folders, files in os.walk( "C:\\" ):
for filename in fnmatch.filter(files, '*.shp'):
file_list.append(os.path.join(root, filename))
for row, filepath in enumerate(file_list, start=1):
(ruta, filename) = os.path.split(filepath)
i = archivo[0]+'.png'
m = mapnik.Map(800,500,"+proj=latlong +datum=WGS84")
m.background = mapnik.Color('#f2eff9')
s = mapnik.Style()
r=mapnik.Rule()
r.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color('steelblue')))
r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('rgb(50%,50%,50%)'),0.1))
s.rules.append(r)
m.append_style('My Style',s)
lyr = mapnik.Layer('world',"+proj=latlong +datum=WGS84")
lyr.datasource = mapnik.Shapefile(base=filepath, file=filepath)
lyr.styles.append('My Style')
m.layers.append(lyr)
m.zoom_to_box(lyr.envelope())
mapnik.render_to_file(m,i, 'png')
print "Listo"
I get the next error:
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import imagen_shp
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "imagen_shp.py", line 32, in <module>
lyr.datasource = mapnik.Shapefile(base=filepath, file=filepath)
File "C:\mapnik-0.7.1\python\2.6\site-packages\mapnik\__init__.py", line
282,
in Shapefile
return CreateDatasource(keywords)
RuntimeError: C:\Ýndice.shp/C:\Ýndice does not exist
>>>
I also reviewed the line which causes the error, it's a script from the
mapnik library:
def Shapefile(**keywords):
"""Create a Shapefile Datasource.
Required keyword arguments:
file -- path to shapefile without extension
Optional keyword arguments:
base -- path prefix (default None)
encoding -- file encoding (default 'utf-8')
>>> from mapnik import Shapefile, Layer
>>> shp = Shapefile(base='/home/mapnik/data',file='world_borders')
>>> lyr = Layer('Shapefile Layer')
>>> lyr.datasource = shp
"""
keywords['type'] = 'shape'
return CreateDatasource(keywords)
Does anyone could help me?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110517/58886d16/attachment.html>
More information about the Tutor
mailing list