<div>Your observation is rigth, so I added an if cicle to verify the shp has an associated prj:</div>
<div>n = os.path.splitext(filepath)<br> p = n[0]+'.prj'<br> if os.path.lexists(p):<br> wksht.row(row).write(9, 1)<br> srsObj = layer.GetSpatialRef()<br> srsText = srsObj.ExportToWkt()<br> wksht.row(row).write(8,srsText)<br>
<br> else:<br> wksht.row(row).write(9, 0)<br> wksht.row(row).write(8, 'Sin prj, no se puede determinar la proyeccion')</div>
<div>I run the completed module, but it showed the same 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 crawler_shp</div>
<div>Traceback (most recent call last):<br> File "<stdin>", line 1, in <module><br> File "crawler_shp.py", line 59, in <module></div>
<div> srsText = srsObj.ExportToWkt()<br>AttributeError: 'NoneType' object has no attribute 'ExportToWkt'<br>>>><br> <br>Besides this, I really don't know how to get the srs value from a shp; do you know it? <br>
</div>
<div class="gmail_quote">2010/10/25 David Fawcett <span dir="ltr"><<a href="mailto:david.fawcett@gmail.com">david.fawcett@gmail.com</a>></span><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">OK, I was just thinking about it and figured out how to reproduce your error...<br><br>If the shapefile does not have a .prj file (and therefore no SRS<br>
definition), you will get the error that you are seeing.<br><br>If you know what SRS the data is in, even though it doesn't have a<br>.prj file, you could add some code to detect this condition and add<br>the SRS info. You could either grab the SRS from another shapefile of<br>
known SRS or use the ImportFromEPSG() function to populate it with an<br>EPSG code.<br><font color="#888888"><br>David.<br></font>
<div>
<div></div>
<div class="h5"><br>On Mon, Oct 25, 2010 at 11:58 AM, David Fawcett <<a href="mailto:david.fawcett@gmail.com">david.fawcett@gmail.com</a>> wrote:<br>> Susana,<br>><br>> I just ran this code on my local machine and it works. It prints the<br>
> text representation of the SRS. (I am actually running these Python<br>> modules from OSGEO4W, but it shouldn't really matter.)<br>><br>> from osgeo import ogr,osr<br>><br>> shpPath = "c:/workshop/examples/data/mn_counties.shp"<br>
> shapeData = ogr.Open(shpPath)<br>> layer = shapeData.GetLayer()<br>><br>> srsObj = layer.GetSpatialRef()<br>><br>> srsText = srsObj.ExportToWkt()<br>><br>> print srsText<br>><br>> On Mon, Oct 25, 2010 at 11:29 AM, Susana Iraiis Delgado Rodriguez<br>
> <<a href="mailto:susana.delgado_s@utzmg.edu.mx">susana.delgado_s@utzmg.edu.mx</a>> wrote:<br>>><br>>><br>>> ---------- Forwarded message ----------<br>>> From: Susana Iraiis Delgado Rodriguez <<a href="mailto:susana.delgado_s@utzmg.edu.mx">susana.delgado_s@utzmg.edu.mx</a>><br>
>> Date: 2010/10/25<br>>> Subject: Re: [FWTools] Get projection from shp using GDAL and Python<br>>> To: David Fawcett <<a href="mailto:david.fawcett@gmail.com">david.fawcett@gmail.com</a>><br>>><br>
>><br>>> Thank you David for your help! I tried the code and got the next error:<br>>><br>>> Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]<br>>> on<br>>> win32<br>
>> Type "help", "copyright", "credits" or "license" for more information.<br>>>>>> import crawler_shp<br>>> Traceback (most recent call last):<br>>> File "<stdin>", line 1, in <module><br>
>> File "crawler_shp.py", line 85, in <module><br>>> srsText = srsObj.ExportToWkt()<br>>> AttributeError: 'NoneType' object has no attribute 'ExportToWkt'<br>>>>>><br>
>><br>>> Any idea?<br>>><br>><br></div></div></blockquote></div><br>