How to use a REST service in Python - DownloadRasters_management

412
10
05-31-2018 10:34 AM
BobBistrais
New Contributor III

I am writing a Python script with uses the DownloadRasters_management tool.  I want to use an Image Service from one of our servers as the input.  According to the documentation, the format is:

arcpy.DownloadRasters_management (in_image_service, out_folder, {where_clause}, {selection_feature}, {clipping}, {convert_rasters}, {format}, {compression_method}, {compression_quality}, {MAINTAIN_FOLDER})

for the in_image_service, I entered the URL to the service in quotes, e.g. "https://myserver/myimageservice/ImageServer"

-When I run the script, I get an error message "pythonw.exe has stopped working.  A problem caused the program to stop working correctly.  Please close the program".

-I also tried using the same URL to the service in ArcGIS Desktop, DownlaodRasters_management tool.  This gives me the message that the tool ran "successfully", but in fact, there is no output.

Any suggestions on how to properly format the URL to the service? 

0 Kudos
10 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Bob, can you show the exact code you were using and not just the help file format string

0 Kudos
BobBistrais
New Contributor III

Yes, here is the actual code:

arcpy.DownloadRasters_management ("https://gistest.maine.gov/arcgis/rest/services/Elevation/Maine_Elevation_DEM_Aggregate/ImageServer", "C:/ImageDiscoveryNextGen/TempOutputs/imagedata0", '', "C:/ImageDiscoveryTest/SelectionGraphic.shp")

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

hmmmm. just make sure that C:/ImageDiscoveryNextGen/TempOutputs/imagedata0 is a folder that actually exists.

Try to use "" rather than '' for unspecified parameters (shouldn't make a difference, until it does)

and the shapefile extent overlaps the inputs and is in the same coordinate system.

And you omitted the import arcpy, I presume for brevity

0 Kudos
BobBistrais
New Contributor III

Yes, the import arcpy is at the top of the script, sorry I didn't paste that here but it is in the script.  The output file does exist, and I changed that single quoted blank to double quote.  And the SRS matches as well.  I also tried a different image service and got the same error.  

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Time to flag ArcGIS REST API‌ since I am not sure it is a python issue since it can't perform, hence it fails

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If you look at the examples in Download Rasters—Data Management toolbox | ArcGIS Desktop , the service names all end with "?", so you might want to try appending a question mark at the end.  I also have some suspicions about your where clause.  I haven't worked with this tool before, but it could be an empty string generating a where clause that returns nothing.  Try leaving out the where clause and passing selection_feature as a named argument.

0 Kudos
BobBistrais
New Contributor III

I tried with and without the question mark, but no difference, also no luck with the where clause.

0 Kudos
BobBistrais
New Contributor III

I also tried this code using a mosaic data set instead of the service URL.  All the rest of the string was the same, but it worked when using the MDS.  

So that suggests that it has something to do with the URL to the REST service.  I think Dan has a good suggestion to flag https://community.esri.com/community/developers/web-developers/arcgis-rest-api 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Since the Geoprocessing Tool is calling a web service, you could use Fiddler or a similar tool to profile the calls to the server and see what, if any, errors are being returned from the server.

0 Kudos