Retrieving UTM from Tif
thejerrytan
Global Mapper User
Hi, I need to extract/ UTM co-ordinates from a .tif map.
Currently GM_ConvertCoordPixelToGround extracts out the lat lon. Is there any function to convert or get the UTM instead?
Currently GM_ConvertCoordPixelToGround extracts out the lat lon. Is there any function to convert or get the UTM instead?
Comments
-
Yes, if you call GM_SetProjection and set the projection to a UTM projection in the proper zone prior to calling GM_ConvertCoordPixelToGround then the returned ground coordinates will be in that UTM projection rather than lat/lon.
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
Hi,
Thanks for the reply.
Is it possible to convert from lat/long into UTM after calling GM_ConvertCoordPixelToGround? -
Yes, you can do that using the GM_ProjectPoint function.
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
I am handling it in C# and did a wrapper class using 'IntPtr' for 'const GM_Projection_t*'.
If I were to convert from lat/long to UTM, what would be the 2 arguments in the function GM_ProjectPoint? -
Don't use IntPtr, use 'ref GM_Projection_t' instead for the 2 projection parameters.
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
In the SDK reference, one of the lines for GM_SetProjection has the following lines for UTM:
theUtmProj.mAttrList[0].mAttr = ZONE;
theUtmProj.mAttrList[0].mValue = 15;
theUtmProj.mNumAttrs = 1;
I've tried to map it in C# equivalent and the possible match I've found for mAttrList[0].mAttr would be Attr1.mAttr. Is it correct?
And how do I set the declaration for 'ZONE' in this case? -
Your declaration should look like the following (at least if you are using the GlobalMapperDLLWrapper.cs from the C# sample app):
theUtmProj.mAttr1.mAttr = PROJATTR.ZONE;
theUtmProj.mAttr1.mValue = 15;
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
There are no variables in theUtmProj with the name mAttr1. I can only find Attr1,Attr2 .... up to Attr16.
Am I missing something in the wrapper? (I took it from the C# sample app) -
In the wrapper I am using the GM_Projection_t type is declared as:
// This type is used to fully describe a projection.
public struct GM_Projection_t
{
public PROJSYS mProjSys; // Projection system
public DATUM mDatum; // Horizontal datum
public UNIT mUnit; // Ground units
public UInt32 mNumAttrs; // Number of attributes in attribute list
public GM_ProjAttrValue_t mAttr1; // Attribute value list items (C# doesn't support fixed length arrays)
public GM_ProjAttrValue_t mAttr2;
public GM_ProjAttrValue_t mAttr3;
public GM_ProjAttrValue_t mAttr4;
public GM_ProjAttrValue_t mAttr5;
public GM_ProjAttrValue_t mAttr6;
public GM_ProjAttrValue_t mAttr7;
public GM_ProjAttrValue_t mAttr8;
public GM_ProjAttrValue_t mAttr9;
public GM_ProjAttrValue_t mAttr10;
public GM_ProjAttrValue_t mAttr11;
public GM_ProjAttrValue_t mAttr12;
public GM_ProjAttrValue_t mAttr13;
public GM_ProjAttrValue_t mAttr14;
public GM_ProjAttrValue_t mAttr15;
public GM_ProjAttrValue_t mAttr16;
};
However it is declared, use either Attr1 or mAttr1.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
Hi
Thanks for the answers, I managed to get the function working.
Now I am struggling to call out the function "GM_GetMGRSCoordinates" using a wrapper class.
It kept throwing the exception "Unable to find an entry point GM_GetMGRSCoordinates in GlobalMapperInterface.dll" whenever I call the function.
My code for the wrapper class is as followed:
[DllImport(DLLFileName, EntryPoint = "GM_GetMGRSCoordinates", CallingConvention = CallingConvention.StdCall)]
public static extern GM_Error_t32 GM_GetMGRSCoordinates(double aX, double aY, int aLatLong, out String aMgrsStr)
Did I put in wrong inputs or have some files missing that throws out this exception? -
What SDK version are you using? This is a relatively new function so you need to make sure you have the latest SDK release otherwise the function won't be there. I would suggest maybe getting the latest beta SDK build at http://www.globalmapper.com/GlobalMapperSDK_v132_beta.zip and using that.
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
Ah okay. Mine should be outdated.
Will there be any function to convert from MGRS to lat / long in the future? -
I could add that if you need it. Global Mapper internally has support for parsing a MGRS coordinate string into lat/lon, so adding it to the SDK is just a matter of me adding a function and calling the internal stuff. Do you need that?
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
Wow if you could add in that would be great! Initially I was planning of using some linear approximation and cross referencing through a table to convert.
-
Ok,, I'll throw that in a new build and point you at it when I get back to the office Sunday night.
Mike -
I have added a new GM_DecodeMGRSCoordinate function and placed a new SDK build with that function at http://www.globalmapper.com/GlobalMapperSDK_v132_beta.zip for you to test.
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
Hi,
I have tried calling GM_GetMGRSCoordinates and it kept throwing System.ExecutionEngineException in my code.
The only details I have is that it points to System.Collections.EmptyReadOnlyDictionaryInternal.
Any possibility of reproducing the exception on your end? From reading MSDN, I suspect it could be my machine -
I just rechecked your declaration and the aLatLong parameter should be of type 'Byte' (or an equivalent), not 'int', which is a different length. I'm guessing this is your problem.
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
Yup, its the parameter that is causing the issue. However i have tried 'Byte' or boolean and doesn't work as long as the input value is 1 or true. (threw the same exception).
Only when I put 0 as the parameter that it return GM_Error_NoProjectionSet without the exception. -
Looking again at your declaration I'm not sure that 'out String' is the proper way to declare the output string buffer. I think instead you should use IntPtr and provide an address to an allocated buffer of sufficient size (32 bytes should be more than enough) in which to store the output string, then you can convert that to a String when you get back into C#.
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
Ah great that was the problem! Thanks!
Do you have the reference for GM_DecodeMGRSCoordinate? I couldn't find in the SDK reference. -
We haven't officially documented GM_DecodeMGRSCoordinate yet. Here is the function header and declaration:
//===================================================================
//
// FUNCTION:
// GM_GetMGRSCoordinates
//
// DESCRIPTION:
// Decodes a MGRS (military grid reference system) coordinate into
// a X/Y or lat/lon location.
//
//===================================================================
GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_DecodeMGRSCoordinates
(
const char* aMgrsStr, // IN: buffer with MGRS coordinate text
double* aX, // OUT: point X/longitude coordinate
double* aY, // OUT: point Y/latitude coordinate
boolean aLatLon // IN: TRUE - return coordinates are lat/lon, FALSE - return coordinates are in the current projection
)
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com
Categories
- 12.7K All Categories
- 5.6K Features Discussion
- 342 Downloading Imagery
- 1.3K Elevation Data
- 380 Georeferencing Imagery Discussion
- 628 GM Script Language
- 53 User Scripts
- 113 GPS Features
- 414 Projection Questions
- 819 Raster Data
- 1.3K Vector Data
- 6.6K Support
- 177 Announcement and News
- 908 Bug Report
- 558 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 562 Other Discussion
- 129 GIS Data Sources
- 27 Global Mapper Showcase
- 233 How I use Global Mapper
- 107 Global Mapper Forum Website