For DNC VPF, Export Vector only IF....
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?
---
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
Answers
-
I also tried setting <Feature Type> as a variable first, but to no avail.. unless I've set this wrong too.DEFINE_VAR NAME="FEATURE_TYPE" VALUE="<Feature Type>"IF COMPARE_STR="%FEATURE_TYPE%=Buoy"
-
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
Cheers,
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
Bob -
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.00UNLOAD_ALLDIR_LOOP_START DIRECTORY="C:\location\DNCFOLDER" FILENAME_MASKS="LHT" RECURSE_DIR=YESIMPORT 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 layerEDIT_VECTOR COMPARE_STR="<Feature Type>=Buoy" \COPY_TO_NEW_LAYER=YES NEW_LAYER_NAME="BUOY_FEATURES"// Export the "Buoy" featuresEXPORT_VECTOR EXPORT_LAYER="BUOY_FEATURES" FILENAME="%OUT_FNAME%\.shp" TYPE=SHAPEFILE SHAPE_TYPE=POINTS GEN_PRJ_FILE=YES SPLIT_BY_LAYER=YESUNLOAD_ALLDIR_LOOP_END -
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
-
Gotcha! I made a really nice script out of this, thank you so much for the help. It's working great.
Categories
- 12.7K All Categories
- 5.6K Features Discussion
- 342 Downloading Imagery
- 1.3K Elevation Data
- 380 Georeferencing Imagery Discussion
- 628 GM Script Language
- 53 User Scripts
- 113 GPS Features
- 414 Projection Questions
- 819 Raster Data
- 1.3K Vector Data
- 6.6K Support
- 177 Announcement and News
- 908 Bug Report
- 558 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 562 Other Discussion
- 129 GIS Data Sources
- 27 Global Mapper Showcase
- 233 How I use Global Mapper
- 107 Global Mapper Forum Website