Пример #1
0
        private static Polygon2 <double> ToGeom(List <List <Point2 <double> > > pts)
        {
            if (pts.Count > 1) //outer and inner
            {
                List <Point2 <double> > outer = pts[0];
                if (outer[0].Equals(outer[outer.Count - 1]))
                {
                    outer.RemoveAt(outer.Count - 1);
                }

                List <Ring2 <double> > inner = new List <Ring2 <double> >();
                for (int i = 1; i < pts.Count; i++)
                {
                    if (pts[i][0].Equals(pts[i][pts[i].Count - 1]))
                    {
                        pts[i].RemoveAt(pts[i].Count - 1);
                    }
                    inner.Add(factory.ConstructRing(pts[i]));
                }
                pts = null;
                return(factory.ConstructPolygon(factory.ConstructRing(outer), factory.ConstructRingSet(inner)));
            }
            else
            {
                return(factory.ConstructPolygon(factory.ConstructRing(pts[0])));
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Fact: " + (GeometryFactory2Double.Instance != null));
            GeometryFactory2Base <double> factory = GeometryFactory2Double.Instance;

            Console.WriteLine("Factory is " + (factory == null ? "null" : "not null"));

            if (factory != null)
            {
                Point2 <double> pt = factory.ConstructPoint(43, 22);
                Console.WriteLine("Created point: " + pt.ToString());
                Ring2 <double>    rg = factory.ConstructRing(new Point2 <double>[] { factory.ConstructPoint(22.45, 33.33), factory.ConstructPoint(23.45, 33.33), factory.ConstructPoint(22.45, 35.33) });
                Polygon2 <double> pl = factory.ConstructPolygon(rg);

                if (rg != null)
                {
                    Console.WriteLine("Created ring: " + rg.ToString());
                    object o = Osrs.Numerics.Spatial.Postgres.NpgSpatialUtils.ToPGis(rg);
                    Console.WriteLine("Created PG Geometry: " + (o != null).ToString());
                }

                if (pl != null)
                {
                    Console.WriteLine(GeoJsonUtils.ToGeoJson(pl).ToString());
                }
            }

            Console.WriteLine("ALL DONE");
            Console.ReadLine();
        }