Editing a grid
Download the source code for this example.
//////////////////////////////////////////////////////////////////////////////
//
// Name : VulcanSDK_grid_example.cpp
// Description : A basic example of using the Vulcan SDK with grids
//
// Maptek Pty Ltd, 2020
//
//////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include "mtkExportedApi_ReadWrite.h"
int RunGridExample(char* filename)
{
int status;
MTK_Grid *grid;
int numNodesX, numNodesY;
char newFilename[MTK_BUFFER_SIZE];
char* extension;
printf("Initialising API using Maptek Extend licence...");
// Setup environment variable 'VULCAN' for this process to a
// Vulcan installation directory for dependencies and licencing.
MTK_SetVulcanEnvironmentVariable("C:/Program Files/Maptek/Vulcan 12.0.3");
// Initialise library using client-side Maptek Extend licence
if (MTK_API_InitExtend())
{
HandleError();
return 1;
}
printf("done\n");
printf("Opening grid %s...", filename);
grid = MTK_Grid_Open(filename);
if (!grid)
{
HandleError();
return 1;
}
printf("done\n");
status = MTK_Grid_NumNodes(grid, &numNodesX, &numNodesY);
if (status)
{
HandleError();
return 1;
}
printf("Grid %s has %d x nodes and %d y nodes\n",
filename, numNodesX, numNodesY);
// This code reads the value of an arbitrary node and replaces it with a
// different arbitrary value
// This would usually be done based on some calculation
if (numNodesX > 0 && numNodesY > 0)
{
double nodeValue;
int nodeMasked;
status = MTK_Grid_GetNodeValue(grid, 0, 0, &nodeValue, &nodeMasked);
if (status)
{
HandleError();
return 1;
}
printf("The node at 0,0 has a value of %f\n", nodeValue);
status = MTK_Grid_SetNodeValue(grid, 0, 0, 50, nodeMasked);
if (status)
{
HandleError();
return 1;
}
printf("The node at 0,0 now has a value of 50\n");
}
strncpy(newFilename, filename, MTK_BUFFER_SIZE - 1);
newFilename[MTK_BUFFER_SIZE - 1] = '\0';
extension = strstr(newFilename, ".00g");
if (extension && strlen(newFilename) < MTK_BUFFER_SIZE - 9)
{
strcpy(extension, "_with_00_at_50.00g");
}
else
{
strcpy(newFilename, "NewGridMadeFromExampleWith00At50.00g");
}
printf("Saving triangulation as %s...", newFilename);
status = MTK_Grid_Save(grid, newFilename);
if (status)
{
HandleError();
return 1;
}
printf("done\n");
status = MTK_Grid_Close(grid);
if (status)
{
HandleError();
return 1;
}
MTK_API_Terminate();
return 0;
}
static void HandleError()
{
char error[MTK_BUFFER_SIZE];
MTK_API_GetError(error);
printf("%s\n", error);
MTK_API_Terminate();
}