예제 #1
0
 /// <summary>
 /// Constructs a <c>Polygon</c> with the given exterior boundary and
 /// interior boundaries.
 /// </summary>
 /// <param name="inShell">
 /// The outer boundary of the new <c>Polygon</c>,
 /// or <c>null</c> or an empty <c>LinearRing</c> if the empty
 /// point is to be created.
 /// </param>
 /// <param name="inHoles">
 /// The inner boundaries of the new <c>Polygon</c>
 ///, or <c>null</c> or empty <c>LinearRing</c>s if the empty
 /// point is to be created.
 /// </param>
 /// <param name="factory"></param>
 /// <exception cref="PolygonException">Holes must not contain null elements</exception>
 public Polygon(ILinearRing inShell, ILinearRing[] inHoles, IGeometryFactory factory)
     : base(factory)
 {
     if (inShell == null)
     {
         inShell = Factory.CreateLinearRing(null);
     }
     if (inHoles == null)
     {
         inHoles = new LinearRing[] { }
     }
     ;
     if (HasNullElements(inHoles))
     {
         throw new PolygonException(TopologyText.PolygonException_HoleElementNull);
     }
     if (inShell.IsEmpty && HasNonEmptyElements(inHoles))
     {
         throw new PolygonException(TopologyText.PolygonException_ShellEmptyButHolesNot);
     }
     _shell = inShell;
     _holes = inHoles;
 }
예제 #2
0
        private static PolygonType ExtractShellPolygon(ref ILinearRing shell, SurfacePropertyType member)
        {
            PolygonType sur = member.Surface as PolygonType;
            LinearRingType li = sur.Exterior.Ring as LinearRingType;
            foreach (DirectPositionListType rings in li.Items)
            {
                List<Coordinate> lstCoor = ExtractCoordinates(rings);

                shell = new LinearRing(lstCoor);

            }
            return sur;
        }
예제 #3
0
        private static void ExtractInteriorPolygon(ILinearRing[] holes, PolygonType sur)
        {
            Collection<AbstractRingPropertyType> lin = sur.Interior as Collection<AbstractRingPropertyType>;
            int i = 0;
            foreach (AbstractRingPropertyType ringis in lin)
            {
                LinearRingType lii = ringis.Ring as LinearRingType;

                foreach (DirectPositionListType rings in lii.Items)
                {
                    List<Coordinate> lstCoor = ExtractCoordinates(rings);

                    holes[i]=new LinearRing(lstCoor);
                    i++;
                }

            }
        }
예제 #4
0
        private IBasicGeometry GetPolyline(MultiLineStringType multi)
        {

             ILinearRing[] lines = new LinearRing[multi.LineStringMembers.Count];
             int nLin = 0;
             foreach (LineStringPropertyType member in multi.LineStringMembers)
             {
                 lines[nLin]= ExtractLineString(member);
                 nLin++;
             }

            return new MultiLineString(lines);
        }
예제 #5
0
        private void HolesCS(object sender, EventArgs e)
        {
            //Defines a new coordinate array
            Coordinate[] coords = new Coordinate[20];
            //Defines a new random number generator
            Random rnd = new Random();
            //defines a randomly generated center for teh polygon
            Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
            for (int i = 0; i < 19; i++)
            {
                //generates random coordinates and adds those coordinates to the array
                coords[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10);
            }
            //sets the last coordinate equal to the first, this 'closes' the polygon
            coords[19] = new Coordinate(coords[0].X, coords[0].Y);
            //defines a new LingRing from the coordinates
            LinearRing Ring = new LinearRing(coords);
            //Repeates the process, but generates a LinearRing with a smaller area, this will be the hole in the polgyon
            Coordinate[] coordshole = new Coordinate[20];
            for (int i = 0; i < 20; i++)
            {
                coordshole[i] = new Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 20), center.Y + (i * 10) * Math.PI / 20);
            }
            coordshole[19] = new Coordinate(coordshole[0].X, coordshole[0].Y);
            LinearRing Hole = new LinearRing(coordshole);
            //This steps addes the hole LinerRing to a ILinearRing Array
            //A Polgyon can contain multiple holes, thus a Array of Hole is required
            ILinearRing[] Holes = new ILinearRing[1];
            Holes[0] = Hole;
            //This passes the Ring, the polygon shell, and the Holes Array, the holes
            Polygon pg = new Polygon(Ring, Holes);

            //Feature f = new Feature();
            FeatureSet fs = new FeatureSet(pg.FeatureType);
            //f = new Feature(pg);
            fs.Features.Add(pg);
            fs.SaveAs("C:\\Temp\\hole.shp", true);

        }
예제 #6
0
        private void InterceptLine(Feature fea)
        {

            Extent exf = fea.Envelope.ToExtent();

            if (currentExtent.Contains(exf))
            {
                #region   exteny
                int endRow = vector.GetCell(exf.MinX, exf.MinY)[1];
                int iniRow = vector.GetCell(exf.MaxX, exf.MaxY)[1];

                if (endRow == -1 || iniRow == -1) return;


                for (int it = iniRow; it <= endRow; it++)
                {
                    Coordinate ini = new Coordinate();
                    Coordinate end = new Coordinate();
                    double[] i = vector.GetCoordenatesByCell(1, it);
                    double[] e = vector.GetCoordenatesByCell(vector.Get_area().NumColumns, it);
                    ini.X = i[0] - cellsize;
                    ini.Y = i[1];
                    end.X = e[0] + cellsize;
                    end.Y = e[1];
                    LinearRing line = new LinearRing(new List<Coordinate>() { ini, end });

                    if (fea.Intersects(line))
                    {
                        IFeature rfea = fea.Intersection(line);
                        IList<Coordinate> cor = rfea.Coordinates;
                        if (cor.Count == 1) break;
                        Filldata(rfea, cor);
                    }
                }


                #endregion
            }
            else
            {
                for (int it = 0; it < vector.Get_area().NumRows; it++)
                {
                    Coordinate ini = new Coordinate();
                    Coordinate end = new Coordinate();
                    double[] i = vector.GetCoordenatesByCell(1, it);
                    double[] e = vector.GetCoordenatesByCell(vector.Get_area().NumColumns, it);
                    ini.X = i[0] - cellsize;
                    ini.Y = i[1];
                    end.X = e[0] + cellsize;
                    end.Y = e[1];


                    LinearRing line = new LinearRing(new List<Coordinate>() { ini, end });
                   

                    if (fea.Intersects(line))
                    {
                        IFeature rfea = fea.Intersection(line);
                        IList<Coordinate> cor = rfea.Coordinates;
                        if (cor.Count == 1) break;
                        Filldata(rfea, cor);
                        if (test)
                        {
                            IFeature fd = li.AddFeature((IBasicGeometry)rfea);
                            fd.DataRow["id"] = "c";
                        }

                    }

                }


            }
        }
예제 #7
0
        /// <summary>
        /// Constructor for a polygon
        /// </summary>
        /// <param name="polygonBase">A simpler BasicPolygon to empower with topology functions</param>
        public Polygon(IBasicPolygon polygonBase)
            : base(DefaultFactory)
        {
            SetHoles(polygonBase.Holes);

            LinearRing shell = new LinearRing(polygonBase.Shell);
            if (HasNullElements(_holes))
                throw new PolygonException(TopologyText.PolygonException_HoleElementNull);
            if (shell.IsEmpty && HasNonEmptyElements(_holes))
                throw new PolygonException(TopologyText.PolygonException_ShellEmptyButHolesNot);
            _shell = shell;
        }
예제 #8
0
       private IGeometry CreatePolygonData(bool type)
        {

            double size = this.spatial.NumberOfLags * 2 * this.spatial.LagSize;
            Coordinate center;
           if (type)
           center = new Coordinate(500000 + (size / 2), size / 2);
           else
           center = new Coordinate(0,0);

            Coordinate[] array = new Coordinate[6];

            array[0] = center;
            array[1] = this.spatial.AzimuthDist(center, azimuth + tolerance, bandWidth*this.spatial.LagSize);
            array[2] = this.spatial.AzimuthDist(array[1], azimuth, this.spatial.LagValue.numLags * this.spatial.LagSize);
            array[3] = this.spatial.AzimuthDist(array[2], azimuth + Math.PI + Math.PI/2, Math.Sin(tolerance) * (bandWidth * this.spatial.LagSize) * 2);
            array[4] = this.spatial.AzimuthDist(array[3], azimuth + Math.PI, this.spatial.LagValue.numLags * this.spatial.LagSize);
            array[5] = center;
            LinearRing shell = new LinearRing(array);
            Polygon poly = new Polygon(shell);
            return poly;

        }
예제 #9
0
 /// <summary>
 /// Constructs a <c>Polygon</c> with the given exterior boundary and
 /// interior boundaries.
 /// </summary>
 /// <param name="inShell">
 /// The outer boundary of the new <c>Polygon</c>,
 /// or <c>null</c> or an empty <c>LinearRing</c> if the empty
 /// point is to be created.
 /// </param>
 /// <param name="inHoles">
 /// The inner boundaries of the new <c>Polygon</c>
 ///, or <c>null</c> or empty <c>LinearRing</c>s if the empty
 /// point is to be created.
 /// </param>
 /// <param name="factory"></param>
 /// <exception cref="PolygonException">Holes must not contain null elements</exception>
 public Polygon(ILinearRing inShell, ILinearRing[] inHoles, IGeometryFactory factory)
     : base(factory)
 {
     if (inShell == null)
         inShell = Factory.CreateLinearRing(null);
     if (inHoles == null)
         inHoles = new LinearRing[] { };
     if (HasNullElements(inHoles))
     {
         throw new PolygonException(TopologyText.PolygonException_HoleElementNull);
     }
     if (inShell.IsEmpty && HasNonEmptyElements(inHoles))
         throw new PolygonException(TopologyText.PolygonException_ShellEmptyButHolesNot);
     _shell = inShell;
     _holes = inHoles;
 }
예제 #10
0
        public static IGeometry DrawEllipse(Kpoint center, double majorRadius, double minorRadius, double azimuth)
        {
            int numVertex = 180;
            Coordinate[] coorPol = new Coordinate[numVertex+1];

            if (majorRadius == minorRadius)
            {
                int j = 0;
                for (int i = 0; i < 360; i += (360/numVertex))
                {
                    Kpoint v = Utils.AzimuthDist(center, i * Math.PI / 180.0, majorRadius);
                    coorPol[j] = new Coordinate(v.X, v.Y);
                    j++;
                }


                coorPol[numVertex] = coorPol[0];
            }
            else
            {
                int j = 0;
                for (int i = 0; i < 360; i += (360 / numVertex))
                {
                    double r = majorRadius * minorRadius / Math.Sqrt(
                        Math.Pow(minorRadius * Math.Cos(-1*azimuth + (i * Math.PI / 180.0)), 2) +
                         Math.Pow(majorRadius * Math.Sin(-1*azimuth + (i * Math.PI / 180.0)), 2)
                        );

                    Kpoint v = Utils.AzimuthDist(center, i * Math.PI / 180.0, r);
                    coorPol[j] = new Coordinate(v.X, v.Y);
                    j++;

                }
                coorPol[numVertex] = coorPol[0];

            }

            LinearRing pol = new LinearRing(coorPol);
            Polygon poly = new Polygon(pol);
            return poly;
        }
예제 #11
0
        public void AddGrid()
        {
            if (pro != null)
            {
                pro.Value = 0;
                pro.Maximum = 100;
                pro.Visible = true;
            }

            _GridLayer.DataSet.Features.Clear();

            Int32 id = 0;

            for (int i = 0; i < _area.NumColumns; i++)
            {
                for (int j = 0; j < _area.NumRows; j++)
                {

                    int val = 100 * id / (_area.NumColumns * _area.NumRows);

                    if (pro != null)
                    {
                        pro.Increment(val);
                    }
                    Coordinate[] array = new Coordinate[5];

                    array[0] = ProjectPointAzimut(new Coordinate(_area.MinX + (i * _area.CellSizeX), _area.MinY + (j * _area.CellSizeY)));
                    array[1] = ProjectPointAzimut(new Coordinate(_area.MinX + (i * _area.CellSizeX), _area.MinY + ((j + 1) * _area.CellSizeY)));
                    array[2] = ProjectPointAzimut(new Coordinate(_area.MinX + ((i + 1) * _area.CellSizeX), _area.MinY + ((j + 1) * _area.CellSizeY)));
                    array[3] = ProjectPointAzimut(new Coordinate(_area.MinX + ((i + 1) * _area.CellSizeX), _area.MinY + (j * _area.CellSizeY)));
                    array[4] = ProjectPointAzimut(new Coordinate(_area.MinX + (i * _area.CellSizeX), _area.MinY + (j * _area.CellSizeY)));
                    LinearRing shell = new LinearRing(array);
                    Polygon poly = new Polygon(shell);
                    IFeature newF = _GridLayer.DataSet.AddFeature(poly);
                    newF.DataRow["polygonID"] = id;
                    newF.DataRow["row"] = j + 1;
                    newF.DataRow["col"] = i + 1;
                    int idcel = _area.NumColumns * ((j + 1) - 1) + (i + 1);
                    newF.DataRow["Value"] = data[idcel].Mean;
                    newF.DataRow["Number"] = data[idcel].num;
                    id++;
                }
            }
            rectangleFs = (FeatureSet)_GridLayer.DataSet;
            _mainMap.ResetBuffer();
            if (pro != null) if (pro.Value == pro.Maximum) pro.Visible = false;

        }
예제 #12
0
        public void AddGrid(IList<IFeature> selected, Dictionary<int, Stat> data, Dictionary<int, RGB> dataRGB)
        {
            this.data = data;
            if (pro != null)
            {
                pro.Value = 0;
                pro.Maximum = 1000;
                pro.Visible = true;
            }

            _GridLayer.DataSet.Features.Clear();

            Int32 id = 0;

            for (int i = 0; i < _area.NumColumns; i++)
            {
                for (int j = 0; j < _area.NumRows; j++)
                {

                    int val = 1000 * id / (_area.NumColumns * _area.NumRows);

                    if (pro != null)
                    {
                        pro.Value = val;
                        //  pro.Increment(val);
                    }
                    Coordinate[] array = new Coordinate[5];


                    array[0] = ProjectPointAzimut(new Coordinate(_area.MinX + (i * _area.CellSizeX), _area.MinY + (j * _area.CellSizeY)));
                    Coordinate start = array[0];
                    array[1] = ProjectPointAzimut(new Coordinate(_area.MinX + ((i + 1) * _area.CellSizeX), _area.MinY + (j * _area.CellSizeY)));
                    array[2] = ProjectPointAzimut(new Coordinate(_area.MinX + ((i + 1) * _area.CellSizeX), _area.MinY + ((j + 1) * _area.CellSizeY)));
                    array[3] = ProjectPointAzimut(new Coordinate(_area.MinX + (i * _area.CellSizeX), _area.MinY + ((j + 1) * _area.CellSizeY)));
                    array[4] = start;

                    LinearRing shell = new LinearRing(array);
                    IGeometry poly = new Polygon(shell);
                    bool contain = true;
                    if (selected != null && selected.Count > 0)
                    {
                        IFeature newF = null;
                        foreach (IFeature fea in selected)
                        {
                            try
                            {
                                if (!fea.Contains(poly))
                                {

                                    if (fea.Intersects((IGeometry)poly))
                                    {
                                        IGeometry newF1 = null;
                                        MultiPolygon poly1 = null;
                                        poly1 = new MultiPolygon(fea);
                                        newF1 = poly.Difference((IGeometry)poly1);
                                        poly = newF1;
                                    }
                                }
                                else
                                    contain = false;
                            }
                            catch
                            {

                            }
                        }

                        if (contain)
                        {
                            newF = _GridLayer.DataSet.AddFeature(poly);
                            newF.DataRow["polygonID"] = id;
                            newF.DataRow["row"] = j + 1;
                            newF.DataRow["col"] = i + 1;
                        }

                        id++;
                    }
                    else
                    {
                        IFeature newF = _GridLayer.DataSet.AddFeature(poly);
                        newF.DataRow["polygonID"] = id;
                        newF.DataRow["row"] = j + 1;
                        newF.DataRow["col"] = i + 1;
                        int idcel = _area.NumColumns * ((j + 1) - 1) + (i + 1);
                        newF.DataRow["Value"] = data[idcel].Mean;
                        newF.DataRow["Number"] = data[idcel].num;
                        newF.DataRow["R"] = dataRGB[idcel].R.Mean;
                        newF.DataRow["G"] = dataRGB[idcel].G.Mean;
                        newF.DataRow["B"] = dataRGB[idcel].B.Mean;


                        id++;

                    }

                }
            }
            rectangleFs = (FeatureSet)_GridLayer.DataSet;
            _mainMap.ResetBuffer();
            if (pro != null) pro.Visible = false;

        }
예제 #13
0
        private IGeometry ReadPolygon()
        {
            ShapefileGeometryType type = (ShapefileGeometryType)_reader.ReadInt32();
            if (type == ShapefileGeometryType.NullShape)
                return _gf.CreatePolygon(null, null);

            if (type != ShapefileGeometryType.Polygon && type != ShapefileGeometryType.PolygonZ)
                throw new Exception("Attempting to load a non-polygon as polygon.");

            // Read the box
            double xMin = _reader.ReadDouble(), yMin = _reader.ReadDouble();
            ShapeEnvelope.Init(xMin, _reader.ReadDouble(),
                yMin, _reader.ReadDouble());

            // Read poly header
            int numParts = _reader.ReadInt32();
            int numPoints = _reader.ReadInt32();

            // Read parts array
            int[] partOffsets = new int[numParts];
            for (int i = 0; i < numParts; i++)
                partOffsets[i] = _reader.ReadInt32();

            // Read the parts and their points
            List<ILinearRing> shells = new List<ILinearRing>();
            List<ILinearRing> holes = new List<ILinearRing>();
            Coordinate[] allCoords = new Coordinate[numPoints];
            for (int part = 0, last = numParts - 1, x = 0; part < numParts; part++)
            {
                int start = partOffsets[part], stop = (part == last ? numPoints : partOffsets[part + 1]);
                Coordinate[] coords = new Coordinate[stop - start];

                for (int i = 0; i < coords.Length; i++)
                    coords[i] = allCoords[x++] = new Coordinate(
                        _reader.ReadDouble(),
                        _reader.ReadDouble());

                ILinearRing ring = _gf.CreateLinearRing(coords);

                // Check for hole.
                if (CgAlgorithms.IsCounterClockwise(coords))
                    holes.Add(ring);
                else
                    shells.Add(ring);
            }

            if (type == ShapefileGeometryType.PolygonZ)
            {
                // z min/max
                _reader.ReadDouble();
                _reader.ReadDouble();

                for (int i = 0; i < allCoords.Length; i++)
                    allCoords[i].Z = _reader.ReadDouble();

                // m min/max
                _reader.ReadDouble();
                _reader.ReadDouble();
                for (int i = 0; i < allCoords.Length; i++)
                    allCoords[i].M = _reader.ReadDouble();
            }

            // Create the polygon
            if (shells.Count == 1)
                return _gf.CreatePolygon(shells[0], holes.ToArray());
            else // Create a multipolygon
            {
                List<IPolygon> polys = new List<IPolygon>(shells.Count);
                foreach (ILinearRing shell in shells)
                {
                    IEnvelope shellEnv = shell.EnvelopeInternal;
                    List<ILinearRing> shellHoles = new List<ILinearRing>();
                    for(int i = holes.Count - 1; i >=0; i--)
                    {
                        ILinearRing hole = holes[i];
                        if (shellEnv.Contains(hole.EnvelopeInternal))
                        {
                            shellHoles.Add(hole);
                            holes.RemoveAt(i);
                        }
                    }

                    polys.Add(_gf.CreatePolygon(shell, shellHoles.ToArray()));
                }

                // Add the holes that weren't contains as shells
                foreach (ILinearRing hole in holes)
                {
                    LinearRing ring = new LinearRing(hole.Reverse());
                    polys.Add(_gf.CreatePolygon(ring, null));
                }

                return _gf.CreateMultiPolygon(polys.ToArray());
            }
        }