Welcome to our new forum platform. We realize there is still some work to do and we appreciate your patience. Please let us know if you have any ideas or suggestions: paul@globalmapperforum.com

VPF - Script Convert DNCs to Shapefiles

agenteh2oagenteh2o Global Mapper UserPosts: 17 ✭✭
edited April 2012 in Vector Data
Hello,

I am looking to get some help on how to batch / script convert any edition of DNC data to Shapefiles.

What I would like to do is open the DNC folder (at c:\Data\DNCs\DNCxx\), and recurse through all of the subfolders (the approach, coastal, general, and harbour folders), open the LHT associated with each, the export those as shaperfiles to the following location (c:\Data\SHPs\DNCxx\) and then the appropriate subfolder name from which the data came from.

In the end I would like to have a mirror of the DNC folder structure with Shapefiles.

Also, when doing this manually, I split the shapefiles by type and would like to continue doing that. For each vector type, I would like to use the prefixes: A, L & P for areas, lines and points.

This is not functional yet... but this is what I have so far:

GLOBAL_MAPPER_SCRIPT VERSION=1.00
UNLOAD_ALL
DIR_LOOP_START DIRECTORY="C:\DATA\DNCs\DNC17" FILENAME_MASKS="LHT" RECURSE_DIR=YES
IMPORT FILENAME="%FNAME_W_DIR%" TYPE="VPF"
EXPORT_VECTOR FILENAME="%FNAME_W_DIR%\A" TYPE=SHAPEFILE SHAPE_TYPE=AREAS SPLIT_BY_LAYER
EXPORT_VECTOR FILENAME="%FNAME_W_DIR%\L" TYPE=SHAPEFILE SHAPE_TYPE=LINES SPLIT_BY_LAYER
EXPORT_VECTOR FILENAME="%FNAME_W_DIR%\P" TYPE=SHAPEFILE SHAPE_TYPE=POINTS SPLIT_BY_LAYER
UNLOAD_ALL
DIR_LOOP_END

I am using GM v13.1.

Thanks for any help.

Comments

  • global_mapperglobal_mapper Administrator Posts: 17,238BMG Staff
    edited March 2012
    You are close, I think you just want to change your output filenames to look like:

    FILENAME="%DIR%A\.SHP"

    So if your layer was "ocean" it would end up like "c:\data\DNCs\DNC12\A\ocean.shp". The one piece that is missing is the changing of the path tree. You can't currently do that, but I think I could add support for some kind of output path replace string, like PATH_REPLACE="DNCs=SHPs" or something like that to replace one string in your path with another. Would that work?

    Thanks,

    Mike
    Global Mapper Guru
    gmsupport@bluemarblegeo.com
    http://www.globalmapper.com
  • agenteh2oagenteh2o Global Mapper User Posts: 17 ✭✭
    edited March 2012
    Yes I think the PATH_REPLACE option you suggested would work very well.

    Also, thanks for the help with the script but it is not quite working right. I would like to run the script on the root of the directory and have it output the shapefiles for every layer and split them. For example, I would like to load all of the features in the A1731740 subfolder that the LHT file is located in and then split the export into every different type. Manually when I load the files into GM I can export vectors and choose the "Split Export based on:" and choose <Feature Type> from the drop down menu.
  • agenteh2oagenteh2o Global Mapper User Posts: 17 ✭✭
    edited March 2012
    Ooops solved the problem... I needed to say SPLIT_BY_LAYER=YES instead of just SPLIT_BY_LAYER.

    Also, how can I get this script to run and load all of the VPF layers automatically for each without prompting the user for that detail. I tried:
    IMPORT FILENAME="%FNAME_W_DIR%" TYPE="VPF" PROMPT_IF_TYPE_UNKNOWN=NO
    but that did not work.

    I assume there must be a way in the IMPORT FILENAME to have it auto load all types.
  • global_mapperglobal_mapper Administrator Posts: 17,238BMG Staff
    edited March 2012
    I have updated the DEFINE_VAR script command to support a REPLACE_STR parameter, so inside your loop you can define a variable whose value is the path you want with the path replaced, like the following:

    DEFINE_VAR NAME="OUT_FNAME" VALUE="%FNAME_WO_DIR%" REPLACE_STR="DNCs=SHPs"

    I have placed a new build at http://www.globalmapper.com/global_mapper13.zip with the latest changes for you to try. Simply download that file and extract the contents into your existing v13.xx installation folder to give it a try. If you are using the 64-bit v13 version there is a new build at http://www.globalmapper.com/global_mapper13_64bit.zip .

    For VPF to load with everything, try adding LOAD_FLAGS="COVERAGES=*" to your IMPORT command.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Guru
    gmsupport@bluemarblegeo.com
    http://www.globalmapper.com
  • agenteh2oagenteh2o Global Mapper User Posts: 17 ✭✭
    edited March 2012
    Mike,

    Thanks for all your help...

    I tried your script suggestion but when the script ran I received the following error:

    WARNING: Error loading VPF library data.
    No library with the name COVERAGES=* found.

    I also tried LOAD_FLAGS="COVERAGES='*'" and LOAD_FLAGS="COVERAGES-ALL" to no avail.

    I haven't tried the new build yet but will soon.

    Thank you.
  • agenteh2oagenteh2o Global Mapper User Posts: 17 ✭✭
    edited March 2012
    Hi Mike,

    I installed the new build and ran the script:

    GLOBAL_MAPPER_SCRIPT VERSION=1.00
    UNLOAD_ALL
    DIR_LOOP_START DIRECTORY="C:\DATA\MAPS\DNCs\DNC20" FILENAME_MASKS="LHT" RECURSE_DIR=YES
    IMPORT FILENAME="%FNAME_W_DIR%" TYPE="VPF"
    DEFINE_VAR NAME="OUT_FNAME" VALUE="%FNAME_WO_DIR%" REPLACE_STR="DNCs=SHPs"
    EXPORT_VECTOR FILENAME="%OUT_FNAME%\A_.SHP" TYPE=SHAPEFILE SHAPE_TYPE=AREAS SPLIT_BY_LAYER=YES
    EXPORT_VECTOR FILENAME="%OUT_FNAME%\L_.SHP" TYPE=SHAPEFILE SHAPE_TYPE=LINES SPLIT_BY_LAYER=YES
    EXPORT_VECTOR FILENAME="%OUT_FNAME%\P_.SHP" TYPE=SHAPEFILE SHAPE_TYPE=POINTS SPLIT_BY_LAYER=YES
    UNLOAD_ALL
    DIR_LOOP_END

    and ended up with the files in a directory called:

    C:\Data\Maps\%FNAME_WO_DIR%

    that had the shapefiles in them. Am I doing something wrong?

    Thanks.
  • global_mapperglobal_mapper Administrator Posts: 17,238BMG Staff
    edited March 2012
    Sorry my sample is bad. There is no loop variable named %FNAME_WO_DIR%, it is just %DIR%.

    Thanks,

    Mike
    Global Mapper Guru
    gmsupport@bluemarblegeo.com
    http://www.globalmapper.com
  • global_mapperglobal_mapper Administrator Posts: 17,238BMG Staff
    edited March 2012
    Sorry I forgot you have to add some extra stuff in there to simulate quotes in the load flags. Try LOAD_FLAGS="COVERAGES=''*''". Note that there are 2 consecutive ' characters inside the value around the * and not direct quote marks.
  • agenteh2oagenteh2o Global Mapper User Posts: 17 ✭✭
    edited April 2012
    You rock Mike. That works perfectly. Thank you.
Sign In or Register to comment.