Example #1
0
        /// <summary>
        /// Inserts a point in the list.  Remember that this list does not need to
        /// end with the first point.  Invalidates derived properties so that they
        /// will be recalculated when queried.
        /// </summary>
        /// <param name="Index">The index specifying where to insert the point</param>
        /// <param name="mwPoint">The MapWinGIS.Point you want to insert into this Polygon</param>
        public void Insert_Point(int Index, MapWinGIS.Point mwPoint)
        {
            Point newPoint = new Point(mwPoint);

            m_Points.Insert(Index, newPoint);
            Invalidate();
        }
Example #2
0
        /// <summary>
        /// Returns the conversion factor between the map units and inches
        /// </summary>
        /// <param name="MapWinUnits">A string represing the MapUnits</param>
        /// <param name="CenterPoint">The center coodinates of the screen in MapUnits</param>
        /// <returns>A double representing the conversion factor between MapUnits and inches. If something goes wrong we return 0</returns>
        private static double getConversionFactor(string MapWinUnits, MapWinGIS.Point CenterPoint)
        {
            switch (MapWinUnits.ToLower())
            {
            case "lat/long":
                return(DegreesFactor(CenterPoint));

            case "meters":
                return(39.3700787);

            case "centimeters":
                return(0.393700787);

            case "feet":
                return(12);

            case "inches":
                return(1);

            case "kilometers":
                return(39370.0787);

            case "miles":
                return(63360);

            case "millimeters":
                return(0.0393700787);

            case "yards":
                return(36);

            default:
                return(0);
            }
        }
Example #3
0
        /// <summary>
        /// Will check to see if two points are identical.
        /// </summary>
        /// <param name="point1">The first point to consider.</param>
        /// <param name="point2">The second point to consider.</param>
        /// <param name="sfType">The type of shapefile the points belong to.</param>
        /// <param name="mergedShp">The result shape</param>
        /// <returns>True if the points were merged successfully, false otherwise.</returns>
        private static bool MergePoints(ref MapWinGIS.Point point1, ref MapWinGIS.Point point2, MapWinGIS.ShpfileType sfType, out MapWinGIS.Shape mergedShp)
        {
            MapWinUtility.Logger.Dbg("MergePoints(point1: " + Macro.ParamName(point1) + "\n," +
                                     "            point2: " + Macro.ParamName(point2) + "\n," +
                                     "            sfType: " + sfType.ToString() + "\n," +
                                     "            mergedShp: out)");

            MapWinGIS.Shape mShp = new MapWinGIS.ShapeClass();
            if (point1.x == point2.x && point1.y == point2.y && point1.Z == point2.Z)
            {
                mShp.Create(sfType);
                int ptIndex = 0;
                mShp.InsertPoint(point1, ref ptIndex);
            }
            mergedShp = mShp;
            if (mergedShp.numPoints > 0)
            {
                MapWinUtility.Logger.Dbg("Finished MergePoints");
                return(true);
            }
            else
            {
                gErrorMsg = "The points are not identical so they cannot be merged.";
                Debug.WriteLine(gErrorMsg);
                Error.SetErrorMsg(gErrorMsg);
                mergedShp = mShp;
                MapWinUtility.Logger.Dbg(gErrorMsg);
                return(false);
            }
        }
        //---------------------------- Derive_Coefficients------------------------------------------
        /// <summary>
        /// Initializes the projective coefficients.  Requires that the input is
        /// a rectangular image, and the output points are the projected output
        /// values corresponding to the input image corners in the following positions:
        /// pt2 - pt3
        ///  |     |
        /// pt1 - pt4
        /// // X' = (aX + bY + c) / (gX + hY + 1)
        /// // Y' = (dX + eY + f) / (gX + hY + 1)
        /// </summary>
        /// <param name="ImageWidth">The width of the entire original image in pixels</param>
        /// <param name="ImageHeight">The height of the entire original image in pixels</param>
        /// <param name="ptLowerLeft">The projected location of the lower left corner of the input image</param>
        /// <param name="ptUpperLeft">The projected location of the upper left corner of the input image</param>
        /// <param name="ptUpperRight">The projected location of the upper right corner of the input image</param>
        /// <param name="ptLowerRight">The projected location of the lower right corner of the input image</param>
        public void Derive_Coefficients(int ImageWidth, int ImageHeight,
                                        MapWinGIS.Point ptLowerLeft, MapWinGIS.Point ptUpperLeft, MapWinGIS.Point ptUpperRight, MapWinGIS.Point ptLowerRight)
        {
            double x, y;

            m_InputHeight = ImageHeight;
            m_InputWidth  = ImageWidth;

            Size_Coordinates(ImageWidth, ImageHeight, ptLowerLeft, ptUpperLeft, ptUpperRight, ptLowerRight);

            x = (double)ImageWidth;
            y = (double)ImageHeight;

            a = -(-Xul * Yll * Xlr + Xur * Yll * Xlr - Xur * Yul * Xlr + Xul * Yur * Xlr + Xll * Yul * Xur - Xul * Yur * Xll - Xur * Ylr * Xll + Xul * Ylr * Xll) / x / (Yur * Xlr + Yul * Xur - Yul * Xlr - Yur * Xul - Ylr * Xur + Ylr * Xul);
            b = (Xul * Yll * Xur - Xul * Yll * Xlr + Xul * Yur * Xlr - Xur * Ylr * Xul - Xll * Yur * Xlr - Xll * Yul * Xur + Xll * Yul * Xlr + Xur * Ylr * Xll) / y / (Yur * Xlr + Yul * Xur - Yul * Xlr - Yur * Xul - Ylr * Xur + Ylr * Xul);
            c = Xll;
            d = -(-Ylr * Yur * Xll + Ylr * Xll * Yul - Ylr * Yul * Xur + Ylr * Yur * Xul + Yll * Yur * Xlr + Yll * Yul * Xur - Yll * Yul * Xlr - Yll * Yur * Xul) / x / (Yur * Xlr + Yul * Xur - Yul * Xlr - Yur * Xul - Ylr * Xur + Ylr * Xul);
            e = (Ylr * Xll * Yul - Yul * Yur * Xll + Yul * Yur * Xlr - Ylr * Yul * Xur - Yll * Yur * Xlr + Yll * Yur * Xul + Ylr * Yll * Xur - Ylr * Xul * Yll) / y / (Yur * Xlr + Yul * Xur - Yul * Xlr - Yur * Xul - Ylr * Xur + Ylr * Xul);
            f = Yll;
            g = -(Yur * Xlr - Yul * Xlr - Xul * Yll - Yur * Xll - Ylr * Xur + Ylr * Xul + Xll * Yul + Yll * Xur) / (Yur * Xlr + Yul * Xur - Yul * Xlr - Yur * Xul - Ylr * Xur + Ylr * Xul) / x;
            h = (Ylr * Xll + Yll * Xur - Yll * Xlr - Yul * Xur + Yul * Xlr - Yur * Xll - Ylr * Xul + Yur * Xul) / y / (Yur * Xlr + Yul * Xur - Yul * Xlr - Yur * Xul - Ylr * Xur + Ylr * Xul);


            // Establish if our affine is good enough
            // evaluate_Affine();

            Defined = true;
            return;
        }
Example #5
0
        // Returns only the point index values of the shapes in the interesection of the shape extents
        private static void PointsOfInterest(MapWinGIS.Shape Shape1, MapWinGIS.Shape Shape2, ref List <int> Points1, ref List <int> Points2)
        {
            Envelope Rect1, Rect2, rectIntersect;

            Rect1         = new Envelope(Shape1.Extents);
            Rect2         = new Envelope(Shape2.Extents);
            rectIntersect = (Envelope)Rect1.Intersection(Rect2);
            MapWinGIS.Point pt = new MapWinGIS.Point();
            // reduce our points to points of interrest
            int numPoints1 = Shape1.numPoints;

            for (int I = 0; I < numPoints1; I++)
            {
                pt = Shape1.get_Point(I);
                if (rectIntersect.Intersects(pt))
                {
                    Points1.Add(I);
                }
            }

            int numPoints2 = Shape2.numPoints;

            for (int I = 0; I < numPoints2; I++)
            {
                pt = Shape2.get_Point(I);
                if (rectIntersect.Intersects(pt))
                {
                    Points2.Add(I);
                }
            }
        }
Example #6
0
 /// <summary>
 /// This creates a strongly typed MapWinGIS Point from a coordinate
 /// </summary>
 /// <param name="Coord">The coordinates to turn into points</param>
 /// <returns>MapWinGIS.Point</returns>
 public static MapWinGIS.Point mwPointFromCoord(Coordinate Coord)
 {
     MapWinGIS.Point mwPoint = new MapWinGIS.Point();
     mwPoint.x = Coord.X;
     mwPoint.y = Coord.Y;
     return(mwPoint);
 }
Example #7
0
        private void ShrinkOrGrowPoly(ref MapWinGIS.Shape shp, double distance)
        {
            MapWinGIS.Point centroid = MapWinGeoProc.Statistics.Centroid(ref shp);
            // Avoid OLE calls; cache centroid point in local variable
            double cx = centroid.x;
            double cy = centroid.y;

            for (int i = 0; i < shp.numPoints; i++)
            {
                double ox = shp.get_Point(i).x;
                double oy = shp.get_Point(i).y;
                // Find the adjusted "real" distance (rdistance)
                double rdistance = Math.Sqrt(Math.Pow(cy - oy, 2) + Math.Pow(cx - ox, 2)) + distance;
                // Find the full distance of point to centroid (fdistance)
                double fdistance = Math.Sqrt(Math.Pow(cy - oy, 2) + Math.Pow(cx - ox, 2));

                if (rdistance < 0.00001)
                {
                    MapWinUtility.Logger.Message("Shrinking the shape by this amount will result in losing some shape geometry; aborting.", "Aborting - Loss of Geometry", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, DialogResult.OK);
                    return;
                }

                // Find the new point (project the old point along the line from point to midpoint)
                shp.get_Point(i).x = cx + (rdistance / fdistance) * (ox - cx);
                shp.get_Point(i).y = cy + (rdistance / fdistance) * (oy - cy);
            }
        }
Example #8
0
 /// <summary>
 /// This creates a strongly typed MapWinGIS Point from a Topology.Point
 /// </summary>
 /// <param name="Loc">The coordinates to turn into points</param>
 /// <returns>MapWinGIS.Point</returns>
 public static MapWinGIS.Point mwPointFromPoint(Point Loc)
 {
     MapWinGIS.Point mwPoint = new MapWinGIS.Point();
     mwPoint.x = Loc.X;
     mwPoint.y = Loc.Y;
     return(mwPoint);
 }
Example #9
0
 /// <summary>
 /// Returns true if X and Y coordinates are different
 /// </summary>
 /// <param name="U">A Point to compare</param>
 /// <param name="objV">An object to compare</param>
 /// <returns>Boolean, true if the vectors are the different</returns>
 public static bool operator !=(Point U, Object objV)
 {
     if (objV.GetType() == typeof(Coordinate))
     {
         Coordinate V = objV as Coordinate;
         if (V.X == U.X && V.Y == U.Y)
         {
             return(false);
         }
         return(true);
     }
     if (objV.GetType() == typeof(Point))
     {
         Point V = objV as Point;
         if (V.X == U.X && V.Y == U.Y)
         {
             return(false);
         }
         return(true);
     }
     if (objV.GetType() == typeof(MapWinGIS.Point))
     {
         MapWinGIS.Point V = objV as MapWinGIS.Point;
         if (V.x == U.X && V.y == U.Y)
         {
             return(false);
         }
         return(true);
     }
     return(true);
 }
Example #10
0
 /// <summary>
 /// This will return a strongly typed MapWinGIS Vector
 /// </summary>
 /// <param name="Vec">Vector</param>
 /// <returns>MapWinGIS.Point</returns>
 public static MapWinGIS.Point mwPointFromVector(Vector Vec)
 {
     MapWinGIS.Point mwPoint = new MapWinGIS.Point();
     mwPoint.x = Vec.X;
     mwPoint.y = Vec.Y;
     return(mwPoint);
 }
        private void MarkAllVertices()
        {
            try
            {
                MapWinGIS.Shape           shp = null;
                MapWinGIS.Shapefile       sf  = m_globals.CurrentLayer;
                MapWindow.Interfaces.View v   = m_globals.MapWin.View;

                //clear the drawings
                v.Draw.ClearDrawing(m_HDraw);
                m_HDraw = v.Draw.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList);

                //display all the vertices for each shape
                for (int i = 0; i < v.SelectedShapes.NumSelected; i++)
                {
                    shp = sf.get_Shape(v.SelectedShapes[i].ShapeIndex);

                    for (int j = 0; j < shp.numPoints; j++)
                    {
                        MapWinGIS.Point shpPoint = shp.get_Point(j);
                        m_globals.MapWin.View.Draw.DrawPoint(shpPoint.x, shpPoint.y, m_globals.VertexSize, System.Drawing.Color.Red);
                    }
                }
            }
            catch (System.Exception ex)
            {
                m_globals.MapWin.ShowErrorDialog(ex);
            }
        }
Example #12
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);
        }
Example #13
0
 /// <summary>
 /// A MapWinGIS.Point Representing the tip of the vector,
 /// where the beginning of the vector is at the origin
 /// /// </summary>
 public MapWinGIS.Point ToMWPoint()
 {
     MapWinGIS.Point pt = new MapWinGIS.Point();
     pt.x = X;
     pt.y = Y;
     pt.Z = Z;
     return(pt);
 }
Example #14
0
        /// <summary>
        /// Creates a MapWinGIS.Point from this point.
        /// </summary>
        /// <returns>A MapWinGIS.Point with the same X, Y and Z values</returns>
        public MapWinGIS.Point To_mwPoint()
        {
            MapWinGIS.Point mwPoint = new MapWinGIS.Point();
            mwPoint.x = X;
            mwPoint.y = Y;

            return(mwPoint);
        }
Example #15
0
        /// <summary>
        /// Stores a set of double values that represents a line segment.
        /// </summary>
        /// <param name="StartPoint">A MapWinGIS.Point representing the beginning of the line segment</param>
        /// <param name="EndPoint">A MapWinGIS.Point representing the end of the line segment</param>
        public Segment(MapWinGIS.Point StartPoint, MapWinGIS.Point EndPoint)
        {
            X1 = StartPoint.x;
            Y1 = StartPoint.y;

            X2 = EndPoint.x;
            Y2 = EndPoint.y;
        }
Example #16
0
 /// <summary>
 /// Checks each value in the point to see if they are the same
 /// </summary>
 /// <param name="Point">The MapWinGIS.Point to compare with this point</param>
 /// <returns>Boolean, true if the points are the same</returns>
 public bool IsIdenticalTo(MapWinGIS.Point Point)
 {
     if ((X == Point.x) && (Y == Point.y) && (Z == Point.Z))
     {
         return(true);
     }
     return(false);
 }
Example #17
0
 /// <summary>
 /// Checks each value in the point to see if they are the same
 /// </summary>
 /// <param name="Point">The MapWinGIS.Point to compare with this point</param>
 /// <returns>Boolean, true if the points are the same</returns>
 public bool Intersects(MapWinGIS.Point Point)
 {
     if ((X == Point.x) && (Y == Point.y) && (Z == Point.Z))
     {
         return(true);
     }
     return(false);
 }
        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 DrawMoveLine(double x, double y, System.Collections.ArrayList snapPoints)
        {
            try
            {
                if (snapPoints.Count == 0)
                {
                    return;
                }

                double projX = 0, projY = 0;
                m_MapWin.View.PixelToProj(x, y, ref projX, ref projY);

                //get the working shapefile
                if (m_globals.CurrentLayer == null)
                {
                    return;
                }
                MapWinGIS.Shapefile shpFile       = m_globals.CurrentLayer;

                //get the current vertex index
                ShapefileEditor.SnapData snapData = (ShapefileEditor.SnapData)snapPoints[0];
                int vertexIndex                   = snapData.pointIndex;

                //get the current shape
                MapWinGIS.Shape shp = shpFile.get_Shape(snapData.shpIndex);

                if (shpFile.ShapefileType == MapWinGIS.ShpfileType.SHP_POINT)
                {
                    m_MapWin.View.Draw.DrawPoint(projX, projY, m_globals.VertexSize, System.Drawing.Color.Red);
                }
                else
                {
                    if (vertexIndex > 0 && vertexIndex < shp.numPoints - 1)
                    {
                        //draw a line from the prev to current to next vertex
                        MapWinGIS.Point prevPoint = shp.get_Point(vertexIndex - 1);
                        MapWinGIS.Point nextPoint = shp.get_Point(vertexIndex + 1);

                        m_MapWin.View.Draw.DrawLine(prevPoint.x, prevPoint.y, projX, projY, 2, System.Drawing.Color.Red);
                        m_MapWin.View.Draw.DrawLine(projX, projY, nextPoint.x, nextPoint.y, 2, System.Drawing.Color.Red);
                    }
                    else if (vertexIndex == 0)
                    {
                        MapWinGIS.Point nextPoint = shp.get_Point(vertexIndex + 1);
                        m_MapWin.View.Draw.DrawLine(projX, projY, nextPoint.x, nextPoint.y, 2, System.Drawing.Color.Red);
                    }
                    else if (vertexIndex == shp.numPoints - 1)
                    {
                        MapWinGIS.Point prevPoint = shp.get_Point(vertexIndex - 1);
                        m_MapWin.View.Draw.DrawLine(prevPoint.x, prevPoint.y, projX, projY, 2, System.Drawing.Color.Red);
                    }
                }
            }
            catch (System.Exception ex)
            {
                m_MapWin.ShowErrorDialog(ex);
            }
        }
Example #20
0
 /// <summary>
 /// Stores a set of double values that represents a line segment.
 /// </summary>
 /// <param name="StartPoint">A MapWinGIS.Point representing the beginning of the line segment</param>
 /// <param name="EndPoint">A MapWinGIS.Point representing the end of the line segment</param>
 public LineSegment(MapWinGIS.Point StartPoint, MapWinGIS.Point EndPoint)
 {
     X1 = StartPoint.x;
     Y1 = StartPoint.y;
     Z1 = StartPoint.Z;
     X2 = EndPoint.x;
     Y2 = EndPoint.y;
     Z2 = EndPoint.Z;
 }
Example #21
0
 /// <summary>
 /// Creates a point from a MapWinGIS.Point passed as a generic object
 /// </summary>
 /// <param name="objPoint">A MapWinGIS.Point</param>
 /// <returns>A Coordinate generated from the MapWinGIS.Point</returns>
 public static Coordinate CreateCoordinate(object objPoint)
 {
     if (objPoint.GetType() != typeof(MapWinGIS.Point))
     {
         return(null);
     }
     MapWinGIS.Point mwPoint = objPoint as MapWinGIS.Point;
     return(new Coordinate(mwPoint.x, mwPoint.y));
 }
Example #22
0
 /// <summary>
 /// Creates a point from a MapWinGIS.Point passed as a generic object
 /// </summary>
 /// <param name="objPoint">A MapWinGIS.Point</param>
 /// <returns>A Point generated fromt he MapWinGIS.Point</returns>
 public static Point CreatePoint(object objPoint)
 {
     if (objPoint.GetType() != typeof(MapWinGIS.Point))
     {
         return(null);
     }
     MapWinGIS.Point mwPoint = objPoint as MapWinGIS.Point;
     return(new Point(mwPoint.x, mwPoint.y));
 }
        /// <summary>
        /// Not implemented
        /// Computes the distance between a point and a polygon.
        /// </summary>
        /// <param name="pt">The point to be considered.</param>
        /// <param name="polygon">The line to be considered.</param>
        /// <param name="distType">Indicates whether the distance should be from the nearest, farthest, or centroid of the polygon.</param>
        /// <returns></returns>
        public static double DistancePointToPolygon(MapWinGIS.Point pt, MapWinGIS.Shape polygon, int distType)
        {
            //TODO: Implement this function
            Error.ClearErrorLog();
            gErrorMsg = "This function is not yet implemented.";
            Error.SetErrorMsg(gErrorMsg);
            Debug.WriteLine(gErrorMsg);

            return(0);
        }
Example #24
0
        public static string ParamName(MapWinGIS.Point point)
        {
            string name = "null";

            if (point != null)
            {
                name = "Point[" + point.x + ", " + point.y + "]";
            }
            return(name);
        }
 private void RotateShape(MapWinGIS.Shape shape, double Angle, double aboutX, double aboutY)
 {
     for (int i = 0; i < shape.numPoints; i++)
     {
         MapWinGIS.Point pt = shape.get_Point(i);
         double          Nx = 0, Ny = 0;
         Rotate(Angle, pt.x, pt.y, aboutX, aboutY, ref Nx, ref Ny);
         pt.x = Nx;
         pt.y = Ny;
     }
 }
        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");
        }
Example #27
0
        /// <summary>
        /// Determines whether a point is inside or on the bounds of the rectangle
        /// </summary>
        /// <param name="Point">A MapWinGIS.Point parameter</param>
        /// <returns>True if the point is inside or on the bounds of the rectangle</returns>
        public bool IntersectWith(MapWinGIS.Point Point)
        {
            if (Point.x < xMin || Point.x > xMax)
            {
                return(false);
            }
            if (Point.y < yMin || Point.y > yMax)
            {
                return(false);
            }

            return(true);
        }
Example #28
0
        private bool AddPointToShapeFile(double x, double y, MapWinGIS.Shapefile shpFile, int shpIndex, int insertIndex)
        {
            try
            {
                MapWinGIS.Point p;

                //start editing shapes
                shpFile.StartEditingShapes(true, null);
                MapWinGIS.Shape shp = shpFile.get_Shape(shpIndex);

                p   = new MapWinGIS.Point();
                p.x = x;
                p.y = y;

                if (!shp.InsertPoint(p, ref insertIndex))
                {
                    return(false);
                }
                else if (shp.NumParts > 1)
                {
                    // Shift up part indices if needed (bugzilla 798)
                    bool shifting = false;
                    for (int i = 0; i < shp.NumParts; i++)
                    {
                        if (shp.get_Part(i) >= insertIndex)
                        {
                            // Shift up this one and all remaining
                            shifting = true;
                        }
                        if (shifting)
                        {
                            shp.set_Part(i, shp.get_Part(i) + 1);
                        }
                    }
                }

                m_Globals.CreateUndoPoint();

                //stop editing and save changes
                shpFile.StopEditingShapes(true, true, null);

                return(true);
            }
            catch (System.Exception ex)
            {
                m_MapWin.ShowErrorDialog(ex);
            }

            return(false);
        }
        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");
        }
        /// <summary>
        /// This function scans a Polygon/PolygonM/PolygonZ to determine if any of the
        /// existing polygons are counter-clockwise.  If they are, then it creates a linear ring
        /// from the shape.
        /// </summary>
        /// <param name="mwShape">A MapWinGIS.Shape Polygon/PolygonM/PolygonZ that might have holes.</param>
        /// <returns>A List of Linear Rings, each item representing one of the holes from the polygon.</returns>
        public static List <ILinearRing> GetHoles(MapWinGIS.Shape mwShape)
        {
            List <ILinearRing> Holes = new List <ILinearRing>();

            MapWinGIS.Point mwPoint = new MapWinGIS.Point();
            int             pt      = 0;
            int             prt     = 0;

            do
            {
                int Start = mwShape.get_Part(prt);
                int End;
                if (prt >= mwShape.NumParts - 1)
                {
                    End = mwShape.numPoints;
                }
                else
                {
                    End = mwShape.get_Part(prt + 1);
                }
                int          Count  = End - Start + 1;
                Coordinate[] Coords = new Coordinate[Count];
                double       area   = 0;
                for (int PrtPoint = 0; PrtPoint < Count - 1; PrtPoint++)
                {
                    // PrtPoint will be tracking the index for the specific linestring
                    mwPoint          = mwShape.get_Point(pt);
                    Coords[PrtPoint] = new Coordinate(mwPoint.x, mwPoint.y);
                    if (PrtPoint > 0)
                    {
                        area += Coords[PrtPoint].X * Coords[PrtPoint - 1].Y - Coords[PrtPoint - 1].X * Coords[PrtPoint].Y;
                    }
                    pt++;
                }
                mwPoint           = mwShape.get_Point(Start); // close the loop
                Coords[Count - 1] = new Coordinate(mwPoint.x, mwPoint.y);
                area += Coords[Count - 2].X * Coords[Count - 1].Y - Coords[Count - 1].X * Coords[Count - 2].Y;

                // if the area is negative, then the shape is counter-clockwise and therefore a hole
                if (area < 0)
                {
                    Holes.Add(new LinearRing(Coords));
                }
                prt++;
            }while (prt < mwShape.NumParts);
            return(Holes);
        }