private static void AddMultiPolygon <T>(SqlGeographyBuilder builder, Geometry <T> geometry) where T : IPoint, new()
        {
            //return CreatePolygon(points, srid);
            //SqlGeometryBuilder builder = new SqlGeometryBuilder();

            //builder.SetSrid(geometry.Srid);

            builder.BeginGeography(OpenGisGeographyType.MultiPolygon);

            foreach (var item in geometry.Geometries)
            {
                builder.BeginGeography(OpenGisGeographyType.Polygon);

                foreach (var lines in item.Geometries)
                {
                    if (lines.NumberOfPoints < minimumPolygonPoints)
                    {
                        Trace.WriteLine($"CreateMultiPolygon escape!");
                        continue;
                    }

                    AddLineStringOrRing(builder, lines, true);
                }

                builder.EndGeography();
            }

            builder.EndGeography();

            //return builder.ConstructedGeometry.MakeValid();
        }
Example #2
0
 private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, MultiLineString multiLineString)
 {
     gb.BeginGeography(OpenGisGeographyType.MultiLineString);
     foreach (var lineString in multiLineString.Coordinates)
     {
         gb.BeginGeography(OpenGisGeographyType.LineString);
         bool beginFigureCalled = false;
         foreach (var ipos in lineString.Coordinates)
         {
             Position pos = ipos as Position;
             if (!beginFigureCalled)
             {
                 gb.BeginFigure(pos.Latitude, pos.Longitude);
                 beginFigureCalled = true;
             }
             else
             {
                 gb.AddLine(pos.Latitude, pos.Longitude);
             }
         }
         gb.EndFigure();
         gb.EndGeography();
     }
     gb.EndGeography();
 }
Example #3
0
        //TOP LEFT LONGITUDE=item1, LATITUDE=item2, //BOTTOM RIGHT LONGITUDE=item3, LATITUDE=item4
        public static SqlGeography CreateMultiRectangle(this List <Tuple <double, double, double, double> > coordinates, int srid = 4326)
        {
            var list = coordinates.Distinct().ToList();
            var b    = new SqlGeographyBuilder();

            b.SetSrid(srid);
            b.BeginGeography(OpenGisGeographyType.MultiPolygon);

            for (var i = 0; i < list.Count; i++)
            {
                b.BeginGeography(OpenGisGeographyType.Polygon);
                b.BeginFigure(list[i].Item1, list[i].Item2);
                b.AddLine(list[i].Item1, list[i].Item4);
                b.AddLine(list[i].Item3, list[i].Item4);
                b.AddLine(list[i].Item3, list[i].Item2);
                b.AddLine(list[i].Item1, list[i].Item2);
                b.EndFigure();
                b.EndGeography();
            }
            b.EndGeography();

            return(b.ConstructedGeography.EnvelopeAngle() > 90
                ? b.ConstructedGeography.ReorientObject()
                : b.ConstructedGeography);
        }
Example #4
0
        public static SqlGeography CreateGeography(this string points, out OpenGisGeographyType geographyType, int srid = 4326)
        {
            geographyType = OpenGisGeographyType.Point;
            SqlGeography firstPoint = null;
            var          pts        = points.Trim().Split(new string[] { "\n" }, StringSplitOptions.None).ToList();

            pts.Add(null);
            var b = new SqlGeographyBuilder();

            b.SetSrid(srid);
            b.BeginGeography(OpenGisGeographyType.GeometryCollection);
            var coordinates = new List <Tuple <double, double> >();

            for (int i = 0; i < pts.Count; i++)
            {
                if (string.IsNullOrWhiteSpace(pts[i]))
                {
                    if (coordinates.Count == 1)
                    {
                        if (firstPoint == null)
                        {
                            firstPoint = coordinates[0].CreatePoint();
                        }
                        b.BeginGeography(OpenGisGeographyType.Point);
                        b.BeginFigure(coordinates[0].Item2, coordinates[0].Item1);
                        b.EndFigure();
                        b.EndGeography();
                    }
                    else if (coordinates.Count > 1)
                    {
                        geographyType = OpenGisGeographyType.GeometryCollection;
                        var list = coordinates.Distinct().ToList();
                        b.BeginGeography(OpenGisGeographyType.Polygon);
                        b.BeginFigure(list[0].Item2, list[0].Item1);
                        for (var j = 1; j < list.Count; j++)
                        {
                            b.AddLine(list[j].Item2, list[j].Item1);
                        }
                        b.AddLine(list[0].Item2, list[0].Item1);
                        b.EndFigure();
                        b.EndGeography();
                    }
                    coordinates = new List <Tuple <double, double> >();
                    continue;
                }
                var pt = pts[i].Trim().Split(new string[] { " ", ",", ";", "\t", ":", "\r" }, StringSplitOptions.RemoveEmptyEntries);
                coordinates.Add(new Tuple <double, double>(double.Parse(pt[0]), double.Parse(pt[1])));
            }
            b.EndGeography();
            if (geographyType == OpenGisGeographyType.GeometryCollection)
            {
                return(b.ConstructedGeography.EnvelopeAngle() > 90 ? b.ConstructedGeography.ReorientObject() : b.ConstructedGeography);
            }
            else
            {
                return(firstPoint);
            }
        }
        private void AddGeometryCollection(IGeometry geometry, OpenGisGeographyType type)
        {
            builder.BeginGeography(type);
            IGeometryCollection coll = geometry as IGeometryCollection;

            Array.ForEach <IGeometry>(coll.Geometries, delegate(IGeometry g)
            {
                AddGeometry(g);
            });
            builder.EndGeography();
        }
Example #6
0
        public void MakeWay(MongoCollection <Node> nodes)
        {
            var builder = new SqlGeographyBuilder();

            builder.SetSrid(base.Srid);

            if (this.NodeIds.Count == 1)
            {
                this.Shape = OpenGisGeographyType.Point;
                builder.BeginGeography(OpenGisGeographyType.Point);
            }
            else if (this.NodeIds.First().Equals(this.NodeIds.Last()))
            {
                if (this.NodeIds.Count == 2)
                {
                    builder.BeginGeography(OpenGisGeographyType.Point);
                    this.Shape = OpenGisGeographyType.Point;
                }
                if (this.NodeIds.Count == 3)
                {
                    builder.BeginGeography(OpenGisGeographyType.LineString);
                    this.Shape = OpenGisGeographyType.LineString;

                    var index = this.NodeIds.Count - 1;
                    this.NodeIds.RemoveAt(index);
                }
                else
                {
                    this.Shape = OpenGisGeographyType.Polygon;
                    builder.BeginGeography(OpenGisGeographyType.Polygon);
                }
            }
            else
            {
                this.Shape = OpenGisGeographyType.LineString;
                builder.BeginGeography(OpenGisGeographyType.LineString);
            }

            var one = nodes.FindOneById(this.NodeIds[0]);

            builder.BeginFigure(one.Latitude, one.Longtitude);
            for (var index = 1; index < this.NodeIds.Count; index++)
            {
                var nodeId = this.NodeIds[index];
                var node   = nodes.FindOneById(nodeId);
                builder.AddLine(node.Latitude, node.Longtitude);
            }

            builder.EndFigure();
            builder.EndGeography();

            this.Lines = builder.ConstructedGeography;
        }
		private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, MultiPoint multiPoint)
		{
			gb.BeginGeography(OpenGisGeographyType.MultiPoint);
			List<Point> coords = multiPoint.Coordinates as List<Point>;
			foreach (var coord in coords)
			{
				GeographicPosition pos = coord.Coordinates as GeographicPosition;
				gb.BeginGeography(OpenGisGeographyType.Point);
				gb.BeginFigure(pos.Latitude, pos.Longitude);
				gb.EndFigure();
				gb.EndGeography();
			}
			gb.EndGeography();
		}
        public static void AddEmptySqlGeometry(SqlGeographyBuilder builder, GeometryType type)
        {
            switch (type)
            {
            case GeometryType.LineString:
                builder.BeginGeography(OpenGisGeographyType.LineString);
                break;

            case GeometryType.MultiLineString:
                builder.BeginGeography(OpenGisGeographyType.MultiLineString);
                break;

            case GeometryType.MultiPoint:
                builder.BeginGeography(OpenGisGeographyType.MultiPoint);
                break;

            case GeometryType.MultiPolygon:
                builder.BeginGeography(OpenGisGeographyType.MultiPolygon);
                break;

            case GeometryType.Point:
                builder.BeginGeography(OpenGisGeographyType.Point);
                break;

            case GeometryType.Polygon:
                builder.BeginGeography(OpenGisGeographyType.Polygon);
                break;

            case GeometryType.GeometryCollection:
                builder.BeginGeography(OpenGisGeographyType.GeometryCollection);
                break;

            case GeometryType.CircularString:
                builder.BeginGeography(OpenGisGeographyType.CircularString);
                break;

            case GeometryType.CompoundCurve:
                builder.BeginGeography(OpenGisGeographyType.CompoundCurve);
                break;

            case GeometryType.CurvePolygon:
                builder.BeginGeography(OpenGisGeographyType.CurvePolygon);
                break;

            default:
                throw new NotImplementedException();
            }

            builder.EndGeography();
        }
        private static void AddMultiLineString <T>(SqlGeographyBuilder builder, Geometry <T> geometry) where T : IPoint, new()
        {
            builder.BeginGeography(OpenGisGeographyType.MultiLineString);

            foreach (var item in geometry.Geometries)
            {
                builder.BeginGeography(OpenGisGeographyType.LineString);

                AddLineStringOrRing(builder, item, false);

                builder.EndGeography();
            }

            builder.EndGeography();
        }
Example #10
0
        private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, MultiPoint multiPoint)
        {
            gb.BeginGeography(OpenGisGeographyType.MultiPoint);
            List <Point> coords = multiPoint.Coordinates.ToList();

            foreach (var coord in coords)
            {
                Position pos = coord.Coordinates as Position;
                gb.BeginGeography(OpenGisGeographyType.Point);
                gb.BeginFigure(pos.Latitude, pos.Longitude);
                gb.EndFigure();
                gb.EndGeography();
            }
            gb.EndGeography();
        }
Example #11
0
        private static void AddMultiLineString(SqlGeographyBuilder builder, GeoJsonMultiLineString geometry, bool isLongitudeFirst)
        {
            builder.BeginGeography(OpenGisGeographyType.MultiLineString);

            foreach (var item in geometry.Coordinates)
            {
                builder.BeginGeography(OpenGisGeographyType.LineString);

                AddLineStringOrRing(builder, item, false, isLongitudeFirst);

                builder.EndGeography();
            }

            builder.EndGeography();
        }
Example #12
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));
         }
     }
 }
Example #13
0
File: Form1.cs Project: XenaMac/MTC
        private void btnCheckIntersection_Click(object sender, EventArgs e)
        {
            lat = Convert.ToDouble(txtLat.Text);
            lon = Convert.ToDouble(txtLon.Text);
            SqlGeographyBuilder builder = new SqlGeographyBuilder();

            builder.SetSrid(4326);
            builder.BeginGeography(OpenGisGeographyType.Point);
            builder.BeginFigure(lat, lon);
            builder.EndFigure();
            builder.EndGeography();

            DrawData(cboBeatSegs.Text, lat, lon);

            //bool tf = GeoClass.checkSegIntersection(cboBeatSegs.Text, builder.ConstructedGeography);
            bool tf = GeoClass.checkEsriIntersect(lat, lon, cboBeatSegs.Text);

            //bool tf = GeoClass.checkIntersects(builder.ConstructedGeography);
            if (tf == true)
            {
                lblInside.Text = "Point is inside figure";
            }
            else
            {
                lblInside.Text = "Point is outside figure";
            }
        }
Example #14
0
        public static SqlGeography AsGeography(this GpxTrack track)
        {
            SqlGeographyBuilder builder = new SqlGeographyBuilder();

            builder.SetSrid(SridHelper.GeodeticWGS84);

            builder.BeginGeography(OpenGisGeographyType.MultiLineString);

            foreach (var item in track.Segments)
            {
                if (item.TrackPoints.Count < 2)
                {
                    continue;
                }

                AddTrackSegment(builder, item);
                //builder.BeginFigure(item.TrackPoints[0].Latitude, item.TrackPoints[0].Longitude);

                //for (int i = 1; i < item.TrackPoints.Count; i++)
                //{
                //    builder.AddLine(item.TrackPoints[i].Latitude, item.TrackPoints[i].Longitude);
                //}

                //builder.EndFigure();
            }

            builder.EndGeography();

            return(builder.ConstructedGeography.STIsValid().Value ? builder.ConstructedGeography : builder.ConstructedGeography.MakeValid());
        }
        public static SqlGeography CreatePolygon(Coordinates[] coordinates, int srid)
        {
            var list = coordinates.Distinct().ToList();

            var b = new SqlGeographyBuilder();

            b.SetSrid(srid);
            b.BeginGeography(OpenGisGeographyType.Polygon);
            b.BeginFigure(list[0].Latitude, list[0].Longitude);

            for (var i = 1; i < list.Count; i++)
            {
                b.AddLine(list[i].Latitude, list[i].Longitude);
            }

            b.AddLine(list[0].Latitude, list[0].Longitude);
            b.EndFigure();
            b.EndGeography();

            //Fix left-hand rule. We always want left-hand.
            var g = b.ConstructedGeography;

            if (!g.STIsValid())
            {
                throw new SisoDbException(ExceptionMessages.NotAValidPolygon.Inject(g.IsValidDetailed()));
            }

            if (g.EnvelopeAngle() > 90)
            {
                g = g.ReorientObject();
            }

            return(g);
        }
        public static SqlGeography CreatePolygon(IEnumerable <Coordinates> coordinates, int srid = 4326)
        {
            var list = coordinates.Distinct().ToList();

            var b = new SqlGeographyBuilder();

            b.SetSrid(srid);
            b.BeginGeography(OpenGisGeographyType.Polygon);
            b.BeginFigure(list[0].Latitude, list[0].Longitude);

            for (var i = 1; i < list.Count; i++)
            {
                b.AddLine(list[i].Latitude, list[i].Longitude);
            }

            b.AddLine(list[0].Latitude, list[0].Longitude);
            b.EndFigure();
            b.EndGeography();

            if (b.ConstructedGeography.EnvelopeAngle() > 90)
            {
                return(b.ConstructedGeography.ReorientObject());
            }

            return(b.ConstructedGeography);
        }
Example #17
0
 private static void SharpMapPointToSqlGeography(SqlGeographyBuilder geogBuilder, SMPoint point)
 {
     geogBuilder.BeginGeography(OpenGisGeographyType.Point);
     geogBuilder.BeginFigure(point.Y, point.X);
     geogBuilder.EndFigure();
     geogBuilder.EndGeography();
 }
        /// <summary>
        /// Makes Geography with default ellipsoid WGS84: 4326
        /// </summary>
        /// <param name="points"></param>
        /// <param name="isClosed"></param>
        /// <returns></returns>
        public static SqlGeography MakeGeography <T>(List <T> points, bool isClosed, int srid = SridHelper.GeodeticWGS84) where T : IPoint, new()
        {
            if (points == null || points.Count < 1)
            {
                return(null);
            }

            SqlGeographyBuilder builder = new SqlGeographyBuilder();

            builder.SetSrid(srid);

            builder.BeginGeography(isClosed ? OpenGisGeographyType.Polygon : OpenGisGeographyType.LineString);

            builder.BeginFigure(points[0].Y, points[0].X);

            for (int i = 1; i < points.Count; i++)
            {
                builder.AddLine(points[i].Y, points[i].X);
            }

            if (isClosed)
            {
                builder.AddLine(points[0].Y, points[0].X);
            }

            builder.EndFigure();

            builder.EndGeography();

            var resultGeography = builder.ConstructedGeography.STIsValid().Value ? builder.ConstructedGeography : builder.ConstructedGeography.MakeValid();

            return(resultGeography.EnvelopeAngle().Value == 180 ? resultGeography.ReorientObject() : resultGeography);
        }
Example #19
0
        public override void OnBeginRender(RenderingContext context)
        {
            base.OnBeginRender(context);

            var sb = new SqlGeographyBuilder();

            sb.SetSrid(4326);
            sb.BeginGeography(OpenGisGeographyType.MultiLineString);

            double lat = context.Projection.GeoMin.Lat;

            lat = Math.Floor(lat / majorStep) * majorStep;

            for (; lat <= context.Projection.GeoMax.Lat; lat += majorStep)
            {
                AddLatitudeLine(sb, context.Projection.GeoMin.Lon, context.Projection.GeoMax.Lon, lat);
            }

            // Longitudes are great circles
            double lon = context.Projection.GeoMin.Lon;

            lon = Math.Floor(lon / majorStep) * majorStep;

            for (; lon <= context.Projection.GeoMax.Lon; lon += majorStep)
            {
                AddLongitudeLine(sb, lon, context.Projection.GeoMin.Lat, context.Projection.GeoMax.Lat);
            }

            sb.EndGeography();
            RenderGeography(context, sb.ConstructedGeography);
        }
        private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, Polygon polygon)
        {
            gb.BeginGeography(OpenGisGeographyType.Polygon);
            bool isExteriorRing = true;

            foreach (var lineString in polygon.Coordinates)
            {
                List <Position>        listGeoCoords    = lineString.Coordinates.Select(p => p as Position).ToList();
                IEnumerable <Position> orderedPositions = EnsureCorrectWinding(listGeoCoords, isExteriorRing);                // exterior ring must be anti clockwise for SqlGeography
                isExteriorRing = false;
                bool beginFigureCalled = false;
                foreach (var pos in orderedPositions)
                {
                    if (!beginFigureCalled)
                    {
                        gb.BeginFigure(pos.Latitude, pos.Longitude);
                        beginFigureCalled = true;
                    }
                    else
                    {
                        gb.AddLine(pos.Latitude, pos.Longitude);
                    }
                }
                gb.EndFigure();
            }
            gb.EndGeography();
        }
Example #21
0
        /// <summary>
        /// Converts the given value from original representation to alternative one.
        /// </summary>
        /// <param name="value">Value in its original representation.</param>
        /// <returns>Value in its alternative representation.</returns>
        public override object Convert(object value)
        {
            object ret = null;
            Models.Location l = null;
            SqlGeographyBuilder builder = null;

            if (value != null && value is Models.Location)
            {
                l = value as Models.Location;
                builder = new SqlGeographyBuilder();

                builder.SetSrid(4326);

                builder.BeginGeography(OpenGisGeographyType.Point);

                builder.BeginFigure(l.Latitude, l.Longitude);
                builder.EndFigure();

                builder.EndGeography();

                ret = builder.ConstructedGeography;
            }

            return ret;
        }
        public static SqlGeography CreatePolygon(Coordinates[] coordinates, int srid)
        {
            var list = coordinates.Distinct().ToList();
            
            var b = new SqlGeographyBuilder();
            b.SetSrid(srid);
            b.BeginGeography(OpenGisGeographyType.Polygon);
            b.BeginFigure(list[0].Latitude, list[0].Longitude);

            for (var i = 1; i < list.Count; i++)
                b.AddLine(list[i].Latitude, list[i].Longitude);

            b.AddLine(list[0].Latitude, list[0].Longitude);
            b.EndFigure();
            b.EndGeography();

            //Fix left-hand rule. We always want left-hand.
            var g = b.ConstructedGeography;
            if (!g.STIsValid())
                throw new SisoDbException(ExceptionMessages.NotAValidPolygon.Inject(g.IsValidDetailed()));

            if (g.EnvelopeAngle() > 90)
                g = g.ReorientObject(); 

            return g;
        }
Example #23
0
        public static SqlGeography GetBounds(SqlDouble xOrLon, SqlDouble yOrLat, SqlDouble xOrLon2, SqlDouble yOrLat2)
        {
            if (xOrLon.IsNull || yOrLat.IsNull)
            {
                return(SqlGeography.Null);
            }
            var builder = new SqlGeographyBuilder();

            builder.SetSrid(4326);
            builder.BeginGeography(OpenGisGeographyType.Polygon);
            double x  = xOrLon.Value;
            double x2 = xOrLon2.Value;
            double y  = yOrLat.Value;
            double y2 = yOrLat2.Value;

            if (Math.Abs(x) > 180 && Math.Abs(y) > 180)
            {
                x  = GetLon(xOrLon).Value;
                x2 = GetLon(xOrLon2).Value;
                y  = GetLat(yOrLat).Value;
                y2 = GetLat(yOrLat2).Value;
            }

            builder.BeginFigure(y, x);
            builder.AddLine(y, x2);
            builder.AddLine(y2, x2);
            builder.AddLine(y2, x);
            builder.AddLine(y, x);
            builder.EndFigure();
            builder.EndGeography();
            return(builder.ConstructedGeography);
        }
Example #24
0
 public static SqlGeography CreateGeography(this string points, out OpenGisGeographyType geographyType, int srid = 4326)
 {
     geographyType = OpenGisGeographyType.Point;
     SqlGeography firstPoint = null;
     var pts = points.Trim().Split(new string[] { "\n" }, StringSplitOptions.None).ToList();
     pts.Add(null);
     var b = new SqlGeographyBuilder();
     b.SetSrid(srid);
     b.BeginGeography(OpenGisGeographyType.GeometryCollection);
     var coordinates = new List<Tuple<double, double>>();
     for (int i = 0; i < pts.Count; i++)
     {
         if (string.IsNullOrWhiteSpace(pts[i]))
         {
             if (coordinates.Count == 1)
             {
                 if (firstPoint == null)
                     firstPoint = coordinates[0].CreatePoint();
                 b.BeginGeography(OpenGisGeographyType.Point);
                 b.BeginFigure(coordinates[0].Item2, coordinates[0].Item1);
                 b.EndFigure();
                 b.EndGeography();
             }
             else if (coordinates.Count > 1)
             {
                 geographyType = OpenGisGeographyType.GeometryCollection;
                 var list = coordinates.Distinct().ToList();
                 b.BeginGeography(OpenGisGeographyType.Polygon);
                 b.BeginFigure(list[0].Item2, list[0].Item1);
                 for (var j = 1; j < list.Count; j++)
                     b.AddLine(list[j].Item2, list[j].Item1);
                 b.AddLine(list[0].Item2, list[0].Item1);
                 b.EndFigure();
                 b.EndGeography();
             }
             coordinates = new List<Tuple<double, double>>();
             continue;
         }
         var pt = pts[i].Trim().Split(new string[] { " ", ",", ";", "\t", ":", "\r" }, StringSplitOptions.RemoveEmptyEntries);
         coordinates.Add(new Tuple<double, double>(double.Parse(pt[0]), double.Parse(pt[1])));
     }
     b.EndGeography();
     if (geographyType == OpenGisGeographyType.GeometryCollection)
         return b.ConstructedGeography.EnvelopeAngle() > 90 ? b.ConstructedGeography.ReorientObject() : b.ConstructedGeography;
     else
         return firstPoint;
 }
		private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, Point point)
		{
			gb.BeginGeography(OpenGisGeographyType.Point);
			GeographicPosition pos = point.Coordinates as GeographicPosition;
			gb.BeginFigure(pos.Latitude, pos.Longitude);
			gb.EndFigure();
			gb.EndGeography();
		}
Example #26
0
 private void AddLongitudeLine(SqlGeographyBuilder sb, double lon, double latmin, double latmax)
 {
     sb.BeginGeography(OpenGisGeographyType.LineString);
     sb.BeginFigure(latmin, lon);
     sb.AddLine(latmax, lon);
     sb.EndFigure();
     sb.EndGeography();
 }
        private static void AddLineString <T>(SqlGeographyBuilder builder, Geometry <T> geometry) where T : IPoint, new()
        {
            builder.BeginGeography(OpenGisGeographyType.LineString);

            AddLineStringOrRing(builder, geometry, false);

            builder.EndGeography();
        }
Example #28
0
        private static void AddLineString(SqlGeographyBuilder builder, GeoJsonLineString geometry, bool isLongitudeFirst)
        {
            builder.BeginGeography(OpenGisGeographyType.LineString);

            AddLineStringOrRing(builder, geometry.Coordinates, false, isLongitudeFirst);

            builder.EndGeography();
        }
Example #29
0
        public void AddLineBeforeBeginFigure()
        {
            SqlGeographyBuilder b = new SqlGeographyBuilder();

            b.SetSrid(4326);
            b.BeginGeography(OpenGisGeographyType.LineString);
            AssertEx.ThrowsException(() => { b.AddLine(1, 2); }, typeof(FormatException), "24301: Expected a call to BeginFigure or EndGeography, but AddLine was called.");
        }
        private static void AddMultiPoint <T>(SqlGeographyBuilder builder, Geometry <T> geometry) where T : IPoint, new()
        {
            builder.BeginGeography(OpenGisGeographyType.MultiPoint);

            foreach (var item in geometry.Geometries)
            {
                builder.BeginGeography(OpenGisGeographyType.Point);

                builder.BeginFigure(longitude: item.Points[0].X, latitude: item.Points[0].Y);

                builder.EndFigure();

                builder.EndGeography();
            }

            builder.EndGeography();
        }
Example #31
0
        public void AddLineOnPoint()
        {
            SqlGeographyBuilder b = new SqlGeographyBuilder();

            b.SetSrid(4326);
            b.BeginGeography(OpenGisGeographyType.Point);
            b.BeginFigure(1, 2);
            AssertEx.ThrowsException(() => { b.AddLine(1, 2); }, typeof(FormatException), "24300: Expected a call to EndFigure, but AddLine was called.");
        }
Example #32
0
 private static void SharpMapMultiPointToSqlGeography(SqlGeographyBuilder geogBuilder, SMMultiPoint multiPoint)
 {
     geogBuilder.BeginGeography(OpenGisGeographyType.MultiPoint);
     for (int i = 0; i < multiPoint.NumPoints; i++)
     {
         SharpMapPointToSqlGeography(geogBuilder, multiPoint[i] as SMPoint);
     }
     geogBuilder.EndGeography();
 }
Example #33
0
 private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, MultiPolygon multiPolygon)
 {
     gb.BeginGeography(OpenGisGeographyType.MultiPolygon);
     foreach (var polygon in multiPolygon.Coordinates)
     {
         Internal_FillGeographyBuilder(gb, polygon);
     }
     gb.EndGeography();
 }
Example #34
0
        private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, Point point)
        {
            gb.BeginGeography(OpenGisGeographyType.Point);
            Position pos = point.Coordinates as Position;

            gb.BeginFigure(pos.Latitude, pos.Longitude);
            gb.EndFigure();
            gb.EndGeography();
        }
        private static SqlGeography CreateEmptyGeography(int srid)
        {
            SqlGeographyBuilder b = new SqlGeographyBuilder();

            b.SetSrid(srid);
            b.BeginGeography(OpenGisGeographyType.GeometryCollection);
            b.EndGeography();
            return(b.ConstructedGeography);
        }
Example #36
0
 //LONGITUDE=item1, LATITUDE=item2
 public static SqlGeography CreatePoint(this Tuple<double, double> coordinates, int srid = 4326)
 {
     var b = new SqlGeographyBuilder();
     b.SetSrid(srid);
     b.BeginGeography(OpenGisGeographyType.Point);
     b.BeginFigure(coordinates.Item2, coordinates.Item1);
     b.EndFigure();
     b.EndGeography();
     return b.ConstructedGeography;
 }
Example #37
0
        public SqlGeography asSqlGeography()
        {
            SqlGeographyBuilder builder = new SqlGeographyBuilder();
            builder.SetSrid(4326);
            builder.BeginGeography(OpenGisGeographyType.Point);
            builder.BeginFigure(latitude, longitude);
            builder.EndFigure();
            builder.EndGeography();

            return builder.ConstructedGeography;
        }
Example #38
0
        //TOP LEFT LONGITUDE=item1, LATITUDE=item2, //BOTTOM RIGHT LONGITUDE=item3, LATITUDE=item4
        public static SqlGeography CreateMultiRectangle(this List<Tuple<double, double, double, double>> coordinates, int srid = 4326)
        {
            var list = coordinates.Distinct().ToList();
            var b = new SqlGeographyBuilder();
            b.SetSrid(srid);
            b.BeginGeography(OpenGisGeographyType.MultiPolygon);

            for (var i = 0; i < list.Count; i++)
            {
                b.BeginGeography(OpenGisGeographyType.Polygon);
                b.BeginFigure(list[i].Item1, list[i].Item2);
                b.AddLine(list[i].Item1, list[i].Item4);
                b.AddLine(list[i].Item3, list[i].Item4);
                b.AddLine(list[i].Item3, list[i].Item2);
                b.AddLine(list[i].Item1, list[i].Item2);
                b.EndFigure();
                b.EndGeography();
            }
            b.EndGeography();

            return b.ConstructedGeography.EnvelopeAngle() > 90
                ? b.ConstructedGeography.ReorientObject()
                : b.ConstructedGeography;
        }
        public static SqlGeography CreatePolygon(IEnumerable<Coordinates> coordinates, int srid = 4326)
        {
            var list = coordinates.Distinct().ToList();

            var b = new SqlGeographyBuilder();
            b.SetSrid(srid);
            b.BeginGeography(OpenGisGeographyType.Polygon);
            b.BeginFigure(list[0].Latitude, list[0].Longitude);

            for (var i = 1; i < list.Count; i++)
                b.AddLine(list[i].Latitude, list[i].Longitude);

            b.AddLine(list[0].Latitude, list[0].Longitude);
            b.EndFigure();
            b.EndGeography();

            if(b.ConstructedGeography.EnvelopeAngle() > 90)
                return b.ConstructedGeography.ReorientObject();

            return b.ConstructedGeography;
        }
		private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, Polygon polygon)
		{
			gb.BeginGeography(OpenGisGeographyType.Polygon);
			bool isExteriorRing = true;
			foreach (var lineString in polygon.Coordinates)
			{
				List<GeographicPosition> listGeoCoords = lineString.Coordinates.Select(p => p as GeographicPosition).ToList();
				IEnumerable<GeographicPosition> orderedPositions = EnsureCorrectWinding(listGeoCoords, isExteriorRing); // exterior ring must be anti clockwise for SqlGeography
				isExteriorRing = false;
				bool beginFigureCalled = false;
				foreach (var pos in orderedPositions)
				{
					if (!beginFigureCalled)
					{
						gb.BeginFigure(pos.Latitude, pos.Longitude);
						beginFigureCalled = true;
					}
					else
					{
						gb.AddLine(pos.Latitude, pos.Longitude);
					}
				}
				gb.EndFigure();
			}
			gb.EndGeography();
		}
		/// <summary>
		/// Converts a GeoJSON MultiPolygon to an SqlGeography
		/// </summary>
		/// <param name="multiPolygon"></param>
		/// <param name="srid"></param>
		/// <returns></returns>
		public static SqlGeography ToSqlGeography(this MultiPolygon multiPolygon, int srid = 4326)
		{
			SqlGeographyBuilder gb = new SqlGeographyBuilder();
			gb.SetSrid(srid);
			gb.BeginGeography(OpenGisGeographyType.MultiPolygon);
			foreach (var polygon in multiPolygon.Coordinates)
			{
				Internal_FillGeographyBuilder(gb, polygon);
			}
			gb.EndGeography();
			return gb.ConstructedGeography;
		}
		private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, MultiPolygon multiPolygon)
		{
			gb.BeginGeography(OpenGisGeographyType.MultiPolygon);
			foreach (var polygon in multiPolygon.Coordinates)
			{
				Internal_FillGeographyBuilder(gb, polygon);
			}
			gb.EndGeography();
		}
        /// <summary>
        /// Create a SqlGeography builder for the polygon specified by the points
        /// </summary>
        /// <param name="points">Latitude longitude points for the polygon</param>
        /// <returns>SqlGeographyBuilder for the polygon</returns>
        private SqlGeography CreatePolygonFromPoints(List<LatLong> points)
        {
            SqlGeographyBuilder polygon = new SqlGeographyBuilder();
            polygon.SetSrid(4326);

            polygon.BeginGeography(OpenGisGeographyType.Polygon);

            //set the initial point to skip, and use that to begin the figure
            LatLong initialPoint = points.First();
            polygon.BeginFigure(initialPoint.Latitude, initialPoint.Longitude);

            foreach (var point in points)
            {
                if (point != initialPoint)
                {
                    //add each point to the geography poly
                    polygon.AddLine(point.Latitude, point.Longitude);
                }
            }

            //end the configuration of the geography
            polygon.EndFigure();
            polygon.EndGeography();

            return polygon.ConstructedGeography;
        }
		private SqlGeography Sample_PolygonGeography()
		{
			SqlGeographyBuilder geoBuilder = new SqlGeographyBuilder();
			geoBuilder.SetSrid(4326);
			geoBuilder.BeginGeography(OpenGisGeographyType.Polygon);
			geoBuilder.BeginFigure(40, -10);
			geoBuilder.AddLine(40, 10);
			geoBuilder.AddLine(50, 0);
			geoBuilder.AddLine(40, -10);
			geoBuilder.EndFigure();
			geoBuilder.EndGeography();
			return geoBuilder.ConstructedGeography;
		}
        /// <summary>
        /// Create a SqlGeography instance for the point specified by the LatLong object
        /// </summary>
        /// <param name="point">LatLong object representing the point</param>
        /// <returns>SqlGeography point</returns>
        private SqlGeography CreatePoint(LatLong point)
        {
            SqlGeographyBuilder geoPoint = new SqlGeographyBuilder();

            //set the SRID and build the sql geography point for the centroid
            geoPoint.SetSrid(4326);
            geoPoint.BeginGeography(OpenGisGeographyType.Point);
            geoPoint.BeginFigure(point.Latitude, point.Longitude);
            geoPoint.EndFigure();
            geoPoint.EndGeography();

            return geoPoint.ConstructedGeography;
        }
Example #46
0
        /// <summary>
        /// Builds the route geography.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns>
        /// New route geography
        /// </returns>
        private Route BuildRouteGeography(Route route)
        {
            var routeBuilder = new SqlGeographyBuilder();
            routeBuilder.SetSrid(4326);
            routeBuilder.BeginGeography(OpenGisGeographyType.LineString);
            SqlGeography beginPoint = route.StartStop.StopGeography;
            routeBuilder.BeginFigure((double)beginPoint.Lat, (double)beginPoint.Long);

            for (var j = route.StartRouteIndex; j <= route.EndRouteIndex; j++)
            {
                var point = route.RouteGeography.STPointN(j);
                routeBuilder.AddLine((double)point.Lat, (double)point.Long);
            }

            SqlGeography endPoint = route.EndStop.StopGeography;
            routeBuilder.AddLine((double)endPoint.Lat, (double)endPoint.Long);

            routeBuilder.EndFigure();
            routeBuilder.EndGeography();
            route.CurrentPath = routeBuilder.ConstructedGeography;

            return route;
        }
		private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, LineString lineString)
		{
			gb.BeginGeography(OpenGisGeographyType.LineString);
			bool beginFigureCalled = false;
			foreach (var ipos in lineString.Coordinates)
			{
				GeographicPosition pos = ipos as GeographicPosition;
				if (!beginFigureCalled)
				{
					gb.BeginFigure(pos.Latitude, pos.Longitude);
					beginFigureCalled = true;

				}
				else
				{
					gb.AddLine(pos.Latitude, pos.Longitude);
				}

			}
			gb.EndFigure();
			gb.EndGeography();
		}
Example #48
0
        public SqlGeography generateLineString(IList<RoutePointModel> points)
        {
            SqlGeographyBuilder builder = new SqlGeographyBuilder();
            builder.SetSrid(4326);
            builder.BeginGeography(OpenGisGeographyType.LineString);
            for (int i = 0; i < points.Count; i++)
            {
                if (i == 0)
                {
                    // First element, create figure
                    builder.BeginFigure(points.ElementAt(0).latitude, points.ElementAt(0).longitude);
                }
                else
                {
                    builder.AddLine(points.ElementAt(i).latitude, points.ElementAt(i).longitude);
                }
            }
            builder.EndFigure();
            builder.EndGeography();

            return builder.ConstructedGeography;
        }
		/// <summary>
		/// Converts a GeoJSON GeometryCollection to an SqlGeography
		/// </summary>
		/// <param name="geometryCollection"></param>
		/// <param name="srid"></param>
		/// <returns></returns>
		public static SqlGeography ToSqlGeography(this GeometryCollection geometryCollection, int srid = 4326)
		{
			SqlGeographyBuilder gb = new SqlGeographyBuilder();
			gb.SetSrid(srid);
			gb.BeginGeography(OpenGisGeographyType.GeometryCollection);
			foreach (var geom in geometryCollection.Geometries)
			{
				switch (geom.Type)
				{
					case GeoJSONObjectType.LineString:
						Internal_FillGeographyBuilder(gb, geom as LineString);
						break;
					case GeoJSONObjectType.MultiLineString:
						Internal_FillGeographyBuilder(gb, geom as MultiLineString);
						break;
					case GeoJSONObjectType.Point:
						Internal_FillGeographyBuilder(gb, geom as Point);
						break;
					case GeoJSONObjectType.MultiPoint:
						Internal_FillGeographyBuilder(gb, geom as MultiPoint);
						break;
					case GeoJSONObjectType.Polygon:
						Internal_FillGeographyBuilder(gb, geom as Polygon);
						break;
					case GeoJSONObjectType.MultiPolygon:
						Internal_FillGeographyBuilder(gb, geom as MultiPolygon);
						break;
					default:
						throw new NotSupportedException("Geometry conversion is not supported for " + geom.Type.ToString());
				}
			}
			gb.EndGeography();
			return gb.ConstructedGeography;
		}
        /// <summary>
        /// Create the SqlGeography line string from the points given
        /// </summary>
        /// <param name="linePoints">List of LatLong that represents the start and end of the line</param>
        /// <returns>SqlGeography line string</returns>
        private SqlGeography CreateLineFromPoints(List<LatLong> linePoints)
        {
            SqlGeographyBuilder geoLine = new SqlGeographyBuilder();

            //build the sql geography representation of the linestring
            geoLine.SetSrid(4326);
            geoLine.BeginGeography(OpenGisGeographyType.LineString);
            geoLine.BeginFigure(linePoints.First().Latitude, linePoints.First().Longitude);
            geoLine.AddLine(linePoints.Last().Latitude, linePoints.Last().Longitude);
            geoLine.EndFigure();
            geoLine.EndGeography();

            return geoLine.ConstructedGeography;
        }
Example #51
0
        /// <summary>
        /// Builds the route geography.
        /// </summary>
        /// <param name="startIndex">The start index.</param>
        /// <param name="endIndex">The end index.</param>
        /// <param name="nearestStop">The nearest stop.</param>
        /// <param name="furtherStop">The further stop.</param>
        /// <param name="route">The route.</param>
        /// <returns>Geography of appropriate route</returns>
        private static Route BuildRouteGeography(int startIndex,int endIndex,Stop nearestStop, Stop furtherStop,Route route)
        {
            var geographyBuilder = new SqlGeographyBuilder();
                geographyBuilder.SetSrid(4326);
                geographyBuilder.BeginGeography(OpenGisGeographyType.LineString);
                SqlGeography beginGb = nearestStop.StopGeography;
                geographyBuilder.BeginFigure((double) beginGb.Lat, (double) beginGb.Long);
                for (var j = startIndex; j <= endIndex; j++)
                {

                    var point = route.RouteGeography.STPointN(j);
                    geographyBuilder.AddLine((double) point.Lat, (double) point.Long);

                }
                SqlGeography endFigure = furtherStop.StopGeography;
                geographyBuilder.AddLine((double) endFigure.Lat, (double) endFigure.Long);
                geographyBuilder.EndFigure();
                geographyBuilder.EndGeography();
                route.RouteGeography = geographyBuilder.ConstructedGeography;

            return route;
        }