Select to view content in your preferred language

Provide arcpy equivalent to ArcGIS Pro "Share as Web Map"

2038
11
12-16-2022 10:14 AM
Status: Open
Labels (1)
DonMorrison1
Frequent Contributor

I have a map in ArcGIS pro that I can upload to ArcGIS online using the "Share as Web Map" dialog, which gives me various options for how I want the data copied (in my case it creates an ArcGIS Online web map and a feature layer).  I'd like to automate that in Python but having some trouble figuring out how to do it. 

 

BTW - I first raised this a a question so there is more discussion there

Tags (2)
11 Comments
DuncanHornby

All the tools you require for you to script in python or model builder are in the Package toolbox.

DonMorrison1

Thanks Duncan, but I'm still not seeing how to use the Package toolset to code the equivalent of "Share as Web Map".. I ran "Package Map" followed by "Share Package" but I ended up with the .mpkx file being upload to ArcGIS Online as a Map Package item.  What I want to is end up with a Web Map item in ArcGIS Online (and a related Feature Layer if needed).

 

BTW - I did figure out how to accomplish thi using a combination of arcpy, REST APIs, and the Python for ArcGIS API, but it was quite a bit of relatively complicated code.

JonahLay
Status changed to: Under Consideration
 
JonahLay
Status changed to: Open
 
cspoerri

hi there, 

we have the same requirements, since we are building Azure DevOps pipelines that publish entire test and demo environment. While we are able to automate the publishing of services and other artifacts, the last piece missing is the publishing of a WebMap based on an ArcGIS Pro map.

 

KoryKramer

Thank you for the comment @cspoerri Please be sure to add your kudo to this idea 😉

kshaba
by

I have the same problem. It appears this isn't supported in ArcPy. I have tried using sddraft and the files are uploaded as a map package and not as a web layer. 

On investigation, it would appear ArcGIS Pro (v2.9.2) is utilising .msd files under the hood when the Share as "Web Map" is invoked.   .sd files are not supported in ArcPy and were deprecated in favor of "sddrafts". 

To verify, under options, navigate to "Share and Download". Open the staging folder and you will see folders for each transaction that include .msd files. 

kshaba_0-1684146686620.png

@DonMorrison1  Are you able to share the solution you arrived at here? 

 

SaumyaManiar

@DonMorrison1 Hi Don, were you able to figure out this? If so, can you please share your python pseudocode? I am trying to automate publishing Map Image Layer from ArcGIS Pro to ArcGIS Enterprise.

DonMorrison1

Here is a rough outline of the steps I went through. The input is a mpxk file and I end up with a hosted feature layer . I'm not sure this is really what you want to do since you are working with image layers and my goal was to get the features published, but in any case here it is

  • Use ExtractPackage to unpack the mpkx file
  • Find the .mapx file in the unpacked files
  • Create a new empty ArcGISProject
  • Use ArcGISProject.importDocument to import the map into the project
  • Use map.listLayer to iterate through the map layers and use map.removeLayer to remove all but Feature Layers and Group Layers (layer.isFeatureLayer and layer.isGroupLayer)
  • Call map.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", rest_id) to get a sharing_draft document
  • Set the sharing_draft attributes (summary, service_name, tags, etc)
  • Call sharing_draft.exportToSDDraft to get a sharing draft file
  • Call arcpy.StageService specifying the sharing draft file
  • Call UploadServiceDefinition to create the hosted feature layer

 

ATFerguson

@DonMorrison1

Thanks for sharing. I'm following a similar workflow to publish a hosted feature layer, but I'm still unable to automate the updating of the associated web map. In my current workflow, if I add new layers to the map in Pro, I have to manually add them to the Web Map JSON, which is cumbersome and error-prone.

Have you found a way to automate the updating of the Web Map JSON specification? This is something I'd like to accomplish, and I'd prefer not to write a custom toolbox to parse and update the Web Map JSON from my previous version. 

Let me know if you have any leads. Thanks!