GM Script. Write the folder name to the attribute

I need a script that does the following:
- import shp files from folder with subfolders
- change projection
- in each shp file I need to add new attribute and write to it the name of the subfolder in which shp located
- export all shp files to one common shp file

Here my no work gm script (attribute "MY_ATTR" is not added. Import and export is done). Please correct my gm script:
GLOBAL_MAPPER_SCRIPT VERSION=1.00

UNLOAD_ALL
IMPORT_DIR_TREE DIRECTORY="C:\Users\Tools\gms\in_3g4g\" FILENAME_MASKS="*.shp"
DEFINE_PROJ PROJ_NAME="MERCAT_WGS84"
Projection MERCATOR
Datum WGS84
Zunits NO
Units METERS
Xshift 0.000000
Yshift 0.000000
Parameters
1.000000000 /* scale factor at central meridian
0 0 0.000 /* central meridian
0 0 0.000 /* latitude of the origin
0.000 /* false easting (meters)
0.000 /* false northing (meters)
END_DEFINE_PROJ
LOAD_PROJECTION PROJ_NAME="MERCAT_WGS84"

LAYER_LOOP_START FILENAME="*"
CALC_ATTR_FORMULA FILENAME="%LAYER_FNAME%" NEW_ATTR="MY_ATTR" FORMULA="%LAYER_PARENT_DIR%"
LAYER_LOOP_END

EXPORT_VECTOR FILENAME="C:\Users\Tools\gms\out\res_3g4g.shp" TYPE=SHAPEFILE SHAPE_TYPE=AREAS GEN_3D_LINES=NO GEN_PRJ_FILE=YES

Answers

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 1,768
    Hello,

    Have you tried using the full path and file name on your CALC_ATTR_FORUMULA command, like this?
    CALC_ATTR_FORUMULA FILENAME="%LAYER_FNAME_W_DIR%" ...
    Cheers,
    Bob
  • oreshnikoreshnik Posts: 2
    Thanks for comments. Change loop strings like this:

    DIR_LOOP_START DIRECTORY="C:\Users\Tools\gms\in_3g4g\" FILENAME_MASKS="*.shp" RECURSE_DIR=YES
    IMPORT FILENAME="%FNAME_W_DIR%" ANTI_ALIAS=YES
    CALC_ATTR_FORMULA FILENAME=%FNAME_W_DIR% NEW_ATTR="MY_ATTR" FORMULA="STR('%PARENT_DIR%')"
    DIR_LOOP_END

    Script started working 
  • BillBBillB Global Mapper User Posts: 83Trusted User
    Oreshnik, parts of your modified script occur in two places in the original script.  Would you mind uploading the entire working script, so we can understand the order of all of the code lines.  Thanks for sharing!
Sign In or Register to comment.