Exemple #1
0
        public void generateGeometryStructureInDLL(ShapeObject shpObject,
            ref GravurGIS.Topology.Grid.Grid partGrid)
        {
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();

            IntPtr cPointObjectPtr;

            if (LayerCount == 0)
                cPointObjectPtr = ShapeLib.SHPGetPolyLineList(shpObject.LayerInfo.FilePath, shpObject.Access,
                    mainControler.MapPanel.Width, mainControler.MapPanel.Height,
                    mainControler.MapPanel.Margin, 1, 1.0d, 0,pointSize, 0);
            else
                cPointObjectPtr = ShapeLib.SHPGetPolyLineList(shpObject.LayerInfo.FilePath, shpObject.Access,
                    mainControler.MapPanel.Width, mainControler.MapPanel.Height,
                    mainControler.MapPanel.Margin, 1, firstScale, 1,0, 0);

            if (cPointObjectPtr.Equals(IntPtr.Zero))
            {
                mainControler.showErrorMessage("Fehler 0x0002: Shapereferenz ist ungültig");
            }
            else
            {
                int momentaryPointCount;
                double[] xWorldList;
                double[] yWorldList;
                int[] xDispList;
                int[] yDispList;
                int pointCount = 0;

                ShapeLib.PointObject pntObj = new ShapeLib.PointObject();
                Marshal.PtrToStructure(cPointObjectPtr, pntObj);

                shpObject.BoundingBox = new WorldBoundingBoxD(pntObj.minBX,
                    pntObj.maxBY, pntObj.maxBX, pntObj.minBY);

                if (pntObj.isWellDefines == 0)
                    shpObject.IsWellDefined = false;
                else
                    shpObject.IsWellDefined = true;

                if (LayerCount == 0)
                {
                    mainControler.MapPanel.AbsolutZoom = 1;

                    if (pntObj.isPoint == 0) //normal shpObject
                    {
                        this.firstScale = this.scale = pntObj.scale;

                        mainControler.MapPanel.DX = firstScale * pntObj.minBX;
                        mainControler.MapPanel.DY = firstScale * pntObj.maxBY;
                    }
                    else //shpObject contains only 1 point
                    {
                        // 1:1 Maßstab oder lieber schon etwas rauszoomen?
                        this.scale = pntObj.scale; // ((mainControler.MapPanel.Width) - 2 * (mainControler.MapPanel.Margin) - 2) / (double)defaultShapeSize;
                        this.firstScale = this.scale;

                        shpObject.IsOnePoint = true;
                        mainControler.MapPanel.DX = firstScale * (pntObj.minBX - (int)(defaultShapeSize / 2));
                        mainControler.MapPanel.DY = firstScale * (pntObj.maxBY + (int)(defaultShapeSize / 2));
                    }
                }

                shpObject.NumberOfShapes = (uint)(pntObj.shapeCount > 0 ? pntObj.shapeCount : 0);

                shpObject.ShapeType = pntObj.shpType;
                shpObject.PartCount = (uint)(pntObj.partCount > 0 ? pntObj.partCount : 0);

                PointList[] polyLinePointList;

                // make sure we have shapes and parts
                if (pntObj.shapeCount > 0
                    && (pntObj.partCount > 0 || pntObj.shpType == ShapeLib.ShapeType.Point))
                {
                    // Create the outer list which holds the pointers to the sublists
                    xWorldList = new double[pntObj.nVertices];
                    Marshal.Copy(pntObj.worldX, xWorldList, 0, pntObj.nVertices);
                    yWorldList = new double[pntObj.nVertices];
                    Marshal.Copy(pntObj.worldY, yWorldList, 0, pntObj.nVertices);
                    xDispList = new int[pntObj.nVertices];
                    Marshal.Copy(pntObj.dispX, xDispList, 0, pntObj.nVertices);
                    yDispList = new int[pntObj.nVertices];
                    Marshal.Copy(pntObj.dispY, yDispList, 0, pntObj.nVertices);

                    // Create a new Grid
                    partGrid = new GravurGIS.Topology.Grid.Grid(25, 25,
                        Convert.ToInt32(shpObject.Width * firstScale),
                        Convert.ToInt32(shpObject.Height * firstScale), false);

                    if (pntObj.shpType != ShapeLib.ShapeType.MultiPoint
                        && pntObj.shpType != ShapeLib.ShapeType.Point)
                    {
                        // Get the list with the lengths of the sublists
                        int[] partListLengths = new int[pntObj.partCount];
                        Marshal.Copy(pntObj.partListLengths, partListLengths, 0, pntObj.partCount);

                        // Copy the sublists to a new pointList
                        polyLinePointList = new PointList[pntObj.partCount];

                        for (int i = 0; i < pntObj.partCount; i++)
                        {
                            momentaryPointCount = partListLengths[i];

                            polyLinePointList[i] = new PointList(momentaryPointCount);

                            // Copy the temporay lists into points and into the polyPointList
                            for (int j = 0; j < momentaryPointCount; j++)
                            {
                                int pos = pointCount + j;
                                polyLinePointList[i].add(xWorldList[pos],
                                    yWorldList[pos], xDispList[pos], yDispList[pos], j);
                            }
                            partGrid.insert(polyLinePointList[i], getBoundingBox(ref polyLinePointList[i]));

                            pointCount += momentaryPointCount;
                        }
                    }
                    else  //shpType == MultiPoint
                    {
                        polyLinePointList = new PointList[pntObj.shapeCount];
                        for (int i = 0; i < pntObj.shapeCount; i++)
                        {
                            polyLinePointList[i] = new PointList(1);
                            polyLinePointList[i].add(xWorldList[i], yWorldList[i], xDispList[i], yDispList[i], 0);
                            partGrid.insert(polyLinePointList[i], getBoundingBox(ref polyLinePointList[i]));
                        }

                    }

                    shpObject.PolyLinePointList = polyLinePointList;
                    //double tempAbsZoom = mainControler.MapPanel.AbsolutZoom;

                    // TODO: Warum wird das hier gemacht? Wird das wirklich gebraucht?
                    // Tom: Ich habe es erstmal auskommentiert
                    //int dispHeight = (int)(shpObject.BoundingBox.Height * scale + 0.5);
                    //for (int pointList = 0; pointList < shpObject.PartCount; pointList++)
                    //    shpObject.PolyLinePointList[pointList].recalculatePoints(scale, dispHeight, pntObj.minBX, pntObj.minBY);
                }

                shpObject.Changed = true;

                stopWatch.Stop();

                mainControler.addLogMessage(String.Format("[Shape] geladen nach {0}ms", stopWatch.ElapsedMilliseconds.ToString()));

                // clean things up
                MapTools.ShapeLib.deletePointObject(cPointObjectPtr);
            }
        }
Exemple #2
0
        /// <summary>
        /// Loads shapefile data for editing
        /// </summary>
        /// <param name="path">Path with filename and extension to the shapefile to open</param>
        /// <param name="clearBeforeImport">true: previous data on this layer will be deleted false: no deletion</param>
        public void ImportAsTransportLayer(string path, bool clearBeforeImport)
        {
            IntPtr cPointObjectPtr;

            // Load the file
            cPointObjectPtr = ShapeLib.SHPGetPolyLineList(path, "rb",
                    mainControler.MapPanel.Width, mainControler.MapPanel.Height,
                    mainControler.MapPanel.Margin, 1, 1.0d, 1, 0, 1);

            if (cPointObjectPtr.Equals(IntPtr.Zero))
                mainControler.addLogMessage("Fehler 0x0002: Shapereferenz ist ungültig\n" + path);
            else
            {
                int momentaryPointCount;
                double[] xList;
                double[] yList;
                int pointCount = 0;
                LayerType lType;

                ShapeLib.PointObject pntObj = new ShapeLib.PointObject();
                Marshal.PtrToStructure(cPointObjectPtr, pntObj);

                double[] MinB = new double[4] { pntObj.minBX, pntObj.minBY, 0.0, 0.0 };
                double[] MaxB = new double[4] { pntObj.maxBX, pntObj.maxBY, 0.0, 0.0 };

                // make sure we have shapes and parts
                if (pntObj.shapeCount > 0 && pntObj.partCount > 0)
                {
                    // Create the outer list which holds the pointers to the sublists
                    xList = new double[pntObj.nVertices];
                    Marshal.Copy(pntObj.worldX, xList, 0, pntObj.nVertices);
                    yList = new double[pntObj.nVertices];
                    Marshal.Copy(pntObj.worldY, yList, 0, pntObj.nVertices);

                    // potentially clear the underlying layers
                    if (clearBeforeImport)
                    {
                        switch (pntObj.shpType)
                        {
                            case ShapeLib.ShapeType.MultiPoint:
                                ClearTransportLayer(LayerType.PointCanvas);
                                break;
                            case ShapeLib.ShapeType.Polygon:
                                ClearTransportLayer(LayerType.PolygonCanvas);
                                break;
                            case ShapeLib.ShapeType.PolyLine:
                                ClearTransportLayer(LayerType.PolylineCanvas);
                                break;
                            default:
                                break;
                        }
                    }

                    // "draw" the data
                    if (pntObj.shpType == ShapeLib.ShapeType.MultiPoint)
                    {
                        for (int i = 0; i <= pntObj.shapeCount - 1; i++)
                            mainControler.PerformAction(
                                new DrawAction(1.0, xList[i], -yList[i], mainControler));
                    }
                    else if (pntObj.shpType == ShapeLib.ShapeType.PolyLine
                        || pntObj.shpType == ShapeLib.ShapeType.Polygon)
                    {
                        if (pntObj.shpType == ShapeLib.ShapeType.PolyLine)
                            lType = LayerType.PolylineCanvas;
                        else
                            lType = LayerType.PolygonCanvas;

                        // Get the list with the lengths of the sublists
                        int[] partListLengths = new int[pntObj.partCount];
                        Marshal.Copy(pntObj.partListLengths, partListLengths, 0, pntObj.partCount);

                        for (int i = 0; i < pntObj.partCount; i++)
                        {
                            momentaryPointCount = partListLengths[i];

                            // if we are loading a polygon we have to decrement
                            // the pointCount of the current part since the last point
                            // is the same as the first one and this is added with
                            // the FinishDrawingAction
                            if (lType == LayerType.PolygonCanvas)
                            {
                                momentaryPointCount--;
                                // add one more (+1) to compensate the decrement before
                                pointCount++;
                            }

                            // add the first polyline point
                            mainControler.PerformAction(
                                new DrawAction(lType,
                                                xList[pointCount], -yList[pointCount],
                                                false, mainControler));

                            // Copy the temporay lists into points and into the polyPointList
                            // we start at 1 since we added the first point seperately
                            for (int j = 1; j < momentaryPointCount; j++)
                            {
                                mainControler.PerformAction(
                                    new DrawAction(lType,
                                                   xList[pointCount + j],
                                                   -yList[pointCount + j],
                                                   true, mainControler));
                            }

                            mainControler.PerformAction(
                                new FinishDrawingAction(lType, this));

                            pointCount += momentaryPointCount;
                        }

                    }
                }
                ShapeLib.deletePointObject(cPointObjectPtr);
            }
        }