AnsweredAssumed Answered

Add OPeNDAP raster layer to mapframe in arcpy

Question asked by jsamson88 on Sep 12, 2019

I am trying to add a opendap raster to an existing .aprx project using arcpy but am unable to do so:

Creating the layer is achieved successfully but I seem unable to add to the map frame...

 

Running the code in the python console adds the layer successfully to the active map frame ... Eventually I will want to loop through a large number of combinations of opendap files to create an atlas of maps etc so I need to be able to do this in a standalone script ... any help would be appreciated...

`

import arcpy

aprx = arcpy.mp.ArcGISProject(r"pathto\TestTemplate.aprx")

mapFrames = aprx.listMaps()

url = 'https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/cccs_portal/indices/Final/BCCAQv2/tg_mean/YS/rcp85/ensemble_percentiles/30yAvg_BCCAQv2+ANUSPLIN300_ensemble-percentiles_historical+rcp85_1950-2100_tg_mean_YS.nc'

m = mapFrames[0]
vari = 'tg_mean_p50'
opendap = arcpy.md.MakeOPeNDAPRasterLayer(url, vari, "lon", "lat", f"{vari}_Layer",
                                                 "-140.958333335 41.041666665 -52.041670225 83.458331635",
                                                 "time '0' '12'", "BY_INDEX",cell_registration='CENTER')
m.addLayer(opendap) #f"{vari}_Layer")

`

Gives error:

 

Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\IPython\core\interactiveshell.py", line 3296, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-4-79cc189255aa>", line 14, in <module>
m.addLayer(opendap)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\utils.py", line 191, in fn_
return fn(*args, **kw)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 1403, in addLayer
return convertArcObjectToPythonObject(self._arc_object.addLayer(*gp_fixargs((add_layer_or_layerfile, add_position), True)))
ValueError: tg_mean_p50_Layer

Outcomes