<p>尝试学习一些地理空间Python。或多或少地遵循类注释<a href="http://www.gis.usu.edu/~chrisg/python/2009/lectures/ospy_slides1.pdf" rel="nofollow">here</a>。</p>
<p><a href="http://pastebin.com/pp2b0CvF" rel="nofollow">My Code</a></p>
<pre><code>#!/usr/bin/python
# import modules
import ogr, sys, os
# set working dir
os.chdir('/home/jacques/misc/pythongis/data')
# create the text file we're writing to
file = open('data_export.txt', 'w')
# import the required driver for .shp
driver = ogr.GetDriverByName('ESRI Shapefile')
# open the datasource
data = driver.Open('road_surveys.shp', 1)
if data is None:
print 'Error, could not locate file'
sys.exit(1)
# grab the datalayer
layer = data.GetLayer()
# loop through the features
feature = layer.GetNextFeature()
while feature:
# acquire attributes
id = feature.GetFieldAsString('Site_Id')
date = feature.GetFieldAsString('Date')
# get coordinates
geometry = feature.GetGeometryRef()
x = str(geometry.GetX())
y = str(geometry.GetY()
# write to the file
file.Write(id + ' ' + x + ' ' + y + ' ' + cover + '\n')
# remove the current feature, and get a new one
feature.Destroy()
feature = layer.GetNextFeature()
# close the data source
datasource.Destroy()
file.close()
</code></pre>
<p>跑步给我带来了以下好处:</p>
<pre><code> File "shape_summary.py", line 38
file.write(id + ' ' + x + ' ' + y + ' ' + cover + '\n')
^
SyntaxError: invalid syntax
</code></pre>
<p>运行Python2.7.1</p>
<p>任何帮助都太棒了!</p>