|
POST
|
I see you are using a distance of "0.0001" as your pour point snapping tolerance... What units are these in? Is the projection of "USGS_Points" defined? I suspect you may be using data in a geographic coordinate system... If so, I would recomend projecting your input data... Something like Albers if your data covers the entire U.S. - otherwise if your data is more local, use State Plane or UTM. Some of the Grid functions end up a bit screwy if you use geographic coordinate systesm.
... View more
02-10-2012
08:45 AM
|
0
|
0
|
578
|
|
POST
|
An even shorter way: if arcpy.SearchCursor(myTable, sql_statement).next() == None:
print "Empty cursor!" The only trick though is to figure out if your SQL is returning any records or not... Which could be accomlished through a cursor statment like the one above or a combo of the MakeFeatureLayer/MakeTableView and the GetCount tool. Which one is faster? I dunno... It would also improve performance if the fields in your SQL were properly indexed also.
... View more
02-09-2012
09:29 AM
|
0
|
0
|
3949
|
|
POST
|
Yes, Densify could work as does exporting to shapefile or coverage, and importing back to Geodatabase format. I did mention these work around options in the last paragraph of my original post. However, both these work arounds would require you to run them on all the inputs, since there doesn't seem to be a way (at least an easy way) to identify features that contain true curve geometry. Like I said, what I am really hoping for here is a new geoprocessing envr. setting that would ensure that true curve features are NOT propogated to the tool outputs. arcpy.env.evilTrueCurves = False Now, it seems all(?) buffer output placed in a geodatabase is going to contain curve features. Try buffering a single point by 500ft or something - put the output directly in a GDB (not a shapefile)... Then export "ALL" the verticies of the buffer polygon using the FeatureVerticesToPoints tool. Uh oh! These circular buffer polygons only have 2 verticies each! What the?!?! How are you to discern this condition, where "normally" you would be expecteding hundreds of densified verticies? An environment setting would make all of us CAD-haters happy! I'll also point out that SDE data has a way to keep true curves out... See the blurbs about that buried in here: http://webhelp.esri.com/arcgisserver/9.3/java/index.htm#geodatabases/using_t1450550752.htm Why not FGDB and PGDB... and in_memory too?
... View more
02-09-2012
08:36 AM
|
0
|
2
|
9428
|
|
POST
|
Sure you can do it in the cursor... I guess an update cursor so you could then populate your angle statistic field value, right? It'd look something like this then: #assuming all features are single part!!! import arcpy lineFC = r"C:\temp\test.shp" dsc = arcpy.Describe(lineFC) shapeFieldName = dsc.ShapeFieldName featureNumber = 0 updateRows = arcpy.UpdateCursor(lineFC) for updateRow in updateRows: vertexList = [] shapeObj = updateRow.getValue(shapeFieldName) partObj = shapeObj.getPart(0) for pointObj in partObj: vertexList.append((pointObj.X, pointObj.Y)) vertexCount = len(vertexList) if vertexCount < 3: break #if only two verticies in the line, break the loop since there is no "angle" to calculate i = 0 # while i + 3 <= vertexCount: #that is until you run out of vertex triplicate pairs to count x1 = vertexList[0] y1 = vertexList[1] x2 = vertexList[i + 1][0] y2 = vertexList[i + 1][1] x3 = vertexList[i + 2][0] y3 = vertexList[i + 2][1] funkyStat = (x1 + y2) / 1.61803399 #blah blah whatever formula i = i + 1 updateRow.FUNKY_STAT = funkyStat updateRows.updateRow(updateRow) del updateRow, updateRows
... View more
02-09-2012
08:09 AM
|
0
|
0
|
4448
|
|
POST
|
Sure, I forget the ESRI credentials, so it would be great if you could email me the FTP instructions at: chris.snyder(at)dnr(dot)wa(dot)gov, and I'll give you some reprod data. Another thought on why true curves are bad: Some of us wanna-be hack programmer types are assuming that we will get a series of constituent verticies when we parse the geometry of polygon or line. It's sort of distressing when you find that your FC (buffer of a single point being the worst case eaxample) has far fewer verticies in it than you thought - the rest of the curve/shape is some sort of wacky equation locked away with no way to access it via a Python script - not that I would know what to do with the equation if I had it! Unless we can get some sort of arcpy environmental setting flag to keep these blasted curves at bay, the good ole' shapefile format is looking pretty pretty pretty good.
... View more
02-08-2012
03:09 PM
|
1
|
0
|
9428
|
|
POST
|
I could add two sort of related things: 1. If you have parallel processes, each using the random function, you can mix things up (scramble the "states" so that they are all out of sequence which is a good thing) by using the .jumpahead() method. For example: timeInt = int(str(int(time.time() * 10000))[-5:])
random.jumpahead(timeInt) 2. When using FGDBs, you can send it absurdly long SQL strings. Such as "OBJECTID in (1,2,3,4,5,.....)" I sent one that was > million characters long and it actually worked! Curious what the character limit is... There must be one, right? I know that I have been frustrated by Oracle SDE having a SQL statement limit of ~1400 characters, which is pretty lame.
... View more
02-08-2012
02:56 PM
|
0
|
0
|
5046
|
|
POST
|
You could read the verticies into a python list... actually a series of imbedded lists. For example: #assuming all features are single part!!!
import arcpy
fcVertexList = []
lineFC = r"C:\temp\test.shp"
dsc = arcpy.Describe(lineFC)
shapeFieldName = dsc.ShapeFieldName
featureNumber = 0
searchRows = arcpy.SearchCursor(lineFC)
for searchRow in searchRows:
featureNumber = featureNumber + 1
fcVertexList.append([])
shapeObj = searchRow.getValue(shapeFieldName)
partObj = shapeObj.getPart(0)
for pointObj in partObj:
fcVertexList[featureNumber - 1].append([pointObj.X, pointObj.Y]) Then it's just a simple matter of slicing a Python list: To retreive all the verticies for the 1st feature: >>> print fcVertexList[0] To cound how many verticies are in the 1st feature: >>> print len(fcVertexList[0]) To retreive the first three verticies for the first feature: >>> fcVertexList[0][0:3] To retreive the next three verticies (incremented by 1 vertex) for the first feature: >>> fcVertexList[0][1:4]
... View more
02-08-2012
08:25 AM
|
0
|
0
|
4448
|
|
POST
|
Woops - yes it is exists() not exits()... I fixed the code block above.
... View more
02-07-2012
11:09 AM
|
0
|
0
|
2021
|
|
POST
|
The code below verifies if the supplied path exists... Might help you figure out what's going wrong. Curious that in Python/PythonWin 2.6.x , you can enter a path as an argument in all sorts of ways: C:\Temp C:\\Temp C:/Temp All these work... As I recall earlier versions of PythonWin didn't do this... I think they liked the 1st example. Could be wrong. import os, sys
myPath = sys.argv[1]
if os.path.exists(myPath) == True:
print "Yes Virginia, there is a " + str(myPath)
else:
print "No, there is no such thing as " + str(myPath)
... View more
02-07-2012
07:48 AM
|
0
|
0
|
2021
|
|
POST
|
Yes, like Mathew says, your issue is that the SQL statement you provide in your cursor is probably incorrect and is returning 0 records (which is why you get no cursor row object). My code will only run the cursor if your query returns 1 or more records.
... View more
02-02-2012
11:20 AM
|
0
|
0
|
10198
|
|
POST
|
Sure - see (code comments denoted by the # symbol): #STEP1: Execute a SQL query (the MakeFeatureLayer tools is probably the quickest way to do this)
arcpy.MakeFeatureLayer_management(indxTileFC, indxTileFL, "HCPUNIT_NM <> 'OESF')
#STEP2: Are any records returned? If 0 records satisfy the SQL query, then let us know! If 0 records are returned, the SQl query is probably incorrect!!!
if int(arcpy.GetCount_management(indxTileFL).getoutput(0)) == 0:
print "Query returned no records!"
#STEP3: If there are records returned by the query, then run a search cursor and look for Null field values in MY_FIELD
else:
#Create a search cursor object using the same query as the one in the MakeFeatureLayer
searchRows = arcpy.SearchCursor(indxTileFC, "HCPUNIT_NM <> 'OESF')
#For each row in the collection of search cursor rows
for searchRow in searchRows:
#if the value in the "MY_FIELD" field is Null let us know... If theer are no Null values in the MY_FIELD field, then no message will be printed.
if searchRow.MY_FIELD == None: #Another way: if searchRow.isNull("MY_FIELD") == True:
print "MY _FIELD is Null!"
#Delete the search cursor objects so the read lock is released on the search cursor table
del searchRow, searchRows
... View more
02-02-2012
11:03 AM
|
0
|
0
|
10198
|
|
POST
|
Maybe this would help? arcpy.MakeFeatureLayer_management(indxTileFC, indxTileFL, "HCPUNIT_NM <> 'OESF'); showGpMessage()
if int(arcpy.GetCount_management(indxTileFL).getoutput(0)) == 0:
print "Query returned no records!"
else: #if there are records returned by the query, then run a search cursor and look for Null field values in MY_FIELD
searchRows = arcpy.SearchCursor(indxTileFC, "HCPUNIT_NM <> 'OESF')
for searchRow in searchRows:
if searchRow.MY_FIELD == None: #Another way: if searchRow.isNull("MY_FIELD") == True:
print "MY _FIELD is Null!"
del searchRow, searchRows
... View more
02-02-2012
07:42 AM
|
0
|
0
|
10198
|
|
POST
|
Unfortunatly the parameter you are supplying 'inPredictors' to is not used in the way you want... It is strictly a ModelBuilder parameter that is ignored when executed in Python code. It has nothing to do with utilizing rasters from differnt workspaces. If your input rasters are all in differnt workspaces, you would have to do something like this: r1 = r"C:\temp1\test1"
r2 = r"C:\temp39\test14"
r3 = r"C:\temp56\test177"
r4 = r"C:\temp563\test765"
eq = 'c1 + c2 + c3'
goodToGoEq = eq.replace("c1", r1).replace("c2", r2).replace("c3", r3).replace("c4", r4)
#Note that the text string "c4" doesn't exist in the equation, and therefore the .replace() for "c4" is ignored... >>> print eq 'C:\\temp1\\test1 + C:\\temp39\\test14 + C:\\temp56\\test177' Like I said earlier, it would be way easier to just store the equations in the Python script file rather than read them from a text file... The reason is that you want to interpret the equations WITH the variables (that are assigned in the script), and not just as the text strings they exits as in the text file. Howevre, if all the input raster existed in the same workspace, you could just use the raw strings as input to the SOMA tool. There is probably a better way to do this sort of string/variable substitution thing, but...
... View more
02-01-2012
02:08 PM
|
0
|
0
|
3534
|
|
POST
|
Whoops, I'm sorry that would be: somaExp = "con(inGrid == 1, 1, setnull(1))".replace("inGrid", inGrid)
... View more
02-01-2012
11:55 AM
|
0
|
0
|
3534
|
|
POST
|
Is ild64p the name of the actual raster datsaset (for example r"C:\temp\ild64p") or just a variable name? If its an actual raster, are you setting the gp.workspace (to where the raster exists) so that ArcGIS knows where to go looking for the raster? If its a variable name, hmm.... Basically you have to feed a text string into the SOMA tool. inGrid = r"C:\temp\input" outGrid = r"C:\temp\output" somaExp = "con(" + inGrid + " == 1, 1, setnull(1))" gp.SingleOutputMapAlgebra_sa (somaExp, outGrid) #BTW: You are using a third parameter to the SOMA tool, which you don't need in the Python script (only in ModelBuilder)! If the equations you are reading in contain variable names (but as text strings), well that's not doing to work... Since: "con( + inGrid + == 1, 1, setnull(1))" is not the same as: "con(" + inGrid + " == 1, 1, setnull(1))" Right? You could do something like this: print "con( + inGrid + == 1, 1, setnull(1))".replace("inGrid", inGrid) and substitute the inGrid string for the inGrid variable (which points to a different string value as defined in your script).
... View more
02-01-2012
11:50 AM
|
0
|
0
|
3534
|
| 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
|