|
POST
|
A fix I saw: you have your variables in quotes, so they won't be interpreted. bathtub = "C:/Temp/dustin.gdb/Coastal_WD_2040"
inRas = "C:/Temp/dustin.gdb/depth_2040"
# using a python list
arcpy.MosaicToNewRaster_management([bathub,inRas],
"C:/Temp/dustin.gdb", "new_test", "#","32_BIT_FLOAT","#", "1", "MAXIMUM", "REJECT")
# this is the "old way" - packing up a ";" delimited string - which will work as well:
arcpy.MosaicToNewRaster_management(bathub + ";" + inRas,
"C:/Temp/dustin.gdb", "new_test", "#","32_BIT_FLOAT","#", "1", "MAXIMUM", "REJECT")
... View more
02-14-2013
07:48 AM
|
0
|
0
|
988
|
|
POST
|
I thought I could use model builder to prompt the user to enter those 8 parameters and then from there recalculate the values in those fields based on the new variable values. But I can't figure out how to get model builder to prompt the user for values because it has been many years since I have used model builder. Any help would be appreciated because I am really stuck. If you set model elements as parameters and run the model as a tool (that is, without opening the model in edit mode) you can successfully run your scenarios. You can add validation (filtering) to set up pick lists, etc. for your input parameters in the model tool properties. Datasets produced at the end of your model are added to the map if exposed as output parameters. Facility with the Calculate Value tool and little bit of Python can be very helpful in setting up a model like this, for example, to convert your input parameters to expressions for the Calculate Field tool.
... View more
02-13-2013
02:18 PM
|
1
|
0
|
3601
|
|
POST
|
I am using 10.1 SP1 and I am getting unexpected results. I am using a simple RGB .img where the values are only 0 or 255 but never 0,0,0 or 255,255,255 (like yellow, cyan, etc) but the tool only returns values that are 0,0,0 or 255,255,255. It would be great if this worked. Thanks Whenever a raster tool does not work I try to see if it works with the Esri grid format. Convert your .img to a grid stack (copy raster with the output set an output raster name with no extension, starting with a letter, less than 11 chars), and see if EMVTP will work on that. Please open an incident with Esri if you can -- we need this tool to work more consistently!
... View more
02-13-2013
11:57 AM
|
0
|
0
|
6596
|
|
POST
|
I just did a fresh install of my OS and installed ActivePython 2.7.2. I want ArcGIS 10.1 to use this Python install. What are the steps do get this to work? I have EPD and have chosen, to avoid issues, to go ahead and install both pythons and add a reference to the EPD modules in my site-packages folder on the ArcGIS-python install. However, if you want to try this out, here are my suggestions: Option 1. Do a custom install of ArcGIS, turning off Python install option. (If you've already installed, you can do a repair install to remove features; remove the Python feature.) You may have to do a repair install of ActivePython to make sure .py files are executable so ArcGIS can find them. A wrinkle: you need to make sure to arcpy is available in your sys.path in your ActivePython setup. file Lib\site-packages\Desktop10.1.pth (should be dropped in your ActivePython site-packages folder):
D:\Users\cprice>type c:\Python27\ArcGIS10.1\Lib\site-packages\Desktop10.1.pth
C:\ArcGIS\Desktop10.1\bin
C:\ArcGIS\Desktop10.1\arcpy
C:\ArcGIS\Desktop10.1\ArcToolbox\Scripts Option 2. The ArcGIS Desktop installer looks for a registry keys to see if Python is already installed. My guess is ActivePython is not populating this key, while the generic Python install does. This involves editing the registry and guessing at the checks in the Esri's setup.msi, so I feel this is less desirable -- unless you open an incident and get some help from Esri. HKLM\SOFTWARE\Python\PythonCore\2.7\InstallPath\InstallGroup
... View more
02-13-2013
11:17 AM
|
0
|
0
|
1786
|
|
POST
|
Why did you include "(nrows-1) -" to calculate the row? Row values, by convention, start at the top with row zero located at the highest y values. In the old days of image processing, the terminology was line and sample. I believe this convention goes back to TV and also when we often looked at raster images printed out using coded values on line printers. Those were the days.
... View more
02-13-2013
10:40 AM
|
0
|
0
|
2858
|
|
POST
|
Never saw inspect used for that before. Cool. I did a little experimenting to see what you get in different Python contexts. In many situations inspect gives you more information.
# file test.py
import sys
import inspect
def x():
print "inspect: ",repr(inspect.getfile(inspect.currentframe()))
print "sys.argv[0]: ", repr(sys.argv[0])
x()
Running python script (like script tool):
D:\Users\cprice>C:\Python27\ArcGIS10.1\python.exe test.py
inspect: 'test.py'
sys.argv[0]: 'test.py' Import:
D:\Users\cprice>C:\Python27\ArcGIS10.1\python.exe
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import test
inspect: 'test.py'
sys.argv[0]: ''
>>> test.x()
inspect: 'test.py'
sys.argv[0]: ''
It should be noted that imported modules have a __file__ property - handy if you're not sure which source of a module you imported...
>>> import test
>>> test.__file__
'test.py'
Interactive, pasting test.py at the >>> prompt (like pasting to ArcGIS Desktop python window): The inspect method reports that your at the python prompt (<stdin>).
>>> import sys
>>> import inspect
>>> def x():
... print "inspect: ",repr(inspect.getfile(inspect.currentframe()))
... print "sys.argv[0]: ", repr(sys.argv[0])
...
>>> x()
inspect: '<stdin>'
sys.argv[0]: ''
>>>
And what if we're not sure which flavor of Python we picked up (say you've got multiple version of Python installed, say, x64 Desktop processing or the Enthought Python distribution, etc.)
>>> import sys
>>> sys.version
'2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'
>>> sys.executable
'C:\\Python27\\ArcGIS10.1\\python.exe'
In the Desktop Python command line - you get this:
sys.version
'2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'
>>> sys.executable
'C:\\ArcGIS\\Desktop10.1\\bin\\ArcMap.exe'
and.. inside Calculate Value in ModelBuilder:
def x():
import sys
import inspect
f = "inspect: %s" + chr(10) + "sys.argv[0]: %s" + chr(10) + \
"sys.version: %s" + chr(10) + "sys.executable: %s"
return f % \
(repr(inspect.getfile(inspect.currentframe())),
repr(sys.argv[0]),sys.version,sys.executable)
--
Executing (Calculate Value): CalculateValue x() "def x():\n import sys\n import inspect\n f = "inspect: %s" + chr(10) + "sys.argv[0]: %s" + chr(10) + "sys.version: %s" + chr(10) + "sys.executable: %s" \n return f % \\n (repr(inspect.getfile(inspect.currentframe())), repr(sys.argv[0]),sys.version,sys.executable)\n" Variant
Start Time: Wed Feb 06 10:37:05 2013
Value = inspect: '<string>'
sys.argv[0]: ''
sys.version: 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]
sys.executable: C:\ArcGIS\Desktop10.1\bin\ArcMap.exe
Succeeded at Wed Feb 06 10:37:05 2013 (Elapsed Time: 0.00 seconds)
... View more
02-06-2013
07:34 AM
|
0
|
0
|
2126
|
|
POST
|
Hello, I have some custom ArcGIS toolboxes containing script tools (v10.0 and v10.1) written in Python. Is there a way in Python to get the folder path of the script tool that is being executed? Try: import sys
import os
print sys.argv[0]
print os.path.dirname(sys.argv[0])
Note this is the path of the python script - not the toolbox.
... View more
02-05-2013
02:20 PM
|
0
|
0
|
2126
|
|
POST
|
The director wants me to revise a map I made three years ago. I finished all the changes except this last one. So close to being done! He wanted an addition to the legend for one item that results in a 150 character string. This will push the legend box way out of shape to stick the whole string in the label field of the category symbology set up. Is there a way to get the label field in symbology to take a line feed/carriage return or maybe two so I can format this legend better? The layer description and the legend text can have embedded linefeeds with ctrl-Enter, but I don't know of a way to do this for an individual key item. If all else fails you can right-click the legend and convert to graphics. The downside is that "freezes" the legend so you want to do it as a last resort, and after you are sure map contents are not going to change. (If they do, no big deal, but you have to re-do it.)
... View more
02-05-2013
02:12 PM
|
0
|
0
|
4718
|
|
POST
|
The Iterate Feature Classes tool in ModelBuilder may get you there faster than a complex python script. It does all the nested paths for you and returns a list of feature classes based on a wild card. If you want to stick with Python and can use 10.1 SP 1 or later, check out arcpy.da.walk. If you don't use the tools above and stick with your current script, might want to mention it would be far more efficient to do a single append operation. Note, the output of Append must an existing feature class, not a folder. (Merge can be used to create a new feature class.)
fcs = []
...do your looping...
fcs.append(fc)
arcpy.Append_management(fcs,outFC,"NO_TEST")
... View more
02-05-2013
12:34 PM
|
0
|
0
|
1054
|
|
POST
|
# Process: Create Mapbook Document, Data Frame, and Layer Objects mxd = mapping.MapDocument(r"V:\gislu\_BasemapMXD\10.1 MXDS\PreApp_Location.mxd") df = mapping.ListDataFrames(mxd, "PreApp Location")[0] Layer = mapping.ListLayers(mxd, "Parcels", df)[0] #Process: Select Layer by Attributes whereClause = "\"ADDRNO\" = " + NUMBER + " AND \"ADDRSTREET\" = '" + STREET + "'" arcpy.AddMessage("SELECTING: " + whereClause) arcpy.SelectLayerByAttribute_management (Layer, "NEW_SELECTION", whereClause) arcpy.AddMessage(arcpy.GetCount_management(Layer).getOutput(0)) #Process: Update the mapbook display in ArcMap df.zoomToSelectedFeatures() for Layer in mapping.ListLayers(mxd, "Parcels", df): if [acreage] < str(153): df.scale = 5000 else: df.scale = 9000 arcpy.RefreshActiveView() arcpy.RefreshTOC() legend = mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "Legend")[0] legend.autoAdd = True Please note the [post=166129]use of the [noparse] [/noparse] block[/post] to format your code in the forum. Mark is correct that you can't get the value this way. Do you want the total acreage of the selected features? You could determine that using the Summary Statistics tool. If you only have one parcel selected, you could get the acreage value out of the table using a search cursor on your layer. What if your parcel is long and skinny? Seems to me a safer approach would be to examine the df.scale after you zoom to selected and decide based on that which standard scale to use: if df.scale <= 5000: df.scale = 5000 elif df.scale <= 9000: df.scale = 9000
... View more
02-05-2013
12:20 PM
|
0
|
0
|
1691
|
|
POST
|
I've tried using Zonal Histogram and I only get a data table. You can make a bar graph from the data table - or graph it in Excel. Help 10.1: Creating bar graphs
... View more
02-05-2013
11:47 AM
|
0
|
0
|
998
|
|
POST
|
Have you got a NIM, or a reproducible test case someone can send in?
... View more
02-05-2013
11:41 AM
|
0
|
0
|
1931
|
|
POST
|
Good deal. One tool you haven't mentioned that you may want to investigate for this process is the Pivot Table tool, which can be used to simplify complex datasets (like the kind that come out a CAD import). Just thought I'd mention it.
... View more
02-04-2013
08:11 AM
|
0
|
0
|
3383
|
|
POST
|
If you expose both parameters they should both be available. Please attach your model using the "paper clip" tool.
... View more
02-01-2013
10:41 AM
|
0
|
0
|
719
|
|
POST
|
could [you] assist me constructing a python expression using calculate value to solve a similar problem. I've attached two print screens of my current model. I'm selecting CAD Features based on their layer name and then using Feature Class to Feature Class to write out the CAD Features to a File Geodatabase based on the Layer Name. The problem that I have is that I need to remove invalid characters from the Layers Name. Here's some code for using Calculate Value to do this: Expression: ValidateName(r"%Layer name%",r"%Output geodatabase%") Code: def ValidateName(fc,wks): import arcpy vName = arcpy.ValidateTableName(fc,wks) return vName The way to connect this up is to make the inputs preconditions (to ensure the input values are ready to go when you run Calculate Value [CV]) and then you can connect the output directly to the Feature Class to Feature Class tool. Depending on the required parameter type for the next tool you may have to set the output Data Type in Calculate Value. In this case, Feature Class to Feature class was happy to accept the default type (Any Value). In some situations (say, the name is part of a pathname or the tool validation doesn't accept a parameter type that CV supports) you cannot easiliy connect the CV output to the tool. In those cases, you connect the CV output with a precondition and use the CV output variable in the tool dialog parameter box (e.g. "MyOutput_%Validated_name%"). Calculate Value, as you have seen by now, is key to make the most of ModelBuilder. [ATTACH=CONFIG]21322[/ATTACH] [ATTACH=CONFIG]21319[/ATTACH] Another approach to your problem is the Feature Class to Geodatabase (Multiple) tool, which does all this iteration and validation for you. (BTW, its source code really helped me get the hang of validation and iteration in Python when I was first learning.)
... View more
02-01-2013
06:54 AM
|
0
|
0
|
3383
|
| 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
|