/// <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."); }
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); } }
/// <summary> /// Initializes a new instance of the <see cref="ProjectionReverseStrategy" /> class. /// </summary> /// <param name="source">The source reference system.</param> /// <exception cref="System.ArgumentNullException">The source coordinate reference system is null.</exception> public ReverseProjectionStrategy(ProjectedCoordinateReferenceSystem source) { if (source == null) { throw new ArgumentNullException("source", "The source reference system is null."); } _source = source; _projection = source.Projection; }
/// <summary> /// Initializes a new instance of the <see cref="ForwardProjectionStrategy" /> class. /// </summary> /// <param name="target">The target reference system.</param> /// <exception cref="System.ArgumentNullException">target;The target coordinate reference system is null.</exception> public ForwardProjectionStrategy(ProjectedCoordinateReferenceSystem target) { if (target == null) { throw new ArgumentNullException("target", "The target reference system is null."); } _target = target; _projection = target.Projection; }
/// <summary> /// Initializes a new instance of the <see cref="ForwardCoordinateProjectionStrategy" /> class. /// </summary> /// <param name="target">The target reference system.</param> /// <exception cref="System.ArgumentNullException">The reference system is null.</exception> public ForwardCoordinateProjectionStrategy(ProjectedCoordinateReferenceSystem target) { this.target = target ?? throw new ArgumentNullException(nameof(target)); }
/// <summary> /// Computes the projected 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 ComputeProjectedCoordinateReferenceSystem(GeoKeyDirectory geoKeyDirectory, ProjectedCoordinateReferenceSystem referenceSystem) { geoKeyDirectory.Add(GeoKey.ModelType, (Int16)1); if (referenceSystem.Identifier != IdentifiedObject.UserDefinedIdentifier) { geoKeyDirectory.Add(GeoKey.ProjectedCoordinateReferenceSystemType, (Int16)referenceSystem.Code); // ProjectedCSTypeGeoKey return; } // user-defined reference system geoKeyDirectory.Add(GeoKey.ProjectedCoordinateReferenceSystemType, Int16.MaxValue); ComputeGeodeticCoordinateReferenceSystem(geoKeyDirectory, referenceSystem.Base); ComputeCoordinateProjection(geoKeyDirectory, referenceSystem.Projection); }
/// <summary> /// Initializes a new instance of the <see cref="ReverseCoordinateProjectionStrategy" /> class. /// </summary> /// <param name="source">The source reference system.</param> /// <exception cref="System.ArgumentNullException">The reference system is null.</exception> public ReverseCoordinateProjectionStrategy(ProjectedCoordinateReferenceSystem source) { this.source = source ?? throw new ArgumentNullException(nameof(source)); }