I am trying to automate the process of publishing WMS services directly from a raster file without using a map document or project file. I am able to publish an imagery layer or a map image layer but when i try to modify the image draft file to enable the WMS or WFS capabilities and create a new draft file it displays a black image for the image layer and the WMS. Probably because the information from previous file is not copied to the new file and i am not referencing the data in my workflow but rather copying it to the server. How can i enable WMS on my layer? Here is how i implement the image draft file:
arcpy.CreateImageSDDraft(rasterimage, output_draft, service, 'FROM_CONNECTION_FILE', con, True, None, "netCDF test", "test,auto")
Here is how i enable WMS :
doc=DOM.parse(output_draft)
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
# Get the TypeName whose properties we want to modify.
if typeName.firstChild.data == "WMSServer":
extension = typeName.parentNode
for extElement in extension.childNodes:
# Enabled SOE.
if extElement.tagName == 'Enabled':
extElement.firstChild.data = 'true'
Here is how i create a new draft file for storing updated properties. and here is the problem. The info from previous file is lost and so i see a black image:
new_draft=r"C:/Users/C/arcgis/image1.sddraft"
f = open(new_draft, 'w')
doc.writexml( f )
f.close()
Dear Rehan,
I share with you the function that I use to enable the WMS capability. The only difference is that I work with CreateMapSDDraft.
def enableWMS(sddraft):
# These are the properties we will change in the sddraft xml.
soe = 'WMSServer'
# Read the sddraft xml.
doc = DOM.parse(sddraft)
# Find all elements named TypeName. This is where the server object extension (SOE) names are defined.
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
# Get the TypeName whose properties we want to modify.
if typeName.firstChild.data == soe:
extension = typeName.parentNode
for extElement in extension.childNodes:
# Enabled SOE.
if extElement.tagName == 'Enabled':
extElement.firstChild.data = 'true'
break
keys = doc.getElementsByTagName('Key')
for key in keys:
if key.hasChildNodes():
if key.firstChild.data == 'isCached':
key.nextSibling.firstChild.data = 'false'
elif key.firstChild.data == 'cacheOnDemand':
key.nextSibling.firstChild.data = 'false'
outXml = sddraft
if os.path.exists(outXml): os.remove(outXml)
f = open(outXml, 'w')
doc.writexml(f)
f.close()
del f, doc
@Borch unfortunately this still gives the same result
Could you share the data you used?
If a WMS getMap returns things (even if it is black), that means WMS is working and the problem is more like a data rendering/visualization issue.
We could check the associated image service export image operation had it displayed well and start investigating from there.
@ZikangZhou1 i am using a netcdf file from esri and then copying its multidimensional raster layer to a raster dataset (crf). After that, i am using the CreateImageSddraft function and not the getMap as i want to publish directly from the file and not the map document. I have added the file and if required i can share the complete workflow as well.
One more thing, if i change the raster dataset from .crf to .tif then i get an error for a WMS layer which is below while the imagery layer is displayed in grayscale.
The WMS service, https://xyz.com/image/services/image/ImageServer/WMSServer, cannot be added to the map. It is either not available or you have entered an invalid URL for the type of layer you want to reference.
I cannot reproduce the problem using my Pro 2.8 and Server 10.9 with your data. Here are my steps:
1. download your netcdf, run make multidimensional raster layer tool with the netcdf.
2. run copy raster tool, select process as multidimensional, output format as crf.
3. run the exact code snippet you provided to generate the sddraft file.
4. stage the sddraft file to make it a sd file; upload the sd file to server.
5. add the wms endpoint to arcgis pro as a new wms server, the layer displays just fine.
@Zikang i finally upload it to a federated esri arcgis portal and that is where i get the above mentioned error that it cannot be added to the map. When i see the layer detail it gives me error code 499 which is related to making the service public as currently it is set to private. I tried making it public directly from the portal but that did not help. How can i make it public using the functions of creating draft file and staging files to server and maybe that might solve the problem?
@ZikangZhou1 i tried making it public through my portal but that did not solve the problem. How can i add a token parameter?