Error Invalid layer on GM_CalcViewShed

Hello
I am trying to calculate view shed using c#. and keep getting GM_Error_InvalidLayer even though I cross check the parameter values in both the C++ (sample application) and my c# program. Would you please tell me what the problem might be.
The code is attached

Thanks

Answers

  • aaronc
    aaronc Trusted User
    Answer ✓
    I haven't had a chance to look into it but it looks like it is not appropriately handling a null layer.  To get it to work try passing in a layer to use.  If you are still having a problem let me know.

    I'll investigate the issue with passing a IntPtr.Zero and see if that is the problem.
  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User
    The issue looks to be the setup of theViewShedParams.mVectorLayerList for providing vector obstructions to the view shed calculation. The sample code is providing the GM_LayerInfo_t* for theCustomLayer rather than providing the address of theCustomLayer itself.

    The mVectorLayerList is an array of GM_LayerHandle_t32 values (GM_LayerHandle_t32* in C/C++). If you needed to pass multiple layer handles you would need to marshal some memory to store an array of the GM_LayerHandle_t32 values, but since you are just passing one I think you can use something like the following:

    fixed ( GM_LayerHandle_t32* theCustomLayerPtr = &theCustomLayer )
    {
        theViewShedParams.mVectorLayerList = theCustomLayerPtr ;
        theViewShedParams.mVectorLayerListCnt = 1;
        theViewShedParams.mDesc = "view shed test";

        IntPtr rlayer = new IntPtr();
        theErr = GlobalMapperDLL.GM_CalcViewShed(IntPtr.Zero, ref theViewShedParams, ref rlayer);
    }

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    http://www.bluemarblegeo.com/
  • Thanks guys that was the answer to my question your help is appreciated.
    I was confused between a pointer to the layer info and the layer itself.

    Just one more silly question:

    1. when I create a point or viewshed, (4) labels appear around the point I just need one label. Should I hide them and draw the label manually.

    Thanks,

    Mehsen
  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User
    Mehsen,

    If you are seeing 4 labels around a point it sounds like you have 4 points at the same location, all with the default label position of 'automatic', which means the label will try positions around the point to place the label if a position already has a label. For 4 points at the same location you would get a label at each corner.

    Are you possibly creating multiple view sheds at the same location?

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    http://www.bluemarblegeo.com/
  • I am adding one point only:

      GM_PointFeature_t thePoint = new GM_PointFeature_t();
               
                IntPtr theLayer = (IntPtr)LayerHandles[0];
                thePoint.mFeatureInfo.mName = "P1";
                thePoint.mFeatureInfo.mDesc = null;
               
                thePoint.mPointStyle.mSymbolName = "dish";
                thePoint.mPointStyle.mDrawLabel = 0;
                thePoint.mPointStyle.mDrawLabelAlways = 0;
                thePoint.mPos.mX = 2088624;
                thePoint.mPos.mY = 1901427;
                thePoint.mFeatureInfo.mClass = (ushort)PointFeatureClass_t16.PFC_LANDMARK;
                
               
                LastGMError = GlobalMapperDLL.GM_AddPointToVectorLayer(theLayer, ref thePoint,0 );
                IntPtr ipInf = GlobalMapperDLL.GM_GetLayerInfo(theLayer);
                GM_LayerInfo_t inf = (GM_LayerInfo_t)Marshal.PtrToStructure(ipInf, typeof(GM_LayerInfo_t));
                Console.WriteLine(inf.mNumPoints.ToString()); // print 1

                DrawLayersToBitmap();
                Refresh();

  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User
    What does your 'DrawLayersToBitmap()' code look like? Is it possible the same layer handle is being provided multiple times to the list of layers to draw?

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    http://www.bluemarblegeo.com/
  • It is from the samples in  official package 
  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User
    Can you call GM_SaveWorkspace to save the loaded layers to a .gmw (workspace) file and then provide that? The .gmw will contain all layers and features. You can also load that in the Global Mapper desktop application and see if you see the same behavior. Thanks, Mike Global Mapper Guru geohelp@bluemarblegeo.com http://www.bluemarblegeo.com/
  • The global mapper app works fine with the attached .txt (.gmw) is not allowed)

    more info:
    1. OS : windows 8.1 (64)
    2. Visual Studio 2010
    2. The c++ from the sample application produces the same behavior:smile:
    3. I tried using 64 binaries. same behavior.:
    4. I downloaded SDK v.16. the same behavior.
  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User
    Answer ✓
    I have been able to reproduce the problem. Indeed any raster layer that also had vector data (like a view shed coverage with a point label) was drawing the vector features 2 or 4 times (depending on the draw order flag). I've fixed this now.

    We are in the process of making new installers for the v17.2 SDK, so for now I've placed a .zip with the updated DLLs at http://www.globalmapper.com/GlobalMapperSDK_v17_latest_beta.zip .

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    http://www.bluemarblegeo.com/
  • Thanks Mike, it works fine