How to publish MDCS as a Geoprocessing Service on ArcGIS server

2179
3
03-11-2014 02:01 PM
SowmyaTiramdasu
New Contributor
Hi,

I am very new to ARCGIS and also Geo processing. I am trying to import the MDCS scripts in to Model Builder, execute it as a task and then publish the results in to ArcGIS server as a Geo processing service. Can anyone give me pointers on how to do it ?

http://www.arcgis.com/home/item.html?id=d1289a749b59477cb82228a09d1d0219 - These are the scripts I am referring to.

Thanks,
Sowmya.
0 Kudos
3 Replies
RebeccaStrauch__GISP
MVP Emeritus

Old thread, but since I'm just being exposed to this (right now)....first, I noticed that the github download and the AGOL version are different....the one you get using the Open-Download seems to be more complete (includes demo data)

The readme.md file mentions

  1. Download and unzip the .zip file.
  2. Create a folder called Image_Mgmt_Workflow in the root of c: drive.
  3. Create a project folder in Image_Mgmt_Workflows
  4. Copy content of zip file to the project folder.

I unzipped and made sure to move the files directly under that folder (although may not really matter)

It's set up to work with 10.1 or 10.2, so to get this to work with 10.3, if needed you need to edit the c:\Image_Mgmt_Workflow\Initialize_Script_Paths.bat file (right click and edit using a text editor like NotePad+ or Wordpad).  Add reference to 10.3 (assuming default install)  I added lines 18-25 below...  This doesn't appear to be a deal breaker, but may help if you have 10.3 installed but never had 10.2 installed.

@echo off
set var=%cd%

rem This batch file will initialize the ArcGIS version number the sample files.
rem It will also set the current folder as the working folder in the batch files and script files. 

IF EXIST c:\python27\arcgis10.1\python.exe (

set id=10.1
goto :RunReplace
) 

IF EXIST c:\python27\arcgis10.2\python.exe (

set id=10.2
goto :RunReplace

)

IF EXIST c:\python27\arcgis10.3\python.exe (

set id=10.3
goto :RunReplace

)

goto :ShowError

:RunReplace
c:\python27\arcgis%id%\python.exe %var%\scripts\search_replace.py %var%\batchFiles arcgisVer arcgis%id% *.bat
c:\python27\arcgis%id%\python.exe %var%\scripts\search_replace.py %var%\batchFiles currFolder %var% *.bat
c:\python27\arcgis%id%\python.exe %var%\scripts\search_replace.py %var%\Parameter\Config currFolder %var% *.xml

copy /y nul Reset_Script_Paths.bat
echo @echo off
echo @echo This batch file was automatically created after successfully executing Intialize_Script_Paths.bat. >Reset_Script_Paths.bat
echo. >>Reset_Script_Paths.bat
echo @echo This batch file will reset the ArcGIS version number and current folder location to be used by the Sample files. >>Reset_Script_Paths.bat
echo @echo The batch files will be reset to the state when you first downloaded the batch file. >>Reset_Script_Paths.bat
echo @echo Type Ctrl + C to cancel execution. >>Reset_Script_Paths.bat  
echo pause >>Reset_Script_Paths.bat  
echo. >>Reset_Script_Paths.bat  
echo c:\python27\arcgis%id%\python.exe %var%\scripts\search_replace.py %var%\batchFiles arcgis%id% arcgisVer *.bat >>Reset_Script_Paths.bat
echo. >>Reset_Script_Paths.bat
echo c:\python27\arcgis%id%\python.exe %var%\scripts\search_replace.py %var%\batchFiles %var% currFolder *.bat >>Reset_Script_Paths.bat
echo. >>Reset_Script_Paths.bat
echo c:\python27\arcgis%id%\python.exe %var%\scripts\search_replace.py %var%\Parameter\Config %var% currFolder *.xml >>Reset_Script_Paths.bat
echo pause >>Reset_Script_Paths.bat  

ECHO "Successfully set ArcGIS version number to %id%."
ECHO "Successfully set sample paths to %var%."
goto :endofbatch 

:ShowError
ECHO "ERROR: Could not find Python Install Location in C:\python27\"

:endofbatch
pause

Then to be able to run the included demo, you need to edit the c:\Image_Mgmt_Workflow\BatchFiles\Amberg1.bat file (use a text editor again) to update your paths ...mine looks like:

@echo off
echo Calling MDCS for Amberg1.
c:\Python27\ArcGIS10.3\python.exe ..\Scripts\mdcs.py -i:..\Parameter\Config\Amberg1.xml
pause

I change the path to be ArcGIS10.3 (for mine) ....and the "currentpath" notation to ..  (two periods, DOS-speak for up-one-folder-level) but you can hardcode the path if you want.

EDIT: one more change....hardcode the path to the Data folder in the C:\Image_Mgmt_Workflow\Parameter\Config\Amberg1.xml file about line 19 ..make path name appropriate

<data_path>C:\Image_Mgmt_Workflow\Data\Amberg</data_path>

I then double-clicked on the Amberg1.bat file and the demo script ran.  This created the demo mosaic dataset in C:\Image_Mgmt_Workflow\MD\Amberg.gdb

If the mosaic dataset is empty and the overviews are not creted, check you log in C:\Image_Mgmt_Workflow\Logs  folder....that will give you a clue if there is a path name issue anyway.

I wanted to document this for myself...comments are closed on the AGOL page.  Your GeoNet question here was the first (and only GeoNet question) that came up for me when I was searching for the download....so figured I would put the info here.

Note: the demo that is being shown to us is showing a DLL error.....no solution for that, but for me it was a new install for the script.

EDIT:  I got it to work.  A few edits are above from my first post.  This just gets the demo to work....I still have to figure out how to do it in production.

0 Kudos
MoritzHackenberg
New Contributor II

It can be done with a toolbox, importing MDCS.py and calling it's main()-function with the two parameters

main(len(list), list)

The list needs to have at least 2 elements, one of them being the path to the xml file (because the command line or batch file delivers the mdcs.py path as one parameter). The execute script of the toolbox could be:

 

import sys
sys.path.insert(0, '...\mdcs-folder\scripts')
import arcpy
import MDCS
from pathlib import Path
import os

def ScriptTool(param0):
    config = "...\mdcs-folder\Parameter\Config\name.xml")).as_posix() 
    list = ["x", f"-i:{config}"]
    argc = len(liste)
    MDCS.main(argc, list)
    pass
    
if __name__ == '__main__':
    ordner_neue_Raster = arcpy.GetParameterAsText(0)
    ScriptTool(param0)
    

 

Half the answer is also given in this video at 23:14, but the script is not shown entirely...but it is propably more elegant.

https://mediaspace.esri.com/meia/t/1_q98qok22

 

 

0 Kudos
MoritzHackenberg
New Contributor II

my problem now is that I get "\Footprints is not registered with the server"

and "tool calculate field cannot use VB expressions as a service", when trying to publish a very simple MDCS with only Create MD and Add Rasters. What do I need to do?

0 Kudos