|
POST
|
.projectAs(outputSR,"Name_Of_The_Transformation") I'll have to remember that one...
... View more
05-07-2013
09:43 AM
|
0
|
0
|
783
|
|
POST
|
How about using a "FeatureSet". This is a data type that you can set up in a toolbox that allows you to interactivly create point, lines or polygons as input to a toolbox, which is very cool. Does not need to be an AddIn. Snapping is enabled, so that when you are creating your point or whatever in the map frame, your cursor snaps to other layers.
... View more
05-02-2013
10:45 AM
|
0
|
0
|
1721
|
|
POST
|
How about using a "FeatureSet". This is a data type that you can set up in a toolbox that allows you to interactivly create point, lines or polygons as input to a toolbox, which is very cool. Does not need to be an AddIn. Snapping is enabled, so that when you are creating your point or whatever in the map frame, your cursor snaps to other layers.
... View more
05-02-2013
10:43 AM
|
0
|
0
|
1721
|
|
POST
|
Awsome! BTW: 90% of my Python-specific parlor tricks come from this single page: http://docs.python.org/2/tutorial/datastructures.html Lists Tuples Sets Dictionaries List Comprehensions Filter Zip etc. It's all there...
... View more
05-02-2013
09:38 AM
|
1
|
0
|
2373
|
|
POST
|
It took me a while to get the syntax of the new map algebra figured out too.... Here's some examples of building some more complex expressions (see the last half): #Process: Set some envr variables - Note: ExtractByMask tool takes care of this for us
inDem = root + "\\dem"
arcpy.env.extent = areaIdPolyFC
arcpy.env.cellSize = inDem
cellSize = float(arcpy.env.cellSize)
#Process: Extract the input DEM
demGrd = areaIdFolderPath + "\\dem"
demTmp = arcpy.sa.ExtractByMask(inDem, areaIdPolyFC); showGpMessage()
demTmp.save(demGrd)
#Process: Run a Fill
fillTmp = arcpy.sa.Fill(demTmp, ""); showGpMessage()
fillGrd = areaIdFolderPath + "\\fill"
fillTmp.save(fillGrd)
#Process: FlowDir
flowDirTmp = arcpy.sa.FlowDirection(fillTmp, "", ""); showGpMessage()
flowDirGrd = areaIdFolderPath + "\\flowdir"
flowDirTmp.save(flowDirGrd)
#Process: Delete fillTmp since we don't need it anymore
arcpy.Delete_management(fillTmp); showGpMessage()
#Process: FlowAcc
flowAccTmp = arcpy.sa.FlowAccumulation(flowDirTmp, "", "INTEGER"); showGpMessage()
flowAccGrd = areaIdFolderPath + "\\flowacc"
flowAccTmp.save(flowAccGrd)
#Process: Create a streamlink
acreThreshold = .25
acreThresholdInPixels = int(43560 * acreThreshold / cellSize ** 2)
streamLinkTmp = arcpy.sa.StreamLink(arcpy.sa.Con(flowAccTmp > acreThresholdInPixels, 1), flowDirTmp); showGpMessage()
streamLinkGrd = areaIdFolderPath + "\\streamlink"
streamLinkTmp.save(streamLinkGrd)
if streamLinkTmp.hasRAT == False:
arcpy.BuildRasterAttributeTable_management(streamLinkTmp, ""); showGpMessage()
#Process: Zonal stats for elev and delete elev since we don't need it anymore
elevationZoneStatTbl = fgdbPath + "\\elevation_zn_stats"
arcpy.sa.ZonalStatisticsAsTable(streamLinkTmp, "VALUE", demTmp, elevationZoneStatTbl, "DATA", "MIN_MAX_MEAN"); showGpMessage()
#Process: Curvature and zonal stats
curvePlanGrd = areaIdFolderPath + "\\curve_plan"
curveTmp = arcpy.sa.Curvature(demTmp, "", "", curvePlanGrd)
arcpy.Delete_management(curveTmp); showGpMessage()
curvePlanTmp = arcpy.sa.Raster(curvePlanGrd)
curvePlan3Tmp = arcpy.sa.FocalStatistics(curvePlanTmp, arcpy.sa.NbrRectangle(3, 3, "CELL"), "MEAN", "DATA"); showGpMessage()
arcpy.Delete_management(curvePlanTmp); showGpMessage()
curvePlan3Grd = areaIdFolderPath + "\\curve3_plan"
curvePlan3Tmp.save(curvePlan3Grd)
curvePlan3ZoneStatTbl = fgdbPath + "\\curve_plan3_zn_stats"
arcpy.sa.ZonalStatisticsAsTable(streamLinkTmp, "VALUE", curvePlan3Tmp, curvePlan3ZoneStatTbl, "DATA", "MEAN"); showGpMessage()
arcpy.Delete_management(curvePlan3Tmp); showGpMessage()
... View more
05-02-2013
08:25 AM
|
0
|
0
|
1230
|
|
POST
|
where it is working there are the same number of records in the update and join tables (one record in each table). Where it isn't working, the join table only has a few matches in the update table What you need to do is to add some logic to deal with the situation where there are no matching keys in the lut, although I'm currious since you should be getting an error that says something to the effect of "key error - key not found". Like Matt said, I think you are getting issues with Null values (which in a cursor come out as a value of None. So for example: lutDict = dict([(r[0], (r[1], r[2])) for r in arcpy.da.SearchCursor(lutTbl, ["SOURCEJOINFIELD","SOURCEFIELD1","SOURCEFIELD2"])]) updateRows = arcpy.da.UpdateCursor(targetTbl, ["TARGETJOINFIELD","TARGETFIELD1","TARGFETFIELD2"]) for updateRow in updateRows: joinFieldValue = updateRow[0] if joinFieldValue in lutDict and joinFieldValue != None: updateRow[1] = updateRow[1] + lutDict[joinFieldValue][0] updateRow[2] = updateRow[2] * lutDict[joinFieldValue][1] else: updateRow[1] = -9999 updateRow[2] = -9999 updateRows.updateRow(updateRow) del updateRow, updateRows
... View more
05-02-2013
08:13 AM
|
0
|
0
|
8882
|
|
POST
|
Hmmm.... I might have missed a bracket or something in my example.... Here's an "real" example that I know works: slopeDict = dict([(r[0], (r[1], r[2], int(r[3] + .5))) for r in arcpy.da.SearchCursor(slopePctZoneStatTbl, ["VALUE","MIN","MAX","MEAN"])]) Another way to write this without so many confounded ([])()([[]]) symbols: slopeDict = {}
searchRows = arcpy.da.SearchCursor(slopePctZoneStatTbl, ["VALUE","MIN","MAX","MEAN"])
for searchRow in searchRows:
keyValue = searchRow[0]
minValue = searchRow[1]
maxValue = searchRow[2]
meanValue = int(searchRow[3] + .5)
slopeDict[keyValue] = (minValue, maxValue, meanValue)
del searchRow, searchRows BTW: This assumes that your key values are all unique (I should have said that up front). As for your concatenation issue, this illustration might help: >>> print "hello" + 1 ERROR! >>> print "hello" + str(1) "hello1" >>> print int("1") + float("1.1") 2.1 >>> print "hello" + "-" + str(1.1234) hello-1.1234
... View more
05-01-2013
12:46 PM
|
0
|
0
|
2472
|
|
POST
|
I think the problem lies in how you are defining your paths (Python is very picky about this). You are using: env.workspace = 'K:\TASS\4_MAPPING_DATA_SUPPORT\Traffic_Mapping\Traffic_Count_Data\District_Labels_Folder\Abilene_Labels.gdb' which should be rewritten to be either one of the following: 1. env.workspace = r'K:\TASS\_MAPPING_DATA_SUPPORT\Traffic_Mapping\Traffic_Count_Data\District_Labels_Folder\Abilene_Labels.gdb' 2. env.workspace = 'K:\\TASS\4_MAPPING_DATA_SUPPORT\\Traffic_Mapping\\Traffic_Count_Data\\District_Labels_Folder\\Abilene_Labels.gdb' 3. env.workspace = 'K:/TASS/4_MAPPING_DATA_SUPPORT/Traffic_Mapping/Traffic_Count_Data/District_Labels_Folder/Abilene_Labels.gdb' This is a common issue! So basicall these are all okay: 1. path = r"C:\temp\test.shp" 2. path = "C:\\temp\\test.shp" 3. path = "C:/temp/test.shp" But this is NOT okay: path = "C:\temp\test.shp" By itself, the "\" charater denotes a "new line", not a path delimter.
... View more
05-01-2013
12:29 PM
|
0
|
0
|
606
|
|
POST
|
How about something like: storeIdSet = set([r[0] for r in arcpy.da.SearchCursor(myFC, ["STORE_ID"])]) for storeId in storeIdSet: outFC = r"C:\temp\test.gdb\store_" + str(storeId) arcpy.Select_analysis(myFC, outFC, "STORE_ID = " + str(storeId))
... View more
05-01-2013
10:39 AM
|
0
|
0
|
3504
|
|
POST
|
This makes perfect sense Practice makes perfect... It took me a while to get proficient with dictonaries (aka "hash tables"). However, once I "got it"... one of the most powerfull tricks I have, and allows for some pretty cool stuff. Some very basic usefull dictionary methods: dict = {} dict[1] = ("cat","Elvis") dict[2] = ("dog","Barky") >> len(dict) #how many keys? 2 >>> dict.keys() #dumps the keys out to a list [2,1] >>> "monkey" in dict #test for the existence of a certain key False #print each key and it's 2nd associated value in the dictionary (2nd value is index 1)
for key in dict:
print str(key) + " - " + str(dict[key][1]) 1 - Elvis 2 - Barky
... View more
05-01-2013
09:26 AM
|
0
|
0
|
6509
|
|
POST
|
Not sure why you would need to make two dictionaries (maybe if you had two look up tables?). Dictionaries are a great way to store tabular information... with the concept that you have a "key" field and then a bunch of other values that are associated with the key... sounds like a RDBMS table, right? dict = {} dict["cat"] = [1, "fish", 5.7654] dict["dog"] = [3, "garbage", 15.5] In this case the key is a string "cat", which is associated with a list of values (age, diet, and weight maybe). Keys must be unique, but can be strings, integers, floats, or even "tuples" such as a value of (1,2). Tuple keys can be extreemly usefull. You retreive values like this: #get the diet of "cat" >>> print dict["cat"][1] 'fish' Dictionaries are great since they are EXTREEMLY fast to access, but a downside is that their size is limited by how much RAM you have. Anyway to do math per my earlier example: lutDict = dict([(r[0], (r[1], r[2])) for r in arcpy.da.SearchCursor(lutTbl, ["SOURCEJOINFIELD","SOURCEFIELD1","SOURCEFIELD2"])])
updateRows = arcpy.da.UpdateCursor(targetTbl, ["TARGETJOINFIELD","TARGETFIELD1","TARGFETFIELD2"])
for updateRow in updateRows:
joinFieldValue = updateRow[0]
updateRow[1] = updateRow[1] + lutDict[joinFieldValue][0] #assuming these values are numeric and not strings or anything!
updateRow[2] = updateRow[2] * lutDict[joinFieldValue][1] #assuming these values are numeric and not strings or anything!
updateRows.updateRow(updateRow)
del updateRow, updateRows
... View more
05-01-2013
08:55 AM
|
1
|
0
|
6509
|
|
POST
|
How about: import arcpy arcpy.CheckOutExtension("Spatial") arcpy.env.workspace = "c:/stuff/SeaLevelRiseAdaptation/10YearStepRasters/Hampton" arcpy.env.cellSize = 3.28 arcpy.env.extent = "myelevation" #the raster 'myelevation' exists in arcpy.env.workspace, correct? arcpy.env.mask = "myelevation" input1 = arcpy.Raster("myelevation") #you must define your input rasters as a "raster object" in order to use them in the new raster algebra (next line) result1 = input1 < 2.22 #once they are raster objects, Python "just knows" what to do... result1.save("my_result") #run a .save() to permanently save the result to disk, otherwise the 'result1' raster object gets a funny scratch name and poofs away when you close python
... View more
05-01-2013
08:38 AM
|
0
|
0
|
1230
|
|
POST
|
Using a dictionary and an update cursor in tandem is the solution.... It's actually pretty straight forward: A basic example in v10.1 syntax that "joins" two fields from the lutTbl to the targetTbl: lutDict = dict([(r[0], (r[1], r[2])) for r in arcpy.da.SearchCursor(lutTbl, ["SOURCEJOINFIELD","SOURCEFIELD1","SOURCEFIELD2"])])
updateRows = arcpy.da.UpdateCursor(targetTbl, ["TARGETJOINFIELD","TARGETFIELD1","TARGFETFIELD2"])
for updateRow in updateRows:
joinFieldValue = updateRow[0]
updateRow[1] = lutDict[joinFieldValue][0]
updateRow[2] = lutDict[joinFieldValue][1]
updateRows.updateRow(updateRow)
del updateRow, updateRows
... View more
05-01-2013
08:28 AM
|
1
|
1
|
6509
|
|
POST
|
Is there something wonkey with the 24th feature in your GSP_Join layer (null/corupt geometry)? Can you do it manually and have it work correctly?
... View more
05-01-2013
08:11 AM
|
0
|
0
|
2779
|
|
POST
|
I manually import a CSV to create a table which I use to make an XY event layer during the creat process I can select the coordinate system of my CSV (NAD 27 LL) and the transformation to use for the conversion to the data frame (Web Mercator). I have been reading about the make xy event functionality, but I am missing the transformation part. So wouldn't your workflow simply be: 1. Make your XY event layer specifying NAD 27 LL as the SR 2. Project the event layer to web mercator specifying the proper datum transformation - output would be an on-disk featureclass. ?
... View more
05-01-2013
08:01 AM
|
0
|
0
|
2609
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 03-25-2014 12:57 PM | |
| 1 | 08-29-2024 08:23 AM | |
| 1 | 08-29-2024 08:21 AM | |
| 1 | 02-13-2012 09:06 AM | |
| 2 | 10-05-2010 07:50 PM |
| Online Status |
Offline
|
| Date Last Visited |
08-30-2024
12:25 AM
|