我有一个简单的arcpy脚本,可使用其内的多边形要素中的信息来更新点shapefile中的字段。在arcpy中完成100点需要9分钟,但是arcmap中的空间连接是瞬时的。我敢肯定有一个快速建立的方法可以解决这个问题。有人可以指出我正确的方向吗?
import took 0:00:07.085000
extent took 0:00:05.991000
one pt loop took 0:00:03.780000
one pt loop took 0:00:03.850000
one pt loop took 0:00:03.791000
import datetime
t1 = datetime.datetime.now()
import arcpy
t2 = datetime.datetime.now()
print "import took %s" % ( t2-t1)
#set up environment
arcpy.env.workspace = "data\\"
arcpy.env.overwriteOutput = True
desc = arcpy.Describe("parcels.shp")
ext = desc.Extent
extent = (ext.XMin,ext.XMax,ext.YMin,ext.YMax)
t3 = datetime.datetime.now()
print "extent took %s" % (t3 -t2)
fc = arcpy.CreateRandomPoints_management("", "malls.shp", "", ext, 100, "", "POINT", "")
arcpy.AddField_management("malls.shp", 'ParcelID', 'LONG')
rows = arcpy.UpdateCursor('malls.shp',"","",'ParcelID')
for row in rows:
t4 = datetime.datetime.now()
pt = row.Shape.getPart()
for polyrow in arcpy.SearchCursor('parcels.shp'):
t6 = datetime.datetime.now()
poly = polyrow.getValue('Shape')
if extent[0]<pt.X<extent[1] and extent[2]<pt.Y<extent[3]:
if poly.contains(pt):
print "works"
row.ParcelID = polyrow.Parcels_ID
rows.updateRow(row)
break #we can stop looking for matches since
t7 = datetime.datetime.now()
"a full poly loop took %s" % (t7-t6)
t5 = datetime.datetime.now()
print "one pt loop took %s" % (t5-t4)
print datetime.datetime.now() -t1
arcpy.da
(Data Access)模块中添加了(快得多的)游标版本。