Exemplo n.º 1
0
        internal static Geometries.LinearRing ToSharpMapLinearRing(LinearRing lineString)
        {
            Collection <Point> vertices = new Collection <Point>();

            foreach (Coordinate coordinate in lineString.Coordinates)
            {
                vertices.Add(ToSharpMapPoint(coordinate));
            }
            return(new Geometries.LinearRing(vertices));
        }
Exemplo n.º 2
0
        private static IMultiPolygon ReadMultiPolygon(JsonTextReader jreader)
        {
            if (jreader == null)
            {
                throw new ArgumentNullException("reader", "A valid JSON reader object is required.");
            }

            IMultiPolygon areas = null;

            if (jreader.TokenClass == JsonTokenClass.Array)
            {
                jreader.ReadToken(JsonTokenClass.Array);
                List <IPolygon> polygons = new List <IPolygon>();
                while (jreader.TokenClass == JsonTokenClass.Array)
                {
                    jreader.ReadToken(JsonTokenClass.Array);

                    //Read the outer shell
                    ILinearRing shell = null;
                    if (jreader.TokenClass == JsonTokenClass.Array)
                    {
                        ICoordinate[] coordinates = new ICoordinate[] { };
                        Read(ref coordinates, jreader);
                        shell = new GisSharpBlog.NetTopologySuite.Geometries.LinearRing(coordinates);
                    }

                    //Read all the holes
                    List <ILinearRing> list = new List <ILinearRing>();
                    while (jreader.TokenClass == JsonTokenClass.Array)
                    {
                        ICoordinate[] coordinates = new ICoordinate[] { };
                        Read(ref coordinates, jreader);
                        ILinearRing hole = new GisSharpBlog.NetTopologySuite.Geometries.LinearRing(coordinates);
                        list.Add(hole);
                    }

                    jreader.ReadToken(JsonTokenClass.EndArray);

                    //An outer shell was found so a polygon can be created
                    if (shell != null)
                    {
                        IPolygon area = new GisSharpBlog.NetTopologySuite.Geometries.Polygon(shell, list.ToArray());
                        polygons.Add(area);
                    }
                }
                jreader.ReadToken(JsonTokenClass.EndArray);

                areas = new GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon(polygons.ToArray());
            }
            return(areas);
        }
Exemplo n.º 3
0
        internal static Polygon ToNTSPolygon(Geometries.Polygon polygon,
                                             GeometryFactory factory)
        {
            LinearRing shell = ToNTSLinearRing(polygon.ExteriorRing, factory);

            LinearRing[] holes = new LinearRing[polygon.InteriorRings.Count];
            int          index = 0;

            foreach (Geometries.LinearRing hole in polygon.InteriorRings)
            {
                holes[index++] = ToNTSLinearRing(hole, factory);
            }
            return(factory.CreatePolygon(shell, holes) as Polygon);
        }
Exemplo n.º 4
0
        public static void ToXML(LinearRing[] rings, XmlWriter writer)
        {
            writer.WriteStartElement("LinearRings");

            foreach (LinearRing ring in rings)
            {
                ToXML(ring, writer);
            }

            writer.WriteEndElement();
        }
Exemplo n.º 5
0
 /// <summary>
 /// Constructs a <c>Polygon</c> with the given exterior boundary.
 /// </summary>
 /// <param name="shell">
 /// The outer boundary of the new <c>Polygon</c>,
 /// or <c>null</c> or an empty <c>LinearRing</c> if the empty
 /// polygon is to be created.
 /// </param>
 public Polygon(LinearRing shell) : this(shell, null, DefaultFactory)
 {
 }
Exemplo n.º 6
0
        /* BEGIN ADDED BY MPAUL42: monoGIS team */

        /// <summary>
        /// Constructs a <c>Polygon</c> with the given exterior boundary.
        /// </summary>
        /// <param name="shell">
        /// The outer boundary of the new <c>Polygon</c>,
        /// or <c>null</c> or an empty <c>LinearRing</c> if the empty
        /// polygon is to be created.
        /// </param>
        /// <param name="factory"></param>
        public Polygon(LinearRing shell, GeometryFactory factory) : this(shell, null, factory)
        {
        }
Exemplo n.º 7
0
 protected Polygon GetDefaultPolygon(Point center, double buffer = 0.1)
 {
     var ring = new LinearRing(center.Buffer(buffer).Coordinates.Reverse().ToArray());
     return (Polygon)Default.GeometryFactory.CreatePolygon(ring, null);
 }
Exemplo n.º 8
0
        private static Polygon ReadPolygon(JsonTextReader jreader)
        {
            if (jreader == null)
                throw new ArgumentNullException("reader", "A valid JSON reader object is required.");

            Polygon area = null;
            if (jreader.TokenClass == JsonTokenClass.Array)
            {
                jreader.ReadToken(JsonTokenClass.Array);

                //Read the outer shell
                LinearRing shell = null;
                if (jreader.TokenClass == JsonTokenClass.Array)
                {
                    Coordinate[] coordinates = new Coordinate[] { };
                    Read(ref coordinates, jreader);
                    shell = new LinearRing(coordinates);
                }

                //Read all the holes
                List<LinearRing> list = new List<LinearRing>();
                while (jreader.TokenClass == JsonTokenClass.Array)
                {
                    Coordinate[] coordinates = new Coordinate[] { };
                    Read(ref coordinates, jreader);
                    LinearRing hole = new LinearRing(coordinates);
                    list.Add(hole);
                }

                jreader.ReadToken(JsonTokenClass.EndArray);

                //An outer shell was found so a polygon can be created
                if (shell != null)
                {
                    if (list.Count > 0)
                        area = new Polygon(shell, list.ToArray());
                    else
                        area = new Polygon(shell);
                }
            }
            return area;
        }
Exemplo n.º 9
0
        /* BEGIN ADDED BY MPAUL42: monoGIS team */

        /// <summary>
        /// Constructs a <c>Polygon</c> with the given exterior boundary.
        /// </summary>
        /// <param name="shell">
        /// The outer boundary of the new <c>Polygon</c>,
        /// or <c>null</c> or an empty <c>LinearRing</c> if the empty
        /// polygon is to be created.
        /// </param>
        /// <param name="factory"></param>
        public Polygon(LinearRing shell, GeometryFactory factory) : this(shell, null, factory) { }
Exemplo n.º 10
0
 public InMemoryGISPolygonFeature(LinearRing outerShell, LinearRing[] innerHoles)
 {
     Shape = new Polygon(outerShell, innerHoles);
 }
Exemplo n.º 11
0
 public InMemoryGISPolygonFeature(LinearRing outerShell)
 {
     Shape = new Polygon(outerShell);
 }
Exemplo n.º 12
0
		private IGeometry BuildPolygon()
		{
			if (this.rings.Count == 0)
			{
				return Polygon.Empty;
			}
			ILinearRing shell = new LinearRing(this.rings[0]);
			ILinearRing[] holes =
				this.rings.GetRange(1, this.rings.Count - 1)
					.ConvertAll<ILinearRing>(delegate(ICoordinate[] coordinates)
					{
						return new LinearRing(coordinates);
					}).ToArray();
			this.rings.Clear();
			return new Polygon(shell, holes);
		}
Exemplo n.º 13
0
 internal static Geometries.LinearRing ToSharpMapLinearRing(LinearRing lineString)
 {
     Collection<Point> vertices = new Collection<Point>();
     foreach (Coordinate coordinate in lineString.Coordinates)
         vertices.Add(ToSharpMapPoint(coordinate));
     return new Geometries.LinearRing(vertices);
 }
Exemplo n.º 14
0
 internal static Polygon ToNTSPolygon(Geometries.Polygon polygon,
                                      GeometryFactory factory)
 {
     LinearRing shell = ToNTSLinearRing(polygon.ExteriorRing, factory);
     LinearRing[] holes = new LinearRing[polygon.InteriorRings.Count];
     int index = 0;
     foreach (Geometries.LinearRing hole in polygon.InteriorRings)
         holes[index++] = ToNTSLinearRing(hole, factory);
     return factory.CreatePolygon(shell, holes) as Polygon;
 }
Exemplo n.º 15
0
 private static IGeometry CreateCell(double offsetX, double offsetY, double extentX, double extentY)
 {
     var vertices = new List<ICoordinate>
                            {
                                GeometryFactory.CreateCoordinate(offsetX, offsetY),
                                GeometryFactory.CreateCoordinate(offsetX + extentX, offsetY),
                                GeometryFactory.CreateCoordinate(offsetX + extentX, offsetY + extentY),
                                GeometryFactory.CreateCoordinate(offsetX, offsetY + extentY)
                            };
     vertices.Add((ICoordinate)vertices[0].Clone());
     ILinearRing newLinearRing = new LinearRing(vertices.ToArray());
     return new Polygon(newLinearRing, null);
 }
Exemplo n.º 16
0
        public static void ToXML(LinearRing ring, XmlWriter writer)
        {
            writer.WriteStartElement("LinearRing");

            ToXML(ring.Coordinates, writer);

            writer.WriteEndElement();
        }
Exemplo n.º 17
0
        public static string ToXML(LinearRing ring)
        {
            StringBuilder text = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(text);

            ToXML(ring, writer);
            writer.Flush();

            return text.ToString();
        }
Exemplo n.º 18
0
        public static FeatureDataRow LocatePolygon(SharpMap.Geometries.Point punto, SharpMap.Data.FeatureDataTable fdt)
        {
            FeatureDataRow fdr = null;

            if ((fdt as DataTable).Rows.Count == 1)
            {
                fdr = (FeatureDataRow)(fdt as DataTable).Rows[0];
            }
            else
            {
                GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory f = new GeometryFactory(new PrecisionModel());
                foreach (DataRow r in (fdt as DataTable).Rows)
                {
                    if ((r as  FeatureDataRow).Geometry.GetType() == typeof(SharpMap.Geometries.MultiPolygon))
                    {
                        // Doble cast: de Geometria a MultiPolygon, y de DataRow a FeatureDataRow.
                        SharpMap.Geometries.MultiPolygon SharpMultiPol = (SharpMap.Geometries.MultiPolygon)(r as  FeatureDataRow).Geometry;

                        foreach (SharpMap.Geometries.Polygon SharpPol in SharpMultiPol.Polygons)
                        {
                            //Contorno
                            int countVExt = SharpPol.ExteriorRing.Vertices.Count;
                            int i         = 0;
                            GisSharpBlog.NetTopologySuite.Geometries.Coordinate[] ListaCoordsExt = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate[countVExt];
                            foreach (SharpMap.Geometries.Point p in SharpPol.ExteriorRing.Vertices)
                            {
                                ListaCoordsExt[i++] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(p.X, p.Y);
                            }

                            //Huecos
                            int countPolInt = SharpPol.InteriorRings.Count;
                            int j           = 0;
                            GisSharpBlog.NetTopologySuite.Geometries.LinearRing[] ListaPolInt = new GisSharpBlog.NetTopologySuite.Geometries.LinearRing[countPolInt];
                            foreach (SharpMap.Geometries.LinearRing ring in SharpPol.InteriorRings)
                            {
                                int countVInt = ring.Vertices.Count;
                                int k         = 0;
                                GisSharpBlog.NetTopologySuite.Geometries.Coordinate[] ListaCoordsInt = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate[countVInt];
                                foreach (SharpMap.Geometries.Point p in ring.Vertices)
                                {
                                    ListaCoordsInt[k++] = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(p.X, p.Y);
                                }
                                ListaPolInt[j++] = f.CreateLinearRing(ListaCoordsInt);
                            }

                            GisSharpBlog.NetTopologySuite.Geometries.Polygon NTSPol = f.CreatePolygon(f.CreateLinearRing(ListaCoordsExt), ListaPolInt);

                            if (NTSPol.Contains(new GisSharpBlog.NetTopologySuite.Geometries.Point(punto.X, punto.Y)) == true)
                            {
                                fdr = (FeatureDataRow)r;
                                break;
                            }
                        }
                        if (fdr != null)
                        {
                            break;
                        }
                    }
                }
            }
            return(fdr);
        }
Exemplo n.º 19
0
 /// <summary>
 /// Constructs a <c>Polygon</c> with the given exterior boundary.
 /// </summary>
 /// <param name="shell">
 /// The outer boundary of the new <c>Polygon</c>,
 /// or <c>null</c> or an empty <c>LinearRing</c> if the empty
 /// polygon is to be created.
 /// </param>
 public Polygon(LinearRing shell) : this(shell, null, DefaultFactory) { }
 private IGeometry ReadPolygon(int dim, int lrsDim, SdoGeometry sdoGeom)
 {
     LinearRing shell = null;
     LinearRing[] holes = new LinearRing[sdoGeom.getNumElements() - 1];
     decimal[] info = sdoGeom.ElemArray;
     int i = 0;
     int idxInteriorRings = 0;
     while (i < info.Length) {
         ICoordinateSequence cs = null;
         int numCompounds = 0;
         if (info.getElementType(i).isCompound()) {
             numCompounds = info.getNumCompounds(i);
             cs = Add(cs, GetCompoundCSeq(i + 1, i + numCompounds, sdoGeom));
         } else {
             cs = Add(cs, GetElementCSeq(i, sdoGeom, false));
         }
         if (info.getElementType(i).isInteriorRing()) {
             holes[idxInteriorRings] = factory
                 .CreateLinearRing(cs);
             holes[idxInteriorRings].SRID = (int)sdoGeom.Sdo_Srid;
             idxInteriorRings++;
         } else {
             shell = factory.CreateLinearRing(cs);
             shell.SRID = (int)sdoGeom.Sdo_Srid;
         }
         i += 1 + numCompounds;
     }
     IPolygon polygon = factory.CreatePolygon(shell, holes);
     polygon.SRID = (int)sdoGeom.Sdo_Srid;
     return polygon;
 }
Exemplo n.º 21
0
		/// <summary>
		/// Create a rectangle containing the study area and dividible by the desired grid size
		/// </summary>
		/// <param name="pol"></param>
		/// <param name="widthDivBy"></param>
		/// <param name="heightDivBy"></param>
		private void roundedRectangle(IPolygon pol, int widthDivBy, int heightDivBy)
		{
			try {
				double width = new  LineSegment(pol.Coordinates[0],pol.Coordinates[1]).Length;
				double height = new LineSegment(pol.Coordinates[1],pol.Coordinates[2]).Length;
				
				var roundedWidth = (int) Math.Sign(width) * Math.Ceiling(Math.Abs(width)/widthDivBy) * widthDivBy;
				var roundedHeight= (int) Math.Sign(height) * Math.Ceiling(Math.Abs(height)/heightDivBy) * heightDivBy;
				
				//get the total num of cols and rows
				_gridCols=(int)roundedWidth/widthDivBy;
				_gridRows=(int)roundedHeight/heightDivBy;
				
				
				ICoordinate origin =(ICoordinate)pol.Coordinates[0];
				
				ICoordinate[] coords=new ICoordinate[5];
				coords[0]= origin;
				coords[1]= new Coordinate(origin.X+roundedWidth, origin.Y);
				coords[2]= new Coordinate(origin.X+roundedWidth,origin.Y+roundedHeight);
				coords[3]= new Coordinate(origin.X,origin.Y+roundedHeight);
				coords[4]= origin;
				
				ILinearRing lr=new LinearRing(coords);
				
				_roundedRectangle=new Polygon(lr);
				
			} catch (Exception ex) {
				throw ex;
			}
			
			
		}
 public InMemoryGISLinearRingFeature(Coordinate[] points)
 {
     Shape = new LinearRing(points);
 }