Create gmc and export raster as part of python module

George Chandeep CoreaGeorge Chandeep Corea Global Mapper UserPosts: 62Trusted User
edited October 2012 in GM Script Language
I am in the process of exporting some ESRI based pages to geoPNG to retain symbology so that the output can be served via Geoserver. See http://gis.stackexchange.com/questions/37233/getting-a-constant-background-color-for-transparency

I would like to run the GMS as part of my ESRI based python script. This is my first attempt with GMS...:cool:

import arcpy, os
from subprocess import Popen
arcpy.env=os.getcwd()
name="LS"
mxd = arcpy.mapping.MapDocument("TRC_LS_Landslide_25k.mxd")
try:
    os.mkdir("Stage1\\"+name)
    os.mkdir("Stage1\\"+name+"\\GeoTif")
    os.mkdir("Stage1\\"+name+"\\GeoPNG")
except:
    print "Directory exists"


ddp = mxd.dataDrivenPages
df = arcpy.mapping.ListDataFrames(mxd)[0]
ar = df.extent.height / df.extent.width
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
 mxd.dataDrivenPages.currentPageID = pageNum
 print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
 arcpy.mapping.ExportToTIFF(mxd,"Stage1\\"+name+"\\GeoTif\\"+name+"_"+str(ddp.pageRow.PageName) + ".tif",df,9306,9306*ar,1200,True)
 arcpy.mapping.ExportToPNG(mxd, "Stage1\\"+name+"\\GeoPNG\\"+name+"_"+str(ddp.pageRow.PageName)+".png", df,\
                          df_export_width=9306,\
                          df_export_height=9306*ar,\
                          world_file=True)


del mxd


    p = Popen("merge_GM.bat "+Item+" "+inSPC +" "+SAGA, cwd=top)
    stdout, stderr = p.communicate()


where merge_GM.bat is something like (this example is for using SAGA with python)

[INDENT]@ECHO OFF[/INDENT]
[INDENT]
[/INDENT]
[INDENT]SET SAGA_MLB = %3\Modules[/INDENT]
[INDENT]SET PATH = %PATH%;%3[/INDENT]
[INDENT]
[/INDENT]
[INDENT]saga_cmd pointcloud_tools "Point Cloud Cutter" -AREA=3 -USER_XMIN=0.000000 -USER_XMAX=0.000000 -USER_YMIN=0.000000 -USER_YMAX=0.000000 -GRID_GRID_NX=0 -GRID_GRID_NY=0 -GRID_GRID_X=0.000000 -GRID_GRID_Y=0.000000 -GRID_GRID_D=-1.000000 -EXTENT_EXTENT=NULL -POLYGONS_POLYGONS=%3[/INDENT]

So in GMS I have
[INDENT]GLOBAL_MAPPER_SCRIPT VERSION=1.00
UNLOAD_ALL
[COLOR=#500050]

// Load a projection file to set the global projection - EPSG 90019
[/COLOR]
LOAD_PROJECTION FILENAME="90019.prj"


// Create the map catalog. Maps should show when they take up at least 10% of display.
EDIT_MAP_CATALOG FILENAME="script_catalog.gmc" CREATE_IF_EMPTY=YES \
    ADD_FILE="*.png"
    ZOOM_DISPLAY="PERCENT,0.10,0"
    
// Load the map catalog
IMPORT FILENAME="script_catalog.gmc"


// Export Raster


EXPORT_RASTER FILENAME="merged.jp2"				\
    TYPE=JPEG GEN_WORLD_FILE=YES GEN_PRJ_FILE=YES
[/INDENT]



I GET
Removed all loaded overlays.
Loading new global projection...
WARNING: Unknown command <EDIT_MAP_CATALOG> ignored.
Importing file script_catalog.gmc...
ERROR: File script_catalog.gmc does not exist.
Exporting raster data to file merged.jp2...
ERROR: Data must be loaded for EXPORT_RASTER command.
Script processing COMPLETED.

What's the issue with EDIT_MAP_CATALOG? I am running ver 13.2. We haven't purchased 14 yet.


Like in the python and saga bat file example above I want to run this at the end of the python script and pass the name of the catalog and directory of input files via %1, %2 etc if possible so that the gms runs as part of the arcpy ddp export by merging the tiles and creating a single output file.

Thanks guys


Comments

  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited October 2012
    The EDIT_MAP_CATALOG command wasn't added until v14, so it wouldn't be available in v13.2.

    While there isn't currently a way to pass command line parameters into a script, what you can do is have your Python script create a very simple .gms file with DEFINE_VAR commands at the top to define some variables based on whatever you need, then also have an EMBED_SCRIPT command to then call the main script that actually works with those variables. So your dynamically created script might look like:

    GLOBAL_MAPPER_SCRIPT VERSION="1.00"
    DEFINE_VAR NAME="WORKING_PATH" VALUE="C:\PATH_TO_MY_FILES\"
    EMBED_SCRIPT FILENAME="script.gms"

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Guru
    gmsupport@bluemarblegeo.com
    http://www.globalmapper.com
Sign In or Register to comment.