public static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid) { ParameterList parameterList = new ParameterList(); for(int i=0; i< projection.NumParameters; i++) { ProjectionParameter param = projection.GetParameter(i); parameterList.Add(param.Name,param.Value); } parameterList.Add("semi_major",ellipsoid.SemiMajorAxis); parameterList.Add("semi_minor",ellipsoid.SemiMinorAxis); IMathTransform transform = null; switch(projection.Name.ToLower()) { case "mercator": //1SP transform = new MercatorProjection(parameterList); break; case "transverse_mercator": transform = new TransverseMercatorProjection(parameterList); break; case "albers": transform = new AlbersProjection(parameterList); break; case "lambert": transform = new LambertConformalConic2SPProjection(parameterList); break; default: throw new NotSupportedException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Projection {0} is not supported.",projection.AuthorityCode)); } return transform; }
public void Test_Test1() { ParameterList paramList = new ParameterList(); paramList.Add("central_meridian",34.0); double centralMeridian1 = paramList.GetDouble("central_meridian"); Assertion.AssertEquals("Get 1",34.0,centralMeridian1); double centralMeridian2 = paramList.GetDouble("central_meridianmissing",4.0); Assertion.AssertEquals("Get 1",4.0,centralMeridian2); }
protected MapProjection( ParameterList parameters) { _parameters = parameters; //todo. Should really convert to the correct linear units?? this._semiMajor = _parameters.GetDouble("semi_major"); this._semiMinor = _parameters.GetDouble("semi_minor"); this._isSpherical = (_semiMajor == _semiMinor); this._es = 1.0 - (_semiMinor * _semiMinor ) / ( _semiMajor * _semiMajor); this._e = Math.Sqrt(_es); }
/// <summary> /// Initializes the MercatorProjection object with the specified parameters. /// </summary> /// <param name="parameters">List of parameters to initialize the projection.</param> /// <param name="isInverse">Indicates whether the projection forward (meters to degrees or degrees to meters).</param> /// <remarks> /// <para>The parameters this projection expects are listed below.</para> /// <list type="table"> /// <listheader><term>Items</term><description>Descriptions</description></listheader> /// <item><term>longitude_of_natural_origin</term><description>The longitude of the point from which the values of both the geographical coordinates on the ellipsoid and the grid coordinates on the projection are deemed to increment or decrement for computational purposes. Alternatively it may be considered as the longitude of the point which in the absence of application of false coordinates has grid coordinates of (0,0). Sometimes known as ""central meridian""."</description></item> /// <item><term>latitude_of_natural_origin</term><description>The latitude of the point from which the values of both the geographical coordinates on the ellipsoid and the grid coordinates on the projection are deemed to increment or decrement for computational purposes. Alternatively it may be considered as the latitude of the point which in the absence of application of false coordinates has grid coordinates of (0,0).</description></item> /// <item><term>scale_factor_at_natural_origin</term><description>The factor by which the map grid is reduced or enlarged during the projection process, defined by its value at the natural origin.</description></item> /// <item><term>false_easting</term><description>Since the natural origin may be at or near the centre of the projection and under normal coordinate circumstances would thus give rise to negative coordinates over parts of the mapped area, this origin is usually given false coordinates which are large enough to avoid this inconvenience. The False Easting, FE, is the easting value assigned to the abscissa (east).</description></item> /// <item><term>false_northing</term><description>Since the natural origin may be at or near the centre of the projection and under normal coordinate circumstances would thus give rise to negative coordinates over parts of the mapped area, this origin is usually given false coordinates which are large enough to avoid this inconvenience. The False Northing, FN, is the northing value assigned to the ordinate .</description></item> /// </list> /// </remarks> public MercatorProjection(ParameterList parameters, bool isInverse) : base(parameters,isInverse) { lon_center = Degrees2Radians( _parameters.GetDouble("longitude_of_natural_origin") ); lat_origin = Degrees2Radians( _parameters.GetDouble("latitude_of_natural_origin") ); _scaleFactor = _parameters.GetDouble("scale_factor_at_natural_origin"); _falseEasting = _parameters.GetDouble("false_easting"); _falseNorthing = _parameters.GetDouble("false_northing"); //double temp = r_minor / r_major; double temp = this._semiMinor / this._semiMajor; es = 1.0 - temp*temp; e = Math.Sqrt(es); m1 = Math.Cos(lat_origin)/(Math.Sqrt(1.0 - es * Math.Sin(lat_origin) * Math.Sin(lat_origin))); }
public void Test_Constructor() { ParameterList parameters = new ParameterList(); parameters.Add("latitude_of_natural_origin",49.0); parameters.Add("longitude_of_natural_origin",-2.0); parameters.Add("scale_factor_at_natural_origin",0.999601272); parameters.Add("false_easting",400000.0); parameters.Add("false_northing",-100000.0); parameters.Add("semi_major",6377563.396); parameters.Add("semi_minor",6377563.396); TransverseMercatorProjection meractor = new TransverseMercatorProjection(parameters); double long1 = -2.0; double lat1 = 49.0; CoordinatePoint pt = new CoordinatePoint(); pt.Ord = new Double[2]; pt.Ord.SetValue(long1,0); pt.Ord.SetValue(lat1,1); CoordinatePoint result1 = meractor.Transform(pt); double metersX = (double)result1.Ord[0]; double metersY = (double)result1.Ord[1]; Assertion.AssertEquals("Transverse Mercator Transform X","400000",metersX.ToString()); Assertion.AssertEquals("Transverse Mercator Transform Y","-100000",metersY.ToString()); CoordinatePoint result2 = meractor.GetInverse().Transform(result1); double long2= (double)result2.Ord[0]; double lat2= (double)result2.Ord[1]; Assertion.AssertEquals("Transverse Mercator InverseTransformPoint X","-2",long2.ToString()); Assertion.AssertEquals("TransverseMercator InverseTransformPoint Y","49",lat2.ToString()); }
/// <summary> /// Initializes the MercatorProjection object with the specified parameters to project points. /// </summary> /// <param name="parameters">ParaemterList with the required parameters.</param> /// <remarks> /// </remarks> public MercatorProjection(ParameterList parameters) : this(parameters,false) { }
/// <summary> /// Given a IProjection and a IEllipsoid, createa a IMathTransform with the required parameters. /// </summary> /// <param name="projection">The projection information.</param> /// <param name="ellipsoid">The ellipsoid to use.</param> /// <returns>An object that implements the IMathTransform interface.</returns> private IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid) { ParameterList parameterList = new ParameterList(); for(int i=0; i< projection.NumParameters; i++) { ProjectionParameter param = projection.GetParameter(i); parameterList.Add(param.Name,param.Value); } parameterList.Add("semi_major",ellipsoid.SemiMajorAxis); parameterList.Add("semi_minor",ellipsoid.SemiMinorAxis); IMathTransform transform = null; switch(projection.AuthorityCode) { case "9804": //1SP transform = new MercatorProjection(parameterList); break; case "9805": //2SP transform = new MercatorProjection(parameterList); break; case "9807": transform = new TransverseMercatorProjection(parameterList); break; case "9633": // we should get these parameters from the file - but since we know them.... ParameterList param = new ParameterList(); parameterList.Add("latitude_of_natural_origin",49.0); parameterList.Add("longitude_of_natural_origin",-2.0); parameterList.Add("scale_factor_at_natural_origin",0.999601272); parameterList.Add("false_easting",400000.0); parameterList.Add("false_northing",-100000.0); transform = new MercatorProjection(parameterList); break; default: throw new NotSupportedException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Projection {0} is not supported.",projection.AuthorityCode)); } return transform; }
/// <summary> /// Creates an instance of an Albers projection object. /// </summary> /// <remarks> /// <para>The parameters this projection expects are listed below.</para> /// <list type="table"> /// <listheader><term>Items</term><description>Descriptions</description></listheader> /// <item><term>latitude_of_false_origin</term><description>The latitude of the point which is not the natural origin and at which grid coordinate values false easting and false northing are defined.</description></item> /// <item><term>longitude_of_false_origin</term><description>The longitude of the point which is not the natural origin and at which grid coordinate values false easting and false northing are defined.</description></item> /// <item><term>latitude_of_1st_standard_parallel</term><description>For a conic projection with two standard parallels, this is the latitude of intersection of the cone with the ellipsoid that is nearest the pole. Scale is true along this parallel.</description></item> /// <item><term>latitude_of_2nd_standard_parallel</term><description>For a conic projection with two standard parallels, this is the latitude of intersection of the cone with the ellipsoid that is furthest from the pole. Scale is true along this parallel.</description></item> /// <item><term>easting_at_false_origin</term><description>The easting value assigned to the false origin.</description></item> /// <item><term>northing_at_false_origin</term><description>The northing value assigned to the false origin.</description></item> /// </list> /// </remarks> /// <param name="parameters">List of parameters to initialize the projection.</param> /// <param name="isInverse">Indicates whether the projection forward (meters to degrees or degrees to meters).</param> public LambertConformalConic2SPProjection(ParameterList parameters, bool isInverse) : base(parameters,isInverse) { double c_lat = Degrees2Radians(_parameters.GetDouble("latitude_of_false_origin")); double c_lon = Degrees2Radians(_parameters.GetDouble("longitude_of_false_origin")); double lat1 = Degrees2Radians(_parameters.GetDouble("latitude_of_1st_standard_parallel")); double lat2 = Degrees2Radians(_parameters.GetDouble("latitude_of_2nd_standard_parallel")); this._falseEasting = _parameters.GetDouble("easting_at_false_origin"); this._falseNorthing = _parameters.GetDouble("northing_at_false_origin"); double sin_po; /* sin value */ double cos_po; /* cos value */ double con; /* temporary variable */ double ms1; /* small m 1 */ double ms2; /* small m 2 */ double temp; /* temporary variable */ double ts0; /* small t 0 */ double ts1; /* small t 1 */ double ts2; /* small t 2 */ /* Standard Parallels cannot be equal and on opposite sides of the equator ------------------------------------------------------------------------*/ if (Math.Abs(lat1+lat2) < EPSLN) { //Debug.Assert(true,"LambertConformalConic:LambertConformalConic() - Equal Latitiudes for St. Parallels on opposite sides of equator"); throw new ArgumentException("Equal Latitiudes for St. Parallels on opposite sides of equator."); } temp = this._semiMinor / this._semiMajor; es = 1.0 - SQUARE(temp); e = Math.Sqrt(es); center_lon = c_lon; center_lat = c_lat; sincos(lat1,out sin_po,out cos_po); con = sin_po; ms1 = msfnz(e,sin_po,cos_po); ts1 = tsfnz(e,lat1,sin_po); sincos(lat2,out sin_po,out cos_po); ms2 = msfnz(e,sin_po,cos_po); ts2 = tsfnz(e,lat2,sin_po); sin_po = Math.Sin(center_lat); ts0 = tsfnz(e,center_lat,sin_po); if (Math.Abs(lat1 - lat2) > EPSLN) ns = Math.Log(ms1/ms2)/ Math.Log (ts1/ts2); else ns = con; f0 = ms1 / (ns * Math.Pow(ts1,ns)); rh = this._semiMajor * f0 * Math.Pow(ts0,ns); }
/// <summary> /// Creates an instance of an LambertConformalConic2SPProjection projection object. /// </summary> /// <remarks> /// <para>The parameters this projection expects are listed below.</para> /// <list type="table"> /// <listheader><term>Items</term><description>Descriptions</description></listheader> /// <item><term>latitude_of_false_origin</term><description>The latitude of the point which is not the natural origin and at which grid coordinate values false easting and false northing are defined.</description></item> /// <item><term>longitude_of_false_origin</term><description>The longitude of the point which is not the natural origin and at which grid coordinate values false easting and false northing are defined.</description></item> /// <item><term>latitude_of_1st_standard_parallel</term><description>For a conic projection with two standard parallels, this is the latitude of intersection of the cone with the ellipsoid that is nearest the pole. Scale is true along this parallel.</description></item> /// <item><term>latitude_of_2nd_standard_parallel</term><description>For a conic projection with two standard parallels, this is the latitude of intersection of the cone with the ellipsoid that is furthest from the pole. Scale is true along this parallel.</description></item> /// <item><term>easting_at_false_origin</term><description>The easting value assigned to the false origin.</description></item> /// <item><term>northing_at_false_origin</term><description>The northing value assigned to the false origin.</description></item> /// </list> /// </remarks> /// <param name="parameters">List of parameters to initialize the projection.</param> public LambertConformalConic2SPProjection(ParameterList parameters) : this(parameters,false) { }
/// <summary> /// Gets projection parameters information. /// </summary> /// <param name="projectionConversionCode">The projeciton conversion code.</param> /// <returns>ParameterList with details about the projection parameters.</returns> public ParameterList GetParameters(string projectionConversionCode)//, string coordOperationMethod) { string sqlQuery="SELECT param.PARAMETER_NAME, paramValue.PARAMETER_VALUE, paramUsage.Param_Sign_Reversal "+ "FROM [Coordinate_Operation Parameter Usage] AS paramUsage, "+ " [Coordinate_Operation Parameter Value] AS paramValue, "+ " [Coordinate_Operation Parameter] AS param "+ "WHERE "+ " paramUsage.COORD_OP_METHOD_CODE = paramValue.COORD_OP_METHOD_CODE AND "+ " paramUsage.PARAMETER_CODE = paramValue.PARAMETER_CODE AND "+ " paramValue.PARAMETER_CODE = param.PARAMETER_CODE AND "+ " (paramValue.COORD_OP_CODE = {0})"; //sqlQuery = String.Format(sqlQuery,coordOperationMethod, projectionConversionCode); sqlQuery = String.Format(sqlQuery, projectionConversionCode); IDataReader reader = Database.ExecuteQuery(_databaseConnection, sqlQuery); ParameterList parameters = new ParameterList(); while (reader.Read()) { string paramNameLong = reader[0].ToString(); string paramNameShort = TranslateParamName(paramNameLong); string paramValueString = reader[1].ToString(); double paramValue = 0.0; if (paramValueString!="" && paramValueString!=null) { paramValue = double.Parse(paramValueString); } string reverse =reader[2].ToString(); // for some reason params, all params are held positive, and there is a flag to determine if params // are negative. if (reverse.ToLower()=="yes") { paramValue = paramValue * -1.0; } parameters.Add(paramNameShort, paramValue); } reader.Close(); return parameters; }
protected MapProjection( ParameterList parameters, bool isInverse) : this(parameters) { _isInverse = isInverse; }
private static IProjection ReadProjection(WktStreamTokenizer tokenizer) { //tokenizer.NextToken();// PROJECTION tokenizer.ReadToken("PROJECTION"); tokenizer.ReadToken("[");//[ string projectionName=tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken("]");//] tokenizer.ReadToken(",");//, tokenizer.ReadToken("PARAMETER"); ParameterList paramList = new ParameterList(); while (tokenizer.GetStringValue()=="PARAMETER") { tokenizer.ReadToken("["); string paramName = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); double paramValue = tokenizer.GetNumericValue(); tokenizer.ReadToken("]"); tokenizer.ReadToken(","); paramList.Add(paramName,paramValue); tokenizer.NextToken(); } ProjectionParameter[] paramArray = new ProjectionParameter[paramList.Count]; int i=0; foreach(string key in paramList.Keys) { ProjectionParameter param= new ProjectionParameter(); param.Name=key; param.Value=(double)paramList[key]; paramArray[i]=param; i++; } string authority=""; string authorityCode=""; IProjection projection = new Projection(projectionName, paramArray,"", "",authority, authorityCode); return projection; }
static double false_easting; /* x offset in meters */ //static double ind; /* spherical flag */ /// <summary> /// Creates an instance of an TransverseMercatorProjection projection object. /// </summary> /// <param name="parameters">List of parameters to initialize the projection.</param> public TransverseMercatorProjection(ParameterList parameters) : this(parameters, false) { }
/// <summary> /// Creates an instance of an Albers projection object. /// </summary> /// <param name="parameters">List of parameters to initialize the projection.</param> /// <remarks> /// <para>The parameters this projection expects are listed below.</para> /// <list type="table"> /// <listheader><term>Items</term><description>Descriptions</description></listheader> <item><term>latitude_of_false_origin</term><description>The latitude of the point which is not the natural origin and at which grid coordinate values false easting and false northing are defined.</description></item> /// <item><term>longitude_of_false_origin</term><description>The longitude of the point which is not the natural origin and at which grid coordinate values false easting and false northing are defined.</description></item> /// <item><term>latitude_of_1st_standard_parallel</term><description>For a conic projection with two standard parallels, this is the latitude of intersection of the cone with the ellipsoid that is nearest the pole. Scale is true along this parallel.</description></item> /// <item><term>latitude_of_2nd_standard_parallel</term><description>For a conic projection with two standard parallels, this is the latitude of intersection of the cone with the ellipsoid that is furthest from the pole. Scale is true along this parallel.</description></item> /// <item><term>easting_at_false_origin</term><description>The easting value assigned to the false origin.</description></item> /// <item><term>northing_at_false_origin</term><description>The northing value assigned to the false origin.</description></item> /// </list> /// </remarks> public AlbersProjection(ParameterList parameters) : this(parameters,false) { }
/// <summary> /// /// </summary> /// <param name="name">Name to give new object.</param> /// <param name="wktProjectionClass">Classification string for projection (e.g. "Transverse_Mercator").</param> /// <param name="parameters">Parameters to use for projection. A default set of parameters can /// be constructed using classification and initialized /// using a chain of SetParameter(...) calls.</param> /// <returns>A projection.</returns> public IProjection CreateProjection(string name, string wktProjectionClass, ProjectionParameter[] parameters) { if (name==null) { throw new ArgumentNullException("name"); } ParameterList parameterList = new ParameterList(); for(int i=0; i< parameters.Length; i++) { ProjectionParameter param = parameters[i]; parameterList.Add(param.Name,param.Value); } IProjection projection= null; switch (wktProjectionClass.ToLower()) { case "transverse_mercator": projection = new TransverseMercatorProjection(parameterList); break; case "mercator": projection = new MercatorProjection(parameterList); break; case "lambert_conformal_conic_2sp": projection = new LambertConformalConic2SPProjection(parameterList); break; case "albers": projection = new AlbersProjection(parameterList); break; default: throw new NotImplementedException(String.Format("The {0} projection is not supported",wktProjectionClass)); } return projection; }
/// <summary> /// Creates an instance of an Albers projection object. /// </summary> /// <remarks> /// <para>The parameters this projection expects are listed below.</para> /// <list type="table"> /// <listheader><term>Items</term><description>Descriptions</description></listheader> <item><term>latitude_of_false_origin</term><description>The latitude of the point which is not the natural origin and at which grid coordinate values false easting and false northing are defined.</description></item> /// <item><term>longitude_of_false_origin</term><description>The longitude of the point which is not the natural origin and at which grid coordinate values false easting and false northing are defined.</description></item> /// <item><term>latitude_of_1st_standard_parallel</term><description>For a conic projection with two standard parallels, this is the latitude of intersection of the cone with the ellipsoid that is nearest the pole. Scale is true along this parallel.</description></item> /// <item><term>latitude_of_2nd_standard_parallel</term><description>For a conic projection with two standard parallels, this is the latitude of intersection of the cone with the ellipsoid that is furthest from the pole. Scale is true along this parallel.</description></item> /// <item><term>easting_at_false_origin</term><description>The easting value assigned to the false origin.</description></item> /// <item><term>northing_at_false_origin</term><description>The northing value assigned to the false origin.</description></item> /// </list> /// </remarks> /// <param name="parameters">List of parameters to initialize the projection.</param> /// <param name="isInverse">Indicates whether the projection forward (meters to degrees or degrees to meters).</param> public AlbersProjection(ParameterList parameters, bool isInverse) : base(parameters,isInverse) { double sin_po,cos_po; /* sin and cos values */ double con; /* temporary variable */ double es,temp; /* eccentricity squared and temp var */ double ms1; /* small m 1 */ double ms2; /* small m 2 */ double qs0; /* small q 0 */ double qs1; /* small q 1 */ double qs2; /* small q 2 */ double lat0 = Degrees2Radians( _parameters.GetDouble("latitude_of_false_origin") ); double lon0 = Degrees2Radians( _parameters.GetDouble("longitude_of_false_origin") ); double lat1 = Degrees2Radians( _parameters.GetDouble("latitude_of_1st_standard_parallel")); double lat2 = Degrees2Radians( _parameters.GetDouble("latitude_of_2nd_standard_parallel")); this._falseEasting = _parameters.GetDouble("easting_at_false_origin"); this._falseNorthing = _parameters.GetDouble("northing_at_false_origin"); lon_center = lon0; if (Math.Abs(lat1 + lat2) < EPSLN) { throw new TransformException("Equal latitudes for St. Parallels on opposite sides of equator."); } temp = this._semiMinor / this._semiMajor; es = 1.0 - SQUARE(temp); e3 = Math.Sqrt(es); sincos(lat1,out sin_po,out cos_po); con = sin_po; ms1 = msfnz(e3,sin_po,cos_po); qs1 = qsfnz(e3,sin_po,cos_po); sincos(lat2,out sin_po,out cos_po); ms2 = msfnz(e3,sin_po,cos_po); qs2 = qsfnz(e3,sin_po,cos_po); sincos(lat0,out sin_po,out cos_po); qs0 = qsfnz(e3,sin_po,cos_po); if (Math.Abs(lat1 - lat2) > EPSLN) ns0 = (ms1 * ms1 - ms2 *ms2)/ (qs2 - qs1); else ns0 = con; c = ms1 * ms1 + ns0 * qs1; rh = this._semiMajor * Math.Sqrt(c - ns0 * qs0)/ns0; }
/// <summary> /// Creates an instance of an TransverseMercatorProjection projection object. /// </summary> /// <param name="parameters">List of parameters to initialize the projection.</param> /// <param name="inverse">Flag indicating wether is a forward/projection (false) or an inverse projection (true).</param> /// <remarks> /// <list type="bullet"> /// <listheader><term>Items</term><description>Descriptions</description></listheader> /// <item><term>semi_major</term><description>Your Description</description></item> /// <item><term>semi_minor</term><description>Your Description</description></item> /// <item><term>scale_factor_at_natural_origin</term><description>Your Description</description></item> /// <item><term>longitude_of_natural_origin</term><description>Your Description</description></item> /// <item><term>latitude_of_natural_origin</term><description>Your Description</description></item> /// <item><term>false_easting</term><description>Your Description</description></item> /// <item><term>false_northing</term><description>Your Description</description></item> /// </list> /// </remarks> public TransverseMercatorProjection(ParameterList parameters, bool inverse) : base(parameters, inverse) { double r_maj=parameters.GetDouble("semi_major"); /* major axis */ double r_min=parameters.GetDouble("semi_minor"); /* minor axis */ double scale_fact=parameters.GetDouble("scale_factor_at_natural_origin"); /* scale factor */ double center_lon=Degrees.ToRadians(parameters.GetDouble("longitude_of_natural_origin")); /* center longitude */ double center_lat=Degrees.ToRadians(parameters.GetDouble("latitude_of_natural_origin")); /* center latitude */ double false_east=parameters.GetDouble("false_easting"); /* x offset in meters */ double false_north=parameters.GetDouble("false_northing"); /* y offset in meters */ double temp; /* temporary variable */ /* Place parameters in static storage for common use -------------------------------------------------*/ r_major = r_maj; r_minor = r_min; scale_factor = scale_fact; lon_center = center_lon; lat_origin = center_lat; false_northing = false_north; false_easting = false_east; temp = r_minor / r_major; es = 1.0 - SQUARE(temp); e = Math.Sqrt(es); e0 = e0fn(es); e1 = e1fn(es); e2 = e2fn(es); e3 = e3fn(es); ml0 = r_major * mlfn(e0, e1, e2, e3, lat_origin); esp = es / (1.0 - es); }