Пример #1
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;
                }
            }
        }
Пример #2
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);
        }