How to export vectors with custom options?! (Python API)
I'm exporting features from Global Mapper Workspace to shapefile and I need to export the Feature Type as an attribute (for future queries). I'm working with GlobalMapper Python SDK and running my script in a Python environment.
Reading docs (https://www.bluemarblegeo.com/knowledgebase/global-mapper-python-23/Enumerations/EnumExport.html): "use GM_ExportOptsSHP_t for aFormatOptions parameter to GM_ExportVector", GM_ExportOptsSHP_t class itself has 3 attributes (mAddLabelAttr, mAddLayerAttr and mAddStyleAttr that should include GM_TYPE, label, etc to the exported dbf) but the aFormatOptions parameter only accepts integer values and the GM_ExportOptsSHP_t class seems to have no method to return an int.
Here is a code example:
exported_features = []
# Load all layers from file
err, array_ptr, array_size = gm.LoadLayerList(workspace_path, gm.GM_LoadFlags_UseDefaultLoadOpts)
if err:
quit()
all_layers = gm.GM_LayerHandle_array_frompointer(array_ptr)
# Vector layers only
vector_layers = []
for layer in gm.carray_to_list(all_layers, array_size):
if gm.GetLayerInfo(layer).mHasVectorData:
vector_layers.append(layer)
for layer in vector_layers:
name = gm.GetLayerInfo(layer).mDescription
name_wo_ext = name[:name.index(".")] if "." in name else name
destination = os.path.join(target_dir, name_wo_ext) + ".shp"
# Export all layer content
err = gm.ExportVector(
aFilename=destination,
aFormat=gm.GM_Export_Shapefile,
aLayer=layer,
aWorldBounds=None,
aFlags=gm.GM_VectorExportFlags_GenPRJFile + gm.GM_VectorExportFlags_ExportAll + gm.GM_VectorExportFlags_ExportAttrs,
aFormatOptions=0x0
)
if not err:
exported_features.append(name_wo_ext)
else:
print(err)
print(exported_features)
How can i use GM_ExportOptsSHP_t in this example? Is there any workaround to include the <Feature Type> inside attributes?!
Thanks 😉
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
