public Boolean STIntersect(Geospatial x) { if (_innerValue != null && x.InnerValue != null && !_innerValue.ToString().Equals(EMPTY_GEOGRAPHY) && !x.InnerValue.ToString().Equals(EMPTY_GEOGRAPHY)) { try { return(((SqlBoolean)(ClassLoader.Invoke(_innerValue, "STIntersects", new object[] { x.InnerValue }))).Equals(SqlBoolean.True)); } catch (Exception ex) { GXLogging.Debug(log, "Error calling Intersect() exception:"); GXLogging.Debug(log, ex.ToString()); return(false); } } else { if (_innerValue == null) { GXLogging.Debug(log, "STIntersect: _innerValue is not valid"); } else { GXLogging.Debug(log, "STIntersect: x.InnerValue is not valid"); } return(false); } }
public Boolean STIntersect(Geospatial x) { if (_innerValue != null && x.InnerValue != null && !_innerValue.ToString().Equals(EMPTY_GEOGRAPHY) && !x.InnerValue.ToString().Equals(EMPTY_GEOGRAPHY)) { try { return(NTSGeographyWrapper.STIntersects(_innerValue, x.InnerValue)); } catch (Exception ex) { GXLogging.Debug(log, "Error calling Intersect() exception:"); GXLogging.Debug(log, ex.ToString()); return(false); } } else { if (_innerValue == null) { GXLogging.Debug(log, "STIntersect: _innerValue is not valid"); } else { GXLogging.Debug(log, "STIntersect: x.InnerValue is not valid"); } return(false); } }
public double STDistance(Geospatial x) { if (_innerValue != null && x.InnerValue != null && !_innerValue.ToString().Equals(EMPTY_GEOGRAPHY) && !x.InnerValue.ToString().Equals(EMPTY_GEOGRAPHY)) { try { return(((SqlDouble)(ClassLoader.Invoke(_innerValue, "STDistance", new object[] { x.InnerValue }))).Value); } catch (Exception ex) { GXLogging.Debug(log, "Error calling Distance() exception:"); GXLogging.Debug(log, ex.ToString()); return(0); } } else { if (_innerValue == null) { GXLogging.Debug(log, "STDistance: _innerValue is not valid"); } else { GXLogging.Debug(log, "STDistance: x.InnerValue is not valid"); } return(0); } }
public double STDistance(Geospatial x) { if (_innerValue != null && x.InnerValue != null && !_innerValue.ToString().Equals(EMPTY_GEOGRAPHY) && !x.InnerValue.ToString().Equals(EMPTY_GEOGRAPHY)) { try { return(NTSGeographyWrapper.STDistance(_innerValue, x.InnerValue)); } catch (Exception ex) { GXLogging.Debug(log, "Error calling Distance() exception:"); GXLogging.Debug(log, ex.ToString()); return(0); } } else { if (_innerValue == null) { GXLogging.Debug(log, "STDistance: _innerValue is not valid"); } else { GXLogging.Debug(log, "STDistance: x.InnerValue is not valid"); } return(0); } }
public void FromString(String s) { if (IsGeoNull(s)) { geoText = EMPTY_GEOMETRY; } else { geoText = s.Trim(); } try { // Parse _innerValue = NTSGeographyWrapper.Parse(geoText); // SRID, Type & Points X, Y if ((!NTSGeographyWrapper.IsValid(_innerValue)) && _innerValue != null) { //_innerValue = NTSGeographyWrapper.MakeValid(_innerValue); } this.srid = NTSGeographyWrapper.Srid(_innerValue); this.setGXGeoType(NTSGeographyWrapper.STGeometryType(_innerValue).ToString()); if (GeographicType == GeoGraphicTypeValue.Point) { this.Point.Longitude = NTSGeographyWrapper.Long(_innerValue); this.Point.Latitude = NTSGeographyWrapper.Lat(_innerValue); } } catch (Exception ex) { if (!String.IsNullOrEmpty(ex.ToString()) && ex.HResult == -2146232832 && ex.Message.Contains("Unknown Type")) { if (GeographicType == GeoGraphicTypeValue.Point && !String.IsNullOrEmpty(geoText)) { _innerValue = Geospatial.FromGXLocation(geoText); } else { // Cannot parse value _innerValue = NTSGeographyWrapper.NullSQLGeography; this.geoText = ""; this.Point.Longitude = 0; this.Point.Latitude = 0; } } else { // Cannot parse value _innerValue = NTSGeographyWrapper.NullSQLGeography; this.geoText = ""; this.Point.Longitude = 0; this.Point.Latitude = 0; } } }
public static Boolean IsNullOrEmpty(Geospatial g) { return(g.InnerValue == null || g.InnerValue.ToString().Equals(EMPTY_POINT) || g.InnerValue.ToString().Equals(EMPTY_LINE) || g.InnerValue.ToString().Equals(EMPTY_POLY) || g.InnerValue.ToString().Equals(EMPTY_GEOGRAPHY) || g.InnerValue.ToString().Equals(EMPTY_GEOMETRY) ); }
public Geospatial(object value) { Geospatial geo = value as Geospatial; if (geo != null) { this.InnerValue = geo.InnerValue; this.setGXGeoType(SQLGeographyWrapper.STGeometryType(_innerValue).ToString()); this.srid = geo.srid; } else { String s = value.ToString(); new Geospatial(s); } }
public static Geospatial FromGXLocation(String geoText) { Geospatial geo = new Geospatial(); if (!String.IsNullOrEmpty(geoText)) { if (geoText.Contains(".")) { // has . as decimal separator and "," as value sep geoText = geoText.Replace(',', ' '); } else { // has comma as DS and space as value sep geoText = geoText.Replace(',', '.'); } try { String[] coord = geoText.Split(new char[] { ' ' }, 2); geo.Point.Longitude = Convert.ToDouble(coord[1].Trim(), CultureInfo.InvariantCulture.NumberFormat); geo.Point.Latitude = Convert.ToDouble(coord[0].Trim(), CultureInfo.InvariantCulture.NumberFormat); geo.srid = 4326; // Latitude and Longitud parameters are reversed in the 'Point' constructor: // construct a point object String wkt = $"POINT({geo.Point.Longitude.ToString("F6")} {geo.Point.Latitude.ToString("F6")})"; geo.InnerValue = NTSGeographyWrapper.STGeomFromText(wkt, geo.Srid); } catch (Exception) { // Can't convert to geography set as null. // set innerval geo.InnerValue = NTSGeographyWrapper.NullSQLGeography; geo.geoText = ""; geo.Point.Longitude = 0; geo.Point.Latitude = 0; } } return(geo); }
public static Geospatial FromGXLocation(String geoText) { Geospatial geo = new Geospatial(); if (!String.IsNullOrEmpty(geoText)) { if (geoText.Contains(".")) { // has . as decimal separator and "," as value sep geoText = geoText.Replace(',', ' '); } else { // has comma as DS and space as value sep geoText = geoText.Replace(',', '.'); } try { String[] coord = geoText.Split(new char[] { ' ' }, 2); geo.Point.Longitude = Convert.ToDouble(coord[1].Trim(), CultureInfo.InvariantCulture.NumberFormat); geo.Point.Latitude = Convert.ToDouble(coord[0].Trim(), CultureInfo.InvariantCulture.NumberFormat); geo.srid = 4326; // Latitude and Longitud parameters are reversed in the 'Point' constructor: geo.InnerValue = ClassLoader.InvokeStatic(SQLGeographyWrapper.GeoAssembly, SQLGeographyWrapper.SqlGeographyClass, "Point", new object[] { geo.Point.Latitude, geo.Point.Longitude, geo.Srid }); } catch (Exception) { // Can't convert to geography set as null. geo.InnerValue = SQLGeographyWrapper.NullSQLGeography; geo.geoText = ""; geo.Point.Longitude = 0; geo.Point.Latitude = 0; } } return(geo); }
public static int IsEqual(Geospatial geoA, Geospatial geoB) { return(String.Equals(geoA.ToString(), geoB.ToString()) ? 0 : 1); }