Saya punya skrip arcpy sederhana untuk memperbarui bidang dalam bentuk titik dengan info dari fitur poligon yang ada di dalamnya. Dibutuhkan 9 menit untuk menghasilkan 100 poin di arcpy, tetapi join spasial di arcmap adalah instan. Saya yakin ada cara cepat untuk menyelesaikan masalah ini. Bisakah seseorang mengarahkan saya ke arah yang benar?
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
modul (Akses Data) dengan versi kursor yang lebih cepat.