Hello members!! Steven, I already changed the settings in the IDE to avoid the trouble when I type the code. In the other hand I added the pass statement so the script keep working even though it finds an error, but the scripts ignore the pass statement. Console prints:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "mapnik_punto_sin_duda.py", line 44, in <module> lyr.datasource = mapnik.Shapefile(base=ruta,file=archivo[0]) File "C:\mapnik-0.7.1\python\2.6\site-packages\mapnik\__init__.py", line 282, in Shapefile return CreateDatasource(keywords) RuntimeError: wrong file code : -1997790976 2011/6/14 James Reynolds <eire1...@gmail.com> > > > On Tue, Jun 14, 2011 at 2:59 PM, Susana Iraiis Delgado Rodriguez < > susana.delgad...@utzmg.edu.mx> wrote: > >> Hello members! >> >> I'm doing a script that needs to loop to get some information, in order to >> do that I'm using modules from OGR and Mapnik. These to get data from >> shapefiles, but some of the files have 0 elements, I wrote a line to >> validate it, but it hasn't worked, so I added a break to keep working. When >> I run the scipt I got the next error: >> Traceback (most recent call last): >> File "<pyshell#0>", line 1, in <module> >> import mapnik_punto_sin_duda >> File "C:\Python26\mapnik_punto_sin_duda.py", line 23 >> break >> ^ >> IndentationError: unexpected indent >> >> But I've read about this stamentet's use and I don't understand the reason >> I'm failing, the complete script is: >> import mapnik >> import os,fnmatch >> from mapnik import LineSymbolizer,PolygonSymbolizer,PointSymbolizer >> from osgeo import ogr,gdal,osr >> >> #Registra todos los drivers de GDAL >> file_list = [] >> #Crear variable para buscar dentro de carpetas en el sistema >> folders = None >> #Se asigna el directorio raiz donde se van buscar los archivos, se hace un >> recorrido en la raiz >> for root, folders, files in os.walk( "c:\\" ): >> #Agregar a la lista los elementos que traiga os.path.join, los >> archivos que terminen en extension .shp >> for filename in fnmatch.filter(files, '*.shp'): >> file_list.append(os.path.join(root, filename)) >> #Recorrer la lista que se creo >> for row, filepath in enumerate(file_list, start=1): >> #Dividir la ruta en dos: directorio y nombre de archivo >> dir(LineSymbolizer().stroke) >> shapeData = ogr.Open(filepath) >> shp = 'Error al abrir el archivo' +filepath >> if shapeData is None: >> print shp >> break >> else: >> layer = shapeData.GetLayer() >> defn = layer.GetLayerDefn() >> geo = defn.GetGeomType() >> (ruta, filename) = os.path.split(filepath) >> archivo = os.path.splitext(filename) >> i = archivo[0]+'.png' >> >> m = mapnik.Map(800,500,"+proj=latlong +datum=WGS84") >> m.background = mapnik.Color('#EBEBEB') >> s = mapnik.Style() >> r=mapnik.Rule() >> >> if geo == 3: >> print "Trabajando mapa "+ruta+"\\"+filename+" con >> geometria "+ str(geo) >> >> r.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color('#EB784B'))) >> >> r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('rgb(170%,170%,170%)'),0.9)) >> s.rules.append(r) >> m.append_style('My Style',s) >> lyr = mapnik.Layer('world',"+proj=latlong >> +datum=WGS84") >> lyr.datasource = >> mapnik.Shapefile(base=ruta,file=archivo[0]) >> lyr.styles.append('My Style') >> m.layers.append(lyr) >> m.zoom_to_box(lyr.envelope()) >> mapnik.render_to_file(m,i, 'png') >> print "La imagen " +i+ " fue creada." >> elif geo == 2: >> print "Trabajando mapa "+ruta+"\\"+filename+" con >> geometria "+ str(geo) >> >> r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('#EB784B'),0.9)) >> s.rules.append(r) >> m.append_style('My Style',s) >> lyr = mapnik.Layer('world',"+proj=latlong >> +datum=WGS84") >> lyr.datasource = >> mapnik.Shapefile(base=ruta,file=archivo[0]) >> lyr.styles.append('My Style') >> m.layers.append(lyr) >> m.zoom_to_box(lyr.envelope()) >> mapnik.render_to_file(m,i, 'png') >> print "La imagen " +i+ " fue creada." >> elif geo == 1: >> print "Trabajando mapa "+ruta+"\\"+filename+" con >> geometria "+ str(geo) >> blue = >> mapnik.PointSymbolizer('C:\Python26\icono.png','png',50,50) >> blue.allow_overlap = True >> s=mapnik.Style() >> r=mapnik.Rule() >> r.symbols.append(blue) >> s.rules.append(r) >> #s.rules.append(blue) >> m.append_style('My Style',s) >> lyr = mapnik.Layer('world',"+proj=latlong >> +datum=WGS84") >> lyr.datasource = >> mapnik.Shapefile(base=ruta,file=archivo[0]) >> lyr.styles.append('My Style') >> m.layers.append(lyr) >> m.zoom_to_box(lyr.envelope()) >> mapnik.render_to_file(m,i, 'png') >> print "La imagen " +i+ " fue creada." >> else: >> print "Algo fallo y no entro a ninguna de las >> geometrias" >> print "Listo" >> >> >> _______________________________________________ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> >> > > > > > > > > > > > > > > > > > > > > > > > > > > > well i'm not 100% what's going on because it appears to line up when I copy > it to my IDE, but you are mixing tabs or # of space indents, you will raise > that error, as an example: > a= None > if a is None: > print 'a' > print True > > The print 'a' line is four spaces (my default) and the print True is five. > When run it raises the following: > > print True >> ^ >> IndentationError: unexpected indent > > > On a side note, if what you want to do is keep working while you work on > the rest of it, you should use the pass statement. At least that is what I > do. >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor