public override DbGeographyWellKnownValue CreateWellKnownValue(DbGeography geographyValue)
        {
            CheckParameterNotNull("geographyValue", geographyValue);

            Debug.Assert(geographyValue.AsBinary() != null, "WKB value must not be null.");
            Debug.Assert(geographyValue.AsText() != null, "WKT value must not be null.");

            return(new DbGeographyWellKnownValue()
            {
                CoordinateSystemId = geographyValue.CoordinateSystemId,
                WellKnownBinary = geographyValue.AsBinary(),
                WellKnownText = geographyValue.AsText()
            });
        }
Example #2
0
 public static SqlGeography ToSqlGeography(this DbGeography dbGeography)
 {
     if (dbGeography == null)
     {
         return(null);
     }
     return(SqlGeography.STGeomFromWKB(new SqlBytes(dbGeography.AsBinary()), dbGeography.CoordinateSystemId));
 }
        public static IGeometry ToGeometry(this DbGeography self)
        {
            if (self == null)
            {
                return(null);
            }

            var reader = new WKBReader(NetTopologySuite.NtsGeometryServices.Instance);

            return(reader.Read(self.AsBinary()));
        }
Example #4
0
 static public GeoJSON.Net.Geometry.IGeometryObject GeometryFromDbGeography(DbGeography p_DbGeography)
 {
     return(WkbDecode.Decode(p_DbGeography.AsBinary()));
 }
Example #5
0
        static public GeoJSON.Net.Feature.Feature FeatureFromDbGeography(DbGeography p_DbGeography, object p_Properties = null, string p_Id = null)
        {
            var v_geo = WkbDecode.Decode(p_DbGeography.AsBinary());

            return(new GeoJSON.Net.Feature.Feature(v_geo, p_Properties, p_Id));
        }
Example #6
0
        private static string approach_one(string polygonWkt)
        {
            var result = "";

            try
            {
                // Create a DbGeography instance from a WKT string
                DbGeography polygon = DbGeography.FromText(polygonWkt);

                // If the polygon area is larger than an earth hemisphere (510 Trillion m2 / 2), we know it needs to be fixed
                if (polygon.Area.HasValue && polygon.Area.Value > 255000000000000L)
                {
                    // Convert our DbGeography polygon into a SqlGeography object for the ReorientObject() call
                    var sqlPolygon = SqlGeography.STGeomFromWKB(new System.Data.SqlTypes.SqlBytes(polygon.AsBinary()), 4326);

                    // ReorientObject will flip the polygon so the outside becomes the inside
                    sqlPolygon = sqlPolygon.ReorientObject();

                    // Convert the SqlGeography object back into a WKT string
                    polygon = DbGeography.FromBinary(sqlPolygon.STAsBinary().Value);
                    result  = polygon.AsText();
                }
            }
            catch (Exception ex)
            {
                result = string.Empty;
            }
            return(result);
        }
 public static IGeometryObject ToGeoJSONGeometry(this DbGeography dbGeography)
 {
     return(WkbDecode.Decode(dbGeography.AsBinary()));
 }
        private SqlGeography MakePolygonValid(DbGeography polygon)
        {
            try
            {
                SqlGeography sqlPolygon = SqlGeography.STGeomFromWKB(new System.Data.SqlTypes.SqlBytes(polygon.AsBinary()), 4326);

                // If the polygon area is larger than an earth hemisphere (510 Trillion m2 / 2), we know it needs to be fixed
                if (polygon.Area.HasValue && polygon.Area.Value > 255000000000000L)
                {
                    // ReorientObject will flip the polygon so the outside becomes the inside
                    sqlPolygon = sqlPolygon.ReorientObject();
                }
                return(sqlPolygon);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Example #9
0
        public static bool IsOverlap(this DbGeography polygon1, DbGeography polygon2)
        {
            SqlGeography sqlPolygon1 = SqlGeography.STGeomFromWKB(new System.Data.SqlTypes.SqlBytes(polygon1.AsBinary()), DbGeography.DefaultCoordinateSystemId).MakeValid();

            sqlPolygon1 = sqlPolygon1.ReorientObject();
            polygon1    = DbGeography.FromBinary(sqlPolygon1.STAsBinary().Value);


            SqlGeography sqlPolygon2 = SqlGeography.STGeomFromWKB(new System.Data.SqlTypes.SqlBytes(polygon2.AsBinary()), DbGeography.DefaultCoordinateSystemId).MakeValid();

            sqlPolygon2 = sqlPolygon2.ReorientObject();
            polygon2    = DbGeography.FromBinary(sqlPolygon2.STAsBinary().Value);

            return(polygon1.Intersects(polygon2));
        }
Example #10
0
        public static bool IsInside(this DbGeography point, DbGeography polygon)
        {
            //DbGeography point = DbGeography.FromText(string.Format("POINT({1} {0})", latitude.ToString().Replace(',', '.'), longitude.ToString().Replace(',', '.')), DbGeography.DefaultCoordinateSystemId);

            // If the polygon area is larger than an earth hemisphere (510 Trillion m2 / 2), we know it needs to be fixed

            /*if (polygon.Area.HasValue && polygon.Area.Value > 255000000000000L)
             * {
             *
             * }*/

            SqlGeography sqlPolygon = SqlGeography.STGeomFromWKB(new System.Data.SqlTypes.SqlBytes(polygon.AsBinary()), DbGeography.DefaultCoordinateSystemId).MakeValid();

            sqlPolygon = sqlPolygon.ReorientObject();
            polygon    = DbGeography.FromBinary(sqlPolygon.STAsBinary().Value);



            return(point.Intersects(polygon));
        }
Example #11
0
        public static bool IsValidPolygon(this DbGeography polygon)
        {
            SqlGeography sqlPolygon = SqlGeography.STGeomFromWKB(new System.Data.SqlTypes.SqlBytes(polygon.AsBinary()), DbGeography.DefaultCoordinateSystemId).MakeValid();

            return(true);
        }