Ejemplo n.º 1
0
        /// <summary>
        /// Returns a MapWinGIS Multi-part PolyLine representing this multiLineString
        /// </summary>
        /// <returns>MapWinGIS Shape</returns>
        public static MapWinGIS.Shape mwShapeFromMultiLineString(MultiLineString MLS, MapWinGIS.ShpfileType sfType)
        {
            MapWinGIS.Shape mwShape = new MapWinGIS.Shape();
            mwShape.Create(sfType);
            int prt      = 0; // Part Index
            int pt       = 0; // Point Index
            int numParts = MLS.NumGeometries;
            int maxpt;

            while (prt < numParts)
            {
                LineString LS = MLS.GeometryN[prt] as LineString;
                maxpt = LS.Coordinates.Count;
                mwShape.InsertPart(pt, ref prt);
                for (int I = 0; I < maxpt; I++)
                {
                    MapWinGIS.Point mwPoint = new MapWinGIS.Point();
                    mwPoint.x = LS.Coordinates[I].X;
                    mwPoint.y = LS.Coordinates[I].Y;
                    bool result = mwShape.InsertPoint(mwPoint, ref pt);
                    if (result == false)
                    {
                        throw new ApplicationException(mwShape.get_ErrorMsg(mwShape.LastErrorCode));
                    }
                    pt++;
                }
                prt++;
            }
            return(mwShape);
        }
        private void AddRectangle(double LeftmostX, double LowestY, double RightmostX, double HighestY)
        {
            MapWinGIS.Shape newPolygon = new MapWinGIS.Shape();

            int partIndex = 0;

            newPolygon.Create(MapWinGIS.ShpfileType.SHP_POLYGON);
            newPolygon.InsertPart(0, ref partIndex);

            int shpIndex = 0;

            MapWinGIS.Point newPt = new MapWinGIS.Point();
            newPt.x = LeftmostX;
            newPt.y = HighestY;
            newPt.Z = 0;
            newPolygon.InsertPoint(newPt, ref shpIndex);

            newPt   = new MapWinGIS.Point();
            newPt.x = RightmostX;
            newPt.y = HighestY;
            newPt.Z = 0;
            newPolygon.InsertPoint(newPt, ref shpIndex);

            newPt   = new MapWinGIS.Point();
            newPt.x = RightmostX;
            newPt.y = LowestY;
            newPt.Z = 0;
            newPolygon.InsertPoint(newPt, ref shpIndex);

            newPt   = new MapWinGIS.Point();
            newPt.x = LeftmostX;
            newPt.y = LowestY;
            newPt.Z = 0;
            newPolygon.InsertPoint(newPt, ref shpIndex);

            // Finalize -- add it.
            MapWinGIS.Shapefile sf = (MapWinGIS.Shapefile)g.MapWin.Layers[g.MapWin.Layers.CurrentLayer].GetObject();
            if (!sf.EditingShapes || !sf.EditingTable)
            {
                sf.StartEditingShapes(true, null);
            }

            int addedShapes = sf.NumShapes;

            sf.EditInsertShape(newPolygon, ref addedShapes);

            g.CreateUndoPoint();

            sf.StopEditingShapes(true, true, null);

            // Release memory used by point reallocations above
            GC.Collect();

            // And show it:
            g.UpdateView();

            g.MapWin.Plugins.BroadcastMessage("ShapefileEditor: Layer " + g.MapWin.Layers.CurrentLayer.ToString() + ": New Shape Added");
        }
        private void AddEllipse(double LeftmostX, double LowestY, double RightmostX, double HighestY)
        {
            MapWinGIS.Shape newPolygon = new MapWinGIS.Shape();

            int partIndex = 0;

            newPolygon.Create(MapWinGIS.ShpfileType.SHP_POLYGON);
            newPolygon.InsertPart(0, ref partIndex);

            int shpIndex = 0;

            double t, a, b, tinc, centx, centy;

            a     = RightmostX - LeftmostX;
            b     = HighestY - LowestY;
            tinc  = Math.PI * 2 / (a + b);
            centx = (LeftmostX + RightmostX) * .5;
            centy = (LowestY + HighestY) * .5;

            MapWinGIS.Point newPt = new MapWinGIS.Point();
            newPt.x = centx + a;
            newPt.y = centy;
            newPt.Z = 0;
            newPolygon.InsertPoint(newPt, ref shpIndex);

            for (t = 0; t < Math.PI * 2; t += tinc)
            {
                MapWinGIS.Point nextPt = new MapWinGIS.Point();
                nextPt.x = centx + a * Math.Cos(t);
                nextPt.y = centy - b * Math.Sin(t);
                nextPt.Z = 0;
                newPolygon.InsertPoint(nextPt, ref shpIndex);
            }

            // Finalize -- add it.
            MapWinGIS.Shapefile sf = (MapWinGIS.Shapefile)g.MapWin.Layers[g.MapWin.Layers.CurrentLayer].GetObject();
            if (!sf.EditingShapes || !sf.EditingTable)
            {
                sf.StartEditingShapes(true, null);
            }

            int addedShapes = sf.NumShapes;

            sf.EditInsertShape(newPolygon, ref addedShapes);

            g.CreateUndoPoint();

            sf.StopEditingShapes(true, true, null);

            // And show it:
            g.UpdateView();

            g.MapWin.Plugins.BroadcastMessage("ShapefileEditor: Layer " + g.MapWin.Layers.CurrentLayer.ToString() + ": New Shape Added");
        }
        private void AddRegularPolygon(int sides, double sidelength, double centroidX, double centroidY)
        {
            double pi      = 3.1415926535897932384626433832795;
            double apothem = sidelength / (2 * Math.Tan(pi / sides));
            double radius  = sidelength / (2 * Math.Sin(pi / sides));

            MapWinGIS.Shape newPolygon = new MapWinGIS.Shape();

            int partIndex = 0;

            newPolygon.Create(MapWinGIS.ShpfileType.SHP_POLYGON);
            newPolygon.InsertPart(0, ref partIndex);

            double i        = 0;
            int    shpIndex = 0;

            // Approximate the polygon with n line segments
            double increment = ((2 * pi) / sides);

            for (; i <= 2 * pi; i += increment, shpIndex++)
            {
                MapWinGIS.Point newPt = new MapWinGIS.Point();

                newPt.x = (radius * Math.Cos(i) + centroidX);
                newPt.y = (radius * Math.Sin(i) + centroidY);
                newPt.Z = 0;

                newPolygon.InsertPoint(newPt, ref shpIndex);
            }

            // Finalize -- add it.
            MapWinGIS.Shapefile sf = (MapWinGIS.Shapefile)g.MapWin.Layers[g.MapWin.Layers.CurrentLayer].GetObject();
            if (!sf.EditingShapes || !sf.EditingTable)
            {
                sf.StartEditingShapes(true, null);
            }

            int addedShapes = sf.NumShapes;

            sf.EditInsertShape(newPolygon, ref addedShapes);

            g.CreateUndoPoint();

            sf.StopEditingShapes(true, true, null);

            // And show it:
            g.UpdateView();

            g.MapWin.Plugins.BroadcastMessage("ShapefileEditor: Layer " + g.MapWin.Layers.CurrentLayer.ToString() + ": New Shape Added");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Insers part to polygon based on given rectange
        /// </summary>
        private void InsertPart(MapWinGIS.Shape shp, double xMin, double xMax, double yMin, double yMax)
        {
            int numParts = shp.NumParts;

            shp.InsertPart(shp.numPoints, ref numParts);

            // to left
            int index = shp.numPoints;

            MapWinGIS.Point pnt = new MapWinGIS.Point();
            pnt.x = xMin; pnt.y = yMax;
            shp.InsertPoint(pnt, ref index); index++;

            pnt   = new MapWinGIS.Point();
            pnt.x = xMax; pnt.y = yMax;
            shp.InsertPoint(pnt, ref index); index++;

            pnt   = new MapWinGIS.Point();
            pnt.x = xMax; pnt.y = yMin;
            shp.InsertPoint(pnt, ref index); index++;

            pnt   = new MapWinGIS.Point();
            pnt.x = xMin; pnt.y = yMin;
            shp.InsertPoint(pnt, ref index); index++;

            pnt   = new MapWinGIS.Point();
            pnt.x = xMin; pnt.y = yMax;
            shp.InsertPoint(pnt, ref index); index++;

            if (!shp.get_PartIsClockWise(0))
            {
                bool val = shp.ReversePointsOrder(0);
                if (!val)
                {
                    System.Diagnostics.Debug.Print("CCW");
                }
            }

            if (!shp.get_PartIsClockWise(0))
            {
                System.Diagnostics.Debug.Print("CCW");
            }
        }