[Community] loads wkt error?

iomeneandrei aborruso at tin.it
Thu Aug 12 17:12:36 EEST 2010


Dear all,
I have written this simple code to read every features of a polygon vector
file, and print the centroid coordinates of each feature.


### the code ###
import os, sys
from osgeo import ogr
from shapely.wkt import dumps, loads

os.chdir('./')

# open nadir2r.shp and get the layer
driver1 = ogr.GetDriverByName('ESRI Shapefile')
quadrati = driver1.Open('nadir2r.shp', 0)
if quadrati is None:
  print 'Could not open nadir2r.shp'
  sys.exit(1)
layer_in = quadrati.GetLayer()

# loop through the features in the layer
feature = layer_in.GetNextFeature()

while feature:
	geom = feature.GetGeometryRef()
	#print geom
	polywkt=loads(str(geom))
	print polywkt.centroid

	feature.Destroy()
  	feature = layer_in.GetNextFeature()

# close the data source
quadrati.Destroy()
### the code ###

The process starts without any error but I have this one before the end of
the while loop:
"Traceback (most recent call last):
  File "shapely_error.py", line 21, in <module>
    polywkt=loads(str(geom))
  File "C:\Python26\lib\site-packages\shapely\wkt.py", line 17, in loads
    "Could not create geometry because of errors while reading input."
shapely.geos.ReadingError: Could not create geometry because of errors while
reading input."

What's wrong in my code? 

I'm attaching the vector layer I have used to test my .py code.
http://community-gispython-org-community-projects.955323.n3.nabble.com/file/n1111154/nadir2r.zip
nadir2r.zip 

Thank you very much,

Andrea


-----
Andrea Borruso

----------------------------------------------------
email: aborruso at tin.it
website: http://blog.spaziogis.it
my 2.0 life: http://aborruso.spaziogis.it
feed: http://feeds2.feedburner.com/Tanto
38° 7' 48" N, 13° 21' 9" E
----------------------------------------------------
-- 
View this message in context: http://community-gispython-org-community-projects.955323.n3.nabble.com/loads-wkt-error-tp1111154p1111154.html
Sent from the Community -- gispython.org community projects mailing list archive at Nabble.com.


More information about the Community mailing list