/// <summary> /// The function convertToGeodetic converts UPS (hemisphere, easting, /// and northing) coordinates to geodetic (latitude and longitude) coordinates /// according to the current ellipsoid parameters. If any errors occur, an /// exception is thrown with a description of the error. /// </summary> /// <param name="upsCoordinates"></param> /// <returns></returns> public GeodeticCoordinates convertToGeodetic(UPSCoordinates upsCoordinates) { /* * hemisphere : Hemisphere either 'N' or 'S' (input) * easting : Easting/X in meters (input) * northing : Northing/Y in meters (input) * latitude : Latitude in radians (output) * longitude : Longitude in radians (output) */ string errorStatus = ""; char hemisphere = upsCoordinates.getHemisphere(); double easting = upsCoordinates.getEasting(); double northing = upsCoordinates.getNorthing(); if ((hemisphere != 'N') && (hemisphere != 'S')) { errorStatus += ErrorMessages.hemisphere; } if ((easting < MIN_EAST_NORTH) || (easting > MAX_EAST_NORTH)) { errorStatus += ErrorMessages.easting; } if ((northing < MIN_EAST_NORTH) || (northing > MAX_EAST_NORTH)) { errorStatus += ErrorMessages.northing; } //this.UPS_Origin_Latitude = MAX_ORIGIN_LAT; //if (hemisphere == 'N') //{ // UPS_Origin_Latitude = MAX_ORIGIN_LAT; //} //else if (hemisphere == 'S') //{ // UPS_Origin_Latitude = -MAX_ORIGIN_LAT; //} if (errorStatus.Length > 0) { throw new ArgumentException(errorStatus); } PolarStereographic polarStereographic = new PolarStereographic(this.semiMajorAxis, this.flattening, this.UPS_Origin_Longitude, 0.994, hemisphere, this.UPS_False_Easting, this.UPS_False_Northing); GeodeticCoordinates geodeticCoordinates = polarStereographic.convertToGeodetic(new MapProjectionCoordinates(CoordinateType.Enum.polarStereographicStandardParallel, easting, northing)); double latitude = geodeticCoordinates.latitude; if ((latitude < 0) && (latitude >= (MAX_SOUTH_LAT + EPSILON))) { throw new ArgumentException(ErrorMessages.latitude); } if ((latitude >= 0) && (latitude < (MIN_NORTH_LAT - EPSILON))) { throw new ArgumentException(ErrorMessages.latitude); } return(geodeticCoordinates); }
/// <summary> /// The function convertFromGeodetic converts geodetic (latitude and /// longitude) coordinates to UPS (hemisphere, easting, and northing) /// coordinates, according to the current ellipsoid parameters. /// If any errors occur, an exception is thrown with a description /// of the error. /// </summary> /// <param name="geodeticCoordinates"></param> /// <returns></returns> public UPSCoordinates convertFromGeodetic(GeodeticCoordinates geodeticCoordinates) { /* * latitude : Latitude in radians (input) * longitude : Longitude in radians (input) * hemisphere : Hemisphere either 'N' or 'S' (output) * easting : Easting/X in meters (output) * northing : Northing/Y in meters (output) */ char hemisphere; string errorStatus = ""; double longitude = geodeticCoordinates.longitude; double latitude = geodeticCoordinates.latitude; if ((latitude < -MAX_LAT) || (latitude > MAX_LAT)) { /* latitude out of range */ errorStatus += ErrorMessages.latitude; } else if ((latitude < 0) && (latitude >= (MAX_SOUTH_LAT + EPSILON))) { errorStatus += ErrorMessages.latitude; } else if ((latitude >= 0) && (latitude < (MIN_NORTH_LAT - EPSILON))) { errorStatus += ErrorMessages.latitude; } if ((longitude < -Math.PI) || (longitude > (2 * Math.PI))) { /* longitude out of range */ errorStatus += ErrorMessages.longitude; } if (errorStatus.Length > 0) { throw new ArgumentException(errorStatus); } if (latitude < 0) { //this.UPS_Origin_Latitude = -MAX_ORIGIN_LAT; hemisphere = 'S'; } else { //this.UPS_Origin_Latitude = MAX_ORIGIN_LAT; hemisphere = 'N'; } PolarStereographic polarStereographic = new PolarStereographic(this.semiMajorAxis, this.flattening, this.UPS_Origin_Longitude, 0.994, hemisphere, this.UPS_False_Easting, this.UPS_False_Northing); MapProjectionCoordinates polarStereographicCoordinates = polarStereographic.convertFromGeodetic(geodeticCoordinates); double easting = polarStereographicCoordinates.getEasting(); double northing = polarStereographicCoordinates.getNorthing(); return(new UPSCoordinates(CoordinateType.Enum.universalPolarStereographic, hemisphere, easting, northing)); }
/// <summary> /// The function convertFromGeodetic converts geodetic (latitude and /// longitude) coordinates to UPS (hemisphere, easting, and northing) /// coordinates, according to the current ellipsoid parameters. /// If any errors occur, an exception is thrown with a description /// of the error. /// </summary> /// <param name="geodeticCoordinates"></param> /// <returns></returns> public UPSCoordinates convertFromGeodetic(GeodeticCoordinates geodeticCoordinates) { /* * latitude : Latitude in radians (input) * longitude : Longitude in radians (input) * hemisphere : Hemisphere either 'N' or 'S' (output) * easting : Easting/X in meters (output) * northing : Northing/Y in meters (output) */ char hemisphere; string errorStatus = ""; double longitude = geodeticCoordinates.longitude; double latitude = geodeticCoordinates.latitude; if ((latitude < -MAX_LAT) || (latitude > MAX_LAT)) { /* latitude out of range */ errorStatus += ErrorMessages.latitude; } else if ((latitude < 0) && (latitude >= (MAX_SOUTH_LAT + EPSILON))) { errorStatus += ErrorMessages.latitude; } else if ((latitude >= 0) && (latitude < (MIN_NORTH_LAT - EPSILON))) { errorStatus += ErrorMessages.latitude; } if ((longitude < -Math.PI) || (longitude > (2 * Math.PI))) { /* longitude out of range */ errorStatus += ErrorMessages.longitude; } if (errorStatus.Length > 0) { throw new ArgumentException(errorStatus); } if (latitude < 0) { //this.UPS_Origin_Latitude = -MAX_ORIGIN_LAT; hemisphere = 'S'; } else { //this.UPS_Origin_Latitude = MAX_ORIGIN_LAT; hemisphere = 'N'; } PolarStereographic polarStereographic = new PolarStereographic(this.semiMajorAxis, this.flattening, this.UPS_Origin_Longitude, 0.994, hemisphere, this.UPS_False_Easting, this.UPS_False_Northing); MapProjectionCoordinates polarStereographicCoordinates = polarStereographic.convertFromGeodetic(geodeticCoordinates); double easting = polarStereographicCoordinates.getEasting(); double northing = polarStereographicCoordinates.getNorthing(); return new UPSCoordinates(CoordinateType.Enum.universalPolarStereographic, hemisphere, easting, northing); }
/// <summary> /// The function convertToGeodetic converts UPS (hemisphere, easting, /// and northing) coordinates to geodetic (latitude and longitude) coordinates /// according to the current ellipsoid parameters. If any errors occur, an /// exception is thrown with a description of the error. /// </summary> /// <param name="upsCoordinates"></param> /// <returns></returns> public GeodeticCoordinates convertToGeodetic(UPSCoordinates upsCoordinates) { /* * hemisphere : Hemisphere either 'N' or 'S' (input) * easting : Easting/X in meters (input) * northing : Northing/Y in meters (input) * latitude : Latitude in radians (output) * longitude : Longitude in radians (output) */ string errorStatus = ""; char hemisphere = upsCoordinates.getHemisphere(); double easting = upsCoordinates.getEasting(); double northing = upsCoordinates.getNorthing(); if ((hemisphere != 'N') && (hemisphere != 'S')) { errorStatus += ErrorMessages.hemisphere; } if ((easting < MIN_EAST_NORTH) || (easting > MAX_EAST_NORTH)) { errorStatus += ErrorMessages.easting; } if ((northing < MIN_EAST_NORTH) || (northing > MAX_EAST_NORTH)) { errorStatus += ErrorMessages.northing; } //this.UPS_Origin_Latitude = MAX_ORIGIN_LAT; //if (hemisphere == 'N') //{ // UPS_Origin_Latitude = MAX_ORIGIN_LAT; //} //else if (hemisphere == 'S') //{ // UPS_Origin_Latitude = -MAX_ORIGIN_LAT; //} if (errorStatus.Length > 0) { throw new ArgumentException(errorStatus); } PolarStereographic polarStereographic = new PolarStereographic(this.semiMajorAxis, this.flattening, this.UPS_Origin_Longitude, 0.994, hemisphere, this.UPS_False_Easting, this.UPS_False_Northing); GeodeticCoordinates geodeticCoordinates = polarStereographic.convertToGeodetic(new MapProjectionCoordinates(CoordinateType.Enum.polarStereographicStandardParallel, easting, northing)); double latitude = geodeticCoordinates.latitude; if ((latitude < 0) && (latitude >= (MAX_SOUTH_LAT + EPSILON))) { throw new ArgumentException(ErrorMessages.latitude); } if ((latitude >= 0) && (latitude < (MIN_NORTH_LAT - EPSILON))) { throw new ArgumentException(ErrorMessages.latitude); } return geodeticCoordinates; }