Example #1
0
        internal static void Populate(IGeometrySink sink, IList<PointNode> points, GeometryType type)
        {
            if (points.Count>0)
            {
                if (type!=GeometryType.LineString)
                    sink.BeginGeometry(GeometryType.Point);

                sink.BeginFigure(points[0].X, points[0].Y, null);
                if (type==GeometryType.MultiPoint)
                    sink.EndFigure();

                for (int i=1; i<points.Count; ++i)
                    if (type==GeometryType.MultiPoint)
                    {
                        sink.BeginFigure(points[i].X, points[i].Y, null);
                        sink.EndFigure();
                    } else
                        sink.AddLine(points[i].X, points[i].Y, null);

                if (type!=GeometryType.MultiPoint)
                    sink.EndFigure();

                if (type!=GeometryType.LineString)
                    sink.EndGeometry();
            }
        }
Example #2
0
        public void Populate(IGeometrySink sink)
        {
            if (srsName!=null)
                sink.SetCoordinateSystem(CoordinateSystem);

            InternalPopulate(sink);
        }
Example #3
0
        private static void CreateFigure(IGeometrySink sink, IList <SmGeometries.Point> points)
        {
            if ((points == null) || (points.Count == 0))
            {
                return;
            }

            var p0  = points[0];
            var p03 = p0 as SmGeometries.Point3D;

            if (p03 != null)
            {
                sink.BeginFigure(p03.X, p03.Y, p03.Z);
            }
            else
            {
                sink.BeginFigure(p0.X, p0.Y, null);
            }

            for (int i = 1; i < points.Count; ++i)
            {
                var pi  = points[i];
                var pi3 = pi as SmGeometries.Point3D;
                if (pi3 != null)
                {
                    sink.AddLine(pi3.X, pi3.Y, pi3.Z);
                }
                else
                {
                    sink.AddLine(pi.X, pi.Y, null);
                }
            }

            sink.EndFigure();
        }
Example #4
0
        public void Populate(IGeometrySink sink)
        {
            sink.SetCoordinateSystem(CoordinateSystem);

            sink.BeginGeometry(GeometryType.Polygon);

            if (
                (lowerCorner!=null) && (lowerCorner.TypedValue!=null) && (lowerCorner.TypedValue.Count==2) &&
                (upperCorner!=null) && (upperCorner.TypedValue!=null) && (upperCorner.TypedValue.Count==2)
            )
            {
                double minlon=Math.Min(lowerCorner.TypedValue[0], upperCorner.TypedValue[0]);
                double maxlon=Math.Max(lowerCorner.TypedValue[0], upperCorner.TypedValue[0]);
                double minlat=Math.Min(lowerCorner.TypedValue[1], upperCorner.TypedValue[1]);
                double maxlat=Math.Max(lowerCorner.TypedValue[1], upperCorner.TypedValue[1]);

                sink.BeginFigure(minlon, minlat, null);
                sink.AddLine(maxlon, minlat, null);
                sink.AddLine(maxlon, maxlat, null);
                sink.AddLine(minlon, maxlat, null);
                sink.AddLine(minlon, minlat, null);
                sink.EndFigure();
            }

            sink.EndGeometry();
        }
Example #5
0
        /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
        /// <param name="sink">The sink to populate.</param>
        /// <remarks>
        ///   <para>The call sequence is a set of figures, lines, and points for geometry types.</para>
        /// </remarks>
        public void Populate(IGeometrySink sink)
        {
            sink.SetCoordinateSystem(CoordinateSystem);

            switch (_Geometry.GeometryType)
            {
            case SmGeometries.GeometryType2.LineString:
            case SmGeometries.GeometryType2.Point:
            case SmGeometries.GeometryType2.Polygon:
                _PopulateSimpleType(sink, _Geometry);
                break;

            case SmGeometries.GeometryType2.GeometryCollection:
            case SmGeometries.GeometryType2.MultiLineString:
            case SmGeometries.GeometryType2.MultiPoint:
            case SmGeometries.GeometryType2.MultiPolygon:
                sink.BeginGeometry(GeometryTypeUtils.Convert(_Geometry.GeometryType));
                foreach (SmGeometries.Geometry g in (IEnumerable <SmGeometries.Geometry>)_Geometry)
                {
                    _PopulateSimpleType(sink, g);
                }
                sink.EndGeometry();
                break;

            default:
                throw new NotSupportedException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              SR.UnsupportedGeometryTypeException,
                              _Geometry.GeometryType
                              )
                          );
            }
        }
Example #6
0
        public void Populate(IGeometrySink sink)
        {
            sink.SetCoordinateSystem(CoordinateSystem);

            sink.BeginGeometry(GeometryType.Polygon);

            if (
                (lowerCorner != null) && (lowerCorner.TypedValue != null) && (lowerCorner.TypedValue.Count == 2) &&
                (upperCorner != null) && (upperCorner.TypedValue != null) && (upperCorner.TypedValue.Count == 2)
                )
            {
                double minlon = Math.Min(lowerCorner.TypedValue[0], upperCorner.TypedValue[0]);
                double maxlon = Math.Max(lowerCorner.TypedValue[0], upperCorner.TypedValue[0]);
                double minlat = Math.Min(lowerCorner.TypedValue[1], upperCorner.TypedValue[1]);
                double maxlat = Math.Max(lowerCorner.TypedValue[1], upperCorner.TypedValue[1]);

                sink.BeginFigure(minlon, minlat, null);
                sink.AddLine(maxlon, minlat, null);
                sink.AddLine(maxlon, maxlat, null);
                sink.AddLine(minlon, maxlat, null);
                sink.AddLine(minlon, minlat, null);
                sink.EndFigure();
            }

            sink.EndGeometry();
        }
Example #7
0
 public unsafe static void AddLines(this IGeometrySink sink, ReadOnlySpan <PointF> points)
 {
     fixed(PointF *p = &MemoryMarshal.GetReference(points))
     {
         sink.AddLines(p, (uint)points.Length);
     }
 }
 /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
 /// <param name="sink">The sink to populate.</param>
 public void Populate(IGeometrySink sink)
 {
     sink.BeginGeometry(GeometryType.GeometryCollection);
     foreach (IGeometryTap g in _Geometries)
         g.Populate(sink);
     sink.EndGeometry();
 }
Example #9
0
        internal protected override void InternalPopulate(IGeometrySink sink)
        {
            int dim = 2;

            if (srsDimension.HasValue)
            {
                dim = Convert.ToInt32(srsDimension.Value);
            }

            sink.BeginGeometry(GeometryType.Point);

            //if (pos!=null)
            if (Untyped.Descendants("{http://www.opengis.net/gml}pos").Any <XElement>())
            {
                if (pos.srsDimension.HasValue)
                {
                    dim = Convert.ToInt32(pos.srsDimension.Value);
                }

                if ((pos.TypedValue != null) && (pos.TypedValue.Count >= dim))
                {
                    sink.BeginFigure(pos.TypedValue[0], pos.TypedValue[1], dim > 2 ? pos.TypedValue[2] : (double?)null);
                    sink.EndFigure();
                }
            }

            sink.EndGeometry();
        }
Example #10
0
            public Sink(IGeometrySink sink)
            {
                Debug.Assert(sink!=null);
                if (sink==null)
                    throw new ArgumentNullException("sink");

                _Sink=sink;
            }
Example #11
0
 private void PopulateFigure(IGeometrySink sink)
 {
     m_figure[0].BeginFigure(sink);
     for (int i = 1; i < m_figure.Count; i++)
     {
         m_figure[i].AddLine(sink);
     }
     sink.EndFigure();
 }
Example #12
0
        public void Populate(IGeometrySink sink)
        {
            if (srsName != null)
            {
                sink.SetCoordinateSystem(CoordinateSystem);
            }

            InternalPopulate(sink);
        }
Example #13
0
 /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
 /// <param name="sink">The sink to populate.</param>
 public void Populate(IGeometrySink sink)
 {
     sink.BeginGeometry(GeometryType.GeometryCollection);
     foreach (IGeometryTap g in _Geometries)
     {
         g.Populate(sink);
     }
     sink.EndGeometry();
 }
Example #14
0
 /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
 /// <param name="sink">The sink to populate.</param>
 public void Populate(IGeometrySink sink)
 {
     sink.BeginGeometry(GeometryType.Point);
     if (_Point!=null)
     {
         sink.BeginFigure(_Point.X, _Point.Y, null);
         sink.EndFigure();
     }
     sink.EndGeometry();
 }
Example #15
0
 /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
 /// <param name="sink">The sink to populate.</param>
 public void Populate(IGeometrySink sink)
 {
     sink.BeginGeometry(GeometryType.Point);
     if (_Point != null)
     {
         sink.BeginFigure(_Point.X, _Point.Y, null);
         sink.EndFigure();
     }
     sink.EndGeometry();
 }
Example #16
0
            public Sink(IGeometrySink sink)
            {
                Debug.Assert(sink != null);
                if (sink == null)
                {
                    throw new ArgumentNullException("sink");
                }

                _Sink = sink;
            }
Example #17
0
        /// <summary>Creates a new instance of the <see cref="ReversedGeometrySink" /> class.</summary>
        public ReversedGeometrySink(IGeometrySink sink) :
            base()
        {
            Debug.Assert(sink!=null);
            if (sink==null)
                throw new ArgumentNullException("sink");
            _Sink=sink;

            _Figures=new Stack<LinkedList<Point>>();
        }
Example #18
0
        protected internal override void InternalPopulate(IGeometrySink sink)
        {
            sink.BeginGeometry(GeometryType.MultiPoint);

            //if ((pointMember!=null)
            if (Untyped.Descendants("{http://www.opengis.net/gml}pointMember").Any<XElement>())
                foreach (pointMember p in pointMember)
                    p.Point.Populate(sink);

            sink.EndGeometry();
        }
Example #19
0
        protected internal override void InternalPopulate(IGeometrySink sink)
        {
            sink.BeginGeometry(GeometryType.GeometryCollection);

            //if ((geometryMember!=null)
            if (Untyped.Descendants("{http://www.opengis.net/gml}geometryMember").Any<XElement>())
                foreach (geometryMember g in geometryMember)
                    g._Geometry.Populate(sink);

            sink.EndGeometry();
        }
Example #20
0
        protected internal override void InternalPopulate(IGeometrySink sink)
        {
            sink.BeginGeometry(GeometryType.MultiLineString);

            //if ((lineStringMember!=null)
            if (Untyped.Descendants("{http://www.opengis.net/gml}lineStringMember").Any<XElement>())
                foreach (lineStringMember l in lineStringMember)
                    l.LineString.Populate(sink);

            sink.EndGeometry();
        }
Example #21
0
        /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
        /// <param name="sink">The sink to populate.</param>
        /// <remarks>
        ///   <para>The call sequence is a set of figures, lines, and points for geometry types.</para>
        /// </remarks>
        public void Populate(IGeometrySink sink)
        {
            var sgs = sink as SqlTypes.IGeometrySink110;

            if (sgs == null)
            {
                sgs = new Sink(sink);
            }

            _Geometry.Populate(sgs);
        }
Example #22
0
        internal protected override void InternalPopulate(IGeometrySink sink)
        {
            sink.BeginGeometry(GeometryType.Polygon);

            if ((exterior!=null) && (exterior._Ring!=null))
                exterior._Ring.Populate(sink);
            if (interior!=null)
                foreach (interior intr in interior)
                    intr._Ring.Populate(sink);

            sink.EndGeometry();
        }
Example #23
0
        /// <summary>Creates a new instance of the <see cref="ReversedGeometrySink" /> class.</summary>
        public ReversedGeometrySink(IGeometrySink sink) :
            base()
        {
            Debug.Assert(sink != null);
            if (sink == null)
            {
                throw new ArgumentNullException("sink");
            }
            _Sink = sink;

            _Figures = new Stack <LinkedList <Point> >();
        }
Example #24
0
        protected internal override void InternalPopulate(IGeometrySink sink)
        {
            int dim=2;
            if (srsDimension.HasValue)
                dim=Convert.ToInt32(srsDimension.Value);
            if (posList.srsDimension.HasValue)
                dim=Convert.ToInt32(posList.srsDimension.Value);

            sink.BeginFigure(posList.TypedValue[0], posList.TypedValue[1], dim>2 ? posList.TypedValue[2] : (double?)null);
            for (int i=dim; i<posList.TypedValue.Count; i+=dim)
                sink.AddLine(posList.TypedValue[i], posList.TypedValue[i+1], dim>2 ? posList.TypedValue[i+2] : (double?)null);
            sink.EndFigure();
        }
Example #25
0
        /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
        /// <param name="sink">The sink to populate.</param>
        public void Populate(IGeometrySink sink)
        {
            sink.BeginGeometry(GeometryType);
            foreach (SeriesNode series in _PolygonsSeries)
            {
                sink.BeginGeometry(GeometryType.Polygon);

                List<SeriesNode> lineStrings=series.Select<ParseTreeNode, SeriesNode>(n => (SeriesNode)n.AstNode).ToList<SeriesNode>();
                MultiLineStringNode.Populate(sink, lineStrings, GeometryType.Polygon);

                sink.EndGeometry();
            }
            sink.EndGeometry();
        }
Example #26
0
        /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
        /// <param name="sink">The sink to populate.</param>
        public void Populate(IGeometrySink sink)
        {
            sink.BeginGeometry(GeometryType);
            foreach (SeriesNode series in _PolygonsSeries)
            {
                sink.BeginGeometry(GeometryType.Polygon);

                List <SeriesNode> lineStrings = series.Select <ParseTreeNode, SeriesNode>(n => (SeriesNode)n.AstNode).ToList <SeriesNode>();
                MultiLineStringNode.Populate(sink, lineStrings, GeometryType.Polygon);

                sink.EndGeometry();
            }
            sink.EndGeometry();
        }
Example #27
0
        internal static void Populate(IGeometrySink sink, IList<SeriesNode> pointSeries, GeometryType type)
        {
            foreach (SeriesNode series in pointSeries)
            {
                if (type!=GeometryType.Polygon)
                    sink.BeginGeometry(GeometryType.LineString);

                List<PointNode> points=series.Select<ParseTreeNode, PointNode>(n => (PointNode)n.AstNode).ToList<PointNode>();
                MultiPointNode.Populate(sink, points, GeometryType.LineString);

                if (type!=GeometryType.Polygon)
                    sink.EndGeometry();
            }
        }
Example #28
0
        protected internal override void InternalPopulate(IGeometrySink sink)
        {
            sink.BeginGeometry(GeometryType.GeometryCollection);

            //if ((geometryMember!=null)
            if (Untyped.Descendants("{http://www.opengis.net/gml}geometryMember").Any <XElement>())
            {
                foreach (geometryMember g in geometryMember)
                {
                    g._Geometry.Populate(sink);
                }
            }

            sink.EndGeometry();
        }
Example #29
0
        protected internal override void InternalPopulate(IGeometrySink sink)
        {
            sink.BeginGeometry(GeometryType.MultiLineString);

            //if ((lineStringMember!=null)
            if (Untyped.Descendants("{http://www.opengis.net/gml}lineStringMember").Any <XElement>())
            {
                foreach (lineStringMember l in lineStringMember)
                {
                    l.LineString.Populate(sink);
                }
            }

            sink.EndGeometry();
        }
Example #30
0
        /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
        /// <param name="sink">The sink to populate.</param>
        /// <remarks>
        ///   <para>The call sequence is a set of figures, lines, and points for geometry types.</para>
        /// </remarks>
        public void Populate(IGeometrySink sink)
        {
            sink.SetCoordinateSystem(CoordinateSystem);

            sink.BeginGeometry(GeometryType.Polygon);

            sink.BeginFigure(_Envelope.MinX, _Envelope.MinY, null);
            sink.AddLine(_Envelope.MaxX, _Envelope.MinY, null);
            sink.AddLine(_Envelope.MaxX, _Envelope.MaxY, null);
            sink.AddLine(_Envelope.MinX, _Envelope.MaxY, null);
            sink.AddLine(_Envelope.MinX, _Envelope.MinY, null);
            sink.EndFigure();

            sink.EndGeometry();
        }
Example #31
0
        protected internal override void InternalPopulate(IGeometrySink sink)
        {
            sink.BeginGeometry(GeometryType.MultiPolygon);

            //if ((polygonMember!=null)
            if (Untyped.Descendants("{http://www.opengis.net/gml}polygonMember").Any <XElement>())
            {
                foreach (polygonMember p in polygonMember)
                {
                    p.Polygon.Populate(sink);
                }
            }

            sink.EndGeometry();
        }
Example #32
0
        private static void _PopulateSimpleType(IGeometrySink sink, FGeometry.IGeometry geometry)
        {
            sink.BeginGeometry(GeometryTypeUtils.Convert(geometry.DerivedType));

            switch (geometry.DerivedType)
            {
            case FCommon.GeometryType.GeometryType_LineString:
                using (FGeometry.DirectPositionCollection positions = ((FGeometry.ILineString)geometry).Positions)
                    CreateFigure(sink, positions);
                break;

            case FCommon.GeometryType.GeometryType_Point:
                using (FGeometry.DirectPositionCollection positions = new FGeometry.DirectPositionCollection())
                    using (FGeometry.IDirectPosition dp = ((FGeometry.IPoint)geometry).Position)
                    {
                        positions.Add(dp);
                        CreateFigure(sink, positions);
                    }
                break;

            case FCommon.GeometryType.GeometryType_Polygon:
            {
                var polygon = (FGeometry.IPolygon)geometry;
                using (FGeometry.ILinearRing exterior = polygon.ExteriorRing)
                    using (FGeometry.DirectPositionCollection positions = exterior.Positions)
                        CreateFigure(sink, positions);

                for (int i = 0; i < polygon.InteriorRingCount; ++i)
                {
                    using (FGeometry.ILinearRing interior = polygon.GetInteriorRing(i))
                        using (FGeometry.DirectPositionCollection positions = interior.Positions)
                            CreateFigure(sink, positions);
                }
            }
            break;

            default:
                throw new NotSupportedException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              SR.UnsupportedGeometryTypeException,
                              geometry.DerivedType
                              )
                          );
            }

            sink.EndGeometry();
        }
Example #33
0
        internal protected override void InternalPopulate(IGeometrySink sink)
        {
            sink.BeginGeometry(GeometryType.LineString);

            //if (posList!=null)
            if (Untyped.Descendants("{http://www.opengis.net/gml}posList").Any<XElement>())
                if ((posList.TypedValue!=null) && (posList.TypedValue.Count>=2))
                {
                    sink.BeginFigure(posList.TypedValue[0], posList.TypedValue[1], null);
                    for (int i=2; i<posList.TypedValue.Count; i+=2)
                        sink.AddLine(posList.TypedValue[i], posList.TypedValue[i+1], null);
                    sink.EndFigure();
                }

            sink.EndGeometry();
        }
Example #34
0
        internal static void Populate(IGeometrySink sink, IList <SeriesNode> pointSeries, GeometryType type)
        {
            foreach (SeriesNode series in pointSeries)
            {
                if (type != GeometryType.Polygon)
                {
                    sink.BeginGeometry(GeometryType.LineString);
                }

                List <PointNode> points = series.Select <ParseTreeNode, PointNode>(n => (PointNode)n.AstNode).ToList <PointNode>();
                MultiPointNode.Populate(sink, points, GeometryType.LineString);

                if (type != GeometryType.Polygon)
                {
                    sink.EndGeometry();
                }
            }
        }
Example #35
0
        internal protected override void InternalPopulate(IGeometrySink sink)
        {
            sink.BeginGeometry(GeometryType.Polygon);

            if ((exterior != null) && (exterior._Ring != null))
            {
                exterior._Ring.Populate(sink);
            }
            if (interior != null)
            {
                foreach (interior intr in interior)
                {
                    intr._Ring.Populate(sink);
                }
            }

            sink.EndGeometry();
        }
        // Selectively filter unwanted artifacts in input object:
        //	- empty shapes (if [filterEmptyShapes] is true)
        //	- points (if [filterPoints] is true)
        //	- linestrings shorter than provided tolerance (if lineString.STLength < [lineStringTolerance])
        //	- polygon rings thinner than provied tolerance (if ring.STArea < ring.STLength * [ringTolerance])
        //	- general behaviour: Returned spatial objects will always to the simplest OGC construction
        //
        public static SqlGeometry FilterArtifactsGeometry(SqlGeometry g, bool filterEmptyShapes, bool filterPoints, double lineStringTolerance, double ringTolerance)
        {
            if (g == null || g.IsNull)
            {
                return(g);
            }

            SqlGeometryBuilder b      = new SqlGeometryBuilder();
            IGeometrySink      filter = b;

            if (filterEmptyShapes)
            {
                filter = new GeometryEmptyShapeFilter(filter);
            }
            if (ringTolerance > 0)
            {
                filter = new GeometryThinRingFilter(filter, ringTolerance);
            }
            if (lineStringTolerance > 0)
            {
                filter = new GeometryShortLineStringFilter(filter, lineStringTolerance);
            }
            if (filterPoints)
            {
                filter = new GeometryPointFilter(filter);
            }

            g.Populate(filter);
            g = b.ConstructedGeometry;

            if (g == null || g.IsNull || !g.STIsValid().Value)
            {
                return(g);
            }

            // Strip collections with single element
            while (g.STNumGeometries().Value == 1 && g.InstanceOf("GEOMETRYCOLLECTION").Value)
            {
                g = g.STGeometryN(1);
            }

            return(g);
        }
Example #37
0
        protected internal override void InternalPopulate(IGeometrySink sink)
        {
            int dim = 2;

            if (srsDimension.HasValue)
            {
                dim = Convert.ToInt32(srsDimension.Value);
            }
            if (posList.srsDimension.HasValue)
            {
                dim = Convert.ToInt32(posList.srsDimension.Value);
            }

            sink.BeginFigure(posList.TypedValue[0], posList.TypedValue[1], dim > 2 ? posList.TypedValue[2] : (double?)null);
            for (int i = dim; i < posList.TypedValue.Count; i += dim)
            {
                sink.AddLine(posList.TypedValue[i], posList.TypedValue[i + 1], dim > 2 ? posList.TypedValue[i + 2] : (double?)null);
            }
            sink.EndFigure();
        }
Example #38
0
        internal protected override void InternalPopulate(IGeometrySink sink)
        {
            sink.BeginGeometry(GeometryType.LineString);

            //if (posList!=null)
            if (Untyped.Descendants("{http://www.opengis.net/gml}posList").Any <XElement>())
            {
                if ((posList.TypedValue != null) && (posList.TypedValue.Count >= 2))
                {
                    sink.BeginFigure(posList.TypedValue[0], posList.TypedValue[1], null);
                    for (int i = 2; i < posList.TypedValue.Count; i += 2)
                    {
                        sink.AddLine(posList.TypedValue[i], posList.TypedValue[i + 1], null);
                    }
                    sink.EndFigure();
                }
            }

            sink.EndGeometry();
        }
Example #39
0
        private static void _PopulateSimpleType(IGeometrySink sink, SmGeometries.Geometry geometry)
        {
            sink.BeginGeometry(GeometryTypeUtils.Convert(geometry.GeometryType));

            switch (geometry.GeometryType)
            {
            case SmGeometries.GeometryType2.LineString:
                CreateFigure(sink, ((SmGeometries.LineString)geometry).Vertices);
                break;

            case SmGeometries.GeometryType2.Point:
                CreateFigure(sink, new SmGeometries.Point[] { (SmGeometries.Point)geometry });
                break;

            case SmGeometries.GeometryType2.Polygon:
            {
                var pol = (SmGeometries.Polygon)geometry;
                CreateFigure(sink, pol.ExteriorRing.Vertices);

                if (pol.InteriorRings != null)
                {
                    foreach (SmGeometries.LinearRing lr in pol.InteriorRings)
                    {
                        CreateFigure(sink, lr.Vertices);
                    }
                }
            }
            break;

            default:
                throw new NotSupportedException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              SR.UnsupportedGeometryTypeException,
                              geometry.GeometryType
                              )
                          );
            }

            sink.EndGeometry();
        }
Example #40
0
        private void AddRandomSegment(IGeometrySink sink)
        {
            double which = Random.NextDouble();

            if (which < 0.25)
            {
                sink.AddLine(RandomNearPoint());
            }
            else if (which < 0.5)
            {
                sink.AddArc(RandomArc());
            }
            else if (which < 0.75)
            {
                sink.AddBezier(RandomBezier());
            }
            else if (which < 1.0)
            {
                sink.AddQuadraticBezier(RandomQuadraticBezier());
            }
        }
Example #41
0
        internal static void Populate(IGeometrySink sink, IList <PointNode> points, GeometryType type)
        {
            if (points.Count > 0)
            {
                if (type != GeometryType.LineString)
                {
                    sink.BeginGeometry(GeometryType.Point);
                }

                sink.BeginFigure(points[0].X, points[0].Y, null);
                if (type == GeometryType.MultiPoint)
                {
                    sink.EndFigure();
                }

                for (int i = 1; i < points.Count; ++i)
                {
                    if (type == GeometryType.MultiPoint)
                    {
                        sink.BeginFigure(points[i].X, points[i].Y, null);
                        sink.EndFigure();
                    }
                    else
                    {
                        sink.AddLine(points[i].X, points[i].Y, null);
                    }
                }

                if (type != GeometryType.MultiPoint)
                {
                    sink.EndFigure();
                }

                if (type != GeometryType.LineString)
                {
                    sink.EndGeometry();
                }
            }
        }
Example #42
0
        internal protected override void InternalPopulate(IGeometrySink sink)
        {
            int dim=2;
            if (srsDimension.HasValue)
                dim=Convert.ToInt32(srsDimension.Value);

            sink.BeginGeometry(GeometryType.Point);

            //if (pos!=null)
            if (Untyped.Descendants("{http://www.opengis.net/gml}pos").Any<XElement>())
            {
                if (pos.srsDimension.HasValue)
                    dim=Convert.ToInt32(pos.srsDimension.Value);

                if ((pos.TypedValue!=null) && (pos.TypedValue.Count>=dim))
                {
                    sink.BeginFigure(pos.TypedValue[0], pos.TypedValue[1], dim>2 ? pos.TypedValue[2] : (double?)null);
                    sink.EndFigure();
                }
            }

            sink.EndGeometry();
        }
Example #43
0
        private void AddRandomFigure(IGeometrySink sink, int segmentCount)
        {
            previousPoint = null;
            sink.BeginFigure(
                RandomNearPoint(),
                CoinFlip ? FigureBegin.Filled : FigureBegin.Hollow);
            FigureEnd end = CoinFlip ? FigureEnd.Closed : FigureEnd.Closed;

            if (end == FigureEnd.Closed)
            {
                segmentCount--;
            }
            if (CoinFlip)
            {
                for (int i = 0; i < segmentCount; i++)
                {
                    AddRandomSegment(sink);
                }
            }
            else
            {
                double which = Random.NextDouble();
                if (which < 0.33)
                {
                    sink.AddLines(RandomLines(segmentCount));
                }
                else if (which < 0.67)
                {
                    sink.AddQuadraticBeziers(RandomQuadraticBeziers(segmentCount));
                }
                else
                {
                    sink.AddBeziers(RandomBeziers(segmentCount));
                }
            }
            sink.EndFigure(end);
        }
Example #44
0
        private static void CreateFigure(IGeometrySink sink, FGeometry.DirectPositionCollection positions)
        {
            if ((positions == null) || (positions.Count == 0))
            {
                return;
            }

            using (FGeometry.IDirectPosition p0 = positions[0])
            {
                if (p0.Dimensionality > 2)
                {
                    sink.BeginFigure(p0.X, p0.Y, p0.Z);
                }
                else
                {
                    sink.BeginFigure(p0.X, p0.Y, null);
                }
            }

            for (int i = 1; i < positions.Count; ++i)
            {
                using (FGeometry.IDirectPosition pi = positions[i])
                {
                    if (pi.Dimensionality > 2)
                    {
                        sink.AddLine(pi.X, pi.Y, pi.Z);
                    }
                    else
                    {
                        sink.AddLine(pi.X, pi.Y, null);
                    }
                }
            }

            sink.EndFigure();
        }
Example #45
0
        private static void _PopulateSimpleType(IGeometrySink sink, FGeometry.IGeometry geometry)
        {
            sink.BeginGeometry(GeometryTypeUtils.Convert(geometry.DerivedType));

            switch (geometry.DerivedType)
            {
            case FCommon.GeometryType.GeometryType_LineString:
                using (FGeometry.DirectPositionCollection positions=((FGeometry.ILineString)geometry).Positions)
                    CreateFigure(sink, positions);
                break;
            case FCommon.GeometryType.GeometryType_Point:
                using (FGeometry.DirectPositionCollection positions=new FGeometry.DirectPositionCollection())
                    using (FGeometry.IDirectPosition dp=((FGeometry.IPoint)geometry).Position)
                    {
                        positions.Add(dp);
                        CreateFigure(sink, positions);
                    }
                break;
            case FCommon.GeometryType.GeometryType_Polygon:
                {
                    var polygon=(FGeometry.IPolygon)geometry;
                    using (FGeometry.ILinearRing exterior=polygon.ExteriorRing)
                        using (FGeometry.DirectPositionCollection positions=exterior.Positions)
                            CreateFigure(sink, positions);

                    for (int i=0; i<polygon.InteriorRingCount; ++i)
                        using (FGeometry.ILinearRing interior=polygon.GetInteriorRing(i))
                            using (FGeometry.DirectPositionCollection positions=interior.Positions)
                                CreateFigure(sink, positions);
                }
                break;
            default:
                throw new NotSupportedException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        SR.UnsupportedGeometryTypeException,
                        geometry.DerivedType
                    )
                );
            }

            sink.EndGeometry();
        }
Example #46
0
 /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
 /// <param name="sink">The sink to populate.</param>
 /// <remarks>
 ///   <para>The call sequence is a set of figures, lines, and points for geometry types.</para>
 /// </remarks>
 public void Populate(IGeometrySink sink)
 {
     Gml._Geometry g=Gml._Geometry.Parse(_Geometry.AsGml());
     g.Populate(sink);
 }
Example #47
0
 private void AddRandomSegment(IGeometrySink sink)
 {
     double which = Random.NextDouble();
     if (which < 0.25)
         sink.AddLine(RandomNearPoint());
     else if (which < 0.5)
         sink.AddArc(RandomArc());
     else if (which < 0.75)
         sink.AddBezier(RandomBezier());
     else if (which < 1.0)
     sink.AddQuadraticBezier(RandomQuadraticBezier());
 }
Example #48
0
 private void AddRandomFigure(IGeometrySink sink, int segmentCount)
 {
     previousPoint = null;
     sink.BeginFigure(
         RandomNearPoint(),
         CoinFlip ? FigureBegin.Filled : FigureBegin.Hollow);
     FigureEnd end = CoinFlip ? FigureEnd.Closed : FigureEnd.Closed;
     if (end == FigureEnd.Closed)
         segmentCount--;
     if (CoinFlip)
         for (int i = 0; i < segmentCount; i++)
             AddRandomSegment(sink);
     else
     {
         double which = Random.NextDouble();
         if (which < 0.33)
             sink.AddLines(RandomLines(segmentCount));
         else if (which < 0.67)
             sink.AddQuadraticBeziers(RandomQuadraticBeziers(segmentCount));
         else
             sink.AddBeziers(RandomBeziers(segmentCount));
     }
     sink.EndFigure(end);
 }
Example #49
0
        /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
        /// <param name="sink">The sink to populate.</param>
        /// <remarks>
        ///   <para>The call sequence is a set of figures, lines, and points for geometry types.</para>
        /// </remarks>
        public void Populate(IGeometrySink sink)
        {
            var sgs=sink as SqlTypes.IGeographySink110;
            if (sgs==null)
                sgs=new Sink(sink);

            _Geography.Populate(sgs);
        }
Example #50
0
        /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
        /// <param name="sink">The sink to populate.</param>
        /// <remarks>
        ///   <para>The call sequence is a set of figures, lines, and points for geometry types.</para>
        /// </remarks>
        public void Populate(IGeometrySink sink)
        {
            sink.SetCoordinateSystem(CoordinateSystem);

            sink.BeginGeometry(GeometryType.Polygon);

            sink.BeginFigure(_Envelope.MinX, _Envelope.MinY, null);
            sink.AddLine(_Envelope.MaxX, _Envelope.MinY, null);
            sink.AddLine(_Envelope.MaxX, _Envelope.MaxY, null);
            sink.AddLine(_Envelope.MinX, _Envelope.MaxY, null);
            sink.AddLine(_Envelope.MinX, _Envelope.MinY, null);
            sink.EndFigure();

            sink.EndGeometry();
        }
Example #51
0
 public void Stream(IGeometrySink geometrySink)
 {
     base.innerRefT.Stream(geometrySink);
 }
Example #52
0
        private static void CreateFigure(IGeometrySink sink, IList<SmGeometries.Point> points)
        {
            if ((points==null) || (points.Count==0))
                return;

            var p0=points[0];
            var p03=p0 as SmGeometries.Point3D;
            if (p03!=null)
                sink.BeginFigure(p03.X, p03.Y, p03.Z);
            else
                sink.BeginFigure(p0.X, p0.Y, null);

            for (int i=1; i<points.Count; ++i)
            {
                var pi=points[i];
                var pi3=pi as SmGeometries.Point3D;
                if (pi3!=null)
                    sink.AddLine(pi3.X, pi3.Y, pi3.Z);
                else
                    sink.AddLine(pi.X, pi.Y, null);
            }

            sink.EndFigure();
        }
Example #53
0
 /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
 /// <param name="sink">The sink to populate.</param>
 public void Populate(IGeometrySink sink)
 {
     sink.BeginGeometry(GeometryType);
     Populate(sink, _Points, GeometryType);
     sink.EndGeometry();
 }
Example #54
0
 internal protected abstract void InternalPopulate(IGeometrySink sink);
Example #55
0
        /// <summary>Applies a geometry type call sequence to the specified <paramref name="sink" />.</summary>
        /// <param name="sink">The sink to populate.</param>
        /// <remarks>
        ///   <para>The call sequence is a set of figures, lines, and points for geometry types.</para>
        /// </remarks>
        public void Populate(IGeometrySink sink)
        {
            sink.SetCoordinateSystem(CoordinateSystem);

            switch (_Geometry.DerivedType)
            {
            case FCommon.GeometryType.GeometryType_LineString:
            case FCommon.GeometryType.GeometryType_Point:
            case FCommon.GeometryType.GeometryType_Polygon:
                _PopulateSimpleType(sink, _Geometry);
                break;
            case FCommon.GeometryType.GeometryType_MultiLineString:
                sink.BeginGeometry(GeometryTypeUtils.Convert(_Geometry.DerivedType));
                {
                    var multiLineString=(FGeometry.IMultiLineString)_Geometry;
                    for (int i=0; i<multiLineString.Count; ++i)
                        using (FGeometry.ILineString lineString=multiLineString[i])
                            _PopulateSimpleType(sink, lineString);
                }
                sink.EndGeometry();
                break;
            case FCommon.GeometryType.GeometryType_MultiPoint:
                sink.BeginGeometry(GeometryTypeUtils.Convert(_Geometry.DerivedType));
                {
                    var multiPoint=(FGeometry.IMultiPoint)_Geometry;
                    using (FGeometry.DirectPositionCollection positions=new FGeometry.DirectPositionCollection())
                        for (int i=0; i<multiPoint.Count; ++i)
                            using (FGeometry.IPoint point=multiPoint[i])
                                _PopulateSimpleType(sink, point);
                }
                sink.EndGeometry();
                break;
            case FCommon.GeometryType.GeometryType_MultiPolygon:
                sink.BeginGeometry(GeometryTypeUtils.Convert(_Geometry.DerivedType));
                {
                    var multiPolygon=(FGeometry.IMultiPolygon)_Geometry;
                    for (int i=0; i<multiPolygon.Count; ++i)
                        using (FGeometry.IPolygon polygon=multiPolygon[i])
                            _PopulateSimpleType(sink, polygon);
                }
                sink.EndGeometry();
                break;
            case FCommon.GeometryType.GeometryType_MultiGeometry:
                sink.BeginGeometry(GeometryTypeUtils.Convert(_Geometry.DerivedType));
                {
                    var multiGeometry=(FGeometry.IMultiGeometry)_Geometry;
                    for (int i=0; i<multiGeometry.Count; ++i)
                        using (FGeometry.IGeometry geometry=multiGeometry[i])
                            _PopulateSimpleType(sink, geometry);
                }
                sink.EndGeometry();
                break;
            default:
                throw new NotSupportedException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        SR.UnsupportedGeometryTypeException,
                        _Geometry.DerivedType
                    )
                );
            }

        }
Example #56
0
 internal protected override void InternalPopulate(IGeometrySink sink)
 {
     throw new NotImplementedException();
 }
Example #57
0
 protected internal override void InternalPopulate(IGeometrySink sink)
 {
     throw new NotImplementedException();
 }
Example #58
0
        private static void _PopulateSimpleType(IGeometrySink sink, SmGeometries.Geometry geometry)
        {
            sink.BeginGeometry(GeometryTypeUtils.Convert(geometry.GeometryType));

            switch (geometry.GeometryType)
            {
            case SmGeometries.GeometryType2.LineString:
                CreateFigure(sink, ((SmGeometries.LineString)geometry).Vertices);
                break;
            case SmGeometries.GeometryType2.Point:
                CreateFigure(sink, new SmGeometries.Point[] { (SmGeometries.Point)geometry });
                break;
            case SmGeometries.GeometryType2.Polygon:
                {
                    var pol=(SmGeometries.Polygon)geometry;
                    CreateFigure(sink, pol.ExteriorRing.Vertices);

                    if (pol.InteriorRings!=null)
                        foreach (SmGeometries.LinearRing lr in pol.InteriorRings)
                            CreateFigure(sink, lr.Vertices);
                }
                break;
            default:
                throw new NotSupportedException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        SR.UnsupportedGeometryTypeException,
                        geometry.GeometryType
                    )
                );
            }

            sink.EndGeometry();
        }
Example #59
0
        private static void CreateFigure(IGeometrySink sink, FGeometry.DirectPositionCollection positions)
        {
            if ((positions==null) || (positions.Count==0))
                return;

            using (FGeometry.IDirectPosition p0=positions[0])
            {
                if (p0.Dimensionality>2)
                    sink.BeginFigure(p0.X, p0.Y, p0.Z);
                else
                    sink.BeginFigure(p0.X, p0.Y, null);
            }

            for (int i=1; i<positions.Count; ++i)
                using (FGeometry.IDirectPosition pi=positions[i])
                {
                    if (pi.Dimensionality>2)
                        sink.AddLine(pi.X, pi.Y, pi.Z);
                    else
                        sink.AddLine(pi.X, pi.Y, null);
                }

            sink.EndFigure();
        }
Example #60
0
        /// <summary>Populates the specified <paramref name="sink" /> with the specified <paramref name="text" /> and <paramref name="coordinateSystem" />.</summary>
        /// <param name="sink">The object to fill.</param>
        /// <param name="text">The WKT representation of the source geometry.</param>
        /// <param name="coordinateSystem">The coordinate system of the WKT representation.</param>
        public static void Populate(IGeometrySink sink, string text, ICoordinateSystem coordinateSystem)
        {
            Debug.Assert(sink!=null);
            if (sink==null)
                throw new ArgumentNullException("sink");
            Debug.Assert(coordinateSystem!=null);
            if (coordinateSystem==null)
                throw new ArgumentNullException("coordinateSystem");

            sink.SetCoordinateSystem(coordinateSystem);
            if (string.IsNullOrEmpty(text))
                return;

            // Parse the WKT
            var parser=new Parser(LanguageData);
            ParseTree tree=parser.Parse(text);

            if (tree.ParserMessages.Count>0)
            {
                var logger=LogManager.GetCurrentClassLogger();
                var exl=new List<Exception>();

                foreach (LogMessage lm in tree.ParserMessages)
                    switch (lm.Level)
                    {
                    case ErrorLevel.Error:
                        logger.Error(CultureInfo.InvariantCulture, m => m("({0},{1}): {2}", lm.Location.Line, lm.Location.Column, lm.Message));
                        exl.Add(
                            new ArgumentException(
                                string.Format(
                                    parser.Context.Culture,
                                    "({0},{1}): {2}: {3}",
                                    lm.Location.Line,
                                    lm.Location.Column,
                                    lm.Level,
                                    lm.Message
                                ),
                                "text"
                            )
                        );
                        break;
                    case ErrorLevel.Info:
                        logger.Info(CultureInfo.InvariantCulture, m => m("({0},{1}): {2}", lm.Location.Line, lm.Location.Column, lm.Message));
                        break;
                    default:
                        logger.Warn(CultureInfo.InvariantCulture, m => m("({0},{1}): {2}", lm.Location.Line, lm.Location.Column, lm.Message));
                        break;
                    }

                if (exl.Count>0)
                    throw new AggregateException(exl);
            }

            // Fill the sink
            ((IGeometryTap)tree.Root.AstNode).Populate(sink);
        }