Esempio n. 1
0
        public void CreatePolygonFromNonClosedLineString()
        {
            LineString ls = new LineString(new GeographicPosition[] { new GeographicPosition(-10, 10), new GeographicPosition(-10, 5) }.Cast<IPosition>().ToList());

            Polygon poly = new Polygon(new LineString[] { ls }.ToList());

            poly.ToGml();
        }
Esempio n. 2
0
 static string GeometryToWktString(Polygon polygon)
 {
     return string.Format("({0})", string.Join(",", polygon.LineStrings.Select(GeometryToWktString)));
 }
Esempio n. 3
0
        public static GeometryObject SplitWorldExtent(Polygon poly)
        {
            MultiPolygon newpoly = new MultiPolygon();

            List<LineString> OuterlineStrings = new List<LineString>();

            List<LineString> InnerlineStrings = new List<LineString>();

            OuterlineStrings.AddRange(SplitWorldExtent(poly.LineStrings.First()));

            foreach (LineString lineString in poly.LineStrings.Skip(1)) {
                InnerlineStrings.AddRange(SplitWorldExtent(lineString));
            }

            if (OuterlineStrings.Count == 1) {
                return poly;
            }

            List<Polygon> newpolygons = new List<Polygon>();

            if (OuterlineStrings.Count > 0) {
                foreach (LineString ls in OuterlineStrings) {

                    Polygon curpoly = new Polygon();
                    newpoly.Polygons.Add(curpoly);
                    curpoly.LineStrings.Add(ls);
                    foreach (var innerls in InnerlineStrings) {
                        NetTopologySuite.IO.WKTReader wktreader = new NetTopologySuite.IO.WKTReader();
                        var innerlr = wktreader.Read(innerls.ToWkt());
                        NetTopologySuite.Geometries.Polygon polygon = (NetTopologySuite.Geometries.Polygon)wktreader.Read(curpoly.ToWkt());

                        if (polygon.Contains(innerlr))
                            curpoly.LineStrings.Add(innerls);
                    }
                    newpolygons.Add(curpoly);
                }

            }

            return newpoly;
        }
Esempio n. 4
0
        public static GeometryObject SplitWorldExtent(Polygon poly)
        {
            MultiPolygon newpoly = new MultiPolygon();

            List<List<LineString>> lineStringss = new List<List<LineString>>();

            foreach (LineString lineString in poly.LineStrings) {
                lineStringss.Add(SplitWorldExtent(lineString));
            }

            if (poly.LineStrings.Count == lineStringss.First().Count) {
                return poly;
            }

            List<List<LineString>> lineStringss2 = new List<List<LineString>>();

            if (lineStringss.Count > 0) {
                foreach (LineString ls in lineStringss[0]) {
                    var pls = new List<LineString>();
                    lineStringss2.Add(pls);
                    pls.Add(ls);
                }
                int i = 1;
                while (i < lineStringss.Count) {
                    foreach (LineString ls in lineStringss[i]) {
                        lineStringss2[i].Add(ls);
                    }
                    i++;
                }
            }

            foreach (var lss in lineStringss2) {
                newpoly.Polygons.Add(new Polygon(lss));
            }

            return newpoly;
        }
        public static GeometryObject ToGeometry(this Terradue.GeoJson.GeoRss10.GeoRss10Polygon georssPolygon)
        {
            if (georssPolygon.Item == null)
                return null;

            Polygon polygon = new Polygon();

            polygon.LineStrings = new System.Collections.Generic.List<LineString>();

            LineString ls = new LineString(new DirectPositionListType(){ Text = georssPolygon.Item }.ToGeometry());

            if (ls.Positions.Count < 4 || !ls.IsClosed())
                throw new InvalidFormatException("invalid GML representation: linearring is not a closed ring of minimum 4 positions");

            polygon.LineStrings.Add(ls);

            return polygon;
        }
 static string GeometryToWktString(Polygon polygon)
 {
     return(string.Format("({0})", string.Join(",", polygon.LineStrings.Select(GeometryToWktString))));
 }
        public static Terradue.GeoJson.Gml.PolygonType GeometryToGml(Polygon polygon)
        {
            Terradue.GeoJson.Gml.PolygonType gmlPolygon = new Terradue.GeoJson.Gml.PolygonType();
            if (polygon.LineStrings.Count > 0) {
                var exterior = new Terradue.GeoJson.Gml.AbstractRingPropertyType();
                gmlPolygon.exterior = exterior;
                var linearRing = new Terradue.GeoJson.Gml.LinearRingType();
                exterior.Item = linearRing;
                linearRing.ItemsElementName = new Terradue.GeoJson.Gml.ItemsChoiceType6[1];
                linearRing.ItemsElementName[0] = Terradue.GeoJson.Gml.ItemsChoiceType6.posList;
                linearRing.Items = new object[1];
                linearRing.Items[0] = GeometryToGml(polygon.LineStrings[0].Positions.ToArray());
                if (polygon.LineStrings.Count > 1) {
                    var interiors = new List<Terradue.GeoJson.Gml.AbstractRingPropertyType>();
                    foreach (var lineString in polygon.LineStrings.Take(1)) {
                        var interior = new Terradue.GeoJson.Gml.AbstractRingPropertyType();
                        linearRing = new Terradue.GeoJson.Gml.LinearRingType();
                        exterior.Item = linearRing;
                        linearRing = new Terradue.GeoJson.Gml.LinearRingType();
                        linearRing.ItemsElementName = new Terradue.GeoJson.Gml.ItemsChoiceType6[1];
                        linearRing.ItemsElementName[0] = Terradue.GeoJson.Gml.ItemsChoiceType6.posList;
                        linearRing.Items = new object[1];
                        linearRing.Items[0] = GeometryToGml(lineString.Positions.ToArray());
                        interiors.Add(interior);
                    }
                    gmlPolygon.interior = interiors.ToArray();
                }
            }

            return gmlPolygon;
        }