/// <summary>
        /// This method populates the given sink with the information about the geography instance
        /// extracted from the KML string
        /// </summary>
        /// <param name="sink">Sink to be filled</param>
        /// <param name="makeValid">If true and the extracted geography instance is invalid then the MakeValid
        /// function will be executed on the extracted geography instance</param>
        public void Populate(
            IGeographySink110 sink,
            bool makeValid)
        {
            sink.SetSrid(Srid);

            var numOfGeographies = _parser.Geographies.Count;

            if (numOfGeographies == 1)
            {
                _parser.Geographies[0].Populate(sink, makeValid);
            }
            else if (numOfGeographies > 1)
            {
                sink.BeginGeography(OpenGisGeographyType.GeometryCollection);

                foreach (var g in _parser.Geographies)
                {
                    g.Populate(sink, makeValid);
                }

                sink.EndGeography();
            }
            else
            {
                // Geography instance is not found. The empty geography collection will be generated.
                sink.BeginGeography(OpenGisGeographyType.GeometryCollection);
                sink.EndGeography();
            }
        }
 public void Read(BinaryReader r)
 {
     if (r.ReadBoolean())
     {
         Init();
     }
     else
     {
         SqlGeography g = new SqlGeography();
         g.Read(r);
         if (g.IsNull)
         {
             m_srid    = -1;
             m_error   = true;
             m_builder = null;
             m_sink    = null;
         }
         else
         {
             m_srid    = g.STSrid.Value;
             m_builder = new SqlGeographyBuilder();
             m_sink    = new StripSRID(m_builder);
             m_builder.SetSrid(m_srid);
             m_builder.BeginGeography(OpenGisGeographyType.GeometryCollection);
             g.Populate(new StripCollection(m_builder));
         }
     }
 }
        /// <summary>
        /// This method populates the given sink with the data from this geography instance
        /// </summary>
        /// <param name="sink">Sink to be populated</param>
        public override void Populate(IGeographySink110 sink)
        {
            CheckCoordinates();

            // The coordinates for this geography instance will be:
            // (west, south), (east, south), (east, north), (west, north), (west, south)
            sink.BeginGeography(OpenGisGeographyType.Polygon);

            // (west, south)
            sink.BeginFigure(South, West, Altitude, Measure);

            // (east, south)
            sink.AddLine(South, East, Altitude, Measure);

            // (east, north)
            sink.AddLine(North, East, Altitude, Measure);

            // (west, north)
            sink.AddLine(North, West, Altitude, Measure);

            // (west, south)
            sink.AddLine(South, West, Altitude, Measure);

            sink.EndFigure();

            sink.EndGeography();
        }
 public void Init()
 {
     m_srid    = -1;
     m_builder = null;
     m_sink    = null;
     m_error   = false;
 }
Exemplo n.º 5
0
        /// <summary>
        /// This method populates the given sink with the data from this geography instance
        /// </summary>
        /// <param name="sink">Sink to be populated</param>
        public override void Populate(IGeographySink110 sink)
        {
            if (OuterRing?.Points == null || OuterRing.Points.Count == 0)
            {
                return;
            }

            sink.BeginGeography(OpenGisGeographyType.Polygon);

            // Populates the outer boundary
            sink.BeginFigure(
                OuterRing.Points[0].Latitude,
                OuterRing.Points[0].Longitude,
                OuterRing.Points[0].Altitude,
                OuterRing.Points[0].Measure);

            for (var i = 1; i < OuterRing.Points.Count; i++)
            {
                sink.AddLine(
                    OuterRing.Points[i].Latitude,
                    OuterRing.Points[i].Longitude,
                    OuterRing.Points[i].Altitude,
                    OuterRing.Points[i].Measure);
            }

            sink.EndFigure();

            if (InnerRing != null && InnerRing.Count > 0)
            {
                // Populates the inner boundaries

                foreach (var linearRing in InnerRing)
                {
                    if (linearRing.Points == null || linearRing.Points.Count == 0)
                    {
                        continue;
                    }

                    sink.BeginFigure(
                        linearRing.Points[0].Latitude,
                        linearRing.Points[0].Longitude,
                        linearRing.Points[0].Altitude,
                        linearRing.Points[0].Measure);

                    for (var i = 1; i < linearRing.Points.Count; i++)
                    {
                        sink.AddLine(
                            linearRing.Points[i].Latitude,
                            linearRing.Points[i].Longitude,
                            linearRing.Points[i].Altitude,
                            linearRing.Points[i].Measure);
                    }

                    sink.EndFigure();
                }
            }

            sink.EndGeography();
        }
Exemplo n.º 6
0
        /// <summary>
        /// This method populates the given sink with the data about this geography instance
        /// </summary>
        /// <param name="sink">Sink to be populated</param>
        public override void Populate(IGeographySink110 sink)
        {
            sink.BeginGeography(OpenGisGeographyType.Point);
            sink.BeginFigure(Latitude, Longitude, Altitude, Measure);

            sink.EndFigure();
            sink.EndGeography();
        }
Exemplo n.º 7
0
        /// <summary>
        /// This method populates the given sink with the valid geography instance constructed from this geography instance.
        /// </summary>
        /// <param name="sink">Sink to be populated</param>
        private void MakeValid(IGeographySink110 sink)
        {
            // 1. Creates the valid geography for this WKT
            var vg = Geog.MakeValidGeographyFromText(WKT, Constants.DefaultSRID);

            // 2. Populates the given sink with the valid geography
            vg.Populate(new FilterSetSridGeographySink(sink));
        }
 private void PopulateFigure(IGeographySink110 sink)
 {
     _figure[0].BeginFigure(sink);
     for (int i = 1; i < _figure.Count; i++)
     {
         _figure[i].AddLine(sink);
     }
     sink.EndFigure();
 }
Exemplo n.º 9
0
        /// <summary>
        /// This method populates the given sink with the information about this multi geometry instance
        /// </summary>
        /// <param name="sink">Sink to be populated</param>
        public override void Populate(IGeographySink110 sink)
        {
            sink.BeginGeography(OpenGisGeographyType.GeometryCollection);

            if (Geographies != null && Geographies.Count > 0)
            {
                foreach (var geography in Geographies)
                {
                    geography.Populate(sink);
                }
            }

            sink.EndGeography();
        }
 private void Reset(int srid)
 {
     if (m_builder == null)
     {
         m_srid    = srid;
         m_builder = new SqlGeographyBuilder();
         m_builder.SetSrid(m_srid);
         m_builder.BeginGeography(OpenGisGeographyType.GeometryCollection);
         m_sink = new StripSRID(m_builder);
     }
     else if (srid != m_srid)
     {
         m_srid    = -1;
         m_builder = null;
         m_sink    = null;
         m_error   = true;
     }
 }
        /// <summary>
        /// This method populates the given sink with the data from this geography instance
        /// </summary>
        /// <param name="sink">Sink to be populated</param>
        public override void Populate(IGeographySink110 sink)
        {
            if (Points == null || Points.Count == 0)
            {
                return;
            }

            sink.BeginGeography(GeographyType);
            sink.BeginFigure(Points[0].Latitude, Points[0].Longitude, Points[0].Altitude, Points[0].Measure);

            for (var i = 1; i < Points.Count; i++)
            {
                sink.AddLine(Points[i].Latitude, Points[i].Longitude, Points[i].Altitude, Points[i].Measure);
            }

            sink.EndFigure();
            sink.EndGeography();
        }
Exemplo n.º 12
0
        // Selectively filter unwanted artifacts in input object:
        //	- empty shapes (if [filterEmptyShapes] is true)
        //	- points (if [filterPoints] is true)
        //	- line strings shorter than provided tolerance (if lineString.STLength < [lineStringTolerance])
        //	- polygon rings thinner than provided tolerance (if ring.STArea < ring.STLength * [ringTolerance])
        //	- general behavior: Returned spatial objects will always to the simplest OGC construction
        //
        public static SqlGeography FilterArtifactsGeography(SqlGeography geography, bool filterEmptyShapes, bool filterPoints, double lineStringTolerance, double ringTolerance)
        {
            if (geography == null || geography.IsNull)
            {
                return(geography);
            }

            var geogBuilder          = new SqlGeographyBuilder();
            IGeographySink110 filter = geogBuilder;

            if (filterEmptyShapes)
            {
                filter = new GeographyEmptyShapeFilter(filter);
            }
            if (ringTolerance > 0)
            {
                filter = new GeographyThinRingFilter(filter, ringTolerance);
            }
            if (lineStringTolerance > 0)
            {
                filter = new GeographyShortLineStringFilter(filter, lineStringTolerance);
            }
            if (filterPoints)
            {
                filter = new GeographyPointFilter(filter);
            }

            geography.Populate(filter);
            geography = geogBuilder.ConstructedGeography;

            if (geography == null || geography.IsNull)
            {
                return(geography);
            }

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

            return(geography);
        }
Exemplo n.º 13
0
 /// <summary>
 /// This method populates the given sink with the data from this geography instance.
 /// If this geography instance is invalid and the makeValid flag is set then a valid geography instance
 /// will be constructed and the given sink will be populated with that instance.
 /// </summary>
 /// <param name="sink">Sink to be populated</param>
 /// <param name="makeValid">If true and this geography instance is invalid then the MakeValid
 /// function will be executed on this geography instance</param>
 public void Populate(
     IGeographySink110 sink,
     bool makeValid)
 {
     if (makeValid)
     {
         if (IsValid)
         {
             Populate(sink);
         }
         else
         {
             MakeValid(sink);
         }
     }
     else
     {
         Populate(sink);
     }
 }
 private void PopulateFigure(IGeographySink110 sink, bool reverse)
 {
     if (reverse)
     {
         _figure[_figure.Count - 1].BeginFigure(sink);
         for (int i = _figure.Count - 2; i >= 0; i--)
         {
             _figure[i].AddLine(sink);
         }
     }
     else
     {
         _figure[0].BeginFigure(sink);
         for (int i = 1; i < _figure.Count; i++)
         {
             _figure[i].AddLine(sink);
         }
     }
     sink.EndFigure();
 }
        public void Merge(GeographyCollectionAggregate group)
        {
            if (group.IsInitialState())
            {
                return;
            }

            SqlGeography g = group.ConstructedGeography();

            if (g.IsNull)
            {
                m_srid    = -1;
                m_builder = null;
                m_sink    = null;
                m_error   = true;
            }
            else
            {
                Reset(g.STSrid.Value);
                g.Populate(new StripCollection(m_builder));
            }
        }
 public GeographyThinRingFilter(IGeographySink110 sink, double tolerance)
 {
     _sink      = sink;
     _tolerance = tolerance;
 }
Exemplo n.º 17
0
 public void AddLine(IGeographySink110 sink)
 {
     sink.AddLine(_x, _y, _z, _m);
 }
Exemplo n.º 18
0
 public void BeginFigure(IGeographySink110 sink)
 {
     sink.BeginFigure(_x, _y, _z, _m);
 }
            private readonly double _z;                 // How much to shift in the x direction.

            // We take an amount to shift in the x and y directions, as well as a target sink, to which
            // we will pipe our result.
            public ShiftGeographySink(double z, IGeographySink110 target)
            {
                _target = target;
                _z      = z;
            }
Exemplo n.º 20
0
 public GeometryToPointGeographySink(IGeographySink110 sink)
 {
     _sink  = sink;
     _count = 0;
 }
 public VacuousGeometryToGeographySink(int targetSrid, IGeographySink110 target)
 {
     _target     = target;
     _targetSrid = targetSrid;
 }
 public StripSRID(IGeographySink110 sink)
 {
     _sink = sink;
 }
 public GeographyPointFilter(IGeographySink110 sink)
 {
     _sink = sink;
 }
Exemplo n.º 24
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 /// <param name="targetSink">Target sink</param>
 public FilterSetSridGeographySink(IGeographySink110 targetSink)
 {
     _targetSink = targetSink;
 }
 public GeographyShortLineStringFilter(IGeographySink110 sink, double tolerance)
 {
     _sink      = sink;
     _tolerance = tolerance;
 }
        // Constructor.
        public DensifyGeographySink(IGeographySink110 sink, double angle)
        {
            _sink = sink ?? throw new ArgumentNullException(nameof(sink), "sink");

            _angle = angle < MinAngle ? MinAngle : angle;
        }
 public GeographyEmptyShapeFilter(IGeographySink110 sink)
 {
     _sink = sink;
 }
Exemplo n.º 28
0
 /// <summary>
 /// This method populates the given sink with the data from this geography instance
 /// </summary>
 /// <param name="sink">Sink to be populated</param>
 public abstract void Populate(IGeographySink110 sink);
 public UnProjector(SqlProjection projection, IGeographySink110 sink, int newSrid)
 {
     _projection = projection;
     _sink       = sink;
     _sink.SetSrid(newSrid);
 }
 public StripCollection(IGeographySink110 sink)
 {
     _sink = sink;
 }