Example #1
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "ProjectionInfo" /> class.
 /// </summary>
 public ProjectionInfo()
 {
     GeographicInfo = new GeographicInfo();
     Unit = new LinearUnit();
     _scaleFactor = 1; // if not specified, default to 1
     AuxiliarySphereType = AuxiliarySphereType.NotSpecified;
     NoDefs = true;
 }
Example #2
0
 public Proj4CrsGeographic(GeographicInfo geographicInfo)
     : base(geographicInfo.Name ?? geographicInfo.Datum.Name ?? "Unknown", new AuthorityTag("PROJ4", String.Empty))
 {
     Contract.Requires(geographicInfo != null);
     Contract.Requires(geographicInfo.Meridian != null);
     Contract.Requires(geographicInfo.Datum != null);
     Contract.Requires(geographicInfo.Datum.Spheroid != null);
     Core = geographicInfo;
     Datum = Proj4DatumWrapper.CreateWrapper(geographicInfo);
 }
Example #3
0
        /// <summary>
        /// This will try to read the string, but if the validation fails, then it will return false,
        ///   rather than throwing an exception.
        /// </summary>
        /// <param name="esriString">
        /// The string to test and define this projection if possible.
        /// </param>
        /// <returns>
        /// Boolean, true if at least the GEOGCS tag was found.
        /// </returns>
        public bool TryParseEsriString(string esriString)
        {
            if (esriString == null)
            {
                return(false);
            }

            if (!esriString.Contains("GEOGCS"))
            {
                return(false);
            }

            if (esriString.Contains("PROJCS") == false)
            {
                GeographicInfo.ParseEsriString(esriString);
                IsLatLon  = true;
                Transform = new LongLat();
                Transform.Init(this);
                return(true);
            }

            int iStart = esriString.IndexOf(@""",");

            Name = esriString.Substring(8, iStart - 8);
            int    iEnd = esriString.IndexOf("PARAMETER");
            string gcs;

            if (iEnd != -1)
            {
                gcs = esriString.Substring(iStart + 1, iEnd - (iStart + 2));
            }
            else
            {
                // an odd Esri projection string that doesn't have PARAMETER
                gcs = esriString.Substring(iStart + 1);
            }
            GeographicInfo.ParseEsriString(gcs);

            FalseEasting    = GetParameter(new string[] { "False_Easting", "Easting_At_False_Origin" }, ref FalseEastingAlias, esriString);
            FalseNorthing   = GetParameter(new string[] { "False_Northing", "Northing_At_False_Origin" }, ref FalseNorthingAlias, esriString);
            CentralMeridian = GetParameter("Central_Meridian", esriString);
            // Esri seems to indicate that these should be treated the same, but they aren't here... http://support.esri.com/en/knowledgebase/techarticles/detail/39992
            // CentralMeridian = GetParameter(new string[] { "Longitude_Of_Center", "Central_Meridian", "Longitude_Of_Origin" }, ref LongitudeOfCenterAlias, esriString);
            LongitudeOfCenter = GetParameter("Longitude_Of_Center", esriString);
            StandardParallel1 = GetParameter("Standard_Parallel_1", esriString);
            StandardParallel2 = GetParameter("Standard_Parallel_2", esriString);
            _scaleFactor      = GetParameter("Scale_Factor", esriString);
            alpha             = GetParameter("Azimuth", esriString);
            _longitudeOf1st   = GetParameter("Longitude_Of_1st", esriString);
            _longitudeOf2nd   = GetParameter("Longitude_Of_2nd", esriString);
            LatitudeOfOrigin  = GetParameter(new string[] { "Latitude_Of_Origin", "Latitude_Of_Center", "Central_Parallel" }, ref LatitudeOfOriginAlias, esriString);
            iStart            = esriString.LastIndexOf("UNIT");
            string unit = esriString.Substring(iStart, esriString.Length - iStart);

            Unit.ParseEsriString(unit);

            if (esriString.Contains("PROJECTION"))
            {
                iStart = esriString.IndexOf("PROJECTION") + 12;
                iEnd   = esriString.IndexOf("]", iStart) - 1;
                string projection = esriString.Substring(iStart, iEnd - iStart);

                Transform = TransformManager.DefaultTransformManager.GetProjection(projection);
                Transform.Init(this);
            }

            double?auxType = GetParameter("Auxiliary_Sphere_Type", esriString);

            if (auxType != null)
            {
                // While the Esri implementation sort of tip-toes around the datum transform,
                // we simply ensure that the spheroid becomes properly spherical based on the
                // parameters we have here.  (The sphereoid will be read as WGS84).
                AuxiliarySphereType = (AuxiliarySphereType)auxType;
                if (AuxiliarySphereType == AuxiliarySphereType.SemimajorAxis)
                {
                    // added by Jiri to properly re-initialize the 'web mercator auxiliary sphere' transform
                    Transform = KnownCoordinateSystems.Projected.World.WebMercator.Transform;
                }
                else if (AuxiliarySphereType == AuxiliarySphereType.SemiminorAxis)
                {
                    double r = GeographicInfo.Datum.Spheroid.PolarRadius;
                    GeographicInfo.Datum.Spheroid = new Spheroid(r);
                }
                else if (AuxiliarySphereType == AuxiliarySphereType.Authalic ||
                         AuxiliarySphereType == AuxiliarySphereType.AuthalicWithConvertedLatitudes)
                {
                    double a = GeographicInfo.Datum.Spheroid.EquatorialRadius;
                    double b = GeographicInfo.Datum.Spheroid.PolarRadius;
                    double r =
                        Math.Sqrt(
                            (a * a
                             +
                             a * b * b
                             / (Math.Sqrt(a * a - b * b) * Math.Log((a + Math.Sqrt(a * a - b * b)) / b, Math.E)))
                            / 2);
                    GeographicInfo.Datum.Spheroid = new Spheroid(r);
                }
            }

            if (FalseEasting != null)
            {
                FalseEasting = FalseEasting * Unit.Meters;
            }

            if (FalseNorthing != null)
            {
                FalseNorthing = FalseNorthing * Unit.Meters;
            }

            return(true);
        }
Example #4
0
 public static Proj4DatumWrapper CreateWrapper(GeographicInfo geographicInfo)
 {
     if (geographicInfo == null) throw new ArgumentNullException("geographicInfo");
     if (geographicInfo.Meridian == null) throw new ArgumentException("Must have a meridian.", "geographicInfo");
     Contract.Requires(geographicInfo.Datum != null);
     Contract.Requires(geographicInfo.Datum.Spheroid != null);
     Contract.Ensures(Contract.Result<Proj4DatumWrapper>() != null);
     return new Proj4DatumWrapper(
         geographicInfo.Datum,
         new Proj4MeridianWrapper(geographicInfo.Meridian));
 }
Example #5
0
        public static GeographicInfo CreateGeographic(ICrsGeodetic crsGeodetic)
        {
            if (crsGeodetic == null) throw new ArgumentNullException("crsGeodetic");
            Contract.Requires(crsGeodetic.Datum.PrimeMeridian != null);
            Contract.Ensures(Contract.Result<GeographicInfo>() != null);

            var result = new GeographicInfo {
                Name = crsGeodetic.Name
            };

            result.Datum = Proj4DatumWrapper.Create(crsGeodetic.Datum);

            Contract.Assume(crsGeodetic.Datum.PrimeMeridian != null);
            result.Meridian = Proj4MeridianWrapper.Create(crsGeodetic.Datum.PrimeMeridian);

            // TODO: set the unit

            return result;
        }