コード例 #1
0
        /// <summary>
        /// Computes the projected coordinate reference system.
        /// </summary>
        /// <returns>The projected coordinate reference system.</returns>
        /// <exception cref="System.IO.InvalidDataException">Projected coordinate reference system code is invalid.</exception>
        private ProjectedCoordinateReferenceSystem ComputeProjectedCoordinateReferenceSystem()
        {
            Int32 code = Convert.ToInt32(_currentGeoKeys[GeoKey.ProjectedCoordinateReferenceSystemType]);

            // EPSG Projected Coordinate Reference System codes
            if (code < 32767)
            {
                ProjectedCoordinateReferenceSystem referenceSystem = ProjectedCoordinateReferenceSystems.FromIdentifier("EPSG::" + code).FirstOrDefault();

                if (referenceSystem == null)
                {
                    return(new ProjectedCoordinateReferenceSystem("EPSG::" + code, "undefined", Geographic2DCoordinateReferenceSystems.WGS84, CoordinateSystems.CartesianENM, AreasOfUse.World, null));
                }

                return(referenceSystem);
            }
            // user-defined Projected Coordinate Reference System
            if (code == Int16.MaxValue)
            {
                GeographicCoordinateReferenceSystem baseReferenceSystem = ComputeGeodeticCoordinateReferenceSystem();
                CoordinateProjection projection = ComputeProjection(baseReferenceSystem.Datum.Ellipsoid);

                return(new ProjectedCoordinateReferenceSystem(ProjectedCoordinateReferenceSystem.UserDefinedIdentifier, ProjectedCoordinateReferenceSystem.UserDefinedName,
                                                              baseReferenceSystem, CoordinateSystems.CartesianENM, baseReferenceSystem.AreaOfUse, projection));
            }

            throw new InvalidDataException("Projected coordinate reference system code is invalid.");
        }
        /// <summary>
        /// Converts the specified content.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <returns>The converted reference.</returns>
        protected override ProjectedCoordinateReferenceSystem Convert(String[] content)
        {
            switch (content[3])
            {
            case "projected":
                AreaOfUse areaOfUse = this.areaOfUseCollection[Authority, Int32.Parse(content[2])];
                GeographicCoordinateReferenceSystem baseReferenceSystem = this.baseCoordinateReferenceSystemCollection[Authority, Int32.Parse(content[6])];
                CoordinateSystem coordinateSystem = this.coordinateSystemCollection[Authority, Int32.Parse(content[4])];

                // the projection should use the ellipsoid with the unit specified by the coordinate system
                CoordinateProjection projection = this.coordinateProjectionCollection[Authority, Int32.Parse(content[7]), baseReferenceSystem.Datum.Ellipsoid.ToUnit(coordinateSystem.GetAxis(0).Unit)];

                // TODO: remove condition, once all projections are implemented
                if (projection == null)
                {
                    return(null);
                }

                return(new ProjectedCoordinateReferenceSystem(IdentifiedObject.GetIdentifier(Authority, content[0]), content[1],
                                                              content[11], this.GetAliases(Int32.Parse(content[0])), content[10],
                                                              baseReferenceSystem, coordinateSystem, areaOfUse, projection));

            default:
                return(null);
            }
        }
コード例 #3
0
        /// <summary>
        /// Computes the Geodetic coordinate reference system.
        /// </summary>
        /// <returns>The Geodetic coordinate reference system.</returns>
        /// <exception cref="System.IO.InvalidDataException">Geodetic coordinate reference system code is invalid.</exception>
        private GeographicCoordinateReferenceSystem ComputeGeodeticCoordinateReferenceSystem()
        {
            Int32 code = Convert.ToInt32(_currentGeoKeys[GeoKey.GeodeticCoordinateReferenceSystemType]);

            // EPSG geodetic coordinate reference system codes
            if (code < 32767)
            {
                GeographicCoordinateReferenceSystem referenceSystem = GeographicCoordinateReferenceSystems.FromIdentifier("EPSG::" + code).FirstOrDefault();

                if (referenceSystem == null)
                {
                    return(new GeographicCoordinateReferenceSystem("EPSG::" + code, "undefined", CoordinateSystems.EllipsoidalLatLonD, GeodeticDatums.WGS84, AreasOfUse.World));
                }

                return(referenceSystem);
            }

            // user-defined geodetic coordinate reference system
            if (code == Int16.MaxValue)
            {
                String            citation  = _currentGeoKeys[GeoKey.GeodeticCoordinateReferenceSystemCitation].ToString();
                GeodeticDatum     datum     = ComputeGeodeticDatum();
                UnitOfMeasurement angleUnit = ComputeAngularUnit();

                CoordinateSystem coordinateSystem = new CoordinateSystem(CoordinateSystem.UserDefinedIdentifier, CoordinateSystem.UserDefinedName,
                                                                         CoordinateSystemType.Ellipsoidal,
                                                                         CoordinateSystemAxisFactory.GeodeticLatitude(angleUnit),
                                                                         CoordinateSystemAxisFactory.GeodeticLongitude(angleUnit));

                return(new GeographicCoordinateReferenceSystem(GeographicCoordinateReferenceSystem.UserDefinedIdentifier, GeographicCoordinateReferenceSystem.UserDefinedName,
                                                               citation, null, null, coordinateSystem, datum, null));
            }

            throw new InvalidDataException("Geodetic coordinate reference system code is invalid.");
        }
コード例 #4
0
        public void WellKnownTextConverterIdentifiedObjectTest()
        {
            // conversion from string instance

            String projectedUTMZone33 = "PROJCS[\"UTM Zone 33, Northern Hemisphere\",GEOGCS[\"Geographic Coordinate System\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137,298.257223560493]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",15],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]";
            String UTMZone10NAD83     = "PROJCS[\"NAD_1983_UTM_Zone_10N\", GEOGCS[\"GCS_North_American_1983\", DATUM[ \"D_North_American_1983\",ELLIPSOID[\"GRS_1980\",6378137,298.257222101]], PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]], PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",500000.0], PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",-123.0], PARAMETER[\"Scale_Factor\",0.9996],PARAMETER[\"Latitude_of_Origin\",0.0], UNIT[\"Meter\",1.0]]";
            String geodeticBase       = "GEOGCS[\"Unknown\",DATUM[\"D_Unknown\",SPHEROID[\"Clarke_1866\",6378206.4,294.978698213901]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]";
            String wgs1984            = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.017453292519943295]]";

            Assert.IsNotNull(WellKnownTextConverter.ToWellKnownText(WellKnownTextConverter.ToIdentifiedObject(projectedUTMZone33)));
            Assert.IsNotNull(WellKnownTextConverter.ToWellKnownText(WellKnownTextConverter.ToIdentifiedObject(UTMZone10NAD83)));
            Assert.IsNotNull(WellKnownTextConverter.ToWellKnownText(WellKnownTextConverter.ToIdentifiedObject(geodeticBase)));
            Assert.IsNotNull(WellKnownTextConverter.ToWellKnownText(WellKnownTextConverter.ToIdentifiedObject(wgs1984)));

            // conversion from identified object instance

            foreach (ProjectedCoordinateReferenceSystem projected in ProjectedCoordinateReferenceSystems.All)
            {
                String wkt = WellKnownTextConverter.ToWellKnownText(projected as IReferenceSystem);
                ProjectedCoordinateReferenceSystem converted = WellKnownTextConverter.ToIdentifiedObject(wkt) as ProjectedCoordinateReferenceSystem;
                Assert.AreEqual(projected, converted);
            }

            foreach (GeographicCoordinateReferenceSystem geodetic in Geographic2DCoordinateReferenceSystems.All)
            {
                String wkt = WellKnownTextConverter.ToWellKnownText(geodetic as IReferenceSystem);
                GeographicCoordinateReferenceSystem converted = WellKnownTextConverter.ToIdentifiedObject(wkt) as GeographicCoordinateReferenceSystem;
                Assert.AreEqual(geodetic, converted);
            }
        }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GeographicTranslation" /> class.
 /// </summary>
 /// <param name="identifier">The identifier.</param>
 /// <param name="name">The name.</param>
 /// <param name="remarks">The remarks.</param>
 /// <param name="aliases">The aliases.</param>
 /// <param name="parameters">The parameters of the operation.</param>
 /// <param name="source">The source coordinate reference system.</param>
 /// <param name="target">The target coordinate reference system.</param>
 /// <param name="areaOfUse">The area of use.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The identifier is null.
 /// or
 /// The source coordinate reference system is null.
 /// or
 /// The target coordinate reference system is null.
 /// or
 /// The area of use is null.
 /// </exception>
 public GeographicTranslation(String identifier, String name, String remarks, String[] aliases, IDictionary <CoordinateOperationParameter, Object> parameters,
                              GeographicCoordinateReferenceSystem source, GeographicCoordinateReferenceSystem target, AreaOfUse areaOfUse)
     : base(identifier, name, remarks, aliases, CoordinateOperationMethods.Geographic2DOffsets, parameters, source, target, areaOfUse)
 {
     this.latitudeOffset  = this.GetParameterValue(CoordinateOperationParameters.LatitudeOffset);
     this.longitudeOffset = this.GetParameterValue(CoordinateOperationParameters.LongitudeOffset);
 }
コード例 #6
0
        /// <summary>
        /// Creates a strategy for converting coordinates between reference systems.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <returns>The produced transformation strategy.</returns>
        /// <exception cref="System.NotSupportedException">Conversion does not exist between the specified reference systems.</exception>
        public ICoordinateOperationStrategy CreateStrategy(ReferenceSystem source, ReferenceSystem target)
        {
            ICoordinateOperationStrategy <Coordinate, GeoCoordinate>    conversionToGeographic   = null;
            ICoordinateOperationStrategy <GeoCoordinate, GeoCoordinate> transformation           = null;
            ICoordinateOperationStrategy <GeoCoordinate, Coordinate>    conversionFromGeographic = null;

            switch (source.Type)
            {
            case ReferenceSystemType.Projected:
                conversionToGeographic = new ReverseCoordinateProjectionStrategy(source as ProjectedCoordinateReferenceSystem);
                break;

            case ReferenceSystemType.Geographic2D:
            case ReferenceSystemType.Geographic3D:
                conversionToGeographic = this.CreateReverseConversion(source as CoordinateReferenceSystem);
                break;
            }

            switch (target.Type)
            {
            case ReferenceSystemType.Projected:
                conversionFromGeographic = new ForwardCoordinateProjectionStrategy(target as ProjectedCoordinateReferenceSystem);
                break;

            case ReferenceSystemType.Geographic2D:
            case ReferenceSystemType.Geographic3D:
                conversionFromGeographic = this.CreateForwardConversion(target as CoordinateReferenceSystem);
                break;
            }

            // if no transformation is needed
            if (conversionFromGeographic.TargetReferenceSystem.Equals(conversionToGeographic.SourceReferenceSystem))
            {
                return(new CoordinateConversionStrategy(conversionToGeographic, conversionFromGeographic));
            }

            GeographicCoordinateReferenceSystem conversionTargetReferenceSystem = conversionToGeographic.TargetReferenceSystem as GeographicCoordinateReferenceSystem;
            GeographicCoordinateReferenceSystem conversionSourceReferenceSystem = conversionFromGeographic.SourceReferenceSystem as GeographicCoordinateReferenceSystem;

            // load matching forward transformation
            IEnumerable <CoordinateTransformation <GeoCoordinate> > transformations = this.provider.GeoCoordinateTransformations.WithProperties(conversionTargetReferenceSystem, conversionSourceReferenceSystem);

            if (transformations.Any())
            {
                transformation = new ForwardGeographicCoordinateTransformationStrategy(conversionTargetReferenceSystem, conversionSourceReferenceSystem, transformations.First());
                return(new CompoundCoordinateConversionStrategy(conversionToGeographic, transformation, conversionFromGeographic));
            }

            // if none found, load matching reverse transformation
            transformations = this.provider.GeoCoordinateTransformations.WithProperties(conversionSourceReferenceSystem, conversionTargetReferenceSystem);
            if (transformations.Any())
            {
                transformation = new ReverseGeographicCoordinateTransformationStrategy(conversionTargetReferenceSystem, conversionSourceReferenceSystem, transformations.First());
                return(new CompoundCoordinateConversionStrategy(conversionToGeographic, transformation, conversionFromGeographic));
            }

            throw new NotSupportedException(ReferenceMessages.ConversionDoesNotExistBetweenReferenceSystems);
        }
コード例 #7
0
        /// <summary>
        /// Returns all <see cref="GeographicTransformation" /> instances transforming between the specified reference systems.
        /// </summary>
        /// <param name="source">The source reference system.</param>
        /// <param name="target">The target reference system.</param>
        /// <returns>A read-only list containing the <see cref="GeographicTransformation" /> instances transforming between the specified reference systems.</returns>
        public static IList <GeographicTransformation> FromReferenceSystems(GeographicCoordinateReferenceSystem source, GeographicCoordinateReferenceSystem target)
        {
            if (source == null || target == null)
            {
                return(null);
            }

            return(All.Where(referenceSystem => referenceSystem.Source.Equals(source) && referenceSystem.Target.Equals(target)).ToList().AsReadOnly());
        }
コード例 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReverseGeographicStrategy" /> class.
        /// </summary>
        /// <param name="source">The source reference system.</param>
        /// <param name="target">The target reference system.</param>
        /// <param name="transformation">The geographic transformation.</param>
        /// <exception cref="System.ArgumentNullException">
        /// The source coordinate reference system is null.
        /// or
        /// target;The target coordinate reference system is null.
        /// or
        /// transformation;The transformation is null.
        /// </exception>
        public ReverseGeographicStrategy(GeographicCoordinateReferenceSystem source, GeographicCoordinateReferenceSystem target, GeographicTransformation transformation)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source", "The source coordinate reference system is null.");
            }
            if (target == null)
            {
                throw new ArgumentNullException("target", "The target coordinate reference system is null.");
            }
            if (transformation == null)
            {
                throw new ArgumentNullException("transformation", "The transformation is null.");
            }

            _source         = source;
            _target         = target;
            _transformation = transformation;
        }
コード例 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CoordinateFrameRotation" /> class.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <param name="name">The name.</param>
        /// <param name="remarks">The remarks.</param>
        /// <param name="aliases">The aliases.</param>
        /// <param name="parameters">The parameters of the operation.</param>
        /// <param name="source">The source coordinate reference system.</param>
        /// <param name="target">The target coordinate reference system.</param>
        /// <param name="areaOfUse">The area of use.</param>
        /// <exception cref="System.ArgumentNullException">
        /// The identifier is null.
        /// or
        /// The source coordinate reference system is null.
        /// or
        /// The target coordinate reference system is null.
        /// or
        /// The area of use is null.
        /// </exception>
        public CoordinateFrameRotation(String identifier, String name, String remarks, String[] aliases, IDictionary<CoordinateOperationParameter, Object> parameters,
                                       GeographicCoordinateReferenceSystem source, GeographicCoordinateReferenceSystem target, AreaOfUse areaOfUse)
            : base(identifier, name, remarks, aliases, CoordinateOperationMethods.CoordinateFrameRotationGeocentricDomain, parameters, source, target, areaOfUse)
        {
            this.xAxisRotation = -this.xAxisRotation;
            this.yAxisRotation = -this.yAxisRotation;
            this.zAxisRotation = -this.zAxisRotation;

            Double det = 1 + this.xAxisRotation * this.xAxisRotation + this.yAxisRotation * this.yAxisRotation + this.zAxisRotation * this.zAxisRotation;
            this.inverseParams = new Double[3, 3];
            this.inverseParams[0, 0] = 1 / det * (1 + this.xAxisRotation * this.xAxisRotation);
            this.inverseParams[0, 1] = 1 / det * (this.zAxisRotation + this.xAxisRotation * this.yAxisRotation);
            this.inverseParams[0, 2] = 1 / det * (this.xAxisRotation * this.zAxisRotation - this.yAxisRotation);
            this.inverseParams[1, 0] = 1 / det * (this.xAxisRotation * this.yAxisRotation - this.zAxisRotation);
            this.inverseParams[1, 1] = 1 / det * (1 + this.yAxisRotation * this.yAxisRotation);
            this.inverseParams[1, 2] = 1 / det * (this.xAxisRotation + this.yAxisRotation * this.zAxisRotation);
            this.inverseParams[2, 0] = 1 / det * (this.xAxisRotation * this.zAxisRotation + this.yAxisRotation);
            this.inverseParams[2, 1] = 1 / det * (this.yAxisRotation * this.zAxisRotation - this.xAxisRotation);
            this.inverseParams[2, 2] = 1 / det * (1 + this.zAxisRotation * this.zAxisRotation);
        }
コード例 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HelmertTransformation" /> class.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <param name="name">The name.</param>
        /// <param name="remarks">The remarks.</param>
        /// <param name="aliases">The aliases.</param>
        /// <param name="method">The coordinate operation method.</param>
        /// <param name="parameters">The parameters of the operation.</param>
        /// <param name="source">The source coordinate reference system.</param>
        /// <param name="target">The target coordinate reference system.</param>
        /// <param name="areaOfUse">The area of use.</param>
        /// <exception cref="System.ArgumentNullException">
        /// The identifier is null.
        /// or
        /// The method is null.
        /// or
        /// The source coordinate reference system is null.
        /// or
        /// The target coordinate reference system is null.
        /// or
        /// The area of use is null.
        /// </exception>
        protected HelmertTransformation(String identifier, String name, String remarks, String[] aliases, CoordinateOperationMethod method, IDictionary <CoordinateOperationParameter, Object> parameters, GeographicCoordinateReferenceSystem source, GeographicCoordinateReferenceSystem target, AreaOfUse areaOfUse)
            : base(identifier, name, remarks, aliases, method, parameters, source, target, areaOfUse)
        {
            this.xAxisTranslation = this.GetParameterValue(CoordinateOperationParameters.XAxisTranslation);
            this.yAxisTranslation = this.GetParameterValue(CoordinateOperationParameters.YAxisTranslation);
            this.zAxisTranslation = this.GetParameterValue(CoordinateOperationParameters.ZAxisTranslation);
            this.xAxisRotation    = this.GetParameterValue(CoordinateOperationParameters.XAxisRotation);
            this.yAxisRotation    = this.GetParameterValue(CoordinateOperationParameters.YAxisRotation);
            this.zAxisRotation    = this.GetParameterValue(CoordinateOperationParameters.ZAxisRotation);
            this.scaleDifference  = this.GetParameterValue(CoordinateOperationParameters.ScaleDifference);

            this.m = 1 + this.scaleDifference * 1E-6;
        }
コード例 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConcatenatedGeographic2DTransformation" /> class.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <param name="name">The name.</param>
        /// <param name="method">The method.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="source">The source geographic coordinate reference system.</param>
        /// <param name="target">The target geographic coordinate reference system.</param>
        /// <param name="areaOfUse">The area of use.</param>
        /// <exception cref="System.ArgumentException">The specified method does not contain 5 submethods.</exception>
        public CompoundGeographic2DTransformation(String identifier, String name, CompoundCoordinateOperationMethod method, IDictionary <CoordinateOperationParameter, Object> parameters, GeographicCoordinateReferenceSystem source, GeographicCoordinateReferenceSystem target, AreaOfUse areaOfUse)
            : base(identifier, name, method, null, source, target, areaOfUse)
        {
            if (method.Methods.Count != 5)
            {
                throw new ArgumentException("The specified method does not contain 5 submethods.", "method");
            }

            _3DTo2DConversion = new Geographic3DTo2DConversion();
            _sourceConversion = new GeographicToGeocentricConversion((source.Datum as GeodeticDatum).Ellipsoid);
            _transformation   = GeocentricTransformationFactory.FromMethod(method.Methods[2], parameters);
            _targetConversion = new GeographicToGeocentricConversion((target.Datum as GeodeticDatum).Ellipsoid);
        }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CoordinateFrameRotation" /> class.
 /// </summary>
 /// <param name="identifier">The identifier.</param>
 /// <param name="name">The name.</param>
 /// <param name="parameters">The parameters of the operation.</param>
 /// <param name="source">The source coordinate reference system.</param>
 /// <param name="target">The target coordinate reference system.</param>
 /// <param name="areaOfUse">The area of use.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The identifier is null.
 /// or
 /// The source coordinate reference system is null.
 /// or
 /// The target coordinate reference system is null.
 /// or
 /// The area of use is null.
 /// </exception>
 public CoordinateFrameRotation(String identifier, String name, IDictionary<CoordinateOperationParameter, Object> parameters,
                                GeographicCoordinateReferenceSystem source, GeographicCoordinateReferenceSystem target, AreaOfUse areaOfUse)
     : this(identifier, name, null, null, parameters, source, target, areaOfUse)
 {
 }
コード例 #13
0
        /// <summary>
        /// Computes the Geodetic coordinate reference system for the geo-key directory.
        /// </summary>
        /// <param name="geoKeyDirectory">The geo-key directory.</param>
        /// <param name="referenceSystem">The reference system.</param>
        private void ComputeGeodeticCoordinateReferenceSystem(GeoKeyDirectory geoKeyDirectory, GeographicCoordinateReferenceSystem referenceSystem)
        {
            if (!geoKeyDirectory.ContainsKey(GeoKey.ModelType))
            {
                geoKeyDirectory.Add(GeoKey.ModelType, (Int16)2);
            }

            if (referenceSystem.Identifier != IdentifiedObject.UserDefinedIdentifier)
            {
                geoKeyDirectory.Add(GeoKey.GeodeticCoordinateReferenceSystemType, (Int16)referenceSystem.Code);
                return;
            }

            // user-defined reference system
            geoKeyDirectory.Add(GeoKey.GeodeticCoordinateReferenceSystemType, Int16.MaxValue);

            // TODO: process user-defined reference system
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ForwardGeographicCoordinateTransformationStrategy" /> class.
 /// </summary>
 /// <param name="source">The source reference system.</param>
 /// <param name="target">The target reference system.</param>
 /// <param name="transformation">The geographic transformation.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The source reference system is null.
 /// or
 /// The target reference system is null.
 /// or
 /// The transformation is null.
 /// </exception>
 public ForwardGeographicCoordinateTransformationStrategy(GeographicCoordinateReferenceSystem source, GeographicCoordinateReferenceSystem target, CoordinateTransformation <GeoCoordinate> transformation)
 {
     this.source         = source ?? throw new ArgumentNullException(nameof(source));
     this.target         = target ?? throw new ArgumentNullException(nameof(target));
     this.transformation = transformation ?? throw new ArgumentNullException(nameof(transformation));
 }