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