Esempio n. 1
0
        /// <summary>
        /// Converts the specified object to a Geography instance.
        /// </summary>
        /// <param name="instance">Object to convert.</param>
        /// <returns>New Geography instance.</returns>
        internal static Geography ConvertDbGeography(object instance)
        {
            DbGeography geography = (DbGeography)instance;

            switch (geography.GeometryType)
            {
            case "Point":
                return(GeographyFactory.Point((double)geography.Latitude, (double)geography.Longitude));

            case "LineString":
                int numPoints = (int)geography.NumPoints;
                var factory   = GeographyFactory.LineString();

                for (int n = 0; n < numPoints; n++)
                {
                    DbGeography pointN = geography.PointN(n + 1);     // PointN uses a 1-based index
                    Debug.Assert(pointN != null, "Expected PointN to return a non-null value for this position in the linestring");
                    Debug.Assert(pointN.GeometryType == "Point", "Expected PointN to return a Point for this position in the linestring");

                    factory.LineTo(pointN.Latitude.Value, pointN.Longitude.Value, pointN.Z, pointN.M);
                }

                return(factory.Build());

            default:
                Debug.Fail("Unsupported conversion from DbGeography of type: " + geography.GeometryType);
                return(null);
            }
        }