<div>Hello members:</div>
<div> </div>
<div>I start developing a python module to generate a file which will contain some attributes from a shapefile. My code is:</div>
<div> </div>
<div>import os<br>from xlwt import Workbook<br>from osgeo import ogr<br>import time</div>
<div> </div>
<div>#This is for a kind of crawler into my system:</div>
<div>file_list = []<br>folders = None<br> # look in this (root) folder for files with specified extension<br>for root, folders, files in os.walk( "C:\\" ):<br> file_list.extend(os.path.join(root,fi) for fi in files if fi.endswith(".shp"))</div>
<div> </div>
<div>#Create the excel file</div>
<div>wrkbk = Workbook()<br> #Add named parameter to allow overwriting cells: cell_overwrite_ok=True<br>wksht = wrkbk.add_sheet('shp') <br>wksht.row(0).write(0,'ruta')<br>wksht.row(0).write(1,'archivo')<br>
wksht.row(0).write(2,'x_min')<br>wksht.row(0).write(3,'y_min')<br>wksht.row(0).write(4,'x_max')<br>wksht.row(0).write(5,'y_max')<br>wksht.row(0).write(6,'geometria')<br>wksht.row(0).write(7,'num_elem')<br>
wksht.row(0).write(8,'prj')<br>wksht.row(0).write(9,'estrutura bd')<br>wksht.row(0).write(10,'extent')<br>wksht.row(0).write(11,'fecha_modificacion')<br>wksht.row(0).write(12,'maquina_host')</div>
<div> </div>
<div>Start fiiling the cells with data<br>for row, filepath in enumerate(file_list, start=1): <br> #Fill cells with the path</div>
<div> wksht.row(row).write(0, filepath)<br> #Do the featurecount()<br> shapeData = ogr.Open(filepath)<br> layer = shapeData.GetLayer()<br> feature = layer.GetNextFeature()<br> wksht.row(row).write(7, layer.GetFeatureCount())<br>
#Here is the problem, when I want to get the geometry name, </div>
<div> geometry = feature.GetGeometryRef()<br> geometryType = geometry.GetGeometryName()<br> wksht.row(row).write(6, geometryType)<br> #<br><br>wrkbk.save('shp.xls')</div>
<div> </div>
<div>When the module gets to the geometryName part, ti throws me the error:</div>
<div>Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on<br>win32<br>Type "help", "copyright", "credits" or "license" for more information.<br>>>> import excel_craw<br>
Traceback (most recent call last):<br> File "<stdin>", line 1, in <module><br> File "excel_craw.py", line 45, in <module><br> geometry = feature.GetGeometryRef()<br>AttributeError: 'NoneType' object has no attribute 'GetGeometryRef'<br>
>>></div>
<div> </div>
<div>I don't undestand the reason of the error, because I run the next lines in IDLE Python an this is what I got:</div>
<div>>>> import os<br>>>> from osgeo import ogr<br>>>> shapeData = ogr.Open('tapalpa_05_plani_point.shp')<br>>>> layer = shapeData.GetLayer()<br>>>> feature = layer.GetNextFeature()<br>
>>> geometry = feature.GetGeometryRef()<br>>>> geometryType = geometry.GetGeometryName()<br>>>> print geometryType<br>POINT</div>
<div> </div>
<div>Why is my other code wrong?</div>
<div> </div>
<div> </div>