private static void WriteGeographicCoordinateSystem(GeographicCoordinateSystem geogrCoordSystem)
        {
            // +proj=longlat +ellps=clrk80 +towgs84=-294.7,-200.1,525.5,0,0,0,0 +no_defs

            #region Ellipsoid
            Ellipsoid ellipsoid = geogrCoordSystem.HorizontalDatum.Ellipsoid;

            double majorAxis, minorAxis, invFlattening;
            string ellps = ProjDB.SpheroidByName(ellipsoid.Name, out majorAxis, out minorAxis, out invFlattening);

            if (ellps != String.Empty &&
                majorAxis == ellipsoid.SemiMajorAxis &&
                minorAxis == ellipsoid.SemiMinorAxis)
            {
                _p4parameters.Add(new P4Parameter("+ellps", ellps));
            }
            else
            {
                _p4parameters.Add(new P4Parameter("+a", ellipsoid.SemiMajorAxis.ToString(_nhi)));
                _p4parameters.Add(new P4Parameter("+b", ellipsoid.SemiMinorAxis.ToString(_nhi)));
            }
            #endregion

            #region WGS84
            WGS84ConversionInfo wgs84 = geogrCoordSystem.HorizontalDatum.WGS84Parameters;
            if (wgs84.IsInUse)
            {
                _p4parameters.Add(new P4Parameter("+towgs84",
                                                  String.Format("{0},{1},{2},{3},{4},{5},{6}",
                                                                wgs84.Dx.ToString(_nhi), wgs84.Dy.ToString(_nhi), wgs84.Dz.ToString(_nhi),
                                                                wgs84.Ex.ToString(_nhi), wgs84.Ey.ToString(_nhi), wgs84.Ez.ToString(_nhi),
                                                                wgs84.Ppm.ToString(_nhi))));
            }
            #endregion
        }
        private static WGS84ConversionInfo ReadWGS84ConversionInfo(string towgs84)
        {
            WGS84ConversionInfo wgs84ConversionInfo = new WGS84ConversionInfo();

            if (towgs84 != null)
            {
                string[] w = towgs84.Split(',');
                if (w.Length > 2)
                {
                    wgs84ConversionInfo.Dx = double.Parse(w[0], _nhi);
                    wgs84ConversionInfo.Dy = double.Parse(w[1], _nhi);
                    wgs84ConversionInfo.Dz = double.Parse(w[2], _nhi);
                }
                if (w.Length > 5)
                {
                    wgs84ConversionInfo.Ex = double.Parse(w[3], _nhi);
                    wgs84ConversionInfo.Ey = double.Parse(w[4], _nhi);
                    wgs84ConversionInfo.Ez = double.Parse(w[5], _nhi);
                }
                if (w.Length > 6)
                {
                    wgs84ConversionInfo.Ppm = double.Parse(w[6], _nhi);
                }
            }

            return(wgs84ConversionInfo);
        }
Exemplo n.º 3
0
 public HorizontalDatum(string name, DatumType horizontalDatumType, Ellipsoid ellipsoid, WGS84ConversionInfo toWGS84,
                        string remarks, string authority, string authorityCode, string alias, string abbreviation)
     : base(horizontalDatumType, remarks, authority, authorityCode, name, alias, abbreviation)
 {
     if (ellipsoid == null)
     {
         throw new ArgumentNullException("ellipsoid");
     }
     _ellipsoid           = ellipsoid;
     _wgs84ConversionInfo = toWGS84;
 }
        private static void WriteWGS84ConversionInfo(WGS84ConversionInfo conversionInfo, bool esri, IndentedTextWriter writer)
        {
            if (esri)
            {
                return;
            }

            writer.WriteLine(String.Format("TOWGS84[{0},{1},{2},{3},{4},{5},{6}]",
                                           conversionInfo.Dx.ToString(_nhi), conversionInfo.Dy.ToString(_nhi), conversionInfo.Dz.ToString(_nhi),
                                           conversionInfo.Ex.ToString(_nhi), conversionInfo.Ey.ToString(_nhi), conversionInfo.Ez.ToString(_nhi),
                                           conversionInfo.Ppm.ToString(_nhi)));
        }
        private static WGS84ConversionInfo ReadWGS84ConversionInfo(WktStreamTokenizer tokenizer, bool includeAuthority)
        {
            //TOWGS84[0,0,0,0,0,0,0]
            tokenizer.ReadToken("[");
            WGS84ConversionInfo info = new WGS84ConversionInfo();

            tokenizer.NextToken();
            info.Dx = tokenizer.GetNumericValue();
            tokenizer.ReadToken(",");

            tokenizer.NextToken();
            info.Dy = tokenizer.GetNumericValue();
            tokenizer.ReadToken(",");

            tokenizer.NextToken();
            info.Dz = tokenizer.GetNumericValue();
            tokenizer.ReadToken(",");

            tokenizer.NextToken();
            info.Ex = tokenizer.GetNumericValue();
            tokenizer.ReadToken(",");

            tokenizer.NextToken();
            info.Ey = tokenizer.GetNumericValue();
            tokenizer.ReadToken(",");

            tokenizer.NextToken();
            info.Ez = tokenizer.GetNumericValue();
            tokenizer.ReadToken(",");

            tokenizer.NextToken();
            info.Ppm = tokenizer.GetNumericValue();

            tokenizer.ReadToken("]");

            info.IsInUse = true;
            return(info);
        }
 private static void Write(object obj, bool esri, IndentedTextWriter writer)
 {
     if (obj is CoordinateSystem)
     {
         WriteCoordinateSystem(obj as CoordinateSystem, esri, writer);
     }
     else if (obj is Datum)
     {
         WriteDatum(obj as Datum, esri, writer);
     }
     else if (obj is Ellipsoid)
     {
         WriteEllipsoid(obj as Ellipsoid, esri, writer);
     }
     else if (obj is AxisInfo)
     {
         AxisInfo info = (AxisInfo)obj;
         WriteAxis(info, esri, writer);
     }
     else if (obj is WGS84ConversionInfo)
     {
         WGS84ConversionInfo info = (WGS84ConversionInfo)obj;
         WriteWGS84ConversionInfo(info, esri, writer);
     }
     else if (obj is Unit)
     {
         WriteUnit(obj as Unit, esri, writer);
     }
     else if (obj is PrimeMeridian)
     {
         WritePrimeMeridian(obj as PrimeMeridian, esri, writer);
     }
     else
     {
         throw new NotImplementedException(String.Format("Cannot convert {0} to WKT.", obj.GetType().FullName));
     }
 }
        private static HorizontalDatum ReadHorizontalDatum(WktStreamTokenizer tokenizer, bool includeAuthority)
        {
            //DATUM["OSGB 1936",
            //       SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]],
            //       TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6277"]]

            tokenizer.ReadToken("[");
            string name = tokenizer.ReadDoubleQuotedWord();

            tokenizer.ReadToken(",");
            tokenizer.ReadToken("SPHEROID");
            Ellipsoid           ellipsoid     = ReadEllipsoid(tokenizer, includeAuthority);
            string              authority     = String.Empty;
            string              authorityCode = String.Empty;
            WGS84ConversionInfo wgsInfo       = new WGS84ConversionInfo();

            wgsInfo.IsInUse = false;

            if (tokenizer.TryReadToken(","))
            {
                if (tokenizer.TryReadToken("TOWGS84"))
                {
                    wgsInfo = ReadWGS84ConversionInfo(tokenizer, includeAuthority);
                }
                if (includeAuthority)
                {
                    tokenizer.ReadToken(",");
                    tokenizer.ReadAuthority(ref authority, ref authorityCode);
                }
            }
            tokenizer.ReadToken("]");
            // make an assumption about the datum type.
            DatumType       datumType       = DatumType.IHD_Geocentric;
            HorizontalDatum horizontalDatum = new HorizontalDatum(name, datumType, ellipsoid, wgsInfo, String.Empty, authority, authorityCode, String.Empty, String.Empty);

            return(horizontalDatum);
        }
        private static GeographicCoordinateSystem ReadGeographicCoordinateSystem(string[] parameters)
        {
            //+proj=longlat +ellps=intl +pm=ferro +towgs84=145,-187,103,0,0,0,0 +no_defs

            WGS84ConversionInfo wgs84     = ReadWGS84ConversionInfo(ParameterValue(parameters, "+towgs84"));
            LinearUnit          unit      = ReadUnit(parameters) as LinearUnit;
            Ellipsoid           ellipsoid = ReadEllipsoid(parameters, unit);
            HorizontalDatum     datum     = new HorizontalDatum(
                "Unknown",
                DatumType.IHD_Classic,
                ellipsoid,
                wgs84);

            GeographicCoordinateSystem geogrCoordSystem =
                new GeographicCoordinateSystem(
                    "Unknown",
                    new AngularUnit(Math.PI / 180.0, String.Empty, String.Empty, String.Empty, "degree", String.Empty, String.Empty),
                    datum,
                    ReadPrimeMeridian(parameters),
                    new AxisInfo("Geodetic latitude", AxisOrientation.North),
                    new AxisInfo("Geodetic longitude", AxisOrientation.East));

            return(geogrCoordSystem);
        }
Exemplo n.º 9
0
 internal HorizontalDatum(string name, DatumType horizontalDatumType, Ellipsoid ellipsoid, WGS84ConversionInfo toWGS84)
     : this(name, horizontalDatumType, ellipsoid, toWGS84, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty)
 {
 }
        public static object Create(string wkt)
        {
            object             returnObject     = null;
            bool               includeAuthority = (wkt.ToLower().IndexOf("authority") != -1);
            StringReader       reader           = new StringReader(wkt);
            WktStreamTokenizer tokenizer        = new WktStreamTokenizer(reader);

            tokenizer.NextToken();
            string objectName = tokenizer.GetStringValue();

            switch (objectName)
            {
            case "UNIT":
                Unit unit = ReadUnit(tokenizer, includeAuthority);
                returnObject = unit;
                break;

            case "VERT_DATUM":
                VerticalDatum verticalDatum = ReadVerticalDatum(tokenizer, includeAuthority);
                returnObject = verticalDatum;
                break;

            case "SPHEROID":
                Ellipsoid ellipsoid = ReadEllipsoid(tokenizer, includeAuthority);
                returnObject = ellipsoid;
                break;

            case "TOWGS84":
                WGS84ConversionInfo wgsInfo = ReadWGS84ConversionInfo(tokenizer, includeAuthority);
                returnObject = wgsInfo;
                break;

            case "DATUM":
                HorizontalDatum horizontalDatum = ReadHorizontalDatum(tokenizer, includeAuthority);
                returnObject = horizontalDatum;
                break;

            case "PRIMEM":
                PrimeMeridian primeMeridian = ReadPrimeMeridian(tokenizer, includeAuthority);
                returnObject = primeMeridian;
                break;

            case "VERT_CS":
                VerticalCoordinateSystem verticalCS = ReadVerticalCoordinateSystem(tokenizer, includeAuthority);
                returnObject = verticalCS;
                break;

            case "GEOGCS":
                GeographicCoordinateSystem geographicCS = ReadGeographicCoordinateSystem(tokenizer, includeAuthority);
                returnObject = geographicCS;
                break;

            case "PROJCS":
                ProjectedCoordinateSystem projectedCS = ReadProjectedCoordinateSystem(tokenizer, includeAuthority);
                returnObject = projectedCS;
                break;

            case "COMPD_CS":
                CompoundCoordinateSystem compoundCS = ReadCompoundCoordinateSystem(tokenizer, includeAuthority);
                returnObject = compoundCS;
                break;

            case "GEOCCS":
            case "FITTED_CS":
            case "LOCAL_CS":
                throw new NotSupportedException(String.Format("{0} is not implemented.", objectName));

            default:
                throw new ParseException(String.Format("'{0'} is not recongnized.", objectName));
            }
            reader.Close();
            return(returnObject);
        }