Global Mapper v25.0

scripting/SDK? - select entities based on attribute value and export a subset to file

timhoman
timhoman Global Mapper UserTrusted User
edited March 2010 in Technical Support
Is it possible to create a subset of entities based on the search criteria for a specific attribute(s)? YES... I've done it within GM manually.

Now...
Is it possible to automate this process? Yes/No?
How? Scripting and/or SDK?

Specifically, I would like to disassemble an S-57 (ENC) file into individual shapefiles (kml, etc.) based on <feature_type> (or any attribute) values.

Thanks,
Tim

Comments

  • global_mapper
    global_mapper Administrator
    edited March 2010
    Tim,

    Yes, you can split an export on type/layer or attribute value using the EXPORT_VECTOR command and the following parameters:

    # SPLIT_BY_LAYER (SHAPEFILE only) - specifies that the export should generate a separate Shapefile for each layer/type in the input data
    # SPLIT_BY_ATTR - specifies that the export should generate a separate file for each set of attributes values in the input data. Use the FILENAME_ATTR_LIST and FILENAME_INCLUDE_ATTR_NAME parameters to control which attributes are compared to and in what order and how the filename is generated from those attributes and their values. Use SPLIT_BY_ATTR=YES to split your export so that all features with the same values for each of the specified attributes is in the same file.
    # FILENAME_ATTR_LIST - contains a comma-delimited list of attributes to use when naming files exported when using the SPLIT_BY_ATTR=YES parameter.
    # FILENAME_INCLUDE_ATTR_NAME - specifies that the attribute name specified in the FILENAME_ATTR_LIST parameter should be included as part of the filename when using SPLIT_BY_ATTR=YES to split your export into a separate file for each set of attributes.

    With the SDK of course you can basically do whatever you want, but it requires more programming and an additional purchase.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • timhoman
    timhoman Global Mapper User Trusted User
    edited March 2010
    Mike -
    Thanks - GM Rocks!

    From within GM I select the "export vector data" dialog and chose "Split on Feature Description" and meet with some success. However, I am having difficulty with the script...

    Below is the script I created --- the results are a single file.

    GLOBAL_MAPPER_SCRIPT VERSION=1.00
    UNLOAD_ALL
    IMPORT FILENAME="C:\temp\US5FL11M\US5FL11M.000" \
    TYPE=S57
    EXPORT_VECTOR FILENAME="C:\temp\test1.shp" \
    TYPE=SHAPEFILE \
    // SHAPE_TYPE=AREAS \
    // SHAPE_TYPE=LINES \
    SHAPE_TYPE=POINTS \
    GEN_PRJ_FILE=YES \
    SPLIT_BY_ATTR=YES \
    FILENAME_ATTR_LIST="<Feature Name>" \
    FILENAME_INCLUDE_ATTR_NAME

    I don't believe it likes the value "<Feature Name>".
    Any suggestions?

    Thanks,
    Tim
  • global_mapper
    global_mapper Administrator
    edited March 2010
    Tim,

    Actually that looks good for splitting on the display label for features. Do your features actually have display labels though? You also need to use FILENAME_INCLUDE_ATTR_NAME=YES to enable adding the attribute name to the filename, but I'm guessing you actually don't want that for the display label.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • timhoman
    timhoman Global Mapper User Trusted User
    edited March 2010
    Mike,

    When I load the S-57 file and click on the button with the binoculars (search...) the table that is displayed has the 2nd column labeled "<Feature Type>" - this the attribute I would like split by values ... Please note that in my previous replies I was stated the attribute label as "<Feature Name>" to avoid confusion about the entity types (Polygons, Lines, Shapes). The "<Feature Type>" column shows the values by which I wish to name the files... I'm still getting a single file.


    --
    Thanks,
    Tim
  • global_mapper
    global_mapper Administrator
    edited March 2010
    Tim,

    You should be able to use "<Feature Desc>" or "<Feature Type>" to split by the type or description. Can you maybe post your actual .gms file so that I can take a look? Also can you remove the two comment lines from the EXPORT_VECTOR command? They might be causing issues inside of a command, although I don't think so. Finally, if you run your script with the File->Run Script command do you get any errors?

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • timhoman
    timhoman Global Mapper User Trusted User
    edited March 2010
    Mike,

    GM v11.02

    The result for each of the three SHAPE_TYPE's is a single shapefile.

    Here is the actual script:

    GLOBAL_MAPPER_SCRIPT VERSION=1.00
    UNLOAD_ALL
    IMPORT FILENAME="C:\temp\US5FL11M\US5FL11M.000" \
    TYPE=S57
    EXPORT_VECTOR FILENAME="C:\temp\test1.shp" \
    TYPE=SHAPEFILE \
    SHAPE_TYPE=AREAS \
    GEN_PRJ_FILE=YES \
    SPLIT_BY_ATTR=YES \
    FILENAME_ATTR_LIST="<Feature Type>"

    Here are the "script results" when I run the script:

    Removed all loaded overlays.
    Importing file C:\temp\US5FL11M\US5FL11M.000...
    Exporting vector data to file C:\temp\test1.shp...
    Exporting vector data from feature to file C:\temp\TEST1.shp...
    Script processing COMPLETED.

    --
    Tim
  • global_mapper
    global_mapper Administrator
    edited March 2010
    Tim,

    I took a look and discovered the problem when splitting from a script against a feature name, type, or description and was able to fix it. I have placed a new build at http://www.globalmapper.com/global_mapper11.zip with the change for you to try. Simply download that file and extract the contents into your existing v11.xx installation folder to give it a try. If you are using the 64-bit version, there is a new build available at http://www.globalmapper.com/global_mapper11_64bit.zip .

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • timhoman
    timhoman Global Mapper User Trusted User
    edited March 2010
    Mike,

    IT WORKS!

    Thank you very much.

    --
    Tim
  • timhoman
    timhoman Global Mapper User Trusted User
    edited March 2010
    Mike,

    It appears that I am able to successfully apply the EXPORT_VECTOR with SPLIT_BY_ATTR to <Feature Name> and <Feature Type>.

    However, when applying the script to <Description> only a single file is generated.

    --
    Tim
  • global_mapper
    global_mapper Administrator
    edited March 2010
    Tim,

    For description use <Feature Desc> as the field name, not <Description>.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • timhoman
    timhoman Global Mapper User Trusted User
    edited March 2010
    OK - that works... BUT...

    It's a little confusing since the columns header is labeled <Description> when using the Binoculars (Search) tool.

    Thanks,
    Tim
  • global_mapper
    global_mapper Administrator
    edited March 2010
    Tim,

    Yeah I suppose I could make it work either way, but it is documented correctly in the script reference!

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com