/// <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(
            IGeographySink sink,
            bool makeValid)
        {
            sink.SetSrid(m_Srid);

            int numOfGeographies = m_Parser.Geographies.Count;

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

                foreach (Geography g in m_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();
            }
        }
Beispiel #2
0
 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));
         }
     }
 }
Beispiel #3
0
 public void Init()
 {
     m_srid    = -1;
     m_builder = null;
     m_sink    = null;
     m_error   = false;
 }
        /// <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(IGeographySink sink)
        {
            if (this.OuterRing == null || this.OuterRing.Points == null || this.OuterRing.Points.Count == 0)
            {
                return;
            }

            sink.BeginGeography(OpenGisGeographyType.Polygon);

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

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

            sink.EndFigure();

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

                for (int j = 0; j < this.InnerRing.Count; j++)
                {
                    if (this.InnerRing[j].Points == null || this.InnerRing[j].Points.Count == 0)
                    {
                        continue;
                    }

                    sink.BeginFigure(
                        this.InnerRing[j].Points[0].Latitude,
                        this.InnerRing[j].Points[0].Longitude,
                        this.InnerRing[j].Points[0].Altitude,
                        this.InnerRing[j].Points[0].Measure);

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

                    sink.EndFigure();
                }
            }

            sink.EndGeography();
        }
Beispiel #5
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>
        public void MakeValid(IGeographySink sink)
        {
            // 1. Creates the valid geography for this WKT
            SqlGeography vg = SQLSpatialTools.Functions.MakeValidGeographyFromText(this.WKT, Constants.DefaultSRID);

            // 2. Populates the given sink with the valid geography
            vg.Populate(new FilterSetSridGeographySink(sink));
        }
Beispiel #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(IGeographySink sink)
        {
            sink.BeginGeography(OpenGisGeographyType.Point);
            sink.BeginFigure(Latitude, Longitude, Altitude, Measure);

            sink.EndFigure();
            sink.EndGeography();
        }
 private void PopulateFigure(IGeographySink sink)
 {
     m_figure[0].BeginFigure(sink);
     for (int i = 1; i < m_figure.Count; i++)
     {
         m_figure[i].AddLine(sink);
     }
     sink.EndFigure();
 }
Beispiel #8
0
        // Constructor.
        public DensifyGeographySink(IGeographySink sink, double angle)
        {
            if (sink == null)
            {
                throw new ArgumentNullException("sink");
            }
            _sink = sink;

            if (angle < MinAngle)
            {
                _angle = MinAngle;
            }
            else
            {
                _angle = angle;
            }
        }
Beispiel #9
0
 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;
     }
 }
Beispiel #10
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(IGeographySink sink)
        {
            if (Points == null || Points.Count == 0)
            {
                return;
            }

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

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

            sink.EndFigure();
            sink.EndGeography();
        }
        // 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 SqlGeography FilterArtifactsGeography(SqlGeography g, bool filterEmptyShapes, bool filterPoints, double lineStringTolerance, double ringTolerance)
        {
            if (g == null || g.IsNull)
            {
                return(g);
            }

            SqlGeographyBuilder b      = new SqlGeographyBuilder();
            IGeographySink      filter = b;

            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);
            }

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

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

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

            return(g);
        }
Beispiel #12
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(
     IGeographySink sink,
     bool makeValid)
 {
     if (makeValid)
     {
         if (IsValid)
         {
             Populate(sink);
         }
         else
         {
             MakeValid(sink);
         }
     }
     else
     {
         Populate(sink);
     }
 }
 private void PopulateFigure(IGeographySink sink, bool reverse)
 {
     if (reverse)
     {
         m_figure[m_figure.Count - 1].BeginFigure(sink);
         for (int i = m_figure.Count - 2; i >= 0; i--)
         {
             m_figure[i].AddLine(sink);
         }
     }
     else
     {
         m_figure[0].BeginFigure(sink);
         for (int i = 1; i < m_figure.Count; i++)
         {
             m_figure[i].AddLine(sink);
         }
     }
     sink.EndFigure();
 }
Beispiel #14
0
        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));
            }
        }
Beispiel #15
0
 public TransformGeographyToGeographySink(ICoordinateTransformation trans, IGeographySink sink)
 {
     _trans = trans;
     _sink  = sink;
 }
 public GeographyShortLineStringFilter(IGeographySink sink, double tolerance)
 {
     m_sink      = sink;
     m_tolerance = tolerance;
 }
Beispiel #17
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(IGeographySink sink);
Beispiel #18
0
 public VacuousGeometryToGeographySink(int targetSrid, IGeographySink target)
 {
     _target     = target;
     _targetSrid = targetSrid;
 }
 public GeometryToPointGeographySink(IGeographySink sink)
 {
     _sink  = sink;
     _count = 0;
 }
Beispiel #20
0
 public void AddLine(IGeographySink sink)
 {
     sink.AddLine(x, y, z, m);
 }
 public Unprojector(SqlProjection projection, IGeographySink sink, int newSrid)
 {
     _projection = projection;
     _sink       = sink;
     _sink.SetSrid(newSrid);
 }
Beispiel #22
0
 public StripCollection(IGeographySink sink)
 {
     m_sink = sink;
 }
 public GeographyThinRingFilter(IGeographySink sink, double tolerance)
 {
     m_sink      = sink;
     m_tolerance = tolerance;
 }
Beispiel #24
0
 public StripSRID(IGeographySink sink)
 {
     m_sink = sink;
 }
Beispiel #25
0
 public void BeginFigure(IGeographySink sink)
 {
     sink.BeginFigure(x, y, z, m);
 }
 /// <summary>
 /// Default Constructor
 /// </summary>
 /// <param name="targetSink">Target sink</param>
 public FilterSetSridGeographySink(IGeographySink targetSink)
 {
     m_TargetSink = targetSink;
 }
 public GeographyPointFilter(IGeographySink sink)
 {
     m_sink = sink;
 }
Beispiel #28
0
        private readonly int _precision;         // the number of fractional digits in the return value

        public RoundGeography(int precision, IGeographySink target)
        {
            _target    = target;
            _precision = precision;
        }
 public GeographyEmptyShapeFilter(IGeographySink sink)
 {
     m_sink = sink;
 }