C# GM_ContourParams_t can't return a contour layer handle (always 0)

codemousecodemouse Global Mapper UserPosts: 186Trusted User
edited August 2010 in SDK
Trying to extend and create a c# scenario to utilize GM_ContourParams_t.

Here is GlobalMapperDll class entry point:

/// <summary>
/// Generates contours from loaded elevation data and creates a new vector layer with the results. The layer handle returned in aContourLayer must be closed with GM_CloseLayer when you are done with it.
/// See the definition of the GM_ContourParams_t type in the GlobalMapperInterface.h header file for a description of what options are available when generating the contour lines, iso-height areas, and/or min/max spot elevations.
/// </summary>
/// <param name="aLayer">IN: Layer to get elevations from or NULL for topmost layer at each point.</param>
/// <param name="aContourParms">IN: Parameters for generating contours.</param>
/// <param name="aContourLayer">OUT: Created contour layer.</param>
/// <returns></returns>
[DllImport(GlobalMapperInterface, EntryPoint = "GM_GenerateContours")]
public static extern GM_Error_t32 GM_GenerateContours(GM_LayerHandle_t32 aLayer, ref GM_ContourParams_t aContourParms, out GM_LayerHandle_t32 aContourLayer);


Here is my struct:
/// <summary>
    /// This type is used to provide the parameters for generating contours.
    /// </summary>
    public struct GM_ContourParams_t
    {
        /// <summary>
        ///  Size of structure.
        /// </summary>
        public UInt32 mSize;

        /// <summary>
        /// Contour layer description.
        /// </summary>
        public string mDesc;

        /// <summary>
        /// Bounds of contour lines to create. Pass empty rectangle to use entirety of passed in layer(s).
        /// </summary>
        public GM_Rectangle_t mContourBounds;

        /// <summary>
        /// Contour interval.
        /// </summary>
        public float mContourInterval;

        /// <summary>
        /// Set to TRUE if the contour interval is in feet rather than meters.
        /// </summary>
        public Byte mIntervalInFeet;

        /// <summary>
        /// Generate iso-height areas in addition to contour lines.
        /// </summary>
        public Byte mGenerateAreas;

        /// <summary>
        /// Generate spot elevation points at minimum and maximum elevations.
        /// </summary>
        public Byte mGenerateSpotElevs;

        /// <summary>
        /// Only include the value (and not the units string) in the contour labels.
        /// </summary>
        public Byte mNumberOnlyLabels;

        /// <summary>
        /// Display contour generation progress dialog.
        /// </summary>
        public Byte mShowProgress;

        /// <summary>
        /// Do not smooth the generated contour lines to improve their appearance.
        /// </summary>
        public Byte mDisableSmoothing;

        /// <summary>
        /// Sample spacing in the x direction.
        /// </summary>
        public double mXSpacing;

        /// <summary>
        /// Sample spacing in the y direction.
        /// </summary>
        public double mYSpacing;

        /// <summary>
        /// Simplification threshold, use 0.0 for no simplification.
        /// </summary>
        public double mSimpThreshold;
    }
}

Then in an unsafe static method, I am trying to pass in an existing layer (elevation data) that I just created from an ASCII file. SO something like:
private static unsafe void TestMethod(IntPtr layerHandle)
{
            IntPtr contourLayerHandle;

            var contourParameters = new GM_ContourParams_t
            {
                mSize = (UInt32)System.Runtime.InteropServices.Marshal.SizeOf(typeof(GM_ContourParams_t)),
                mDesc = "Generated Contours",
                mContourBounds = new GM_Rectangle_t(),
                mContourInterval = 200,
                mIntervalInFeet = 0,
                mGenerateAreas = 0,
                mGenerateSpotElevs = 0,
                mNumberOnlyLabels = 0,
                mShowProgress = 1,
                mDisableSmoothing = 0,
                mXSpacing = 0.0,
                mYSpacing = 0.0,
                mSimpThreshold = 0.10
            };

            GlobalMapperDLL.GM_GenerateContours(layerHandle, ref contourParameters, out contourLayerHandle);
}

Problem is, the contourLayerHandle out is always 0. What am I missing here?

Thanks,

Brian

Comments

  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited August 2010
    Brian,

    Is there an error code returned by the GM_GenerateContours function? Also, I'm not a C# expert, so I'm not sure if the last aContourLayer parameter should be 'out' or 'ref'. Do those mean the same thing? You just need to make sure that the address of the IntPtr value is provided so that it can be filled in.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • codemousecodemouse Global Mapper User Posts: 186Trusted User
    edited August 2010
    update. error that comes back is:

    GM_Error_t32.GM_Error_NotRegistered

    /// <summary>
    /// No registry key was found to enable this functionality.
    /// </summary>
    GM_Error_NotRegistered = 12,

    Is this functionality possible via c# and the current SDK?
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited August 2010
    That error means that your registration key for the SDK was not found, and generating contours requires a licensed version of the SDK. Make sure that your gmdll_regkey.txt file is in the same folder as the GlobalMapperInterface.dll file that you are using or that you are providing the license information via the GM_SetRegistrationInfo function.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • codemousecodemouse Global Mapper User Posts: 186Trusted User
    edited August 2010
    Mike,

    Answered my own question - this one was silly, the license file was not in the correct /bin folder. Works now - good to know I can extend this if need be, though it's sometimes a bit of a challenge converting types between C# and C++.

    One other question - in the GM_ContourParams_t or in the process to Generate Contours, is there a switch/flag that mimics the UI functionality for "Interpolate to fill small gaps in data"?

    Thank you again...

    Brian
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited August 2010
    Brian,

    While there's not currently a way to control the "fill small gaps" option, that can easily be added if you need it.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • codemousecodemouse Global Mapper User Posts: 186Trusted User
    edited August 2010
    I may - will let you know. I do not need it yet. Some other toggles were missing too, but I haven't needed them quite yet (setting vertical unit in Meters/Feet for example). I see everything defaults to METERS which is OK.

    Brian
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited August 2010
    Brian,

    The GM_ContourParams_t.mIntervalInFeet value should control whether or not your contours are generated at some interval in feet or meters.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • codemousecodemouse Global Mapper User Posts: 186Trusted User
    edited August 2010
    Mike,

    Not the exact one I meant - when doing an ASCII import that is an Elevation Grid, when you get to the Elevation Grid Creation Options screen, you can select Vertical Units of METERS or FEET. I could not find a toggle for that or for Elevation Grid "No Data" Distance Tight/Loose.

    Brian
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited August 2010
    Brian,

    For grid generation, the GM_GridGenSetup_t.mElevUnits value controls the elevation units of the grid and the GM_GridGenSetup_t.mTightnessMult controls the tightness slider setting.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • codemousecodemouse Global Mapper User Posts: 186Trusted User
    edited August 2010
    Mike,

    Thanks for the info about Grid generation - I will try this out.

    Brian
Sign In or Register to comment.