Asking for existing layers to export
kalosh74
Global Mapper UserTrusted User
in User Scripts
Dear all,
I am working in a script trying to put some shape file data from ICC source (Catalonian Cartography Institute) in osm files for a gps navigator device.
To make intermediate treatment to polylines I use CAD processing, so I use dwg as intermeditate format for the files.
This shapes have the routing layers (all kind of roads and railroads)
The structure of the layers is a little bit complex, the use "CAS" attibute, to divide the shape in about 200 layers designed for routing lines.
But some roads have shared layers, so the only way to separate data is using another existing attribute "CFUNC_VIA", that make another separation of data. We have to apply this "CFUNC_VIA" first, and then "CAS" to separate the layers as desired groups.
I have 305 tiles to process, so I use DIR_LOOP_START and DIR_LOOP_END for all files processing.
To make the final osm format I use 10 kind of LINE_TYPE for the main layers groups. Every LINE_TYPE corresponds to a specific layer tag in the osm file. I put both in the following list:
OSM tag sample - Global mapper LINE-TYPE
- <tag k="railway" v="rail"/> - Railroad
- <tag k="highway" v="motorway"/> - Interstate
- <tag k="highway" v="trunk"/> - Major/US Highway
- <tag k="highway" v="primary"/> - State Highway
- <tag k="highway" v="secondary"/> - Arterial Road
- <tag k="highway" v="tertiary"/> - Collector Road
- <tag k="highway" v="service"/> - Alley or Driveway
- <tag k="highway" v="residential"/> - Residential Road
- <tag k="highway" v="track"/> - Unpaved Road
- <tag k="highway" v="footway"/> - not found in global mapper (I use "Trail" instead but it's not real)
The first problem I find is how to make a line type to add the missing tag "highway-footway". For now I have to use a different layer but I have to assume this is not correct.
The next question is about the content of the shapes, obviously, not all 305 parts have "Interstate" lines, or "Railroad" lines, some areas have only 2 or 3 type of lines from the list above.
Because I have to be sure I export all possible layers, I export all of them in the script with this code (only one layer shown in the sample to simplify):
...
GLOBAL_MAPPER_SCRIPT VERSION="1.00"
UNLOAD_ALL
DIR_LOOP_START DIRECTORY="C:\SHP\" FILENAME_MASKS="*.SHP" RECURSE_DIR=NO
UNLOAD_ALL
IMPORT FILENAME="%FNAME_W_DIR%" TYPE=SHAPEFILE
//Two split layers needed to identify all 10 layers groups of layers
SPLIT_LAYER FILENAME=* SPLIT_BY_ATTR="CFUNC_VIA" LAYER_DESC_ATTR_ONLY
SPLIT_LAYER FILENAME=* SPLIT_BY_ATTR="CAS" LAYER_DESC_ATTR_ONLY
//Railroad sample (all layers that have the text "FER")
EXPORT_VECTOR FILENAME="C:\SHP\%FNAME_WO_EXT%_Railroad.dwg" \
TYPE=DWG ALLOW_LONG_LABELS=YES EXPORT_DWG_LABELS=NO VERSION=R27 \
LAYER_ATTR="<Feature Layer Name>" GEN_PRJ_FILE=YES EXPORT_ELEV=NO \
EXPORT_LAYER="*FER*" SHOW_WARNINGS=NO
//The rest of layer groups are not shown in this sample
UNLOAD_ALL
DIR_LOOP_END
UNLOAD_ALL
...
When I do this at the end of the script process, Global Mapper always sends a warning message:
----
The following errors were generated loading the workspace file:
ERROR: Vector data must be loaded for EXPORT_VECTOR command.
----
The last line of this message is repeated for every case in the 10 layer group export x 305 files mismatch. So is very large and produce a strange behaviour in the screen when global mapper finishes the script.
To solve this problem I tried to include the EXPORT_VECTOR in a conditional structure, but I can not find in the "Global Mapper Scripting Reference" the way to use it.
I have tried several COMPARE_STR samples with no success. The logical one shoud be this:
....
IF COMPARE_STR="FILENAME=*FER*"
...
END_IF
....
Knowing the existing layers of the shape before exporting them, is needed to avoid the "ERROR" message.
I wonder is possible to make both, create a LINE_TYPE for the "highway-footway", and using some COMPARE_STR for the conditional structure.
I send attached a zip with 2 of the 305 parts, one with the full layer groups, and one with only 2.
Regards,
Carlos.
I am working in a script trying to put some shape file data from ICC source (Catalonian Cartography Institute) in osm files for a gps navigator device.
To make intermediate treatment to polylines I use CAD processing, so I use dwg as intermeditate format for the files.
This shapes have the routing layers (all kind of roads and railroads)
The structure of the layers is a little bit complex, the use "CAS" attibute, to divide the shape in about 200 layers designed for routing lines.
But some roads have shared layers, so the only way to separate data is using another existing attribute "CFUNC_VIA", that make another separation of data. We have to apply this "CFUNC_VIA" first, and then "CAS" to separate the layers as desired groups.
I have 305 tiles to process, so I use DIR_LOOP_START and DIR_LOOP_END for all files processing.
To make the final osm format I use 10 kind of LINE_TYPE for the main layers groups. Every LINE_TYPE corresponds to a specific layer tag in the osm file. I put both in the following list:
OSM tag sample - Global mapper LINE-TYPE
- <tag k="railway" v="rail"/> - Railroad
- <tag k="highway" v="motorway"/> - Interstate
- <tag k="highway" v="trunk"/> - Major/US Highway
- <tag k="highway" v="primary"/> - State Highway
- <tag k="highway" v="secondary"/> - Arterial Road
- <tag k="highway" v="tertiary"/> - Collector Road
- <tag k="highway" v="service"/> - Alley or Driveway
- <tag k="highway" v="residential"/> - Residential Road
- <tag k="highway" v="track"/> - Unpaved Road
- <tag k="highway" v="footway"/> - not found in global mapper (I use "Trail" instead but it's not real)
The first problem I find is how to make a line type to add the missing tag "highway-footway". For now I have to use a different layer but I have to assume this is not correct.
The next question is about the content of the shapes, obviously, not all 305 parts have "Interstate" lines, or "Railroad" lines, some areas have only 2 or 3 type of lines from the list above.
Because I have to be sure I export all possible layers, I export all of them in the script with this code (only one layer shown in the sample to simplify):
...
GLOBAL_MAPPER_SCRIPT VERSION="1.00"
UNLOAD_ALL
DIR_LOOP_START DIRECTORY="C:\SHP\" FILENAME_MASKS="*.SHP" RECURSE_DIR=NO
UNLOAD_ALL
IMPORT FILENAME="%FNAME_W_DIR%" TYPE=SHAPEFILE
//Two split layers needed to identify all 10 layers groups of layers
SPLIT_LAYER FILENAME=* SPLIT_BY_ATTR="CFUNC_VIA" LAYER_DESC_ATTR_ONLY
SPLIT_LAYER FILENAME=* SPLIT_BY_ATTR="CAS" LAYER_DESC_ATTR_ONLY
//Railroad sample (all layers that have the text "FER")
EXPORT_VECTOR FILENAME="C:\SHP\%FNAME_WO_EXT%_Railroad.dwg" \
TYPE=DWG ALLOW_LONG_LABELS=YES EXPORT_DWG_LABELS=NO VERSION=R27 \
LAYER_ATTR="<Feature Layer Name>" GEN_PRJ_FILE=YES EXPORT_ELEV=NO \
EXPORT_LAYER="*FER*" SHOW_WARNINGS=NO
//The rest of layer groups are not shown in this sample
UNLOAD_ALL
DIR_LOOP_END
UNLOAD_ALL
...
When I do this at the end of the script process, Global Mapper always sends a warning message:
----
The following errors were generated loading the workspace file:
ERROR: Vector data must be loaded for EXPORT_VECTOR command.
----
The last line of this message is repeated for every case in the 10 layer group export x 305 files mismatch. So is very large and produce a strange behaviour in the screen when global mapper finishes the script.
To solve this problem I tried to include the EXPORT_VECTOR in a conditional structure, but I can not find in the "Global Mapper Scripting Reference" the way to use it.
I have tried several COMPARE_STR samples with no success. The logical one shoud be this:
....
IF COMPARE_STR="FILENAME=*FER*"
...
END_IF
....
Knowing the existing layers of the shape before exporting them, is needed to avoid the "ERROR" message.
I wonder is possible to make both, create a LINE_TYPE for the "highway-footway", and using some COMPARE_STR for the conditional structure.
I send attached a zip with 2 of the 305 parts, one with the full layer groups, and one with only 2.
Regards,
Carlos.
Answers
-
Dear all,
Searching deeply in the scripting manual and testing several times I have found the solution to the warning mesages using a combination of LAYER_LOOP_START - LAYER_LOOP_END
and the conditional structure (IF COMPARE_STR ...) to check the name of all the layers in the shp files, to apply LINE_TYPE to the desired layers, only when they exists.
The only problem I have found is about the wildcards and masks, because some layers are not detected.
To have a pair of examples:
"72-30.shp - B - VIA001" -> Detected when I use "*VIA*".
"72-30.shp - <Empty> - FER001" -> Not detected when I use "*FER*".
These names of layers are obtained when I make 2 splits, to make possible all LINE_TYPE cases.
If I change the order of the 2 splits, the names changes to:
"72-30.shp - VIA001 - B" -> Detected when I use "*VIA*".
"72-30.shp - FER001 - <Empty>" -> Detected when I use "*FER*".
This makes me think that maybe some characters included in the layer names produce strange behaviours in masks (perhaps "<" or ">").
Another thing that I still don't know how to manage is about creating a type of line that makes osm layer tag highway-path for later use.
Regards,
Carlos.
-
Dear all,
In case is not possible to fix the problem of the LINE_TYPE creation for custom osm layers, I have found a solution here:
http://no-nonsense-software.com/cgi-bin/redirect/cgirdir.exe?texrep
This is a nice little software to replace text to several files in a folder.
When I make the 305 parts in osm format I have to change the word "footway" to "path", in all of them to fix the missing layer. With this software I can make it in one simple step.
In my opinion, the elegant solution should be obviously to be able to create a specific LINE_TYPE for any other use in osm or wherever.
Anyway, I put my solutions in case other users can have similar problems, to share the solutions with them.
Regards,
Carlos.
Categories
- 12.9K All Categories
- 5.8K Features Discussion
- 349 Downloading Imagery
- 1.3K Elevation Data
- 385 Georeferencing Imagery Discussion
- 651 GM Script Language
- 55 User Scripts
- 115 GPS Features
- 420 Projection Questions
- 835 Raster Data
- 1.4K Vector Data
- 6.7K Support
- 181 Announcement and News
- 937 Bug Report
- 561 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 578 Other Discussion
- 132 GIS Data Sources
- 27 Global Mapper Showcase
- 244 How I use Global Mapper
- 109 Global Mapper Forum Website
