Batch Clip Polygons with Polylines Using DIR_LOOP Script
I am having problems getting my script to work.
I have a directory with a set of polygon .shp files, and another directory with a set of polyline .shp files. I want the script to load in the polygon file, load in the polyline file, and then export out the polygons clipped by the intersection of the polylines. The filename of the polygon is the same filename of the polyline, but they reside in two different folders.
I have a directory with a set of polygon .shp files, and another directory with a set of polyline .shp files. I want the script to load in the polygon file, load in the polyline file, and then export out the polygons clipped by the intersection of the polylines. The filename of the polygon is the same filename of the polyline, but they reside in two different folders.
UNLOAD ALL
DIR_LOOP_START DIRECTORY="D:\Prototype\Polygons" FILENAME_MASKS="*.shp" TYPE=SHAPEFILE
IMPORT FILENAME="%FNAME_W_DIR%"
DIR_LOOP_START DIRECTORY="D:\Prototype\Polylines" FILENAME_MASKS="*.shp" TYPE=SHAPEFILE
IMPORT FILENAME="%FNAME_W_DIR%"
CROP_AREAS_TO_LINES AREA_FILENAME="D:\Prototype\Polygons\%FNAME_WO_EXT%.shp" LIST_FILENAME="D:\Prototype\Polylines\%FNAME_WO_EXT%.shp"
EXPORT_VECTOR FILENAME="D:\Prototype\Clipped\%FNAME_WO_EXT%_cropped.shp" TYPE=SHAPEFILE SHAPE_TYPE=AREAS GEN_PRJ_FILE="YES"
UNLOAD_ALL
DIR_LOOP_END
I am unsure of the proper syntax to call two separate directories to load in the files in a directory loop.
Any help is greatly appreciated!
I am unsure of the proper syntax to call two separate directories to load in the files in a directory loop.
Any help is greatly appreciated!
Tagged:
Answers
-
Hello,
You indicated that the file names in the two directories are the same, so you only need to loop through one of them, being sure to use the other directory where appropriate. Something like this ought to work:UNLOAD ALL
DEFINE_VAR NAME="POLYLINE_DIR" VALUE="D:\Prototype\Polylines"
DIR_LOOP_START DIRECTORY="D:\Prototype\Polygons" FILENAME_MASKS="*.shp"
IMPORT FILENAME="%FNAME_W_DIR%" TYPE="SHAPEFILE"
IMPORT FILENAME="%POLYLINE_DIR%\%FNAME%" TYPE="SHAPEFILE"
CROP_AREAS_TO_LINES AREA_FILENAME="%FNAME_W_DIR%" LINE_FILENAME="%POLYLINE_DIR%\%FNAME%"
EXPORT_VECTOR FILENAME="D:\Prototype\Clipped\%FNAME_WO_EXT%_cropped.shp" TYPE=SHAPEFILE SHAPE_TYPE=AREAS GEN_PRJ_FILE="YES"
UNLOAD_ALL
DIR_LOOP_ENDNote that although the documentation for CROP_AREAS_TO_LINES indicates a parameter called LIST_FILENAME, it should actually be LINE_FILENAME. This is a typo in the documentation.
Cheers,
Bob -
Thank you so much Bob! I will give this a try.
-
It worked great, thanks again Bob!
Categories
- 13K All Categories
- 5.8K Features Discussion
- 350 Downloading Imagery
- 1.3K Elevation Data
- 385 Georeferencing Imagery Discussion
- 652 GM Script Language
- 56 User Scripts
- 115 GPS Features
- 421 Projection Questions
- 835 Raster Data
- 1.4K Vector Data
- 6.7K Support
- 181 Announcement and News
- 939 Bug Report
- 562 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 579 Other Discussion
- 132 GIS Data Sources
- 27 Global Mapper Showcase
- 244 How I use Global Mapper
- 110 Global Mapper Forum Website

