Export of elevation grid to global mapper package file changes the grid

OseiOsei Global Mapper UserPosts: 119Trusted User
edited August 2010 in SDK
I have noticed that whenever I load an elevation grid and export to a global mapper package file and reload it, the elevation grid changes a little bit.

I have created a modified version of the GM SDK sample application (please find attached). I have a large array which I use to create an elevation grid using GM_CreateCustomElevGridLayer.

To reproduce problem
1. Click on "Load XYZ Grid" to create elevation grid using GM_CreateCustomElevGridLayer.
2. Click on "Get Z at point" to get the elevation at point [338000, 652000] and I get ~33.4980.
3. Click on "Set Custom Shader" to change the shader for the grid layer.
Continuously clicking this button toggles between Bilinear interpolation and Nearest Neighbour.
4. While it is at Bilinear interpolation (smooth edges), click on "Set Extent" to zoom in to observe closer the grid.
5. Click on "Export to gmp" to export the grid to a global mapper package file.

6. Select the layer and close it.
7. Load the previously-exported gmp file back into the application
8. Clicking on "Get Z at point" to get the elevation at point [338000, 652000] gives 34.5000 which is different from what was acquired at Step 2.
9. Click on "Set Extent" to zoom in
10. Click on "Set Custom Shader" twice to get "Bilinear interpolation" and it shows that the grid has changed slightly. The edges are no longer smooth.

==============================================
I am assuming that this is because when a grid is exported, it is converted to a GeoTIFF format as pointed out in an earlier post @ http://www.globalmapperforum.com/forums/sdk/5709-sdk-too-slow-moving-map-display.html .

I am wondering if there is a way to conserve the data between export and reload of grid data so that the data does not change much.

Comments

  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited August 2010
    I'm guessing the difference is caused by a reprojection of the data to the current projection when doing the export to a package rather than keeping the native projection of the layer. Try passing in the GM_ExportPackage_UseNativeProj to the GM_ExportPackage function to see if that fixes the issue. That should give you basically the exact same thing as your grid.

    Note that gridded elevation layers are embedded in package files as Global Mapper Grid files, GeoTIFF is just used for raster/image layers.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • OseiOsei Global Mapper User Posts: 119Trusted User
    edited August 2010
    Exporting to a gmp file with the UseLayerNativeProjection switch does not change the outcome of the tests. The only change is the mTypeName from AUTO to GLOBAL_MAPPER_GRID. Apart from the Z value changing at points, the edges seem distorted if Bilinear Interpolation is used.

    How do I maintain an AUTO elevation grid so that when I export to a package file, the elevation grid still comes back as an AUTO elevation grid?

    Thanks
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited August 2010
    Ok, I'll try your sample application when I'm back in the office on Tuesday to see if I can find what is happening.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited August 2010
    Osei,

    I took a look and found what is happening. The actual elevation value coming from the GMP file is 33.5, which is your original value (33.497971) rounded to the nearest decimeter (the integer elevation units used within the GMG file within the GMP file).

    It is coming out as 34.5 because the API test code when you load an elevation grid with the SDK sample application in Debug mode calls GM_SetElevationOverrides and sets the elevation offset to 1.0, which means 1.0 is being added to each value extracted from the loaded layer. You should turn off that API test code in the GM_MapWindow.cpp file in your own project (just remove the GM_TEST_API definition from the Debug build of the project) to avoid confusion.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • OseiOsei Global Mapper User Posts: 119Trusted User
    edited August 2010
    After stubbing out the TestAPI method, I get the same results for Get Z @ point. There seem to be slight differences if I take Z at a point that is not a grid point.

    I changed the location on line 1758 to [338251, 652879] and I get different values.
    ____________________________Before export_______________After Export
    Nearest Neighbour______________ 36.6221 _________________36.6000
    Bilinear Interpolation_____________36.6275 _________________36.6040
    The values are not so different but my problem is with the drawing. If you zoom in, you realize before export, with bilinear interpolation, the edges of the grid are quite smooth. If you load the exported gmp file however, you realize the edges are not smooth.
    If we could get the edges to smooth out, we would be quite satisfied.

    If I may ask, when exporting a grid to a gmp file, does the layer save the Z array that was used during CreateCustomElevGrid and is there a way for getting it back so that we could get it back and recreate the grid from the array as if it wasn't loaded from a gmp file?

    Thanks in advance for your time and effort.
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited August 2010
    Osei,

    The loss of smoothness was caused by the elevation values being rounded to the nearest decimeter value on export to a Global Mapper Package. I went ahead and increased the package export to use centimeters rather than decimeters for metric elevation values, which fixed the issue (at the expense of a slightly larger GMP file).

    I have placed a new SDK build with this change at http://www.globalmapper.com/GlobalMapperSDK_v134_beta.zip for you to try.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • OseiOsei Global Mapper User Posts: 119Trusted User
    edited August 2010
    I understand now. If the changes are just caused by rounding approximations, then the grid itself has not changed.
    I can see in the application, the user can change the units just before export of grid layers. Maybe something like a scale factor can be applied to grid layers in the future.

    Thanks for the updated SDK.
  • OseiOsei Global Mapper User Posts: 119Trusted User
    edited August 2010
    Osei wrote: »
    I understand now. If the changes are just caused by rounding approximations, then the grid itself has not changed.
    I can see in the application, the user can change the units just before export of grid layers. Maybe something like a scale factor can be applied to grid layers in the future.

    Thanks for the updated SDK.

    In relation to above post, is there the possibility of setting the scale factor on grid layers? So that when they are exported in to a gmp file for instance, I can say I want them exported as millimeters ( x 10^3) or even 10^5 if I so desire. We do not even need an offset value but just a scale factor for Z values.

    Some of the grid data that we have are not so vertically sparsed as elevation data and may thus require a finer sense of accuracy. For instance, the data that I sent to you earlier has a maximum of just 56. This means we may need accuracy of up to 3 decimal places or more for such data. Elevation data may however not need such level of accuracy and therefore we may want to use 10^2 (or centimeters).

    Can we therefore have a custom scale factor for grid layers?


    Thanks.
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited August 2010
    If you want additional precision what you can do is instead of exporting to a package, use GM_ExportElevation and either export to a Global Mapper Grid file with units of GM_ElevUnit_Millimeters, or you can export to an elevation format that stored full 32-bit floating point values, like GM_Export_FloatGrid.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • OseiOsei Global Mapper User Posts: 119Trusted User
    edited August 2010
    I believe I may have misunderstood your earlier post on changing the "decimeter" package export to "centimeters". Does that mean you changed it in the source code and not by calling a method to set it to centimeters?
    That is, it is fixed and not some global parameter you can set arbitrarily in user code.

    If so, then I think we can live with millimeter export. That should be accurate for all our purposes for now. Can that be arranged for us?
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited August 2010
    That is correct, for the Global Mapper Package export the elevation units are fixed for the export and there isn't a parameter to control that. They were just changed from decimeters to centimeters. I'm thinking I might add a parameter rather than changing them to millimeters because it would inflate the size of the package files with extra precision that only a tiny number of users would have need of. I'll let you know when I have a new build with a way to specify additional precision for the elevation values.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited August 2010
    I have placed a new SDK build at http://www.globalmapper.com/GlobalMapperSDK_v134_beta.zip which includes a new package export flag (GM_ExportPackage_ExtraElevPrecision) which should create millimeter precision in the created package files rather than centimeter precision.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • OseiOsei Global Mapper User Posts: 119Trusted User
    edited August 2010
    I have placed a new SDK build at http://www.globalmapper.com/GlobalMapperSDK_v134_beta.zip which includes a new package export flag (GM_ExportPackage_ExtraElevPrecision) which should create millimeter precision in the created package files rather than centimeter precision.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com

    Thanks for the updated SDK.
    I however cannot find this flag in the header file (GlobalMapperInterface.h).
    I am assuming this extra flag is
    GM_PackageExport_ExtraElevPrecision = 0x00000080
    Can you confirm or otherwise if my assumption is right?
    Thanks in advance.
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited August 2010
    Sorry I forgot to update the header in the .zip file. The new flag is defined as follows:

    GM_ExportPackage_ExtraElevPrecision = 0x00000080, // Store elevation values from elevation grid files with extra precision


    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
Sign In or Register to comment.