|
POST
|
you guys know how to determine domes in a raster. I thought something of "curvature", but still cannot distinguish them from basins. Bill Huber would probably have a better idea -- but I can't resist suggesting that if you're looking for local maxima you could try selecting areas where (ingrid == focalmax(ingrid)) and (ingrid > focalmin(ingrid)) Using a larger-than-default neighborhood may help you find broader "domes" that have some flat areas on the top. These areas could then be collapsed to single-cells or points using the Zonal Geometry tool with the CENTROID option.
... View more
03-09-2013
09:24 PM
|
0
|
0
|
2613
|
|
POST
|
What I want to do is test the maximum value in the resulting raster and stop the iteration if the max value does not equal -999 (the value in the cells is -999 they need to be changed). I can't figure out how to make the "while" or "if" iterators work with raster statistics (max cell value). One way is to write a little Python script using the the Calculate Value tool, the tool output can then be referenced in the While tool. For example: Expression: StopTest(r"%output raster%") Code Block:
def StopTest(outRaster):
import arcpy
max = int(arcpy.GetRasterProperties_management (outRaster,"MAX").getOutput(0))
if max == -999:
return True # keep iterating
else:
return False # time to stop Data Type: Boolean A less python-heavy approach would be to add the GetRasterProperties tool to the model, connect your raster to it, then connect the GetRasterProperties output to Calculate Value and use this simple python expression instead (no code block needed): int(%RasterPropertyOut%) == -999 The downside to this second approach is that if the output of GetRasterProperties is zero, that evaluates to False and the Calculate Value will not run, as its input will be false. Such is the simplicity and elelegance that is ModelBuilder.
... View more
03-09-2013
09:07 PM
|
0
|
0
|
1082
|
|
POST
|
This method works perfectly when the model is run within the Edit mode of ModelBuilder. However, when the model is saved and run as a tool, the layer is created, with the correct name, but the layer is not added to the map. This is how all tools (including script tools) work. If the output is not a parameter, it will not be added to the map. The "Add To Display" property of a Model Builder element only works when running the model in Edit mode. With script tools, you can set the output as "Derived" so the output parameter exists, but doesn't show up in the tool dialog. You may be able to get around this in 10.0 by using arcpy.mapping in a Calculate Value tool code block to add the layer to the current data frame. Arc 10.0 help: AddLayer
... View more
03-09-2013
08:48 PM
|
0
|
0
|
2238
|
|
POST
|
Woohoo! I highly recommend using nested quotes and substitution - easier to read and debug. This is equivalent to your solution: arcpy.CalculateField_management(species, "TypeName", \ '"{0}"'.format(nameVariable), "PYTHON")
... View more
03-09-2013
08:32 PM
|
1
|
0
|
1431
|
|
POST
|
I have made a workflow in Model Builder (with topo-to-raster interpolation) and i want to iterate this with a "for"-loop beween the values 0 to 1 within 0.1 steps (=11 loops overall). But it is not possible for me to set the incremet (By Value) to 0.1 or any other decimal number. Do anybody have a workaround solution for this problem? A way to get what you want in ModelBuilder is to calculate a float value from your index using the Calculate Value tool. [ATTACH=CONFIG]22467[/ATTACH] Another approach could be to try Iterate Multi-value instead of For. I also tried to iterate over the "maximum iteration number" field in the topo-to-raster parameter settings, but it seems to be not possible to connect this with a "for"-loop. Calculate Value has a parameter called Data Type that can cast the output into the data type your tool requires. Often you can just enter %element name% in your tool dialog within ModelBuilder as well. A similar approach would work with your other parameter. The way to nest loops in model buider to put one model inside another: Integrating a model within a model
... View more
03-08-2013
08:57 AM
|
0
|
0
|
2436
|
|
POST
|
If you don't expect a lot of rows, GetCount would probably be very quick for this test:
numRows = int(arcpy.GetCount_management(fc).getOutput(0))
if numRows == 1:
arcpy.AddMessage("All is good, there's one and only one ...")
else:
arcpy.AddError("All is not good: {0} rows found".format(numRows))
This worked for me too:
with arcpy.da.SearchCursor(fc, "ST_ID") as cursor:
arcpy.AddMessage("In the With")
try:
test = cursor.next()
arcpy.AddMessage("Got one.")
test = cursor.next() # try get a second row
except StopIteration:
arcpy.AddError("ERROR: There is more than one ...")
sys.exit(1)
except:
arcpy.AddError("Something else happened!")
... View more
03-08-2013
08:42 AM
|
0
|
0
|
883
|
|
POST
|
Alternatively you could do something like this, inside your action set the program/script to path of the 32 bit python exe and in the Add arguements set it equal to the path to the python script. I usually use a .bat file driver with scheduled tasks so I can capture any error messages from stderr, in case something goes wrong at the system level, or the Python script writes something to stderr:
C:\Python27\ArcGIS10.1\python.exe Geocode_Address_Data.py ^
>> Address_Research_Data_Update.log 2>&1
... View more
03-08-2013
06:20 AM
|
0
|
0
|
3720
|
|
POST
|
Hi, The following code add two arguments to the Python call. The first argument works fine but the second gives an invalid SQL error when using SELECT. The script I have attached shows the parcel string hard coded to a Parcels variable, this works OK. Can someone provide the correct string for strParcels? Note the \\ is meant to relate to a \ in the final SQL strOwner = "Lett" strParcels = "PARCEL_SPI = '1\\TP8994'" retVal = Shell("cmd.exe /K S:\MID_Owners_Database_Workspace\OwnerProperty.py " & strOwner & " " & strParcels, 1) Wow, that's a tricky one because you need to pass your string arguments through VBScript/VB/VBA (whatever that is), Windows shell, and Python to your tool! Here's my guess at it. I used literal double-quotes (""") to make sure arguments get passed to thru the Windows shell command line. I don't think you need to escape the "\" in your SQL expression because it will be read as a literal string before the Python interpreter gets a hold of it. strOwner = """Lett""" strParcels = """PARCEL_SPI = '1\TP8994'""" retVal = Shell("cmd.exe /K " & _ "C:\Python27\ArcGIS10.1\python.exe " &_ "S:\MID_Owners_Database_Workspace\OwnerProperty.py " &_ strOwner & " " & strParcels, _ 1) This is as if you typed the command line (probably a good way to test it): C:\> cmd.exe /K C:\Python27\ArcGIS10.1\python.exe ^ S:\MID_Owners_Database_Workspace\OwnerProperty.py "Lett" "PARCEL_SPI = '1\TP8994'" Note cmd.exe /c may be a better choice, otherwise the shell continues to sit out there. Or you could just run Python directly: C:\> C:\Python27\ArcGIS10.1\python.exe ^ S:\MID_Owners_Database_Workspace\OwnerProperty.py "Lett" "PARCEL_SPI = '1\TP8994'"
... View more
03-07-2013
01:58 PM
|
0
|
0
|
1296
|
|
POST
|
Curtis: What if I am running the python script from a Windows Server 2008 Scheduled Task? I do not believe I have the option of running the script in the background, as by default, the script runs in the foreground. As such, I thought geoprocessing at v10.1 can be run in the 64 bit environment, but if I cannot force the script to run in the background it will still run in the 32 bit environment. So even though I have access to a 64 bit environment, I cannot make use of this environment with a scheduled task because it can only run in the foreground. Am I correct with this assessment? Foreground and background only really makes sense when running in the Desktop application environment, ie ArcCatalog/ArcMap. In that situation, foreground is 32 bit and background is 64 bit (if you've installed the 10.1 Sp 1 patch). If you want to run 64 bit in a standalone Python script, import arcpy in a 64 bit Python session. You will only have 64 bit python available if you if you have installed ArcGIS Server --or-- the Desktop x64 geoprocessing patch for ArcGIS 10.1 SP 1.
... View more
03-07-2013
07:24 AM
|
0
|
0
|
3253
|
|
POST
|
Curtis: How can you tell if a python script is running in the foreground vs the background? This is spelled out in the help, with pictures: Arc 10.1 Help: Foreground and background processing On review, I don't think x64 geoprocessing is probably Nathan's problem; it's probably the new setup with database connections in 10.1, which has changed quite a bit. Hopefully someone with more expertise will chime in. Nathan, if you haven't, I suggest you read this: Arc 10.1 Help: What's new for databases in ArcGIS 10.1
... View more
03-07-2013
07:07 AM
|
0
|
0
|
3253
|
|
POST
|
I currently have a script that pulls information from a Microsoft SQL Server Table View and exports it to a file geodatabase using an .odc connection. This script will run fine in version 10.0, but will error out using version 10.1. Have you tried running the python script in the foreground? If you installed x64 geoprocessing I believe many ODBC drivers will not work in 64 bit python.
... View more
03-07-2013
06:22 AM
|
0
|
0
|
3253
|
|
POST
|
I have a model which will pull 30 features from a database and a second model which will perform a feature class rename on these 30 different features. This is done on a daily basis. Sometimes one of the names will change or a feature won't be pulled in for some reason. The problem is that when the rename model is running if it can't find a feature it will error the entire model instead of ignoring the error and skipping to the next feature to rename. None of the processes have preconditions. Is their a way I can tell the model to ignore errors and move on if it can't find a feature? A green error instead of a red one? The only way I can think to do this is to use the Calculate Value tool to do the rename and have it return a message. Calculate Value will print out the function results to geoprocessing messages as the model runs. Of course this involves writing a small Python script: I'm assuming you have two model elements "From FC" and "To FC" with the names. Calculate Value tool Expression: FCRename(r"%From FC%",r"%To FC%")
def FCRename(from,to):
import arcpy
try:
arcpy.Rename_management(from,to)
return "rename %s to %s success!" % (from,to)
except:
return "rename %s to %s failed" % (from,to)
Note, you can pass as many arguments as you want. The "r" preceding the strings is important to make sure full path backslashes get interpreted right.
... View more
03-06-2013
08:19 PM
|
0
|
0
|
1286
|
|
POST
|
I have a model which will pull 30 features from a database and a second model which will perform a feature class rename on these 30 different features. This is done on a daily basis. Sometimes one of the names will change or a feature won't be pulled in for some reason. The problem is that when the rename model is running if it can't find a feature it will error the entire model instead of ignoring the error and skipping to the next feature to rename. None of the processes have preconditions. Is their a way I can tell the model to ignore errors and move on if it can't find a feature? A green error instead of a red one? The only way I can think to do this is to use the Calculate Value tool to do the rename and have it return a message. Calculate Value will print out the function results to geoprocessing messages as the model runs. Of course this involves writing a small Python script: I'm assuming you have two model elements "From FC" and "To FC" with the names. Calculate Value tool Expression: FCRename(r"%From FC%",r"%To FC%")
def FCRename(from,to):
import arcpy
try:
arcpy.Rename_management(from,to)
return "rename %s to %s success!" % (from,to)
except:
return "rename %s to %s failed" % (from,to)
(note, you can pass as many arguments to the function as you want, or put the dictionary and for loop inside the Calculate Value if you want.)
... View more
03-06-2013
08:13 PM
|
0
|
0
|
1286
|
|
POST
|
"flowtopo" * "K_factor_100" * "C_factor_1000" * 280 * Cos((("Aspect") * (-1)) + 450) * .01745) However, everytime I try I get error 00539: Error running expression: rcexec. I counted up your parens (an old trick) and didn't see any issues. I would check to make sure all of your strings map directly to raster layers in your ArcMap session. Maybe you mispelled one?
... View more
03-06-2013
07:55 PM
|
0
|
0
|
827
|
|
POST
|
I have a raster with a resolution of .47-meters, it contains one field that defines the presence or absence of forest canopy (1 or 0). I need to use a 5-meter fishnet, (or 5-meter raster) to average the coverage within each each cell. The 5-meter raster obviously doesn't line up perfectly with the .47-meter raster. How do I get the exact percent coverage of the underlying forest canopy coverage into the 5-meter raster or fishnet. The tool you are looking for is Aggregate. You can't get an "exact" aggregation - as .47 does not equally divide into 5 -- but it will be very close if you resample on the fly at a smaller cell size (.2) that equally divides into 5 meters.
from arcpy.sa import *
arcpy.env.cellSize = 0.2
# .2m * 25 = 5m (you could also use other values, say 0.1 and 50)
fiveMeterMean = Aggregate("p47rast",25,"MEAN")
# to get 0-100 percents:
fiveMeterPct = Aggregate("p47rast",5,"MEAN") * 100
... View more
03-06-2013
07:47 PM
|
0
|
0
|
773
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-11-2021 01:26 PM | |
| 5 | 12-10-2021 04:58 PM | |
| 1 | 02-27-2017 09:30 AM | |
| 2 | 12-04-2023 01:05 PM | |
| 1 | 04-12-2016 10:17 AM |
| Online Status |
Offline
|
| Date Last Visited |
06-19-2024
12:10 AM
|