POST
|
Neil, Thanks for the reply. The keyval SiteID is indeed the first column in dbffieldList. This all makes sense to me however I guess what I am asking is how to skip constructing a data list so that the script can be run on a table with fewer or more fields than this specific example I am working with. Is there a way to iterate through the fields saying: for updateRow in updateRows:
updateRow[x] = valueDict[SiteID][y] This might be a simple question but my head is swimming since I haven't used dictionaries or cursors much!
... View more
05-02-2017
07:21 AM
|
0
|
1
|
510
|
POST
|
Hello All, I am working on a script to copy attributes to their respective feature from a user edited DBF to a feature class. My organization creates sites in GIS, fills in a few key attributes, exports the attribute table to a DBF where our non-GIS users update the table in excel and then export to a tab delimited text file. Previously we have taken the updated DBF table, created a join, and manually used field calculator to copy the information back into the feature class but this takes quite a bit of time when we are dealing with 30-40 fields. I have written a basic script so far using search and update cursors using a value dictionary to relate the SiteID field (unique value) in the DBF to the SiteID field in the feature class however I can't get past how to make the script iterate through all of the rows and update the information. import os
import arcpy as ap
fc = r"Path\To\SitesFc"
dbf = r"Path\To\UpdatedTable.txt"
fcfieldList = [f.name for f in ap.ListFields(fc)]
dbffieldList = [f.name for f in ap.ListFields(dbf)]
valueDict = {r[0]:(r[1:]) for r in ap.da.SearchCursor(dbf, dbffieldList)}
#[0] is SiteID field in DBF
with ap.da.UpdateCursor(fc, fcfieldList) as updateRows:
for updateRow in updateRows:
siteIDVal = updateRow[2] #[2] is SiteID field in FC
if siteIDVal in valueDict:
# This is where I am lost. Not sure how to iterate through the fields
updateRows.updateRow(updateRow) I would type out updateRow = valueDict[SiteIDVal] but sometimes our field schemas change depending on the project and I want this to be a somewhat generic tool we can utilize. Thaks in advance for the help! Judson
... View more
05-02-2017
06:40 AM
|
0
|
4
|
822
|
POST
|
The str(overwrite) == 'true' returns a checkbox being checked in the script interface. The boolean parameter returns 'true' in lower case when the box is checked.
... View more
04-27-2017
05:17 AM
|
0
|
0
|
616
|
POST
|
It does not return any error when I run the script. It just does not overwrite the JPEG files but while overwrite the PDF files when exporting.
... View more
04-27-2017
05:15 AM
|
0
|
0
|
616
|
POST
|
Hello All, I am working on a script to batch export a list of user selected MXD's to either JPEG, PDF, or JPEG & PDF using arcpy.mapping.exportToJPEG. I give the user the option to overwrite existing images in the selected output location however the JPEG's will not overwrite while the PDF's will. Does anyone know why this might happen? I have researched it a bit and am unable to find a solution. import arcpy as ap
import os
docs = ap.GetParameterAsText(0)
exportPath = ap.GetParameterAsText(1)
imgRes = ap.GetParameterAsText(2)
imgJPEG = ap.GetParameterAsText(3) #Boolean
imgPDF = ap.GetParameterAsText(4) #Boolean
overwrite = ap.GetParameterAsText(5) #Boolean
def transmit(message):
ap.AddMessage(message)
return
def exportGraphics(docs, exportPath, imgRes, imgJPEG, imgPDF, overwrite):
if str(overwrite) == 'true':
ap.env.overwriteOutput = True
for doc in docs.split(';'):
mxdname = os.path.basename(doc)
mxdname = mxdname.split('.mxd')[0]
mxd = ap.mapping.MapDocument(doc)
if str(imgJPEG) == 'true':
jpg = os.path.join(exportPath,mxdname) + '.jpg'
ap.mapping.ExportToJPEG(mxd, jpg, resolution = imgRes)
transmit(mxdname + '.jpg Has Exported!')
if str(imgPDF) == 'true':
pdf = os.path.join(exportPath,mxdname) + '.pdf'
ap.mapping.ExportToPDF(mxd,pdf, resolution = imgRes)
transmit(mxdname + '.pdf Has Exported!')
del mxd
if __name__ == '__main__':
exportGraphics(docs, exportPath, imgRes, imgJPEG, imgPDF, overwrite) Thanks in advance! Judson
... View more
04-26-2017
09:19 AM
|
0
|
4
|
1283
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|