Global Mapper v25.0

rendering vector layer between raster layers

hubermedia
hubermedia Global Mapper User
edited September 2013 in SDK
Hello,

I am exporting GeoTIFFs using GM_ExportRasterEx - 1 or more base raster layers + 1 or more vector layers above. This works quite well.

Now I am trying to render another raster layer above the vector data (by loading it after loading the vector layers).
However the vector features are always rendered after all raster layers.

So I reproduced the situation in GlobalMapper directly, where the same happens. After some searching i found the Vector Display configuration option "Order Vector Features by Layer Order First [...]" and activated it. This solves the issue in GlobalMapper (both the shown view as well as raster exports).

I traced the setting back to the registry value VectorDrawOrder which I confirmed to now have the value 1.
I'm not using GM_SetRegistryKey so the settings should be shared.

However, it shows no effect on the SDK.

So my question: Am I doing something wrong or is that really the case? How can I achieve what I want?

Thank you!

Comments

  • global_mapper
    global_mapper Administrator
    edited September 2013
    Good job tracing that down, but in the SDK it's a little bit different :) What you would need to do is use GM_DrawLayerList to draw your layers one at a time to an offscreen bitmap in the order that you want, then use GM_ExportRasterFromBitmap to export a raster from that bitmap. See the GM_MapWindow::DrawToOffscreenBuffer function in the C++ sample application in the branch handling the ( eDrawOrderAsLoaded == aDrawOrder ) setting for most of the code you need.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • hubermedia
    hubermedia Global Mapper User
    edited September 2013
    Thanks for your help!
    The output now looks as hoped :).

    However this brings 2 new issues:

    Memory consumption seems to be about twice of that before. It's especially increasing during the GM_DrawLayerList calls.
    Testcase 1: GM_ExportRasterEx: 500MB peak
    Testcase 1: GM_ExportRasterFromBitmap: 1GB peak
    Testcase 2: GM_ExportRasterEx: 900MB peak
    Testcase 2: GM_ExportRasterFromBitmap: 1.6GB peak
    Do you have any hints regarding that? I'm actually using C#, not sure if there is a relevant overhead when using System.Drawing.

    And I'm actually using the aExtraFlags parameter to set the dpi, which GM_ExportRasterFromBitmap doesn't accept.

    I'm currently thinking of just exporting the vector layer into a temporary raster file and loading it again to workaround, might be the fastest way to reach my goal.

    Relevant code part:
    using (var bitmap = new Bitmap(exportSize.Width, exportSize.Height))
    {
        using (var graphics = Graphics.FromImage(bitmap))
        {
            graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, exportSize.Width, exportSize.Height);
    
    
            for (var i = 0; i < layers.Count; i++)
            {
                using (var layerlist = new LayerListWrap(new List<IntPtr> { layers[i] }))
                {
                    var hdc = graphics.GetHdc();
                    _lastError = GlobalMapperDLL.GM_DrawLayerList(hdc, layerlist.Ptr, (int)layerlist.Length,
                        (GlobalMapperDLL.GM_DrawFlags_t32)0, ref mercRect, 0, 0, exportSize.Width, exportSize.Height);
                    graphics.ReleaseHdc(hdc);
                    AssertSuccess(_lastError, "GM_DrawLayerList");
                }
            }
    
    
            var hdc2 = graphics.GetHdc();
            _lastError = GlobalMapperDLL.GM_ExportRasterFromBitmap(outputfilename, bitmap.GetHbitmap(), hdc2, format, ref mercRect, exportFlags);
            graphics.ReleaseHdc(hdc2);
            AssertSuccess(_lastError, "GM_ExportRasterFromBitmap");
        }
    }
    
  • global_mapper
    global_mapper Administrator
    edited September 2013
    How large is your export in pixel dimensions? You will use the pixel width * pixel height * 3 in bytes for the offscreen bitmap, then temporarily the export of a rasterized vector will also allocated some memory, although it will split up large rasterizations into smaller chunks internally and send those to files, then export from those files. There really shouldn't be any different in GM_ExportRasterEx and GM_ExportRaster assuming the export size is the same.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • hubermedia
    hubermedia Global Mapper User
    edited September 2013
    The export sizes are 6495*4480 (test case 1) 6554*4521 (test case 2). new Bitmap() in .NET without specifying the format uses 32bpp, so these should be around 110MB.

    A bit larger however are the raster input files.
    Test case 1 is made of 4 17000*17000 24bbp files -> each 826MB.
    Test case 2 has 8 of them.
  • hubermedia
    hubermedia Global Mapper User
    edited September 2013
    Forgot to mention: test case 2 actually produces 3 output files(all same size, 2 of them only with the vector data), test case 1 only 1
  • global_mapper
    global_mapper Administrator
    edited September 2013
    What are the multiple files that you are getting? I would expect only one output file (not counting world files, etc.) from a single export call.

    Also what is the format of the data you are exporting from? Perhaps the access is just filling up an internal in-memory cache. It will stop growing once it hits limits, but memory usage will grow as it is accessed until that is done. So if you had stacked raster layers doing a single draw with all layers would only cause the top-most one to be hit and thus not grow the bottom layer cache. But that's just one thought assuming all else is equal. The important thing is does it continue to grow or does it stop growing?

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation