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.

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!

Tagged:

Answers

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 1,834
    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_END
    Note 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!
Sign In or Register to comment.