jhedmonton 0 Newbie Poster

I am using the shapelib dll, which is an older c-based dll. in order to get all values I use Marshal.Copy and everything works however I can't seem to get my head around the following problem:

`Inline Code Example Here`
 pshpObj = ShapeLib.SHPReadObject(hShp, i);
                                // Get the SHPObject associated with our IntPtr pshpObj
                                // We create a new SHPObject in managed code, then use Marshal.PtrToStructure
                                // to copy the unmanaged memory pointed to by pshpObj into our managed copy.
                                ShapeLib.SHPObject shpObj = new ShapeLib.SHPObject();
                                Marshal.PtrToStructure(pshpObj, shpObj);
                                 if ((shpObj.nParts > 0) || (shpObj.nVertices >0))
                                {
                                  myshape.parts = shpObj.nParts;
                                    myshape.partstart.Add(0);
                                             long[] partoffset = new long[shpObj.nParts];
                                        Marshal.Copy(shpObj.paPartStart, partoffset, 0, shpObj.nParts);
                                    //   System.Diagnostics.Debug.WriteLine("ShapeID=" + shpOb                  j.nShapeId.ToString());

                                    // Recover the vertices for this shape. Use Marshal.Copy to copy the memory pointed 
                                    // to by shpObj.padfX and shpObj.padfX (each an IntPtr) to a actual array.
                                    //   int iVertex = 2;
                                    double[] xCoord = new double[shpObj.nVertices];
                                    double[] yCoord = new double[shpObj.nVertices];


                                    Marshal.Copy(shpObj.padfX, xCoord, 0, shpObj.nVertices);
                                    Marshal.Copy(shpObj.padfY, yCoord, 0, shpObj.nVertices);
                                    bool watchformorepolygons = false;
                                    //do we have several polygons in ONE????
                                    if (shpObj.nParts > 1)
                                    {
                                    }
                                }

I can get the array of values from the c-dll (double[] xCoord) however if there are several parts, the c-dll has offsets into this one array to mark the start points of each part. I can get a long[] partoffset out of the c-dll however these pointervalues don't give me anything to determine the start index in my double[] array. On the C-side these are just pointers into a memory structure, since I use Marshal.Copy to get to values, how do I go about finding the right index into my c# double[] array?
Not sure I described this well..... hope I did...
Thanks!
Johannes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.