Copying Items Between Portals Using Python | Getech
文章推薦指數: 80 %
Sometimes it's extremely useful to be able to manage your Portal via scripting and handily Esri provides the ArcGIS API for Python for doing ... Skiptocontent TwitterpageopensinnewwindowLinkedinpageopensinnewwindowYouTubepageopensinnewwindowinfo@getech.com+44(0)1133222200 Search: Search HomeLocateIndustriesIndustriesCarbonCapture&StorageCriticalMineralsGeothermalHealth,Safety,SecurityandEnvironmentHydrogenPetroleumPipelineRenewablesProductsCapabilitiesBasinEvolutionCrustalStructureDepositionalSystemsGIS&MappingPalaeoClimatePlateModellingPlayBasedExplorationUnconventionalDevelopmentsTechnologyDataAssistantExplorationAnalystGlobeHeatSeekerMaptiumUnconventionalsAnalystContentGravityDataMagneticDataDepthtoBasementSearchOurDataLibrarySolutionsSolutionsArcGISforRenewablesArcGISPipelineReferencingEmergencyResponseExplorationRiskManagementProductionOptimisationSiteAnalysis&PlanningServices&SupportServices&SupportG&MServicesG&MTrainingGISServicesGISTrainingCountryFocusCountryFocusAfricaAmericasEuropeMiddleEastAsia/AustralasiaDevelop&OperateGreenHydrogenGeothermalResponsibilityCorporateGovernanceSustainabilityInvestorsDirectorsandManagementBusinessModelStockExchangeAnnouncementsFinancialReportsPresentationsDocuments&CircularsAIMRule26AdvisersMedia&EventsMediaNewsBlogWebinarsUpcomingEventsContact CopyingItemsBetweenPortalsUsingPython Sometimesit’sextremelyusefultobeabletomanageyourPortalviascriptingandhandilyEsriprovidestheArcGISAPIforPythonfordoingjustthis. ThereasonfordevelopingthescriptwediscussinthisBlogwasaneedforacustomertoviewourdatawithinit’scorporateon-siteArcGISEnterprisePortal.SomeofourdatalayersarepublishedwithinArcGISOnline(AGOL),anditcanbetimeconsumingtosharelargevolumesofmapservicesbetweenPortals.Inthisinstancewewantedtoshareroughly1500items,soagoodoptionwastousetheArcGISAPIforPython. Whatdoesthescriptdo? Thisscriptallowsyoutocopyitemsofinterest(inthiscaseMapandImageServices)betweenanAGOLPortalandanEnterprisePortal.Thescriptdoesnotexplicitlycopytheactualitem,insteaditcopiesthekey‘ingredients’thatmakeupthatiteminAGOLe.g.,thetitle,URL,andtypeofitem. HowwouldIgetstarted? YouwillneedtohaveArcGISProinstalledandlicensesonthemachineyouaredevelopingsoyoucanimporttherelevantEsriPythonlibraries,aswellasaPythonIDErunningtheArcGISProPythonenvironment. Thecode Thesectionbelowshowsthestartofthescript.Notethatthevariablesneedtobeconfiguredtoyourspecificsetup.TheAGOLPortalwillbethesource,whileyourlocalArcGISEnterprisewillbethetargetPortal. Fromarcgis.gisimportGIS #localArcGISEnterpriseserviceinformation localUsername=“ENTERPRISEUSERNAME” localPassword=“ENTERPRISEPASSWORD” localPortalServer=“myserver.yourcompanyname.local” localPortalServerPath=“portal” localPortalServerPort=“443” #AGOLserviceinformation agolUsername=“AGOLUSERNAME” agolPassword=“AGOLPASSWORD” ThescriptsectionbelowconnectstothelocalEnterprisePortal.InthiscodeexampleIhaveincluded“verify_cert=False”.Thismaynotbenecessaryforyoursetupasmostlive/productioninstallationswillhaveproperlyconfiguredsecuritycertification–howeverIhadanunsecuredtestEnterprisePortalinstalledandforthecodetoworkIhadtopassthisargument. #connecttothedestinationportalinstance localgis=GIS(“https://”+localPortalServer+“:”+localPortalServerPort+“/”+localPortalServerPath,localUsername,localPassword,verify_cert=False) WhencopyingitemsintothetargetPortal,bydefaulttheitemswillbecopiedintotherootdirectory.Inmostcasesthisisprobablynotideal,soIdecidedtocreateafolderforallcontenttobecopiedto.Ifafolderofsamenamealreadyexiststhennoerroristhrown.Thismeansthatthereisnoneedtocheckforanexistingfolderwiththesamename,andalsothatthecontentsofthefolderwillnotbedeleted. However,thesamecannotbesaidofitemsthatyoucreate(e.g.mapimageorfeaturelayers)–thenamesforwhichshouldbeunique.Later,youwillseethatthecodeskipsitemsiftheyalreadyexistinthetargetdestination. #createfoldertoputcontentinto folder_name=“upload_folder” localgis.content.create_folder(folder_name) NowwearereadytoconnecttothesourcewhichisanAGOLPortal.Onceconnectedwemustgetasessiontoken. #connecttosourceportal(ArcGISOnlineinthiscase) gis=GIS(“https://arcgis.com”,agolUsername,agolPassword) token=gis._con.token Wearegoingtosearchforitemsinthesourceportalwhichhaveatag“Load21”.Youmayuseothersearchcriteriae.g.,searchbytitleorevenURL.Max_itemsisanimportantargumenthere.Thedefaultis1000,whichmaybesufficientforyourneeds.FurtherinformationonsearchoptionscanbefoundintheEsrionlineHelpforContentManager. #searchforitemsinsourceportalthatmatchthetag“Load21″ search_result=gis.content.search(query=”tags:”+‘Load21’,max_items=5000) ThelastpartofthescriptloopsthroughthesearchresultsfromtheAGOLPortalandcheckstoseeiftheitemalreadyexistswithintheEnterprise/targetPortal.Ifthesearchresultcountiszero,thentheitemisaddedusingdataPropsvariable.Thishasbeenpopulatedwiththeitemdetailsharvestedfromthesearchresult.Youneedthisinformationalongwiththetokeninordertoaddtheitem: Title Type URL Asanoptionalargumentwealsopassthefoldernametoplacethenewlycopieditemsinto. #loopthrougheachiteminsearch_resultlistandaddtodestinationPortal foriteminsearch_result: dataProps={‘title’:item.title,‘type’:item.type,‘url’:item.url,‘serviceUsername’:agolUsername,‘servicePassword’:agolPassword,‘token’:token} #checkifitemisalreadyinlocalGISbeforetryingtoadd. local_result=localgis.content.search(query=”title:”+item.title,max_items=1) iflen(local_result)==0: localgis.content.add(item_properties=dataProps,folder=folder_name) print(“Finished”) Conclusion Theprocessforcopyinganitemviasuchscriptingisveryquick–justafewseconds.YoushouldfindthatusingtheArcGISAPIforPythoninthiswaywillsaveyoualotoflaboriousandtediouswork–especiallyifyouhavehundredsorthousandsofitemstocopy. PostedbySimonEarnshaw,GISDeveloper Category: Blog9thNovember2021 RelatedPostsDiagenesis:Akeydiscipline,ThenandNow27thJune2022GetechCommentaryonIEAWorldEnergyInvestmentReport202222ndJune2022MyTop5Featuresinv2.2ofUnconventionalsAnalystforArcGISPro15thJune2022ProbingtheFrontierinNamibia10thMay2022Maptium–Yourgatewaytogeoenergydataandinsight5thMay2022GeologicHistoryinBavariaUncoversPathwaystotheEnergyFuture31stJanuary2022 GotoTop Thiswebsiteusescookiestoimproveyouronlineexperience.PleasereadourupdatedPrivacyPolicytolearnhowwemanageandprotectyourdatainlinewiththenewGDPR.ReadMoreCookiesettingsACCEPTGetechGroupUpdatedPrivacy&CookiesPolicy Close PrivacyOverview Thiswebsiteusescookiestoimproveyourexperiencewhileyounavigatethroughthewebsite.Outofthese,thecookiesthatarecategorizedasnecessaryarestoredonyourbrowserastheyareessentialfortheworkingofbasicfunctionalitiesofthewebsite.Wealsousethird-partycookiesthathelpusanalyzeandunderstandhowyouusethiswebsite.Thesecookieswillbestoredinyourbrowseronlywithyourconsent.Youalsohavetheoptiontoopt-outofthesecookies.Butoptingoutofsomeofthesecookiesmayaffectyourbrowsingexperience. Necessary Necessary AlwaysEnabled Necessarycookiesareabsolutelyessentialforthewebsitetofunctionproperly.Thiscategoryonlyincludescookiesthatensuresbasicfunctionalitiesandsecurityfeaturesofthewebsite.Thesecookiesdonotstoreanypersonalinformation. Non-necessary Non-necessary Anycookiesthatmaynotbeparticularlynecessaryforthewebsitetofunctionandisusedspecificallytocollectuserpersonaldataviaanalytics,ads,otherembeddedcontentsaretermedasnon-necessarycookies.Itismandatorytoprocureuserconsentpriortorunningthesecookiesonyourwebsite. SAVE&ACCEPT
延伸文章資訊
- 1How To: Copy/clone content from one ArcGIS Online ...
Procedure. The following Python script (run from a Jupyter Notebook interface) uses the clone_ite...
- 2Solved: Can you use clone_items to move items from one por...
You can use the Python API to deep clone items and their dependencies using "clone_items" like th...
- 3Error when cloning ArcGIS Portal file based items
I'm trying to set up some ArcGIS Python code (in ArcGIS Pro ... typeKeywords: #Use 'clone_items' ...
- 4Cloning Content | ArcGIS API for Python
clone_items() clones the dependencies for the more complex items listed above. For example, cloni...
- 5Clone_items returns _ItemCreateException #924 - GitHub
I am attempting to clone a group of items in ArcGIS Online that inclues hosted ... OS: Windows 10...