|
POST
|
If anyone is interested, this v9.3 code will list (i.e. print) field values in a sort of ArcInfo Workstation-esque sort of way. Needs updating to arcpy probably... Sytax is like this: listRecords(myTable, 20, "MYFIELD = 1") def listRecords(inputValue, numberOfRecordsToList = 25, whereClause = ""):
"Lists field names and values in inputValue"
if gp.exists(inputValue) == 1:
fieldNamesList = []
fieldList = gp.listfields(inputValue)
field = fieldList.next()
while field:
fieldNamesList.append(field.name)
field = fieldList.next()
searchRows = gp.SearchCursor(inputValue, whereClause)
searchRow = searchRows.next()
rowCount = 1
recordCount = int(gp.GetCount_management(inputValue))
if int(numberOfRecordsToList) > recordCount:
numberOfRecordsToList = recordCount
while rowCount <= int(numberOfRecordsToList):
print "RECORD #" + str(rowCount)
print "-" * 100
for fieldName in fieldNamesList:
try:
print fieldName + ": " + str(searchRow.getvalue(fieldName))
except:
print fieldName + ": !?!"
print ""
print ""
rowCount = rowCount + 1
searchRow = searchRows.next()
del searchRow
del searchRows
print ""
print ""
print "LISTED " + str(numberOfRecordsToList) + " RECORDS"
else:
print "ERROR: " + inputValue + " does not exist!" The output looks like this: RECORD #1 ---------------------------------------------------------------------------------------------------- OBJECTID: 1 REMSOFT_ID: 13 ALTERNATIVE: Landscape T3_ID: 102 WAU_NM: Sekiu LPU_NM: Sekiu REGIME_NM: Undefined rotation ROTATION: 0 REGEN_PERS: 9 REGEN_CNT: 1 THIN_PERS: THIN_CNT: 0 ENTRIES: 1 PRE_THINS: 0 POST_THINS: 0 INTR_THINS: 0 MGMT_SEVR: 1.0 FREQUENCY: 10 MIN_ACRES: 0.372585348944 FIRST_HARV_AGE: None RECORD #2 ---------------------------------------------------------------------------------------------------- OBJECTID: 2 REMSOFT_ID: 13 ALTERNATIVE: No Action T3_ID: 102 WAU_NM: Sekiu LPU_NM: Sekiu REGIME_NM: No harvest expected ROTATION: 0 REGEN_PERS: REGEN_CNT: 0 THIN_PERS: THIN_CNT: 0 ENTRIES: 0 PRE_THINS: 0 POST_THINS: 0 INTR_THINS: 0 MGMT_SEVR: 0.0 FREQUENCY: 10 MIN_ACRES: 0.372585348944 FIRST_HARV_AGE: None RECORD #3 ---------------------------------------------------------------------------------------------------- OBJECTID: 3 REMSOFT_ID: 15 ALTERNATIVE: Landscape T3_ID: 102 WAU_NM: Sekiu LPU_NM: Sekiu REGIME_NM: Undefined rotation ROTATION: 0 REGEN_PERS: 7 REGEN_CNT: 1 THIN_PERS: THIN_CNT: 0 ENTRIES: 1 PRE_THINS: 0 POST_THINS: 0 INTR_THINS: 0 MGMT_SEVR: 1.0 FREQUENCY: 10 MIN_ACRES: 0.563606092746 FIRST_HARV_AGE: None
... View more
01-27-2012
07:59 AM
|
0
|
0
|
2238
|
|
POST
|
What if your coworker runs the CalculateStatistics_management() tool prior to running the script? Is the raster stored somewhere where both of you lack write access? If so, are your rasterproxy directories set to the same location? If not, perhaps it works for you since you calced stats on it (maybe a long time ago) and have that data in the raster's .aux file in your rasterproxy directory, where your coworker hasn't ever calced stats, and can't read the .aux from your rasterproxy directory. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009t00000024000000
... View more
01-26-2012
03:19 PM
|
0
|
0
|
1367
|
|
POST
|
Late is better than never.... This code generates equadistant points that more than covers the extent out the 'containerFC'. Further code could be written to limit the points to those that are contained in the containerFC... either in the insert cursor using the .contains() geometry method, or at the very end, a SelectByLocation and then export to a new FC. I put in a 'useRandomShift' flag so that the points don't necessarily have to be tied to the containerFC's extent. #Chris Snyder, WADNR, 20120126
import arcpy, math, random
containerFC = r"C:\csny490\test.shp"
outputFC = r"C:\csny490\out.shp"
spacing = 100
useRandomShift = True
arcpy.env.overwriteOutput = True
dsc = arcpy.Describe(containerFC)
dscExtent = dsc.extent
xMin = dscExtent.xMin
yMin = dscExtent.yMin
xMax = dscExtent.xMax
yMax = dscExtent.yMax
randomXshift = random.uniform(0, spacing)
randomYshift = random.uniform(0, spacing)
yOffset = math.sqrt((spacing **2) - ((spacing / 2) **2))
pntDict = {}
i = 0
rowNumber = 1
xCoord = xMin - spacing
yCoord = yMin - spacing
while xCoord < xMax + spacing or yCoord < yMax + spacing:
i = i + 1
if xCoord > xMax + spacing:
rowNumber = rowNumber + 1
xCoord = xMin - spacing
if bool(rowNumber & 1) == False:
xCoord = xCoord + spacing / 2
yCoord = yCoord + yOffset
elif i == 1:
xCoord = xCoord
else:
xCoord = xCoord + spacing
if useRandomShift == True:
pntDict = (xCoord + randomXshift, yCoord + randomYshift)
else:
pntDict = (xCoord, yCoord)
arcpy.CreateFeatureclass_management(outputFC[:-len(outputFC.split("\\")[-1]) - 1], outputFC.split("\\")[-1], "POINT", "", "", "", dsc.spatialreference, "", "", "", "")
shapeFieldName = arcpy.Describe(outputFC).shapeFieldName
insertRows = arcpy.InsertCursor(outputFC)
for pnt in pntDict:
insertRow = insertRows.newRow()
pointObj = arcpy.CreateObject("Point")
pointObj.X = pntDict[pnt][0]
pointObj.Y = pntDict[pnt][1]
insertRow.setValue(shapeFieldName, pointObj)
insertRows.insertRow(insertRow)
del pointObj, insertRow, insertRows
... View more
01-26-2012
02:01 PM
|
0
|
0
|
2493
|
|
POST
|
This seems like an issue with the tool. Network Analyst and Utility Network Analyst are still very much 2-D tools, or at least the come from that lineage and rely on those associated assumptions. Two possbible work arounds I can think of: 1. Edit the pipe so it is not "perfectly" vertical, and therefore has a XY length > 0. In reality the pipe is probably not perfectly verticals, right? Maybe it's off by a few millimeters? 2. Edit the pipe so that it is merged with some other feature that has a XY length > 0. The final upside down "L" shaped feature would have x,y,z coordinates of something like (0,0,0), (0,0,10), (1,1,10). thus preserving the vertical infomation and instilling a horizontal length, teh latter seeming to be a be a requirement.
... View more
01-26-2012
08:51 AM
|
0
|
0
|
838
|
|
POST
|
As far as I know, the auto-calced Shape_Length field only refers to horizontal length (xy) and doesn't incorporate z values in the calculation. Maybe you could edit this feature so that it has some length > 0? Or maybe delete it if it is not a significant part of the Network Analysis? Just curious, but what does this vertical feature represent?
... View more
01-25-2012
09:23 AM
|
0
|
0
|
838
|
|
POST
|
In this case, use a space as the delimiter. However, if you have multiple fields/stats then you would use a semicolon. DissolveTool.statistics_fields = "instln_id FIRST" or DissolveTool.statistics_fields = "instln_id FIRST; otherfield SUM"
... View more
01-25-2012
09:04 AM
|
0
|
0
|
1785
|
|
POST
|
Try using a semicolon as the field name delimiter. For example: dislvFields = "FIELD1;FIELD2" In Python in v10.0 you can also use list objects as input. For example: dslvFields = ["FILED1","FIELD2"]
... View more
01-25-2012
08:48 AM
|
0
|
0
|
1785
|
|
POST
|
Don't forget to use the "result object"! The syntax would actually be like this: min = arcpy.GetRasterProperties_management(file, "MINIMUM").GetOutput(0)
... View more
01-24-2012
09:07 AM
|
0
|
0
|
1218
|
|
POST
|
Unsuported in new v10.0 Map Algebra! Although you can get $$NCOLS through the describe property in Python or the GetRasterProperties toolbox tool. See: https://c.na1.visual.force.com/apex/ideaView?id=087300000008DT2AAM#comments You can still use the good ole' Map Algebra sytax in v10 though: arcpy.gp.SingleOutputMapAlgebra_sa(blah, blah)
... View more
01-24-2012
08:56 AM
|
1
|
0
|
3802
|
|
POST
|
The Union tool? http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00080000000s000000.htm
... View more
01-24-2012
08:03 AM
|
0
|
0
|
623
|
|
POST
|
Related, you can use the built in "divmod" function in Python to evalute/test for multiples. For example: >>> divmod(120, 10) (12, 0) and >>> divmod(121, 10) (12, 1) for i in range (0,1001):
if divmod(i, 10)[1] == 0: #if the remainder is 0 when dividing by 10...
print "Processing #" + str(i)
... View more
01-19-2012
08:14 AM
|
0
|
0
|
780
|
|
POST
|
If you want every feature exported as a seperate feature class, you would probably want to use the OBJECTID field (or some other unique ID field). #DISCLAIMER: Untested code - just typed it on the fly - may not work "out of the box"
import arcpy
myFC = r"C:\temp\my_fc.shp"
oidFieldName = arcpy.Describe(myFC).OIDFieldName
searchRows = arcpy.SearchCursor(myFC)
for searchRow in searchRows:
oidFieldValue = searchRow.getValue(oidFieldName)
outFC = r"C:\temp\output_" + str(oidFieldValue) + ".shp"
arcpy.Select_analysis(myFC, outFC, oidFieldName + " = " + str(oidFielValue))
del searchRow, searchRows
... View more
01-19-2012
08:03 AM
|
0
|
0
|
646
|
|
POST
|
A "feature layer" and/or "table view" is basically a handy in-memory pointer to an on disk feature class or table. Basically it stores, in-memory, a number of descriptors concerning the feature class or table. One of those things is the OBJECTIDs that are currently selected. One of the great things about a feature layer / view is that most of the geoprocessing tools can operate directly on the feature layer / view itself (e.g. the tools honor definition queries and selections). Therefore there is no need to make an export of your selected set. Just run the stats tool (or maybe the GetCount tool?) directly on the feature layer that is the output of the SelectByLocation or the SelectByAttributes tool. To clear the selection, just run the SelectByLocation or the SelectByAttributes tool again on the feature layer, but this time don't specify a SQL statement or spatial selection type (you will note these are optional tool parameters) and just specify the "CLEAR_SELECTION" selection type parameter.
... View more
01-19-2012
07:45 AM
|
0
|
0
|
4659
|
|
POST
|
Use the CopyRaster tool (from the toolbox). In my experience, this has preserved the join fields in the output raster.
... View more
01-19-2012
07:29 AM
|
0
|
0
|
3774
|
| 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
|