Example #1
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 #2
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 #3
0
        public void Populate(IGeometrySink sink)
        {
            if (srsName!=null)
                sink.SetCoordinateSystem(CoordinateSystem);

            InternalPopulate(sink);
        }
Example #4
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 #5
0
        public void Populate(IGeometrySink sink)
        {
            if (srsName != null)
            {
                sink.SetCoordinateSystem(CoordinateSystem);
            }

            InternalPopulate(sink);
        }
Example #6
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 #7
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.GetLogger <GeometryWktGrammar>();
                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);
        }
Example #8
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);
        }
Example #9
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 #10
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 #11
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 #12
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
                    )
                );
            }

        }