For DNC VPF, Export Vector only IF....

KotastrophyKotastrophy Posts: 4
edited March 2016 in GM Script Language
Hey all, am new to GM Scripting.. 

My input is a VPF directory of DNC data. The below code works fine for me when I remove the three lines of IF / ELSE / END_IF. But without those lines, I get a bunch of extra file outputs that I do not want. With this code, I'm trying to export just the features that have the <Feature Type> "Buoy" (hence my attempt at a IF COMPARE_STR scenario). 

The code below gives me no outputs.

Am I going about this the correct way? Or are there usage / syntax issues?

---


GLOBAL_MAPPER_SCRIPT VERSION=1.00
UNLOAD_ALL

DIR_LOOP_START DIRECTORY="C:\location\DNCFOLDER" FILENAME_MASKS="LHT" RECURSE_DIR=YES
IMPORT FILENAME="%FNAME_W_DIR%" TYPE="VPF" LOAD_FLAGS="COVERAGES=''Aids to Navigation, Obstructions''"
DEFINE_VAR NAME="OUT_FNAME" VALUE="%DIR%" REPLACE_STR="C:\location\DNCFOLDER=C:\location\DNCFOLDER_EXPORT"
LOAD_PROJECTION FILENAME="C:\location\WGS 1984.prj" 

IF COMPARE_STR="<Feature Type>=Buoy"
EXPORT_VECTOR FILENAME="%OUT_FNAME%\.shp" TYPE=SHAPEFILE SHAPE_TYPE=POINTS GEN_PRJ_FILE=YES  SPLIT_BY_LAYER=YES
ELSE
END_IF

UNLOAD_ALL
DIR_LOOP_END







Best Answers

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,180
    Answer ✓
    Hello,

    The DIR_LOOP command allows you to iterate over each layer that is loaded, but not over each feature.  To iterate the features, you need to use EDIT_VECTOR.  In your case, you will probably want to use EDIT_VECTOR to copy your desired features to a new layer, something like this would replace your IF/ELSE/END_IF block:

    // Copy "Buoy" features to a new layer
    EDIT_VECTOR COMPARE_STR="<Feature Type>=Buoy" \
                          COPY_TO_NEW_LAYER=YES NEW_LAYER_NAME="BUOY_FEATURES"
    // Export the "Buoy" features
    EXPORT_VECTOR EXPORT_LAYER="BUOY_FEATURES" // other export parameters go here
    UNLOAD_ALL

    Cheers,

    Bob
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,180
    Answer ✓
    Hello,

    Try this:
    COMPARE_STR="DESCRIPTION=Buoy"
    The "<" and ">" are only used to identify special feature values, such as Feature Type, that are not actually stored on the feature as attributes.

    Cheers,

    Bob

Answers

  • I also tried setting <Feature Type> as a variable first, but to no avail.. unless I've set this wrong too.  :o

    DEFINE_VAR NAME="FEATURE_TYPE" VALUE="<Feature Type>"

    IF COMPARE_STR="%FEATURE_TYPE%=Buoy"
  • That worked a treat and I was able to get it to work just fine with the following code. 

    However I now need to parse via an actual attribute field, where the value is the same (Buoy). And I'm having trouble getting it to work... the attribute field name is called Description, but if I simply replace <Feature Type> with <Description> in the below code, nothing happens.... any ideas? Is the syntax different when pointing to a regular attribute field? 



    GLOBAL_MAPPER_SCRIPT VERSION=1.00
    UNLOAD_ALL

    DIR_LOOP_START DIRECTORY="C:\location\DNCFOLDER" FILENAME_MASKS="LHT" RECURSE_DIR=YES

    IMPORT FILENAME="%FNAME_W_DIR%" TYPE="VPF" LOAD_FLAGS="COVERAGES=''Aids to Navigation''"

    DEFINE_VAR NAME="OUT_FNAME" VALUE="%DIR%" REPLACE_STR="C:\location\DNCFOLDER=C:\location\DNCFOLDER_EXPORT"

    LOAD_PROJECTION FILENAME="C:\location\WGS 1984.prj" 


    // Copy "Buoy" features to a new layer
    EDIT_VECTOR COMPARE_STR="<Feature Type>=Buoy" \
                          COPY_TO_NEW_LAYER=YES NEW_LAYER_NAME="BUOY_FEATURES"
    // Export the "Buoy" features
    EXPORT_VECTOR EXPORT_LAYER="BUOY_FEATURES" FILENAME="%OUT_FNAME%\.shp" TYPE=SHAPEFILE SHAPE_TYPE=POINTS GEN_PRJ_FILE=YES SPLIT_BY_LAYER=YES


    UNLOAD_ALL
    DIR_LOOP_END
  • Gotcha! I made a really nice script out of this, thank you so much for the help. It's working great. :) 
Sign In or Register to comment.