Invalid Layer error in GM_GetPathProfile after using GM_LoadLayerList
Hi,
I have a zip file that contains some .gmg files. In C#, I am using the GM_LoadLayerList function to load the files. The function returns no errors, and the out UInt32 "aNumLoadedLayers" number matches the number of files I have in the zip file. However, when I use the out IntPtr "aLayerList" in the GM_GetPathProfile function to get elevations from these layers specifically, I get the GM_Error_InvalidLayer exception.
Here is an example of my code:
UInt32 numOfLayers;
IntPtr aLayerList;
gmError = GlobalMapperDLL.GM_LoadLayerList(zipFile, out aLayerList, out numOfLayers, 0);
gmError = GlobalMapperDLL.GM_GetPathProfile(aLayerList, lon1, lat1, lon2, lat2, ptrToElevArr, numOfPoitns, 0);
Any help is much appreciated. Thank you!
I have a zip file that contains some .gmg files. In C#, I am using the GM_LoadLayerList function to load the files. The function returns no errors, and the out UInt32 "aNumLoadedLayers" number matches the number of files I have in the zip file. However, when I use the out IntPtr "aLayerList" in the GM_GetPathProfile function to get elevations from these layers specifically, I get the GM_Error_InvalidLayer exception.
Here is an example of my code:
UInt32 numOfLayers;
IntPtr aLayerList;
gmError = GlobalMapperDLL.GM_LoadLayerList(zipFile, out aLayerList, out numOfLayers, 0);
gmError = GlobalMapperDLL.GM_GetPathProfile(aLayerList, lon1, lat1, lon2, lat2, ptrToElevArr, numOfPoitns, 0);
Any help is much appreciated. Thank you!
Answers
-
Hello Obada,
You are using a pointer to a layerhandle as a layerhandle. You need to Marshal it. This function will get all of the layer handles into an ArrayList:public static ArrayList convertIntPtrtoLayerList(IntPtr aLayerListPtr, uint aNumLayers){ArrayList theArrayList = new ArrayList();if ((aPtrListPtr == IntPtr.Zero) || (aNumPoints == 0)){return theArrayList;}IntPtr tmpPoint = new IntPtr();for (int i = 0; i < aNumPoints; ++i){IntPtr tmpPointPtr = (IntPtr)((UInt32)aPtrListPtr + (i * IntPtr.Size));tmpPoint = (IntPtr)Marshal.PtrToStructure(tmpPointPtr, typeof(IntPtr));theArrayList.Add(tmpPoint);}return theArrayList;}
Then you can just reference it as:
gmError = GlobalMapperDLL.GM_LoadLayerList(zipFile, out aLayerList, out numOfLayers, 0);
ArrayList theLayerList = convertIntPtrtoLayerList(aLayerList, uint numOfLayers);
for (int i = 0; i < theLayerList.Count; ++i)
{
IntPtr aLayer = (IntPtr)ArrayList[i];
gmError = GlobalMapperDLL.GM_GetPathProfile(aLayer, lon1, lat1, lon2, lat2, ptrToElevArr, numOfPoitns, 0);
}
this should do it for each layer loaded. -
It worked. Thank you
Categories
- 12.8K All Categories
- 5.7K Features Discussion
- 346 Downloading Imagery
- 1.3K Elevation Data
- 385 Georeferencing Imagery Discussion
- 639 GM Script Language
- 54 User Scripts
- 115 GPS Features
- 417 Projection Questions
- 829 Raster Data
- 1.3K Vector Data
- 6.6K Support
- 179 Announcement and News
- 922 Bug Report
- 559 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 573 Other Discussion
- 131 GIS Data Sources
- 27 Global Mapper Showcase
- 241 How I use Global Mapper
- 108 Global Mapper Forum Website