Esempio n. 1
0
        public static FeatureDataRow LocatePolygon2(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;
                        GisSharpBlog.NetTopologySuite.Geometries.Geometry[] NTSGeom = GeometryConverter.ToNTSGeometry(new SharpMap.Geometries.Geometry[1] {
                            SharpMultiPol
                        }, f);
                        GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon NTSMultiPol = (GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon)NTSGeom[0];
                        if (NTSMultiPol.Contains(new GisSharpBlog.NetTopologySuite.Geometries.Point(punto.X, punto.Y)) == true)
                        {
                            fdr = (FeatureDataRow)r;
                            break;
                        }
                    }
                }
            }
            return(fdr);
        }
Esempio n. 2
0
 internal static Geometries.MultiPolygon ToSharpMapMultiPolygon(MultiPolygon multiPolygon)
 {
     Geometries.MultiPolygon collection = new Geometries.MultiPolygon();
     foreach (Polygon polygon in multiPolygon.Geometries)
     {
         collection.Polygons.Add(ToSharpMapPolygon(polygon));
     }
     return(collection);
 }
Esempio n. 3
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);
        }
Esempio n. 4
0
        private static MultiPolygon ReadMultiPolygon(JsonTextReader jreader)
        {
            if (jreader == null)
                throw new ArgumentNullException("reader", "A valid JSON reader object is required.");

            MultiPolygon areas = null;
            if (jreader.TokenClass == JsonTokenClass.Array)
            {
                jreader.ReadToken(JsonTokenClass.Array);
                List<Polygon> polygons = new List<Polygon>();
                    while (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)
                        {
                            Polygon area = null;
                            if (list.Count > 0)
                                area = new Polygon(shell, list.ToArray());
                            else
                                area = new Polygon(shell);
                            polygons.Add(area);
                        }
                    }
                jreader.ReadToken(JsonTokenClass.EndArray);

                areas = new MultiPolygon(polygons.ToArray());
            }
            return areas;
        }
Esempio n. 5
0
        public static void Write(MultiPolygon areas, TextWriter writer)
        {
            if (areas == null)
                return;
            if (writer == null)
                throw new ArgumentNullException("writer", "A valid text writer object is required.");

            JsonTextWriter jwriter = new JsonTextWriter(writer);
            Write(areas, jwriter);
        }
Esempio n. 6
0
        public static void Write(MultiPolygon areas, JsonTextWriter jwriter)
        {
            if (areas == null)
                return;
            if (jwriter == null)
                throw new ArgumentNullException("jwriter", "A valid JSON writer object is required.");

            jwriter.WriteStartObject();

                jwriter.WriteMember("type");
                jwriter.WriteString("MultiPolygon");

                jwriter.WriteMember("coordinates");
                jwriter.WriteStartArray();

                    foreach (Polygon area in areas.Geometries)
                    {
                        jwriter.WriteStartArray();

                        //Write the exterior boundary or shell
                        Write(area.Shell.Coordinates, jwriter);

                        //Write all the holes
                        foreach (LineString hole in area.Holes)
                        {
                            Write(hole.Coordinates, jwriter);
                        }

                        jwriter.WriteEndArray();
                    }

                jwriter.WriteEndArray();

            jwriter.WriteEndObject();
        }
 public InMemoryGISMultiPolygonFeature(Polygon[] polygons)
 {
     Shape = new MultiPolygon(polygons);
 }
Esempio n. 8
0
 internal static Geometries.MultiPolygon ToSharpMapMultiPolygon(MultiPolygon multiPolygon)
 {
     Geometries.MultiPolygon collection = new Geometries.MultiPolygon();
     foreach (Polygon polygon in multiPolygon.Geometries)
         collection.Polygons.Add(ToSharpMapPolygon(polygon));
     return collection;
 }