Scripting - Crop layer using areas in other layer
Hi,
I have a layer X and in layer Y i have a series of polygon areas that i want to use to crop layer X. Manually, i do this by first highlighting the lines in layer y, then using the "Create Areas from Lines" function, then going to layer X Options>Cropping>Crop to current selected polygons.
I cannot crop in the generation of layer x as i use this to first generate the layer y polygons first before cropping back.
To do this in code does not appear to be possible, specifically the "Create Areas from Lines" function. I know there is the option to generate the DEFINE_SHAPE coordinates of each polygon, but this is not practical as there are multiple small polygons to crop to.
The use of SET_LAYER_OPTIONS does not give cropping funcionality like the UI which would be a good feature to add in the future. Also tried COMBINE_LINES but this just creates another layer of the polgons (another layer y).
Grateful for any help.
Answers
-
There is actually a CREATE_AREAS_FROM_LINES=YES parameter that you can add to the EDIT_VECTOR script command to turn closed lines into areas. It seems this is missing from the documentation. So you can use that to create a new layer to crop from.
I'll have our documentation updates.
Thanks,
Mike
Global Mapper Guru
geohelp@bluemarblegeo.com
-
I did try the CREATE_AREAS_FROM_LINES=YES using the COMBINE_LINES function (this generated a duplicate layer y). The issue is how i crop the layer x with the created areas.
-
Actually that is incorrect, the CREATE_AREAS_FROM_LINES parameter is for COMBINE_LINES, as you indicated.
You should be able to use something like:
COMBINE_LINES CREATE_AREAS_FROM_LINES="YES" FILENAME="layer Y" LAYER_DESC="layer Y Areas"
Then you can use POLYGON_CROP_FILE="layer Y Areas" in whatever operation you need the cropping done.
-
Thanks Mike, the first line as per your COMBINE_LINES code is very similar to what i have and tested. This indeed generates the "Layer Y Areas". My issue is how i apply this to Layer x. In other words, how do i call layer x and crop to the polygon crop file.
Just as a comment i need to use POLYGON_CROP_USE_ALL otherwise only the largest single polygon is called (not all in the layer).
-
You would do the crop on export to a new layer, so if you have 'layer X' and 'layer Y areas' loaded, you could do the following:
EXPORT_VECTOR FILENAME="output.xxx" TYPE="your format here" EXPORT_LAYER="layer X" POLYGON_CROP_FILE="layer Y Areas" POLYGON_CROP_USE_ALL="YES"
That should export just the data in 'layer X' cropped to the areas in 'layer Y Areas' to a new file.
-
Thanks Mike,
I was trying to do this without a new layer generation. I have found a work around that gives me what i want for a continuation of the work flow i have.
SET_LAYER_OPTIONS FILENAME="Layer X" POLYGON_CROP_FILE="Layer Y" POLYGON_CROP_USE_ALL="YES" LAYER_DESC="Layer X-OUT"
I lose the original Layer X of course.
-
Adding a POLYGON_CROP_FILE parameter to SET_LAYER_OPTIONS shouldn't have any effect at all. From your command, just the LAYER_DESC would be used to change the layer description, the POLYGON_CROP_FILE parameter would just be ignored as it isn't used with SET_LAYER_OPTIONS.
You can always use UNLOAD_LAYER to unload the temporary 'layer Y areas' layer that you create for cropping on export.
You could also do your export to a temporary file (maybe use EXPORT_PACKAGE to export a GMP file since it's self-contained), then after you reload it, use RUN_COMMAND to delete the file from disk, like below:
COMMAND_LINE="cmd /C del 'C:\path_to_temp_file\filename.gmp'"
-
I did notice the POLYGON_CROP_FILE was not in the original reference documentation for SET_LAYER_OPTIONS, but decided to try it at the time. For some reason it works. I just ran a test and commented out the entire SET_LAYER_OPTIONS line and it did not crop or set the layer properties, so the code does actually call the poly crop layer or maybe it was getting tickled by previous calls.
Eitherway, this is a good feature if it can be formally added as its very useful with big workflows.
-
I just checked the code and it turns out that POLYGON_CROP_FILE will be used for SET_LAYER_OPTIONS to set the display crop polygon for an image or terrain layer.
Is your 'layer X' just a raster layer? I thought it was a vector layer containing other polygons that you wanted to crop.
-
Yes Layer X is a raster that i am cropping using polygons in Layer Y
-
Ah ok, sorry I misunderstood what you wanted from the beginning. Yes SET_LAYER_OPTIONS with the POLYGON_CROP_FILE is the easiest way to crop the raster layer for display.
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
- 837 Raster Data
- 1.4K Vector Data
- 6.7K Support
- 182 Announcement and News
- 943 Bug Report
- 562 SDK
- 1.2K Suggestion Box
- 3.8K Technical Support
- 581 Other Discussion
- 132 GIS Data Sources
- 27 Global Mapper Showcase
- 245 How I use Global Mapper
- 111 Global Mapper Forum Website
