|
POST
|
Benjamin Simpson wrote: Would this mean that the only way for me to get the arcpy.SetProgress function to work with my script is to transfer my script into a toolbox and then call the toolbox using the arcpy.GPToolDialog function in my python addin? Yes, that's what I said. Benjamin Simpson wrote: If this is the case is it possible to store this toolbox within the Install folder of the python addin? I am thinking purely about ease of sharing this python addin. Yes. Then in your add-in use something like: arcpy.GPToolDialog(os.path.join(os.path.dirname(__file__), 'mytoolbox.tbx'), 'MyTool')
... View more
11-18-2015
03:39 PM
|
1
|
0
|
5316
|
|
POST
|
The pythonaddins.ProgressDialog is not available in 10.2. What you could do is use pythonaddins.GPToolDialog (note: gotchas if using a python pyt toolbox instead of a tbx and script tool) to kick off a script tool that does the actual long running operations and uses the arcpy.SetProgressor object to advance the result window progress bar. import arcpy, time
arcpy.SetProgressor('step','Some description', 0, 100, 1)
for i in range(100):
time.sleep(0.25) #Fake doing some stuff
arcpy.SetProgressorPosition()
arcpy.SetProgressorLabel("Step %s"%(i+1))
... View more
11-17-2015
01:58 PM
|
1
|
3
|
5316
|
|
DOC
|
I recommend having a read of my GIS Stack Exchange answer that Duncan Hornby links to as it covers a few more gotchas/tips.
... View more
11-01-2015
10:23 AM
|
1
|
0
|
15626
|
|
POST
|
Freddie, it's not necessary 'stitch together the call to the tool along with its variables' for the eval call. i.e. print eval('int(1.23)') You only need to use the eval call to get a reference to the model/tool, then you just treat the model object as a normal python function and call it as such. i.e. a = int
b = eval('int')
print int(1.23), a(2.34), b(3.45) 1 2 3
... View more
10-22-2015
04:51 PM
|
1
|
0
|
1732
|
|
POST
|
I had a quick look at the ArcGIS help and there doesn't seem to be an arcpy way of calling a tool/model with a name from a variable. You can however use the eval() function. import os
import arcpy
##Set folder location of the Toolbox.
ToolboxFolder = r"C:\Temp"
##Set the name of the Toolbox.
ToolboxName = "Toolbox"
##Set the model name.
ModelName = "Model"
##Call the Toolbox.
arcpy.ImportToolbox(os.path.join(ToolboxFolder, ToolboxName+".tbx"), "TBX")
##Call the model.
model = eval("arcpy.{}_TBX".format(ModelName))
result=model('blah blah')
... View more
10-22-2015
02:49 PM
|
1
|
2
|
1732
|
|
POST
|
ncols, nrows = [int(s) for s in open(inWeightFile).readlines()[0].strip().split()]
NbrCellsBuffer = ncols * nrows The above opens the file and grabs the first line, strips off the newline ('\n') character and splits it into a list of two strings at the space then uses python list comprehension to convert the strings to integer values.
... View more
10-15-2015
03:04 PM
|
1
|
0
|
2138
|
|
POST
|
I had a quick look at this and I *think* Darren Wiens is right, arcpy.da.Walk (or a combination of arcpy.ListDatasets() and arcpy.ListFeatureClasses() etc.) is the only way to get the Feature Dataset name if you only know the Feature Class name at runtime: Something like: import arcpy,os
gdb = r"C:\Temp\Default.gdb"
fcs = ["TESTFC", # standalone FC
"TESTFDFC"] # FC in a feature dataset
def get_paths(path):
"""Use this if you have multiple FCs to check"""
paths = {}
for dirname,subdirs,files in arcpy.da.Walk(path):
paths.update(zip(files, [os.path.basename(dirname.replace(path,""))]*len(files)))
return paths
def get_fd(fc):
"""Use this if you only have one FC to check"""
path = os.path.normpath(os.path.dirname(fc))
if path == ".":
path = arcpy.env.workspace
for dirname,subdirs,files in arcpy.da.Walk(path):
if fc in files:
return os.path.basename(dirname.replace(path,""))
arcpy.env.workspace = gdb
paths = get_paths(gdb)
for fc in fcs:
print os.path.join(paths[fc], fc)
print os.path.join(get_fd(fc), fc) TESTFC TESTFC TESTFD\TESTFDFC TESTFD\TESTFDFC
... View more
10-05-2015
06:51 PM
|
2
|
0
|
1155
|
|
POST
|
The easiest way to secure a python toolbox is publish it as a geoprocessing service with ArcGIS Server.
... View more
10-05-2015
05:05 PM
|
2
|
0
|
3186
|
|
POST
|
Then this method will not work. It requires a NIR band.
... View more
09-28-2015
09:47 PM
|
0
|
1
|
1734
|
|
POST
|
Files with a .tfw extension are usually "world files" that contain georeferencing information for TIFF rasters. I'm not all that familiar with lidar data formats, but I'd be surprised if a tfw was associated with a las file. Do you have any .tif files as well? You could try right clicking on one of the LAS files in ArcCatalog, selecting Item Description and then export that to FGDC: If that works, you may be able to batch or script all of the LAS files using the Export Metadata or Export Metadata Multiple tools .
... View more
09-24-2015
09:53 PM
|
1
|
2
|
1868
|
|
POST
|
You haven't defined the nrows or ncols variables (number of rows, number of columns). The RasterToNumPyArray function accepts lower_left_corner, ncols, nrows parameters which you can use to extract a subset of each raster.
... View more
09-23-2015
06:48 PM
|
1
|
0
|
2818
|
|
POST
|
How much RAM have you got? Make sure you're using 64bit python, 32bit can't make use of much of your RAM. Prebuild the stack then populate it rather than using a list so less memory is required (due to the way numpy makes copies of arrays) i.e stack = numpy.zeroes((nrasters, nrows, ncols), dtype = numpy.some_appropriate_dtype) i=0 for folder, subs, files in os.walk(ws): for filename in files: stack[i, nrows, ncols] = arcpy.RasterToNumPyArray(os.path.join(folder,filename)) Even with 64bit and loads of RAM, you'll probably still have issues with memory, you may need to process the timeseries in chunks, i.e the full time series for a portion of the image.
... View more
09-22-2015
08:38 PM
|
0
|
2
|
2818
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 07-24-2022 03:08 PM | |
| 1 | 07-30-2025 03:00 PM | |
| 1 | 06-10-2025 08:06 PM | |
| 5 | 05-20-2025 07:56 PM | |
| 1 | 05-04-2025 10:34 PM |