Grid export tiles geometry not matching

MorganRSMorganRS Global Mapper UserPosts: 77Trusted User
I'm trying to script a grid export of two different datasets. Dataset 1 is a state area. Dataset 2 are county parcel files. I'm trying to load dataset 1, preform a grid export based on the layers extents, and turn that layer off. Then load the directory that holds dataset 2, and grid those out using the previous export bounds, so all the tiles will be exactly the same. Here's where I'm at as of now:
GLOBAL_MAPPER_SCRIPT VERSION=1.00
DEFINE_VAR NAME="state" VALUE="MN"DEFINE_VAR NAME="state_background" VALUE="C:\Workspace\Data_State\MN\ERASE\MN_ERASE.shp"DEFINE_PROJ FILENAME="C:\Workspace\Data_State\MN\nm_projection.prj"

SET_LOG_FILE FILENAME="C:\Workspace\Data_State\%state%\ERASE\grid_Export_Logfile.log"
IMPORT FILENAME="%state_background%" TYPE=SHAPEFILE
EXPORT_VECTOR FILENAME="C:\Workspace\Data_State\MN\ERASE\MN_ERASE_INPUTS\er_MN.shp" TYPE=SHAPEFILE SHAPE_TYPE=AREAS GEN_PRJ_FILE=YES GRID_TYPE_ROWS_COLS="8,10" GRID_NAMING=SEPARATE GRID_NAMING_COLS="NUM,1," GRID_NAMING_ROWS="ALPHA,A,"  LAT_LON_BOUNDS="-97.23919600,43.49936100,-89.4833850,49.38435800"
SET_LAYER_OPTIONS FILENAME="%state_background%" HIDDEN=YES

IMPORT_DIR_TREE DIRECTORY="C:\Workspace\Data_State\%state%\ERASE\COUNTIES" FILENAME_MASKS="*.SHP" RECURSE_DIR=NO
EXPORT_VECTOR FILENAME="C:\Workspace\Data_State\%state%\ERASE\%state%_ERASE_INPUTS\MN.shp" TYPE=SHAPEFILE SHAPE_TYPE=AREAS GEN_PRJ_FILE=YES GRID_TYPE_ROWS_COLS="8,10" GRID_NAMING=SEPARATE GRID_NAMING_COLS="NUM,1," GRID_NAMING_ROWS="ALPHA,A,"  LAYER_BOUNDS="%state_background%"
UNLOAD_ALL
Everything loads fine and dataset 1 exports as it should, however, dataset 2 doesn't start with it's first tile, or the tile size where it should and they're not even close to matching.

When I do this from the user interface I simply specify the tiles, and draw a bounding box over the first dataset, turn that one off, load the second, tick the tile radio button, and "reset to last export bounds" and everything works as it should.
Can anyone see where I'm going wrong here?
Thanks


Best Answer

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,218
    Answer ✓
    Currently, Global Mapper makes sure that the specified bounds intersect the full bounds of the loaded data, then uses the intersection as the bounds for creating the grid.  In the case of your county data set, the loaded data bounds (the county data set) are much smaller than the specified bounds (i.e., the state bounds), so the resulting grid does not match the state grid.

    I added a parameter, USE_EXACT_BOUNDS, so that you can customize this behavior.  When you specify USE_EXACT_BOUNDS=YES, Global Mapper will use the bounds specified on the command instead of performing the intersection.  Add this parameter to the export of your county data set, and it should make the state and county grids match up.

    This parameter is implemented in the latest daily build of Global Mapper.   Simply download the appropriate installer and run it to install the latest build.

Answers

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,218
    I think that you need to specify the same bounds on both EXPORT_VECTOR commands.  I see that the first one has a LAT_LON_BOUNDS parameter.  Assuming that those coordinates are the bounds for the data that you want to export, you could simply use the same parameter on the second EXPORT_VECTOR command instead of the LAYER_BOUNDS parameter.
  • MorganRSMorganRS Global Mapper User Posts: 77Trusted User
    edited November 2015
    bmg_bob said:
    I think that you need to specify the same bounds on both EXPORT_VECTOR commands.  I see that the first one has a LAT_LON_BOUNDS parameter.  Assuming that those coordinates are the bounds for the data that you want to export, you could simply use the same parameter on the second EXPORT_VECTOR command instead of the LAYER_BOUNDS parameter.

    I tried that too with the same results. I have found a back way around where I assigned a unique value to dataset 1 and DIDN'T turn that layer off when dataset 2 was loaded. Then dataset 2 loads and exports to a temp folder. Then I did a directory loop on the temp folder and deleted the features with the unique value, and exported them, while maintaining their name, to the final folder for my other script.
    It's not very neat, but for now, it works
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,218
    Just to clarify, are you saying that you used the same LAT_LON_BOUNDS parameter on both exports, with the same tiling parameters, and the resulting sets of tiles were in different locations?  That sounds like a bug to me.  

    Could you elaborate a little more about what you mean by, "dataset 2 doesn't start with it's first tile, or the tile size where it should"?
      
    What version of Global Mapper are you using?

    Can you post a zip archive containing a copy of your script that produces the incorrect output (before you implemented the workaround) and your data?  If you prefer, you can send it to geohelp@bluemarblegeo.com, and refer to this forum thread.
  • MorganRSMorganRS Global Mapper User Posts: 77Trusted User
    Yes, I set the LAT_LON_BOUNDS parameter to be the same for both exports, and they had the same tiling parameters. The first dataset in a state area, that one tiles out exactly as it should. The second dataset are a few county files randomly around the state I was using to test the script. The second export should have skipped tiles that would have been empty, but instead started the tiling numbering at it's first export.
    I'm using GMv. 17
    Here is the script I just tested again that gave faulty results:
    GLOBAL_MAPPER_SCRIPT VERSION=1.00

    DEFINE_VAR NAME="state" VALUE="MN"
    DEFINE_VAR NAME="state_background" VALUE="G:\Users\Morgan\DATA_STATE\MN\ERASE\MN_ERASE.shp"

    SET_LOG_FILE FILENAME="C:\Workspace\Data_State\%state%\ERASE\grid_Export_Logfile.log"

    IMPORT FILENAME="%state_background%" TYPE=SHAPEFILE
    EDIT_VECTOR ATTR_VAL="LAYER=BACKGROUND"
    EXPORT_VECTOR FILENAME="G:\Users\Morgan\DATA_STATE\%state%\ERASE\%state%_ERASE_INPUTS\er_MN.shp" TYPE=SHAPEFILE SHAPE_TYPE=AREAS GEN_PRJ_FILE=YES GRID_TYPE_ROWS_COLS="8,10" GRID_NAMING=SEPARATE GRID_NAMING_COLS="NUM,1," GRID_NAMING_ROWS="ALPHA,A," LAT_LON_BOUNDS="-97.23919600,43.49936100,-89.4833850,49.38435800"
    SET_LAYER_OPTIONS FILENAME="%state_background%" HIDDEN=YES

    IMPORT_DIR_TREE DIRECTORY="G:\Users\Morgan\DATA_STATE\%state%\ERASE\COUNTIES" FILENAME_MASKS="*.SHP" RECURSE_DIR=NO
    EXPORT_VECTOR FILENAME="G:\Users\Morgan\DATA_STATE\%state%\ERASE\%state%_ERASE_INPUTS\MN.shp" TYPE=SHAPEFILE SHAPE_TYPE=AREAS GEN_PRJ_FILE=YES LAT_LON_BOUNDS="-97.23919600,43.49936100,-89.4833850,49.38435800" GRID_KEEP_CELL_SIZE=YES GRID_TYPE_ROWS_COLS="8,10" GRID_NAMING=SEPARATE GRID_NAMING_COLS="NUM,1," GRID_NAMING_ROWS="ALPHA,A,"
    UNLOAD_ALL

    And these are the results

    those are both named with the same column and row name. When I add:
    DIR_LOOP_START DIRECTORY="G:\Users\Morgan\DATA_STATE\%state%\ERASE\TEMP" FILENAME_MASKS="%state%*.SHP" RECURSE_DIR=NO
    IMPORT FILENAME="%FNAME_W_DIR%"
    EDIT_VECTOR DELETE_FEATURES=YES COMPARE_STR="LAYER=BACKGROUND"
    EXPORT_VECTOR FILENAME="G:\Users\Morgan\DATA_STATE\%state%\ERASE\MN_ERASE_INPUTS\%FNAME_WO_EXT%.SHP" TYPE=SHAPEFILE SHAPE_TYPE="AREAS" GEN_PRJ_FILE=YES
    UNLOAD_ALL
    DIR_LOOP_END

    To the end of the script the results are exactly as they should be:


    I have attached the script that creates the faulty results.
    Thanks
  • MorganRSMorganRS Global Mapper User Posts: 77Trusted User
    attachment failed with previous post
  • MorganRSMorganRS Global Mapper User Posts: 77Trusted User
    Forgot to upload sample data. I attached state, and county shapefiles. the state shapefile should be dataset 1
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,218
    Thanks for the script and data.  I will take a look and let you know what I find.
  • MorganRSMorganRS Global Mapper User Posts: 77Trusted User
    Perfect! Thank you!
Sign In or Register to comment.