can i save file using SDK?

usama khanusama khan Global Mapper UserPosts: 19Trusted User
edited July 2014 in SDK
hello,
i have really stupid question. .
can i save my work as a project using global mapper? if yes, can u refer me the path. Coz my application has alot of marking, and if i couldnt save it as a project the user has to do all the work from zero the moment he closes the program. plz let me know the direction.
for example, when i am using adobe photoshop or AutoCAD, i can reuse the file accordingly. does global mapper SDK gives this facility?
please help

Comments

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,038
    edited July 2014
    Hello Usama,

    In Global Mapper, the user's current maps, layers, display options, etc., can be saved in a file called a workspace. You can add functionality in your program to load and save a workspace using the following API functions (found in GlobalMapperInterface.h):
    // Runs a Global Mapper script (.gms) or workspace (.gmw), either from a file or from script text
    GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_RunScript
        ( 
        const char*             aFilenameOrText,    // IN: string with full path of script or the actual text of the script
        GM_LayerHandle_t32**    aLayerList,         // OUT: list of layer handles loaded by the script (NULL if you don't want to keep them around)
        uint32*                 aNumLoadedLayers,   // OUT: number of layer handles in aLayerList (NULL if you don't want to keep the list)
        GM_LoadFlags_t32        aLoadFlags,         // IN: Extra flags for load behavior
        void*                   aReserved           // IN: Reserved for future use, must be NULL
        );
    
    
    // Saves the current list of loaded layers and display options to a workspace (GMW) file
    GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_SaveWorkspace
        (
        const char* aFilename,  // IN: name of workspace file to save
        void*       aReserved   // IN: reserved for later use, must be NULL
        );
    
    
    // Saves custom list of loaded layers and display options to a workspace (GMW) file
    GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_SaveWorkspaceEx
        (
        const char*             aFilename,      // IN: name of workspace file to save
        GM_LayerHandle_t32*     aLayerList,     // IN: List of layers in order to save to workspace or NULL for all in order they were loaded
        uint32                  aLayerCount,    // IN: Number of layers in list (0 for all)
        void*                   aReserved       // IN: reserved for later use, must be NULL
        );
    

    Let me know if you have any additional questions.

    Cheers,

    Bob
  • usama khanusama khan Global Mapper User Posts: 19Trusted User
    edited July 2014
    hi, i am using C# as a language. Is it included in the C# sample as well? and how will i add in my program. .just guide me thorugh the steps. . Basically i am civil engineer and trying to learn GIS things through ur SDK, i have acheived alot, but this API stuff is somewhat out of my scope. . I will do everything myself. .just guide me through the steps i have to follow to save the workspace. .??
  • usama khanusama khan Global Mapper User Posts: 19Trusted User
    edited July 2014
    if i want to just save it as a tiff image? then will it be the same thing as you are saving. .assuming i have only one layer that was default in C# sample?
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,038
    edited July 2014
    Hi Usama,
    usama khan wrote: »
    hi, i am using C# as a language. Is it included in the C# sample as well? and how will i add in my program. .just guide me thorugh the steps. . Basically i am civil engineer and trying to learn GIS things through ur SDK, i have acheived alot, but this API stuff is somewhat out of my scope. . I will do everything myself. .just guide me through the steps i have to follow to save the workspace. .??

    All of those API functions are available in the GlobalMapperDLLWrapper namespace in C#, although they don't seem to be used in the sample program. If you want to save a workspace, the easiest function to use is:
    // Saves the current list of loaded layers and display options to a workspace (GMW) file
    [DllImport(DLLFileName, EntryPoint="GM_SaveWorkspace")]
    public static extern GM_Error_t32 GM_SaveWorkspace
    (
        String      aFilename,  // IN: name of workspace file to save
        IntPtr      aReserved   // IN: reserved for later use, must be NULL
    );
    

    You will need to prompt the user for a file name (I assume you already have code to do this...you should be able to adapt code you are using to prompt the user for layer data), then use that file name to save the workspace:
    String theFileName = String.Empty; 
    // Prompt the user for a file name.  Filter should be "*.gmw".
    GlobalMapperDLL.GM_SaveWorkspace(theFilename, (IntPtr)null);
    

    Cheers,

    Bob
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,038
    edited July 2014
    Hi Usama,
    usama khan wrote: »
    if i want to just save it as a tiff image? then will it be the same thing as you are saving. .assuming i have only one layer that was default in C# sample?

    Saving a TIFF image is not the same as saving a workspace. The workspace contains information about the map styles, map projection, loaded layers, etc. If you save a TIFF, this just saves an image of the current data. To save data as a TIFF image, use:
    /// <summary>
    /// GM_ExportRaster
    ///  Exports one or more layers to a new raster file (not implemented on WinCE)
    /// </summary>
    [DllImport( DLLFileName, EntryPoint = "GM_ExportRaster" )]
    public static extern GM_Error_t32 
    GM_ExportRaster
    (
        String                        aFilename, 
        GM_RasterExportFormat_t32            aFormat, 
        IntPtr                        aLayer, 
        ref GM_Rectangle_t            aWorldBounds, 
        Int32                        aPixelWidth, 
        Int32                        aPixelHeight, 
        GM_RasterExportFlags_t32            aFlags 
    );
    

    Use GM_Export_GeoTIFF for the aFormat parameter.

    Cheers,

    Bob
Sign In or Register to comment.