예제 #1
0
        public static GeographyLineString ConvertLineStringTo(DbGeography dbGeo)
        {
            Debug.Assert(dbGeo.SpatialTypeName == "LineString");
            SpatialBuilder builder  = SpatialBuilder.Create();
            var            pipeLine = builder.GeographyPipeline;

            pipeLine.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
            pipeLine.BeginGeography(SpatialType.LineString);

            int numPionts = dbGeo.PointCount ?? 0;

            for (int n = 0; n < numPionts; n++)
            {
                DbGeography       pointN   = dbGeo.PointAt(n + 1);
                double            lat      = pointN.Latitude ?? 0;
                double            lon      = pointN.Longitude ?? 0;
                double?           alt      = pointN.Elevation;
                double?           m        = pointN.Measure;
                GeographyPosition position = new GeographyPosition(lat, lon, alt, m);
                if (n == 0)
                {
                    pipeLine.BeginFigure(position);
                }
                else
                {
                    pipeLine.LineTo(position);
                }
            }

            pipeLine.EndFigure();
            pipeLine.EndGeography();
            return((GeographyLineString)builder.ConstructedGeography);
        }
예제 #2
0
        public static GeographyPoint Create(CoordinateSystem coordinateSystem, double latitude, double longitude, double?z, double?m)
        {
            var builder  = SpatialBuilder.Create();
            var pipeline = builder.GeographyPipeline;

            pipeline.SetCoordinateSystem(coordinateSystem);
            pipeline.BeginGeography(SpatialType.Point);
            pipeline.BeginFigure(new GeographyPosition(latitude, longitude, z, m));
            pipeline.EndFigure();
            pipeline.EndGeography();
            return((GeographyPoint)builder.ConstructedGeography);
        }
예제 #3
0
        public static GeometryPoint Create(CoordinateSystem coordinateSystem, double x, double y, double?z, double?m)
        {
            var builder  = SpatialBuilder.Create();
            var pipeline = builder.GeometryPipeline;

            pipeline.SetCoordinateSystem(coordinateSystem);
            pipeline.BeginGeometry(SpatialType.Point);
            pipeline.BeginFigure(new GeometryPosition(x, y, z, m));
            pipeline.EndFigure();
            pipeline.EndGeometry();
            return((GeometryPoint)builder.ConstructedGeometry);
        }
        /// <summary>
        /// Converts the given geometry into a geography.
        /// </summary>
        /// <param name="geometry">The geometry to convert.</param>
        /// <param name="treatXCoordinateAsLatitude">if set to <c>true</c> the x coordinate should be converted to latitude. Otherwise, it should be longitude.</param>
        /// <returns>The converted geography</returns>
        public object Convert(object geometry, bool treatXCoordinateAsLatitude)
        {
            ExceptionUtilities.CheckArgumentNotNull(geometry, "geometry");
            var afterCast = geometry as Geometry;

            ExceptionUtilities.CheckObjectNotNull(afterCast, "Given object '{0}' was not of type {1}", geometry, typeof(Geometry));

            var builder = SpatialBuilder.Create();
            var chain   = CreateConversionChain(builder, GetConvertDelegate(treatXCoordinateAsLatitude));

            afterCast.SendTo(chain);
            return(builder.ConstructedGeography);
        }
예제 #5
0
 private void EnsureParsePipeline()
 {
     if (this.parsePipeline == null)
     {
         this.builder       = this.creator.CreateBuilder();
         this.parsePipeline = this.creator.CreateValidator().ChainTo(this.builder);
     }
     else
     {
         this.parsePipeline.GeographyPipeline.Reset();
         this.parsePipeline.GeometryPipeline.Reset();
     }
 }
예제 #6
0
        /// <summary>
        /// Convert a DbGeography to Edm GeographyPoint
        /// </summary>
        /// <param name="geography"> The DbGeography to be converted</param>
        /// <returns>A Edm GeographyLineString</returns>
        public static GeographyLineString ToGeographyLineString(this DbGeography geography)
        {
            if (geography == null)
            {
                return(null);
            }

            if (geography.SpatialTypeName != GeographyTypeNameLineString)
            {
                throw new InvalidOperationException(string.Format(
                                                        CultureInfo.InvariantCulture,
                                                        Resources.InvalidLineStringGeographyType,
                                                        geography.SpatialTypeName));
            }

            SpatialBuilder    builder   = SpatialBuilder.Create();
            GeographyPipeline pipleLine = builder.GeographyPipeline;

            pipleLine.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
            pipleLine.BeginGeography(SpatialType.LineString);

            int numPoints = geography.PointCount ?? 0;

            if (numPoints > 0)
            {
                DbGeography point = geography.PointAt(1);
                pipleLine.BeginFigure(new GeographyPosition(
                                          point.Latitude ?? 0, point.Latitude ?? 0, point.Elevation, point.Measure));

                for (int n = 2; n <= numPoints; n++)
                {
                    point = geography.PointAt(n);
                    pipleLine.LineTo(new GeographyPosition(
                                         point.Latitude ?? 0, point.Latitude ?? 0, point.Elevation, point.Measure));
                }

                pipleLine.EndFigure();
            }

            pipleLine.EndGeography();
            GeographyLineString lineString = (GeographyLineString)builder.ConstructedGeography;

            return(lineString);
        }
예제 #7
0
        /// <summary>
        ///     Converts an NTS LineString to a Microsoft.Spatial GeogaphyLineString.
        /// </summary>
        /// <param name="lineString">The NTS LineString.</param>
        /// <returns></returns>
        public static GeographyLineString ToGeographyLineString(this Geometry lineString)
        {
            if (lineString == null)
            {
                return(null);
            }

            Debug.Assert(lineString.GeometryType == "LineString");
            var builder  = SpatialBuilder.Create();
            var pipeLine = builder.GeographyPipeline;

            pipeLine.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
            pipeLine.BeginGeography(SpatialType.LineString);

            var numPionts = lineString.NumPoints;

            for (var n = 0; n < numPionts; n++)
            {
                var pointN   = lineString.GetGeometryN(n + 1);
                var lat      = pointN.Coordinate.Y;
                var lon      = pointN.Coordinate.X;
                var alt      = pointN.Coordinate.Z;
                var m        = pointN.Length;
                var position = new GeographyPosition(lat, lon, alt, m);
                if (n == 0)
                {
                    pipeLine.BeginFigure(position);
                }
                else
                {
                    pipeLine.LineTo(position);
                }
            }

            pipeLine.EndFigure();
            pipeLine.EndGeography();
            return((GeographyLineString)builder.ConstructedGeography);
        }
예제 #8
0
        public PlacesController()
        {
            data = new List <Place>();
            data.Add(new Place()
            {
                Id = 0, Name = "Place1", Description = "Desc", Entrance = GeographyPoint.Create(-1.56, 29.76)
            });
            data.Add(new Place()
            {
                Id = 1, Name = "Place1", Description = "Desc", Entrance = GeographyPoint.Create(-2.56, 19.76)
            });
            data.Add(new Place()
            {
                Id = 2, Name = "Place1", Description = "Desc", Entrance = GeographyPoint.Create(-3.56, 9.76)
            });
            data.Add(new Place()
            {
                Id = 3, Name = "Place1", Description = "Desc", Entrance = GeographyPoint.Create(-4.56, -9.76)
            });
            data.Add(new Place()
            {
                Id = 4, Name = "Place1", Description = "Desc", Entrance = GeographyPoint.Create(-10.56, -19.76)
            });


            for (int i = 0; i < data.Count; i++)
            {
                data[i].Gp = GeometryPoint.Create(-1.56 - i, 29.76 + i);

                SpatialBuilder    spatialBuilder    = SpatialBuilder.Create();
                GeographyPipeline geographyPipeline = spatialBuilder.GeographyPipeline;
                geographyPipeline.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
                geographyPipeline.BeginGeography(SpatialType.LineString);
                geographyPipeline.BeginFigure(new GeographyPosition(-1.56, 29.76));
                geographyPipeline.LineTo(new GeographyPosition(-1.58, 29.78));
                geographyPipeline.LineTo(new GeographyPosition(5, 50));
                geographyPipeline.EndFigure();
                geographyPipeline.EndGeography();
                data[i].Ls = (GeographyLineString)spatialBuilder.ConstructedGeography;

                SpatialBuilder    spatialBuilder1    = SpatialBuilder.Create();
                GeographyPipeline geographyPipeline1 = spatialBuilder1.GeographyPipeline;
                geographyPipeline1.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
                geographyPipeline1.BeginGeography(SpatialType.MultiPoint);
                geographyPipeline1.BeginFigure(new GeographyPosition(-1.56, 29.76));
                geographyPipeline1.EndFigure();
                geographyPipeline1.BeginFigure(new GeographyPosition(-3.56, 50));
                geographyPipeline1.EndFigure();
                geographyPipeline1.EndGeography();
                data[i].Mp = (GeographyMultiPoint)spatialBuilder1.ConstructedGeography;

                SpatialBuilder    spatialBuilder2    = SpatialBuilder.Create();
                GeographyPipeline geographyPipeline2 = spatialBuilder2.GeographyPipeline;
                geographyPipeline2.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
                geographyPipeline2.BeginGeography(SpatialType.Polygon);
                geographyPipeline2.BeginFigure(new GeographyPosition(-2, 2));
                geographyPipeline2.LineTo(new GeographyPosition(2, 2));
                geographyPipeline2.LineTo(new GeographyPosition(2, -2));
                geographyPipeline2.LineTo(new GeographyPosition(-2, -2));
                geographyPipeline2.LineTo(new GeographyPosition(-2, 2));
                geographyPipeline2.EndFigure();
                geographyPipeline2.BeginFigure(new GeographyPosition(-1, 1));
                geographyPipeline2.LineTo(new GeographyPosition(1, 1));
                geographyPipeline2.LineTo(new GeographyPosition(1, -1));
                geographyPipeline2.LineTo(new GeographyPosition(-1, -1));
                geographyPipeline2.LineTo(new GeographyPosition(-1, 1));
                geographyPipeline2.EndFigure();
                geographyPipeline2.EndGeography();
                data[i].Pol = (GeographyPolygon)spatialBuilder2.ConstructedGeography;

                SpatialBuilder    spatialBuilder3    = SpatialBuilder.Create();
                GeographyPipeline geographyPipeline3 = spatialBuilder3.GeographyPipeline;
                geographyPipeline3.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
                geographyPipeline3.BeginGeography(SpatialType.MultiPolygon);
                geographyPipeline3.BeginGeography(SpatialType.Polygon);
                geographyPipeline3.BeginFigure(new GeographyPosition(-2, 2));
                geographyPipeline3.LineTo(new GeographyPosition(2, 2));
                geographyPipeline3.LineTo(new GeographyPosition(2, -2));
                geographyPipeline3.LineTo(new GeographyPosition(-2, -2));
                geographyPipeline3.LineTo(new GeographyPosition(-2, 2));
                geographyPipeline3.EndFigure();
                geographyPipeline3.BeginFigure(new GeographyPosition(-1, 1));
                geographyPipeline3.LineTo(new GeographyPosition(1, 1));
                geographyPipeline3.LineTo(new GeographyPosition(1, -1));
                geographyPipeline3.LineTo(new GeographyPosition(-1, -1));
                geographyPipeline3.LineTo(new GeographyPosition(-1, 1));
                geographyPipeline3.EndFigure();
                geographyPipeline3.EndGeography();
                geographyPipeline3.BeginGeography(SpatialType.Polygon);
                geographyPipeline3.BeginFigure(new GeographyPosition(-4, 4));
                geographyPipeline3.LineTo(new GeographyPosition(4, 4));
                geographyPipeline3.LineTo(new GeographyPosition(4, -4));
                geographyPipeline3.LineTo(new GeographyPosition(-4, -4));
                geographyPipeline3.LineTo(new GeographyPosition(-4, 4));
                geographyPipeline3.EndFigure();
                geographyPipeline3.BeginFigure(new GeographyPosition(-1, 1));
                geographyPipeline3.LineTo(new GeographyPosition(1, 1));
                geographyPipeline3.LineTo(new GeographyPosition(1, -1));
                geographyPipeline3.LineTo(new GeographyPosition(-1, -1));
                geographyPipeline3.LineTo(new GeographyPosition(-1, 1));
                geographyPipeline3.EndFigure();
                geographyPipeline3.EndGeography();
                geographyPipeline3.EndGeography();
                data[i].MPol = (GeographyMultiPolygon)spatialBuilder3.ConstructedGeography;

                SpatialBuilder    spatialBuilder4    = SpatialBuilder.Create();
                GeographyPipeline geographyPipeline4 = spatialBuilder4.GeographyPipeline;
                geographyPipeline4.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
                geographyPipeline4.BeginGeography(SpatialType.MultiLineString);
                geographyPipeline4.BeginGeography(SpatialType.LineString);
                geographyPipeline4.BeginFigure(new GeographyPosition(-1.56, 29.76));
                geographyPipeline4.LineTo(new GeographyPosition(-1.58, 29.78));
                geographyPipeline4.LineTo(new GeographyPosition(5, 50));
                geographyPipeline4.EndFigure();
                geographyPipeline4.EndGeography();
                geographyPipeline4.BeginGeography(SpatialType.LineString);
                geographyPipeline4.BeginFigure(new GeographyPosition(-2.56, 30.76));
                geographyPipeline4.LineTo(new GeographyPosition(-2.58, 30.78));
                geographyPipeline4.LineTo(new GeographyPosition(6, 51));
                geographyPipeline4.EndFigure();
                geographyPipeline4.EndGeography();
                geographyPipeline4.BeginGeography(SpatialType.LineString);
                geographyPipeline4.BeginFigure(new GeographyPosition(-1.56, 29.76));
                geographyPipeline4.LineTo(new GeographyPosition(-1.58, 29.78));
                geographyPipeline4.LineTo(new GeographyPosition(5, 50));
                geographyPipeline4.EndFigure();
                geographyPipeline4.EndGeography();
                geographyPipeline4.BeginGeography(SpatialType.LineString);
                geographyPipeline4.BeginFigure(new GeographyPosition(-2.56, 30.76));
                geographyPipeline4.LineTo(new GeographyPosition(-2.58, 30.78));
                geographyPipeline4.LineTo(new GeographyPosition(8, 52));
                geographyPipeline4.EndFigure();
                geographyPipeline4.EndGeography();
                geographyPipeline4.EndGeography();
                data[i].MLs = (GeographyMultiLineString)spatialBuilder4.ConstructedGeography;



                SpatialBuilder    spatialBuilder5    = SpatialBuilder.Create();
                GeographyPipeline geographyPipeline5 = spatialBuilder5.GeographyPipeline;
                geographyPipeline5.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
                geographyPipeline5.BeginGeography(SpatialType.Collection);
                geographyPipeline5.BeginGeography(SpatialType.LineString);
                geographyPipeline5.BeginFigure(new GeographyPosition(-1.56, 29.76));
                geographyPipeline5.LineTo(new GeographyPosition(-1.58, 29.78));
                geographyPipeline5.LineTo(new GeographyPosition(5, 50));
                geographyPipeline5.EndFigure();
                geographyPipeline5.EndGeography();
                geographyPipeline5.BeginGeography(SpatialType.Point);
                geographyPipeline5.BeginFigure(new GeographyPosition(-1.56, 29.76));
                geographyPipeline5.EndFigure();
                geographyPipeline5.EndGeography();
                geographyPipeline5.BeginGeography(SpatialType.LineString);
                geographyPipeline5.BeginFigure(new GeographyPosition(-1.56, 29.76));
                geographyPipeline5.LineTo(new GeographyPosition(-1.58, 29.78));
                geographyPipeline5.LineTo(new GeographyPosition(5, 50));
                geographyPipeline5.EndFigure();
                geographyPipeline5.EndGeography();
                geographyPipeline5.EndGeography();
                data[i].Coll = (GeographyCollection)spatialBuilder5.ConstructedGeography;

                SpatialBuilder   spatialBuilder6    = SpatialBuilder.Create();
                GeometryPipeline geographyPipeline6 = spatialBuilder6.GeometryPipeline;
                geographyPipeline6.SetCoordinateSystem(CoordinateSystem.DefaultGeometry);
                geographyPipeline6.BeginGeometry(SpatialType.Collection);
                geographyPipeline6.BeginGeometry(SpatialType.LineString);
                geographyPipeline6.BeginFigure(new GeometryPosition(-1.56, 29.76));
                geographyPipeline6.LineTo(new GeometryPosition(-1.58, 29.78));
                geographyPipeline6.LineTo(new GeometryPosition(5, 50));
                geographyPipeline6.EndFigure();
                geographyPipeline6.EndGeometry();
                geographyPipeline6.BeginGeometry(SpatialType.Point);
                geographyPipeline6.BeginFigure(new GeometryPosition(-1.56, 29.76));
                geographyPipeline6.EndFigure();
                geographyPipeline6.EndGeometry();
                geographyPipeline6.BeginGeometry(SpatialType.LineString);
                geographyPipeline6.BeginFigure(new GeometryPosition(-1.56, 29.76));
                geographyPipeline6.LineTo(new GeometryPosition(-1.58, 29.78));
                geographyPipeline6.LineTo(new GeometryPosition(5, 50));
                geographyPipeline6.EndFigure();
                geographyPipeline6.EndGeometry();
                geographyPipeline6.EndGeometry();
                data[i].gColl = (GeometryCollection)spatialBuilder6.ConstructedGeometry;
            }
        }