Get error when run script to calculate volume

trong_tdtrong_td Posts: 8
I am trying using C# SDK to calculate cut/fill volume, but i always get Zero result, this is my code

var File = "D:\\Projects\\Drone\\quarry_dsm.tif";
            Console.WriteLine("Load file when caculating volume " + File);
            // Load the layer
            IntPtr theLayerList;
            UInt32 theNumLayers = 0;
            LastGMError = GlobalMapperDLL.GM_LoadLayerList(File, out theLayerList, out theNumLayers, 0);
            // If the layer loaded successfully then get the layer info.
            // User the bounding rectangle in the layer info as the curent
            // view rectangle.
            if (LastGMError == GlobalMapperDLL.GM_Error_t32.GM_Error_None)
            {
                // Add each layer
                for (Int32 i = 0; i < theNumLayers; i++)
                {
                    // Extract the layer handle from the list
                    IntPtr theLayerHandlePtr = (IntPtr)((UInt32)theLayerList + i * IntPtr.Size);
                    IntPtr theLayerHandle;
                    theLayerHandle = (IntPtr)Marshal.PtrToStructure(theLayerHandlePtr, typeof(IntPtr));
                    // Add the layer
                    AddLayer(theLayerHandle, true);
                    Console.WriteLine("Count layer " + LayerHandles.Count);
                    GM_Point_t A;
                    A.mX = 205260.911678;
                    A.mY = 1770722.30487;
                    GM_Point_t B;
                    B.mX = 205269.92369;
                    B.mY = 1770609.09146;
                    GM_Point_t C;
                    C.mX = 205385.39010;
                    C.mY = 1770659.78403;

                    GM_Point_t[] points = new GM_Point_t[3] { A, B, C};
                    IntPtr intPtr;
                    unsafe
                    {
                        // Must pin object on heap so that it doesn't move while using interior pointers.  
                        fixed (GM_Point_t* pArray = points)
                        {
                            // p is pinned as well as object, so create another pointer to show incrementing it.  
                            intPtr = new IntPtr((void*)pArray);
                        }
                    }
                    GlobalMapperDLL.GM_AreaVolumeParams_t gM_AreaVolumeParams_T;
                    gM_AreaVolumeParams_T.mSize = 3;
                    gM_AreaVolumeParams_T.mPoints = intPtr;
                    gM_AreaVolumeParams_T.mNumPoints = 4;
                    gM_AreaVolumeParams_T.mCutHeight = 10;
                    gM_AreaVolumeParams_T.mXSpacing = 0.00927500000000054;
                    gM_AreaVolumeParams_T.mYSpacing = 0.00927500000000029;

                    double cutVolume;
                    double fillVolume;
                    GlobalMapperDLL.GM_CalcVolumeOfArea(theLayerHandle, ref gM_AreaVolumeParams_T, out cutVolume, out fillVolume);
                    System.Console.WriteLine("Calculate Fill volume " + fillVolume.ToString());
                    System.Console.WriteLine("Calculate CUT volume " + cutVolume.ToString());
                }
             }
            else if (GlobalMapperDLL.GM_Error_t32.GM_Error_NotRegistered == LastGMError)
            {
                MessageBox.Show("Please register to load more files.");
                return;
            }

Can you plz help me check ?

Thanks

Answers

  • trong_tdtrong_td Posts: 8
    Anyone can help me  check this please, i need asap.
    Thanks
  • trong_tdtrong_td Posts: 8
    Tell me know if the content is not clear.  Do I make myself perfectly clear?
  • aaroncaaronc Posts: 25Trusted User
    It looks like your problem is here:

                        gM_AreaVolumeParams_T.mSize = 3;
                        gM_AreaVolumeParams_T.mPoints = intPtr;
                        gM_AreaVolumeParams_T.mNumPoints = 4;

    mSize is the size of the structure if you can get that size yourself or if you set it to 0 then I believe it will be calculated internally.  Also mNumPoints should be 3 as you only have 3 points.

    I hope this helps

    - Aaron
    trong_td
  • trong_tdtrong_td Posts: 8
    Hi @aaronc
    Thanks for your answering, but i change mNumPoints to 3, mSize to 0 but it dose not work
    I also tried:
    int size = System.Runtime.InteropServices.Marshal.SizeOf(gM_AreaVolumeParams_T);
    gM_AreaVolumeParams_T.mSize = (uint)size;
    but same issue.
    This is my geotif file: https://drive.google.com/open?id=1ltWKGgVFDsNkNAMqKawYNPIwZgjn9emp
    Can you help me check it ?
  • aaroncaaronc Posts: 25Trusted User
    Sorry, for the delay.  It's been pretty busy here. It looks like the points are not in a valid location this file has this global rectangle.

    mGlobalRect.mMaxX == 440230.32666000008
    mGlobalRect.mMaxY == 4588327.3269700008
    mGlobalRect.mMinX == 439857.01470000006
    mGlobalRect.mMinY == 4587304.1915500006

    -Aaron
Sign In or Register to comment.