POST
|
I'm trying to write a model-builder tool that will allow the user to select individual images in an image service (published from a mosaic dataset), and submit just the selection for further processing. I have a python script tool that does this, but requires the user to copy and paste a field from the image service's attribute table into the tool...= a bit inconvenient. I'd like to make this easier by having the tool grab the attribute data for the selected footprints from the image service. Every tool I've tried, however, does not seem to see the image service's attribute table data. Eg "Make Table View", or "Select Data" or any of the other Select tools. They only see the ObjectID, Value, and Count fields of the image service (eg, not the attribute table data). I would then pass the output of the select operation to the "Get Field Value" tool to pull out the attribute I actually need from the table. Is there any way to access the image service's attribute table data, from a standard tool in Model Builder? And in particular, see a selection of that data made by the user? Thanks for any tips or alternate ways to do this, if there's an easier approach.
... View more
09-12-2018
08:35 AM
|
0
|
0
|
192
|
POST
|
I'm trying to create a python raster function that would be applied to a mosaic dataset, to do some relatively simple on-the-fly processing and display/output the result. I'm unclear how (or if possible) to pass in specific layers in the mosaic dataset, as a result of either a query on the MD's attribute table, or as a result of specifying the date and dimension - I can (and have) setup the mosaic dataset as multidimensional, with two variables, and time as the dimension. (not sure if that helps or hinders). The .getConfiguration method has an extractBands attribute, that is close to what I want. But the data don't have bands. So perhaps one solution is to setup some sort of dummy band structure, but I think that would get overly complicated to read the data in that way. I'd rather just be able to directly set a query on the mosaic dataset attributes to define the raster layer returned from the MD. Or on the multidimensional variables/dimensions. There's also the selectRasters method, but I don't see much documentation on that...the example just shows it selecting one of two already input/defined rasters: PythonRasterFunction · Esri/raster-functions Wiki · GitHub I could also break the mosaic dataset into two separate MDs, one per variable, but I'd still need to select on time...and in this case, I cant just use the time properties to select the time, as I specifically need to access data from both the current day (which could be set using time slider etc) AND the previous day. Is this possible? Or am I on the wrong track here and there's some other better way to go about running a raster function on specific layers (defined by input parameters) in a mosaic dataset? In the end, the idea would be to set this up as a processing template on the mosaic dataset, that a user would then set the parameters for. Thanks in advance for any suggestions.
... View more
05-21-2015
12:33 PM
|
0
|
0
|
2663
|
POST
|
I'm trying to bring a script that runs perfectly well in command-line python into ArcMap as a Script Tool, and am having a couple of intransigent problems: When run as a Script Tool, after the first run in the ArcMap session, there are often (but not always) errors regarding read-only status of data source etc, eg: ... File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 484, in <lambda> return lambda *args: val(*gp_fixargs(args, True)) ExecuteError: ERROR 999999: Error executing function. Workspace or data source is read only. Workspace or data source is read only. Workspace or data source is read only. Workspace or data source is read only. Workspace or data source is read only. ERROR 010302: Unable to create the output raster: C:\Users\Dan Slayback\Documents\ArcGIS\Default.gdb\SetNull_Idw_1 ERROR 010067: Error in executing grid expression. Failed to execute (SetNull). This never happens on the first run in the ArcMap session - sometimes you can run it twice, but rarely if ever 3 times. So I suspect it has to do with something being locked. I've tried lots of variations on deleting intermediate objects, but this has not consistently helped. More problematic is the fact that even when it runs without complaint as a Script Tool in ArcMap, the SetNull part is not working. Whereas, when run from a command prompt, it does. The guts of the code are as follows: import arcpy, string
from arcpy.sa import Idw, RadiusFixed, SetNull
arcpy.env.overwriteOutput = True
spRef = r"E:Code\WGS_1984_UTM_Zone_36N.prj"
pointlayer = "PointLayer"
arcpy.MakeXYEventLayer_management(csvfile, "X", "Y", pointlayer, spRef, 'Median')
arcpy.CheckOutExtension("Spatial")
# Execute IDW
searchRadius = RadiusFixed(1,"")
outIDW = Idw("PointLayer", 'Median', 0.2, 2, searchRadius)
# Convert values < -1000 to NoData
outSetNull = SetNull(outIDW, outIDW, "Value < -1000")
# Save to tiff file
outSetNull.save(outTiff) Finally, this used to run both as a Script Tool (and from the dos prompt), without error, before I added the SetNull line, in an attempt to clean up some very low values that are coming out outside the perimeter of the data. (another problem - Idw does not seem to be doing the right thing here, but figured i could get around it with SetNull). I'd greatly appreciate any suggestions on (1) what I should be deleting at the end of this in order to unlock any relevant files/workspaces for the next run, and whether to use 'del' or arcpy.Delete_management, and (2) why SetNull may not be working when run as a Script Tool.
... View more
09-06-2012
01:47 PM
|
0
|
1
|
884
|
POST
|
Thanks much for the detailed example - this will certainly help! I figured using cursors was one way to do it, but was hoping there might be a simple way to directly transfer an in-memory list/array to a table.
... View more
07-19-2012
07:09 AM
|
0
|
0
|
1463
|
POST
|
I'm wondering if there is a way to convert a list in python (or it could be an array, I think) to a Table object, that I'll then do further geoprocessing on. Currently, the only way I can get this to work is to write the list to a csv file, and then use arcpy.TableToGeodatabase_conversion to bring that csv file into a geodatabase. I dont want the csv file, so would prefer to simply pass the list object in memory to the geodatabase. And actually, I'd like to not even put it in the geodatabase, but just keep it as a Table object in memory. I'll then run arcpy.MakeXYEventLayer_management, and then run the IDW tool on the resulting layer to get the desired output raster. I'd rather not keep around (or have to bother deleting) the intermediate files. Seems like this should be trivially easy, but I cant find any hints on how to do this. I have tried to pass the python list object directly to MakeXYEventLayer, but it just hangs/takes forever. Presumably eventually it would return an error.
... View more
07-18-2012
01:40 AM
|
0
|
2
|
6136
|
POST
|
i was actually trying to avoid using linux commands, because I wanted the code to work under either Windows or Linux. although clearly a simple check on the os and an if statement could solve that problem. However, even this does not work using ESRI's installed python, and yet works with the OS-installed python! Quite bizarre:
$ /home/ags/arcgis/server/tools/python
Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system('chmod g+w 2012-172.log')
os.system('chmod g+w 2012-172.log')
File not found
9009
>>> ^Z
[1]+ Stopped /home/ags/arcgis/server/tools/python
$ ls -l 2012-172.log
-rw-------. 1 ags users 0 Jun 25 08:00 2012-172.log
And giving it the full path does not help. Whereas, for system-installed python: $ python
Python 2.6.6 (r266:84292, Jun 18 2012, 09:57:52)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system('chmod g+w 2012-172.log')
0
>>>
[1]+ Stopped python
$ ls -l 2012-172.log
-rw--w----. 1 ags users 0 Jun 25 08:00 2012-172.log is this possibly correct, or is this likely a bug?
... View more
06-25-2012
04:12 AM
|
0
|
0
|
282
|
POST
|
I've got a python program that needs to write to a log file. Usually that log file exists. If it doesnt, it needs to be created. And if its created, it needs to be group-writeable, because there are other programs that operate under other users that will need to write to it. This all has worked fine using the python installed with ArcGIS Desktop 10.0 on Windows, but using 10.1 Server on Linux, as I now need to do, the group permissions are not getting set correctly, and using shutil to try to set them is failing. And it works correctly using the standard python (version 2.6.6) installed on my workstation (RHEL 6.2). So I'm not sure if the issue is python 2.6 vs 2.7, or if there are additional restrictions on the ArcGIS Server python. Here's what I'm talking about: template.log is simply an empty file with both user and group permissions set to read-write: -rw-rw-r--. 1 dan users 0 Jun 21 13:32 template.log Simple code to illustrate: import shutil
template = 'template.log'
newfile = '2012-172.log'
shutil.copy(template, newfile)
shutil.copymode(template, newfile) Running the above in non-ESRI python 2.6.6: $ python
Python 2.6.6 (r266:84292, Jun 18 2012, 09:57:52)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> template = 'template.log'
>>> newfile = '2012-172.log'
>>> shutil.copy(template, newfile)
>>> quit()
$
$ ls -l template.log 2012-172.log
-rw-r--r--. 1 ags users 0 Jun 21 13:33 2012-172.log
-rw-r--r--. 1 dan users 0 Jun 21 13:32 template.log Just what I need. And I didnt have to bother with the shutil.copymode as the above maintains the source files' permissions. But if I use ArcGIS Server's (10.1) python: $ /home/ags/arcgis/server/tools/python
Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> template = 'template.log'
>>> newfile = '2012-172.log'
>>> shutil.copy(template, newfile)
>>>
[1]+ Stopped /home/ags/arcgis/server/tools/python
$ ls -l template.log 2012-172.log
-rw-------. 1 ags users 0 Jun 21 13:37 2012-172.log
-rw-r--r--. 1 dan users 0 Jun 21 13:32 template.log
$ fg
>>> shutil.copymode(template, newfile)
>>> quit()
$
$ ls -l template.log 2012-172.log
-rw-------. 1 ags users 0 Jun 21 13:37 2012-172.log
-rw-r--r--. 1 dan users 0 Jun 21 13:32 template.log Note that the shutil.copymode isnt able to do anything, nor does it complain. I've also done this with template.log owned by user ags instead of dan; same problem. Thanks much for any clues or suggestions.
... View more
06-21-2012
10:00 AM
|
0
|
2
|
2040
|
POST
|
I'm having some trouble with using the data drive pages functionality in linux. Perhaps I'm missing something obvious here, so if anyone has successfully used this, I'd appreciate any comments. Neither dataDrivenPages.currentPageID or dataDrivenPages.getPageIDFromName work on my system, but both work in Windows, using the same input data. The issue can be recreated easily: Create a new mxd in ArcMap. Add some basic background layer for reference (World Map or whatever). Create a new polygon shapefile in same directory where mxd is. Add several polygons. Add an item name in the polygon's attribute table, and assign each polygon a text name (optional). Save changes to shapefile. Setup data driven pages on the mxd, using that name item as the index. Set MXD to save as relative pathname. Save mxd. Close ArcMap. Open a shell window in the directory where the mxd is located. Start python, import arcpy and attempt to use the above python methods. The results on Linux vs Windows are below. Note the returned pageID should be the same as the "Box" number. Eg Box2 is pageID = 2. Also, on my system, the directory where everything is located is the same for linux and Windows; Windows runs in a virtual machine and accesses the directory as a network drive. Linux (CentOS 5.6, 64-bit, ArcGIS Engine 10.0 SP2): ----------------------------------------------------------- $ source /usr/local/arcgis/engine10.0/init_engine.sh $ source /usr/local/arcgis/engine10.0/python26/setenv_python.sh $ python Python 2.6.5 (r265:79063, Apr 27 2010, 11:08:55) [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import arcpy >>> mxd = arcpy.mapping.MapDocument('Test.mxd') >>> pageID = mxd.dataDrivenPages.getPageIDFromName('Box2') >>> pageID 0 >>> mxd.dataDrivenPages.currentPageID = 2 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/arcgis/engine10.0/python26/lib/python2.6/site-packages/arcpy/arcpy/arcobjects/_base.py", line 77, in _set return setattr(self._arc_object, attr_name, ao) ValueError: PageLayoutObject: Error in SetDataDrivenPageID >>> quit() ----------------------------------------------- Windows (Win7/64-bit, ArcGIS 10.0 SP2): ------------------------------------------------ >C:\Python26\ArcGIS10.0\python.exe Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import arcpy >>> mxd = arcpy.mapping.MapDocument('Test.mxd') >>> pageID = mxd.dataDrivenPages.getPageIDFromName('Box2') >>> pageID 2 >>> mxd.dataDrivenPages.currentPageID = 2 >>> ------------------------------------------------ Any clues as to whether I'm simply doing something wrong or this is a bug? I have had success doing many other operations on mxd's using ArcGIS Engine/Linux, but this particular method fails.
... View more
08-26-2011
04:35 AM
|
0
|
1
|
545
|
POST
|
Ok, yes, that does it - Thank you! However, one additional issue: the replacement filename apparently cannot have any periods in it, except for the one indicating filetype. So, a file named test.tif will work (using simply "test" in replaceDataSource), but a file named test.abc.tif will not work (with "test.abc" in replaceDataSource). Is that expected behavior? Eg the only period in a filename should be the one indicating file type? Dan
... View more
10-20-2010
05:50 AM
|
1
|
1
|
736
|
POST
|
Hi Jeff, Yes, the raster was in the same directory - is that required? I wont have a chance to try it without the .tif until Monday, but will get back to you then if it works (or doesnt). When is the SP1 expected out? thanks for the help! Dan
... View more
10-13-2010
09:16 AM
|
0
|
0
|
736
|
POST
|
I'm trying to take an existing mxd file and update it, automatically, with an updated raster layer. The rasters are geotiffs. However, I only get errors when I try to use replaceDataSource. Here is an example call, after I've setup "lyr" to point to the correct layer in the correct dataframe of the mxd: >>> lyr.replaceDataSource("E:/Projects", "RASTER_WORKSPACE", "NewLayer_2010.tif")
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
floodlayer.replaceDataSource("E:/Projects", "RASTER_WORKSPACE", "NewLayer_2010.tif")
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 179, in fn_
return fn(*args, **kw)
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 559, in replaceDataSource
return convertArcObjectToPythonObject(self._arc_object.replaceDataSource(*gp_fixargs((workspace_path, workspace_type, dataset_name, validate), True)))
ValueError: Layer: Unexpected error I have also tried using a Raster object, as returned by arcpy.Raster(filename), as the third parameter to this call, but also with no luck. I am new to map automation in ArcGIS and arcpy - is what I'm trying to do simply not possible? Or is my syntax wrong, or I'm missing a critical step? As an alternative, I also tried inserting (or adding) a new Layer (arcpy.mapping.AddLayer). This works, but requires a layer object to be added/inserted -- it wont work on a geotiff file. And I cant figure out how to make a geotiff file into a layer object automatically. I can do so interactively in the ArcMap session (Save As Layer File), but I need to automate this. Is there a way to do this automatically? Or a better way all around to do what I'm trying to do? (Update one geotiff layer in mxd with a different one, where both have same size/extent/georeference etc just different values). thanks for any tips or hints.
... View more
10-12-2010
07:09 AM
|
0
|
7
|
3135
|
Title | Kudos | Posted |
---|---|---|
1 | 10-20-2010 05:50 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|