<div>Hello list!</div>
<div> </div>
<div>I designed a python module to get all the information I need from a shapefile. I&#39;ve been using GDAL to work with my script and I already collected all the information I need. My application saves the values in an excel sheet, but I haven&#39;t gotten the projection info, the code is:</div>

<div> </div>
<div>import os, time, socket<br>from xlwt import Workbook<br>from osgeo import ogr,gdal,osr<br>from dbf import *</div>
<div>gdal.AllRegister()<br>file_list = []<br>folders = None<br> # look in this (root) folder for files with specified extension<br>for root, folders, files in os.walk( &quot;C:\\&quot; ):<br> file_list.extend(os.path.join(root,fi) for fi in files if fi.endswith(&quot;.shp&quot;))</div>

<div>wrkbk = Workbook()<br>wksht = wrkbk.add_sheet(&#39;shp&#39;) <br>wksht.row(0).write(0,&#39;ruta&#39;)<br>wksht.row(0).write(1,&#39;archivo&#39;)<br>wksht.row(0).write(2,&#39;x_min&#39;)<br>wksht.row(0).write(3,&#39;x_max&#39;)<br>
wksht.row(0).write(4,&#39;y_min&#39;)<br>wksht.row(0).write(5,&#39;y_max&#39;)<br>wksht.row(0).write(6,&#39;geometria&#39;)<br>wksht.row(0).write(7,&#39;num_elem&#39;)<br>wksht.row(0).write(8,&#39;proyeccion&#39;)<br>wksht.row(0).write(9,&#39;prj&#39;)<br>
wksht.row(0).write(10,&#39;estructura bd&#39;)<br>wksht.row(0).write(11,&#39;fecha_modificacion&#39;)<br>wksht.row(0).write(12,&#39;maquina_host&#39;)<br>wksht.row(0).write(13,&#39;usuario&#39;)</div>
<div><br>for row, filepath in enumerate(file_list, start=1): <br> #Get path and filename<br> wksht.row(row).write(0, filepath)<br> #Get filename</div>
<div> (ruta, filename) = os.path.split(filepath) <br> wksht.row(row).write(1, filename)<br> # Get extent</div>
<div> shapeData = ogr.Open(filepath)<br> layer = shapeData.GetLayer()<br> feature = layer.GetNextFeature()<br> x_min, x_max, y_min, y_max = layer.GetExtent()<br> x_y = layer.GetExtent()<br> wksht.row(row).write(2, x_y[0])<br>
 wksht.row(row).write(3, x_y[1])<br> wksht.row(row).write(4, x_y[2])<br> wksht.row(row).write(5, x_y[3])<br> #Get geometry type;1=Point, 2=LineString, 3=Polygon<br> defn = layer.GetLayerDefn()<br> wksht.row(row).write(6, defn.GetGeomType())<br>
 #Get featurecount()<br> wksht.row(row).write(7, layer.GetFeatureCount())<br> #Verify prj from shp</div>
<div> n = os.path.splitext(filepath)<br> p = n[0]+&#39;.prj&#39;<br> if os.path.lexists(p):<br>  wksht.row(row).write(9, 1)<br> else:<br>  wksht.row(row).write(9, 0)</div>
<div> #Get host from the file</div>
<div> wksht.row(row).write(12, socket.gethostname())<br> <br> #Extarct database</div>
<div> t = n[0]+&#39;_bd.txt&#39;<br> d = n[0]+&#39;.dbf&#39;<br> if os.path.lexists(d):<br>  a = open (t,&quot;w+&quot;)<br>  dbf = Dbf(d,new=False)<br>  <br>  for fldName in dbf.fieldDefs:<br>   a.write(fldName.name)<br>
   a.write(&quot; || &quot;)<br>   a.write(fldName.typeCode)<br>   a.write(&quot;\n&quot;) <br>  dbf.close()<br>  a.close()<br>  wksht.row(row).write(10, t)<br> else:<br>  print &quot;El archivo &quot; +n[0]+&quot;.shp&quot; &quot; no tiene dbf&quot;<br>
  wksht.row(row).write(10, &quot;Sin bd&quot;)<br> <br>#Get projection, this is the part that fails</div>
<div> print layer.GetSpatialRef()<br> wksht.row(row).write(8, layer.GetSpatialRef())</div>
<div> <br> #Get file last modification<br> t = time.strftime(&quot;%m/%d/%Y %I:%M:%S %p&quot;,time.localtime(os.path.getmtime(filepath)))<br> wksht.row(row).write(11, t)<br> #Get username <br> wksht.row(row).write(13,os.environ.get(&quot;USERNAME&quot;))<br>
 <br>wrkbk.save(&#39;shp.xls&#39;)</div>
<div> </div>
<div>SEARCH_PATH = os.getcwd()<br>TARGET_FILE = os.path.realpath(&#39;shp.xls&#39;) <br>print &quot;Buscando en&quot;, SEARCH_PATH, &quot;and writing to&quot;, TARGET_FILE<br>print &quot;Encontrando archivos...&quot;<br>
print &quot;Escribiendo archivo de Excel...&quot;<br>print &quot;Listo.&quot;</div>
<div> </div>
<div>I got the next output:</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 &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>&gt;&gt;&gt; import crawler_shp<br>
None<br>None<br>PROJCS[&quot;WGS_1984_UTM_Zone_13N&quot;,<br>    GEOGCS[&quot;GCS_WGS_1984&quot;,<br>        DATUM[&quot;WGS_1984&quot;,<br>            SPHEROID[&quot;WGS_1984&quot;,6378137,298.257223563]],<br>        PRIMEM[&quot;Greenwich&quot;,0],<br>
        UNIT[&quot;Degree&quot;,0.017453292519943295]],<br>    PROJECTION[&quot;Transverse_Mercator&quot;],<br>    PARAMETER[&quot;latitude_of_origin&quot;,0],<br>    PARAMETER[&quot;central_meridian&quot;,-105],<br>    PARAMETER[&quot;scale_factor&quot;,0.9996],<br>
    PARAMETER[&quot;false_easting&quot;,500000],<br>    PARAMETER[&quot;false_northing&quot;,0],<br>    UNIT[&quot;Meter&quot;,1]]<br>Traceback (most recent call last):<br>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>
  File &quot;crawler_shp.py&quot;, line 85, in &lt;module&gt;<br>    wksht.row(row).write(8, layer.GetSpatialRef())<br>  File &quot;C:\Python26\lib\site-packages\xlwt\Row.py&quot;, line 248, in write<br>    raise Exception(&quot;Unexpected data type %r&quot; % type(label))<br>
Exception: Unexpected data type &lt;class &#39;osgeo.osr.SpatialReference&#39;&gt;<br>&gt;&gt;&gt;</div>
<div>Any idea?</div>
<div> </div>