示例#1
0
 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);
     }
 }
示例#2
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);
            }
        }
示例#3
0
        public Geospatial(String value)
        {
            String s = value.ToString();

            initInstanceVars();
            this.FromString(s);
            // serttype
            this.setGXGeoType(NTSGeographyWrapper.STGeometryType(_innerValue).ToString());
        }
示例#4
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;
                }
            }
        }
示例#5
0
        static PolygonResult STPolygonResult(Geometry instance, bool IsLine)
        {
            Geodesic g      = Geodesic.WGS84;
            var      line   = new GeographicLib.PolygonArea(g, IsLine);
            int      points = NTSGeographyWrapper.STNumPoinst(instance);

            for (int i = 1; i < points; i++)
            {
                Coordinate currentPoint = NTSGeographyWrapper.STPoints(instance)[i];
                line.AddPoint(currentPoint.Y, currentPoint.X);
            }
            PolygonResult r = line.Compute();

            return(r);
        }
示例#6
0
        public Geospatial(object value)
        {
            Geospatial geo = value as Geospatial;

            if (geo != null)
            {
                this.InnerValue = geo.InnerValue;
                // settype
                this.setGXGeoType(NTSGeographyWrapper.STGeometryType(_innerValue).ToString());
                this.srid = geo.srid;
            }
            else
            {
                String s = value.ToString();
                new Geospatial(s);
            }
        }
示例#7
0
        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);
        }
示例#8
0
 public double STArea()
 {
     // HARD calculo area
     if (_innerValue != null &&
         !_innerValue.ToString().Equals(EMPTY_GEOGRAPHY) &&
         GeographicType == GeoGraphicTypeValue.Polygon)
     {
         try
         {
             return(NTSGeographyWrapper.STArea(_innerValue));
         }
         catch (Exception ex)
         {
             GXLogging.Debug(log, "Error calling Area() exception:");
             GXLogging.Debug(log, ex.ToString());
             return(0);
         }
     }
     else
     {
         GXLogging.Debug(log, "STArea: _innerValue is not valid");
         return(0);
     }
 }
示例#9
0
        ArrayList geoToArray(String geoType, Object geoInstance)
        {
            ArrayList ArrayOfPoints = new ArrayList();

            if (geoType.Equals("MultiPoint") || geoType.Equals("LineString"))
            {
                int points = NTSGeographyWrapper.STNumPoinst(geoInstance);
                for (int i = 1; i < points; i++)
                {
                    double[]   CurrentPoint = new double[2];
                    Coordinate currentPoint = NTSGeographyWrapper.STPoints(geoInstance)[i];
                    // lat y long
                    CurrentPoint[0] = currentPoint.X;
                    CurrentPoint[1] = currentPoint.Y;
                    ArrayOfPoints.Add(CurrentPoint);
                }
            }
            else if (geoType.Equals("Point"))
            {
                ArrayOfPoints.Add(NTSGeographyWrapper.Long(geoInstance));
                ArrayOfPoints.Add(NTSGeographyWrapper.Lat(geoInstance));
            }
            else if (geoType.Equals("Polygon"))
            {
                int rings = NTSGeographyWrapper.STNumRings(geoInstance);
                for (int j = 0; j < rings; j++)
                {
                    ArrayList RingArray   = new ArrayList();
                    object    currentRing = NTSGeographyWrapper.STRingN(geoInstance, j);
                    int       p           = NTSGeographyWrapper.STNumPoinst(currentRing);

                    for (int i = 0; i < p; i++)
                    {
                        double[]   CurrentPoint = new double[2];
                        Coordinate currentPoint = NTSGeographyWrapper.STPoints(currentRing)[i];
                        CurrentPoint[0] = currentPoint.X;
                        CurrentPoint[1] = currentPoint.Y;
                        RingArray.Add(CurrentPoint);
                    }
                    ArrayOfPoints.Add(RingArray);
                }
            }
            else if (geoType.Equals("MultiLineString"))
            {
                int geoms = NTSGeographyWrapper.STNumGeometries(geoInstance);
                for (int j = 0; j < geoms; j++)
                {
                    object currentgeom = NTSGeographyWrapper.STGeometryN(geoInstance, j);
                    ArrayOfPoints.Add(geoToArray("LineString", currentgeom));
                }
            }
            else if (geoType.Equals("MultiPolygon"))
            {
                int geoms = NTSGeographyWrapper.STNumGeometries(geoInstance);
                for (int j = 1; j < geoms; j++)
                {
                    object currentgeom = NTSGeographyWrapper.STGeometryN(geoInstance, j);
                    ArrayOfPoints.Add(geoToArray("Polygon", currentgeom));
                }
            }
            return(ArrayOfPoints);
        }
示例#10
0
 internal static object STGeomFromText(string geoText, int sRID)
 {
     return(NTSGeographyWrapper.Parse("SRID=" + sRID.ToString() + ";" + geoText));
 }
示例#11
0
 internal static object GeometryParse(String geoText)
 {
     return(NTSGeographyWrapper.Parse(geoText));
 }