예제 #1
0
        private static GeoAPI.Geometries.IPolygon ReadPolygon(byte[] geom, ref int idx, bool isLittleEndian, GeoAPI.Geometries.IGeometryFactory factory)
        {
            var nRings = ReadUInt32(geom, ref idx, isLittleEndian);

            if (nRings < 1 || nRings > Int32.MaxValue / (2 * 8))
            {
                throw new ApplicationException("Currupt SpatialLite geom");
            }

            List <GeoAPI.Geometries.ILineString> lineStrings = new List <GeoAPI.Geometries.ILineString>();

            for (int i = 0; i < nRings; i++)
            {
                lineStrings.Add(ReadLineString(geom, ref idx, isLittleEndian, factory));
            }

            List <GeoAPI.Geometries.ILinearRing> holes = null;
            var shell = factory.CreateLinearRing(lineStrings[0].Coordinates);

            if (lineStrings.Count > 1)
            {
                holes = new List <GeoAPI.Geometries.ILinearRing>();
                for (int i = 1; i < lineStrings.Count; i++)
                {
                    holes.Add(factory.CreateLinearRing(lineStrings[i].Coordinates));
                }
            }
            return(factory.CreatePolygon(shell, holes == null ? null : holes.ToArray()));
        }
예제 #2
0
        public static GeoAPI.Geometries.ILinearRing CreateRectangle(GeoAPI.Geometries.IGeometryFactory factory,
                                                                    GeoAPI.Geometries.Coordinate leftTop, GeoAPI.Geometries.Coordinate rightBottom)
        {
            var pts = new[]
            {
                leftTop,
                new GeoAPI.Geometries.Coordinate(rightBottom.X, leftTop.Y),
                rightBottom,
                new GeoAPI.Geometries.Coordinate(leftTop.X, rightBottom.Y),
                leftTop
            };

            return(factory.CreateLinearRing(pts));
        }
예제 #3
0
        public static GeoAPI.Geometries.ILinearRing CreateEllipse(GeoAPI.Geometries.IGeometryFactory factory,
                                                                  GeoAPI.Geometries.Coordinate center, System.Drawing.SizeF size, int segmentsPerQuadrant)
        {
            const double piHalf = System.Math.PI * 0.5d;

            var step = piHalf / segmentsPerQuadrant;

            var pts   = new GeoAPI.Geometries.Coordinate[4 * segmentsPerQuadrant + 1];
            var angle = 0d;

            for (var i = 0; i < 4 * segmentsPerQuadrant; i++)
            {
                pts[i] = new GeoAPI.Geometries.Coordinate(center.X + System.Math.Cos(angle) * size.Width,
                                                          center.Y + System.Math.Sin(angle) * size.Height);
                angle += step;
            }
            pts[pts.Length - 1] = pts[0];
            return(factory.CreateLinearRing(pts));
        }