I'm trying to use ogr
module, I tried to install it with pip got the errors :
Could not find a version that satisfies the requirement ogr
(from versions: ) No matching distribution found for ogr
tried to install all the package including GDAL and still getting an error
"No module named
ogr
.
didn't find a working solution on google.
That's the code i'm trying to run:
import ogr,csv,sys
import shapefile
shpfile=sys.argv[1]
# csvfile=r'C:\Temp\test.csv' #sys.argv[2]
#Open files
csvfile=open('converterOutput.csv','wb')
ds=ogr.Open(shpfile)
lyr=ds.GetLayer()
#Get field names
dfn=lyr.GetLayerDefn()
nfields=dfn.GetFieldCount()
fields=[]
for i in range(nfields):
fields.append(dfn.GetFieldDefn(i).GetName())
fields.append('kmlgeometry')
csvwriter = csv.DictWriter(csvfile, fields)
try:csvwriter.writeheader() #python 2.7+
except:csvfile.write(','.join(fields)+'\n')
# Write attributes and kml out to csv
for feat in lyr:
attributes=feat.items()
geom=feat.GetGeometryRef()
attributes['kmlgeometry']=geom.ExportToKML()
csvwriter.writerow(attributes)
#clean up
del csvwriter,lyr,ds
csvfile.close()
from No module named ogr
No comments:
Post a Comment