|
POST
|
I found the easiest way to handle this is to call functions anytime you use a cursor. Simple example.
def main():
rows = arcpy.UpdateCursor(layer)
for row in rows:
row.Field = "value"
rows.updateRow(row)
del rows
if __name__ == '__main__':
main()
This should completely clear the cursors when the function is complete.
... View more
10-24-2011
11:34 AM
|
0
|
0
|
702
|
|
POST
|
Hello, ...any underlying features... Dave What exactly do you mean by that? Other features in an mxd? In the workspace?
... View more
10-19-2011
10:31 AM
|
0
|
0
|
517
|
|
POST
|
Here's an example of some verbose field mapping. Probably not the best example, but a place to start.
field_mappings = arcpy.FieldMappings()
field_mappings.addTable(block_lyr)
fldmap_OBJID = arcpy.FieldMap()
fldmap_BLOCKSTAGE = arcpy.FieldMap()
fldmap_AREAGIS = arcpy.FieldMap()
fldmap_OPTYPE = arcpy.FieldMap()
fldmap_BLOCKTYPE = arcpy.FieldMap()
fldmap_HARVSEASON = arcpy.FieldMap()
fldmap_ROADPERCNT = arcpy.FieldMap()
fldmap_OBJID.addInputField(block_lyr, "OBJECTID")
fld_OBJID = fldmap_OBJID.outputField
fld_OBJID.name = "O_OID"
fldmap_OBJID.outputField = fld_OBJID
field_mappings.addFieldMap(fldmap_OBJID)
fldmap_BLOCKSTAGE.addInputField(block_lyr, "BLOCKSTAGE")
fld_BLOCKSTAGE = fldmap_BLOCKSTAGE.outputField
fld_BLOCKSTAGE.name = "BLOCKSTAGE"
fldmap_BLOCKSTAGE.outputField = fld_BLOCKSTAGE
field_mappings.addFieldMap(fldmap_BLOCKSTAGE)
fldmap_AREAGIS.addInputField(block_lyr, "AREAGIS")
fld_AREAGIS = fldmap_AREAGIS.outputField
fld_AREAGIS.name = "AREAGIS"
fldmap_AREAGIS.outputField = fld_AREAGIS
field_mappings.addFieldMap(fldmap_AREAGIS)
fldmap_OPTYPE.addInputField(block_lyr, "OPERATIONSTYPE")
fld_OPTYPE = fldmap_OPTYPE.outputField
fld_OPTYPE.name = "OPTYPE"
fldmap_OPTYPE.outputField = fld_OPTYPE
field_mappings.addFieldMap(fldmap_OPTYPE)
fldmap_BLOCKTYPE.addInputField(block_lyr, "BLOCKTYPE")
fld_BLOCKTYPE = fldmap_BLOCKTYPE.outputField
fld_BLOCKTYPE.name = "BLOCKTYPE"
fldmap_BLOCKTYPE.outputField = fld_BLOCKTYPE
field_mappings.addFieldMap(fldmap_BLOCKTYPE)
fldmap_HARVSEASON.addInputField(block_lyr, "HARVESTSEASON")
fld_HARVSEASON = fldmap_HARVSEASON.outputField
fld_HARVSEASON.name = "HARVSEASON"
fldmap_HARVSEASON.outputField = fld_HARVSEASON
field_mappings.addFieldMap(fldmap_HARVSEASON)
fldmap_ROADPERCNT.addInputField(block_lyr, "ROADPERCENTAGE")
fld_ROADPERCNT = fldmap_ROADPERCNT.outputField
fld_ROADPERCNT.name = "ROADPERCNT"
fldmap_ROADPERCNT.outputField = fld_ROADPERCNT
field_mappings.addFieldMap(fldmap_ROADPERCNT)
... View more
10-19-2011
06:01 AM
|
0
|
0
|
1042
|
|
POST
|
arcpy.Exists("layer") http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000021000000
... View more
10-17-2011
11:04 AM
|
0
|
0
|
424
|
|
POST
|
Short answer, no. Long answer, hopefully soon. http://support.esri.com/en/knowledgebase/techarticles/detail/38343 This is the part I think you are interested in... ArcGIS Desktop on 64-bit ArcGIS Desktop 10.0 applications are natively 32-bit applications but take advantage of a technology known as large memory awareness. This means that individual processes, such as ArcMap.exe, may be capable of accessing more than 2GB of memory (up to 4GB) when run on a 64-bit OS. Note that some functionality and third-party libraries that are part of ArcGIS are not compatible with large-address-awareness, and as such, some portions of ArcGIS may not be able to address more than 2GB even when running on a 64-bit OS.
... View more
10-13-2011
09:39 AM
|
0
|
0
|
1717
|
|
POST
|
Open a fresh instance of ArcMap, go to Geoprocessing > Environments remember what it says is your current workspace. Then go to the Python window and enter print arcpy.env.workspace If they don't match there is a problem somewhere deeper than simple code may be able to fix. I've seen some wonky things happen with errant registry edits moving default workspaces around.
... View more
10-12-2011
02:30 PM
|
0
|
0
|
2236
|
|
POST
|
Is this being done in the Python window in ArcMap? Have you tried running it as a stand alone script?
... View more
10-12-2011
02:10 PM
|
0
|
0
|
2236
|
|
POST
|
Don't quote me on this, but I seem to recall the add index gives this error if there is already an index with that name, or the field you are indexing is already indexed.
... View more
10-12-2011
10:55 AM
|
0
|
1
|
2116
|
|
POST
|
This line is probably the problem. msg = " - " + polyRow.NAME_1 + " - " + "Urban Population: " + sum(list) You can't concatenate strings and ints. The blow line should fix it. msg = " - " + polyRow.NAME_1 + " - " + "Urban Population: " + str(sum(list)) I didn't see anywhere else where that error is made, but you'd need to change it if you are putting together strings and numeric types anywhere else as well.
... View more
10-12-2011
10:10 AM
|
0
|
0
|
4770
|
|
POST
|
I think your indentation might be off import arcpy
from arcpy import env
import string
env.workspace = "C:\\Users\\gisadmin\\Desktop\\TEST"
filter = ''
cur = arcpy.UpdateCursor("C:\\Users\\gisadmin\\Desktop\\TEST\\FH_Test.shp", filter)
i = 0
for row in cur:
i += 1
row.FACILITY_I = str(i) #This is the label for the column you want to update, eg. OID
cur.updateRow(row)
... View more
10-12-2011
07:36 AM
|
0
|
0
|
800
|
|
POST
|
Glad I could be of help. Those kind of errors are tough to track down if you don't get a helpful error message.
... View more
10-03-2011
01:20 PM
|
0
|
0
|
1090
|
|
POST
|
Did you try this? if platform.version()[0] == "6":
#Check if Windows 7
gp.AddToolbox(r"C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")
gp.AddToolbos(r"C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Analysis Tools.tbx")
elif platform.version()[0] == "5":
#Check if Windows XP
gp.AddToolbox(r"C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")
gp.AddToolbox(r"C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Analysis Tools.tbx")
print "Connection found, continuing"
else:
"No connection."
... View more
10-03-2011
11:51 AM
|
0
|
0
|
1090
|
|
POST
|
I use this
username = getpass.getuser()
if platform.version()[0] == "6":
#Check if Windows 7
sde = "C:\Users\\"+username+"\\AppData\\Roaming\\ESRI\\Desktop10.0\\ArcCatalog\\wisprod.sde"
elif platform.version()[0] == "5":
#Check if Windows XP
sde = r"C:\Documents and Settings\\"+username+"\Application Data\ESRI\ArcCatalog\wisprod.sde"
print "SDE connection found, continuing"
else:
"User <"+username+"> is invalid, not found, or you do not have access to SDE."
... View more
10-03-2011
11:01 AM
|
0
|
0
|
1090
|
|
POST
|
Only successful test I found was using a searchcursor, not field calculator. Null values must be read as something else in field calculator, because they come back as value True.
... View more
09-29-2011
10:57 AM
|
0
|
0
|
5749
|
|
POST
|
Tableview to Tableview temporary join. Here is the code below in the offending function. I tried playing around with table names in field references to try to get it to work, but to no avail. The script does not even step into the cursor, fails hard on {rows = arcpy.UpdateCursor(calc_table)} line.
def pieces():
""" Calculates CON_PIECE, DEC_PIECE, CON_VOL and DEC_VOL fields """
""" ~3.5 hours total, ~3 hours for join """
vol_tab = "strata_volumes"
joinField = "STRATA"
arcpy.AddIndex_management(calc_table, "STRATA", "STRA_IND")
strata_table = arcpy.MakeTableView_management(vol_tab)
print "Starting join at "+datetime.datetime.now().strftime("%H:%M:%S")
#Syntax
#AddJoin_management (in_layer_or_view, in_field, join_table, join_field, {join_type})
arcpy.AddJoin_management(calc_table, joinField, strata_table, joinField)
#arcpy.JoinField_management(calc_table, joinField, vol_tab, joinField)
print "Done join at "+datetime.datetime.now().strftime("%H:%M:%S")
#decid_list = ["Aw","Pb","Bw"]
#con_list = ["Sw", "Sb", "Fb", "Pl", "Pj", "Lt"]
species = [
("C","Fb","FB_STEMS"),("C","Sw","SW_STEMS"),("C","Pj","PJ_STEMS"), # 0,1,2
("C","Pl","PJ_STEMS"),("C","Lt","LT_STEMS"),("C","Sb","SB_STEMS"), # 3,4,5
("D","Bw","BW_STEMS"),("D","Aw","AW_STEMS"),("D","Pb","PB_STEMS") # 6,7,8
]
sp_fields = [("SP1","SP1_PER"),("SP2","SP2_PER"),("SP3","SP3_PER"),
("SP4","SP4_PER"),("SP5","SP5_PER")]
rows = arcpy.UpdateCursor(calc_table)
spec_count = 0
sp_count = 0
row_count = 0
for row in rows:
con = float(0)
dec = float(0)
dec_p = float(row.getValue("avi_copy.DEC_PER"))
for sp in sp_fields:
sp_type = row.getValue("avi_copy."+sp[0])
spp_f = float(row.getValue("avi_copy."+sp[1]))
if spp_f > 0:
for spec in species:
stem_f = row.getValue(strata_table+"."+spec[2])
if spec[0] == "C" and dec_p < 10.0 and sp_type == spec[1]:
con = con + (spp_f * stem_f) / (10 - dec_p)
elif spec[0] == "D" and dec_p > 0.0 and sp_type == spec[1]:
dec = dec + (spp_f * stem_f) / dec_p
else:
continue
else:
continue
vol_ha = row.getValue(strata_table+".VOL_HA")
con_vol = 0
dec_vol = 0
if dec_p == 10:
con_vol = vol_ha * 0.03
dec_vol = vol_ha - con_vol
elif dec_p == 0:
dec_vol = vol_ha * 0.03
con_vol = vol_ha - dec_vol
elif dec_p > 0 and dec_p < 10:
dec_vol = vol_ha * (dec_p / 10)
con_vol = vol_ha - dec_vol
row.avi_copy.con_volha = con_vol
row.avi_copy.dec_volha = dec_vol
row.avi_copy.con_piece = con
row.avi_copy.dec_piece = dec
rows.updateRow(row)
... View more
09-28-2011
12:11 PM
|
0
|
0
|
356
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-17-2011 10:36 AM | |
| 1 | 08-16-2012 10:48 AM | |
| 1 | 10-31-2012 08:39 AM | |
| 1 | 07-16-2012 01:52 PM | |
| 1 | 03-15-2012 10:57 AM |
| Online Status |
Offline
|
| Date Last Visited |
08-22-2024
11:12 PM
|