How can I use the ESRI Terrain service as the in_raster parameter for ExtractValuesToPoints in ArcGIS Pro 2.9 arcpy?

1366
7
Jump to solution
01-18-2022 09:32 PM
by Anonymous User
Not applicable

How can I use the ESRI Terrain service as the in_raster parameter for ExtractValuesToPoints in ArcGIS Pro 2.9?

Code looks something like this:

 

ExtractValuesToPoints(in_point_features='valid/path/in.shp',
    in_raster='https://elevation.arcgis.com/arcgis/services/WorldElevation/Terrain/ImageServer',
    out_point_features='valid/path/out.shp')

 

 

I also tried using MakeImageServerLayer for the in_raster. In both cases, ArcGIS crashes and brings up the ArcGIS Application crash report UI, and does not report a python stacktrace.

 

This was run using the default ArcGIS Pro 2.9 conda env from PyCharm.

 

EDIT
The Terrain page lists the URL as:
https://elevation.arcgis.com/arcgis/rest/services/WorldElevation/Terrain/ImageServer

While the URL from Terrain properties as accessed through ArcGIS Pro is:

https://elevation.arcgis.com/arcgis/services/WorldElevation/Terrain/ImageServer

Using either as described above has the same error.

0 Kudos
1 Solution

Accepted Solutions
RyanDeBruyn
Esri Contributor

As a general rule Image Services are supported as input directly to Spatial Analyst GP tools in Pro.  If you add the IS as a layer you should be able to use it in the tool.

In python you will need to use the MakeImageServiceLayer tool to create a layer,  then use the result as input to Extract Values to Points.

Note:  Be aware of the extent when creating the ISLayer (use template parameter) or set accordingly when running Extract tools.  It would be important to manage the extent to reduce the size (the number of rows and columns)  to process the image, which may affect performance.  Also, to avoid in some cases, processing the entire extent of a large image service.

For example,

 

ISlyr = arcpy.MakeImageServerLayer_management(inRasterIS, "outISlyr", inPointFeatures)
arcpy.sa.ExtractValuesToPoints(inPointFeatures, ISlyr, outPointFeatures)

 




View solution in original post

0 Kudos
7 Replies
DanPatterson
MVP Esteemed Contributor

Extract Values to Points (Spatial Analyst)—ArcGIS Pro | Documentation

requires a raster layer, to be sure, convert the terrain service to a raster layer and/or save a local copy and...

Make Raster Layer (Data Management)—ArcGIS Pro | Documentation


... sort of retired...
0 Kudos
by Anonymous User
Not applicable

After testing this more,

MakeRasterLayer(in_raster=https://elevation.arcgis.com/arcgis/rest/services/WorldElevation/Terrain/ImageServer,
                out_rasterlayer='temp_raster')

ExtractValuesToPoints(in_point_features=r'valid/path/in.shp',
                          in_raster='temp_raster',
                          out_point_features=r'valid/path/out.shp')

 

and

 

MakeImageServerLayer(in_image_service=https://elevation.arcgis.com/arcgis/rest/services/WorldElevation/Terrain/ImageServer,
                out_imageserver_layer='temp_raster')

ExtractValuesToPoints(in_point_features=r'valid/path/in.shp',
                          in_raster='temp_raster',
                          out_point_features=r'valid/path/out.shp')

 

 both crash with the same behavior described in the original post. UI "ArcGIS Application has stopped working" pops up. I tried with SaveToLayerFile as well - no joy.

 

However, the MakeRasterLayer snippet succeeds as intended when run from the Python console within ArcGIS Pro 2.9.

 

The MakeImageServerLayer also runs without error when run from the Python console, but returns incorrect raster extraction values. They are all zeros.

So this is a PyCharm problem when using the ArcGIS conda env. There's no error message returned from ESRI here, only the crash UI, so debugging this further seems difficult.

 

I'm not sure how the server calls work on the backend, but this could also be a corporate firewall issue.

0 Kudos
by Anonymous User
Not applicable

Some more testing on this from within ArcGIS Pro 2.9 GUI:

1. Ribbon > Map > Add Data > Living Atlas Terrain Layer

# 2. Run Make Raster Layer on Terrain service. Copied Python snippet:
arcpy.management.MakeRasterLayer("https://elevation.arcgis.com/arcgis/rest/services/WorldElevation/Terrain/ImageServer", "Terrain_raster_layer", '', "-20037507.84 -20037508.41 20037507.8427882 20037508.34", None)
# 3. Run Make Image Server Layer on Terrain service. Copied Python snippet.
# Tool Exits with WARNING 000950: Output raster exceeds the size limitation #(rows: 5000 and columns: 5000) defined on the image server. Please input a # smaller extent.
arcpy.management.MakeImageServerLayer("https://elevation.arcgis.com/arcgis/rest/services/WorldElevation/Terrain/ImageServer", "Terrain_image_server", "-20037507.84 -20037508.41 20037507.8427882 20037508.34", None, "ByAttribute", '', "0", '', 0.249999999580713, '', "None")

 

4. Run Extract Multi Values to Points, using the 3 layers above as inputs.

 

The output point shapefile shows:

-Correct extract values from the Terrain service added to the Map (Step 1).

-All Zero number values from Terrain service added with MakeRasterLayer (Step 2).

-Correct extract values from the Terrain service added with Make Image Server Layer (Step 3).

0 Kudos
by Anonymous User
Not applicable

Bonus, the Extract Values to Points tool yields the same results as above. Looking like Make Raster Layer isn't the way to go here.

0 Kudos
RyanDeBruyn
Esri Contributor

As a general rule Image Services are supported as input directly to Spatial Analyst GP tools in Pro.  If you add the IS as a layer you should be able to use it in the tool.

In python you will need to use the MakeImageServiceLayer tool to create a layer,  then use the result as input to Extract Values to Points.

Note:  Be aware of the extent when creating the ISLayer (use template parameter) or set accordingly when running Extract tools.  It would be important to manage the extent to reduce the size (the number of rows and columns)  to process the image, which may affect performance.  Also, to avoid in some cases, processing the entire extent of a large image service.

For example,

 

ISlyr = arcpy.MakeImageServerLayer_management(inRasterIS, "outISlyr", inPointFeatures)
arcpy.sa.ExtractValuesToPoints(inPointFeatures, ISlyr, outPointFeatures)

 




0 Kudos
by Anonymous User
Not applicable

@RyanDeBruyn Thank you! You beat me to the write up.

Could you comment on what "Be Aware of extent.." means in this context?

The next step is to solve this question. If I'm extracting values from ESRI Terrain service, which "layer" or data source from within the terrain service am I getting? SRTM, NED, etc are all included.

0 Kudos
RyanDeBruyn
Esri Contributor

Always a good idea think about analysis environments in a workflow. 🙂 

It would be important to manage the extent to reduce the size (the number of rows and columns)  to process the image, which may affect performance.  Also, to avoid in some cases, processing the entire extent of a large image service.

0 Kudos