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); }
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("Projection {0} is not supported.", projection.AuthorityCode)); } return(transform); }
/// <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("Projection {0} is not supported.", projection.AuthorityCode)); } return(transform); }
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> /// 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> /// /// </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> /// 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; }
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; }