private static void WriteProjection(IProjection projection, IndentedTextWriter writer) { writer.WriteLine(String.Format("PROJECTION[\"{0}\"],", projection.Name)); for (int i = 0; i < projection.NumParameters; i++) { string paramName = projection.GetParameter(i).Name; double paramValue = projection.GetParameter(i).Value; writer.WriteLine(String.Format("PARAMETER[\"{0}\",{1}],", paramName, paramValue)); } }
private static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid) { List<ProjectionParameter> parameterList = new List<ProjectionParameter>(projection.NumParameters); for (int i = 0; i < projection.NumParameters; i++) parameterList.Add(projection.GetParameter(i)); parameterList.Add(new ProjectionParameter("semi_major", ellipsoid.SemiMajorAxis)); parameterList.Add(new ProjectionParameter("semi_minor", ellipsoid.SemiMinorAxis)); IMathTransform transform = null; switch (projection.ClassName.ToLower()) { case "mercator_1sp": case "mercator_2sp": //1SP transform = new Mercator(parameterList); break; case "transverse_mercator": transform = new TransverseMercator(parameterList); break; case "albers": transform = new AlbersProjection(parameterList); break; case "lambert_conformal_conic": case "lambert_conformal_conic_2sp": transform = new LambertConformalConic2SP(parameterList); break; default: throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.ClassName)); } return transform; }
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; }
private static void WriteProjection(IProjection projection, XmlTextWriter writer) { writer.WriteStartElement("CS_Projection"); writer.WriteAttributeString("ClassName", projection.ClassName); WriteCSInfo(projection, writer); for (int i = 0; i < projection.NumParameters; i++) { string paramName = projection.GetParameter(i).Name; double paramValue = projection.GetParameter(i).Value; writer.WriteStartElement("CS_ProjectionParameter"); writer.WriteAttributeString("Name", paramName); writer.WriteAttributeString("Value", paramValue.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); }
private static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid) { List <ProjectionParameter> parameters = new List <ProjectionParameter>(projection.NumParameters); for (int i = 0; i < projection.NumParameters; i++) { parameters.Add(projection.GetParameter(i)); } parameters.Add(new ProjectionParameter("semi_major", ellipsoid.SemiMajorAxis)); parameters.Add(new ProjectionParameter("semi_minor", ellipsoid.SemiMinorAxis)); switch (projection.ClassName.ToLower()) { case "mercator_1sp": case "mercator_2sp": return(new Mercator(parameters)); case "transverse_mercator": return(new TransverseMercator(parameters)); case "albers": return(new AlbersProjection(parameters)); case "lambert_conformal_conic": case "lambert_conformal_conic_2sp": return(new LambertConformalConic2SP(parameters)); } throw new NotSupportedException(string.Format("Projection {0} is not supported.", projection.ClassName)); }
/// <summary> /// 构建不同的投影变换方法 /// </summary> /// <param name="projection"></param> /// <param name="ellipsoid"></param> /// <param name="unit"></param> /// <returns></returns> private static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid, ILinearUnit unit) { List <ProjectionParameter> parameterList = new List <ProjectionParameter>(projection.NumParameters); for (int i = 0; i < projection.NumParameters; i++) { parameterList.Add(projection.GetParameter(i)); } parameterList.Add(new ProjectionParameter("semi_major", ellipsoid.SemiMajorAxis)); //长轴 parameterList.Add(new ProjectionParameter("semi_minor", ellipsoid.SemiMinorAxis)); //短轴 parameterList.Add(new ProjectionParameter("unit", unit.MetersPerUnit)); //单位弧度 IMathTransform transform = null; switch (projection.ClassName.ToLower(CultureInfo.InvariantCulture).Replace(' ', '_')) { case "mercator": case "mercator_1sp": case "mercator_2sp": //1SP transform = new Mercator(parameterList); break; case "transverse_mercator": transform = new TransverseMercator(parameterList); break; case "gauss_kruger": //高斯克吕格投影 transform = new GaussKrugerProjection(parameterList); break; case "albers": case "albers_conic_equal_area": transform = new AlbersProjection(parameterList); break; case "krovak": transform = new KrovakProjection(parameterList); break; case "lambert_conformal_conic": case "lambert_conformal_conic_2sp": case "lambert_conic_conformal_(2sp)": transform = new LambertConformalConic2SP(parameterList); break; default: throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.ClassName)); } 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); }
private static void CheckProjection(IProjection projection, string name, IList <Tuple <string, double> > pp = null, string authority = null, long?code = null) { Assert.That(projection, Is.Not.Null, "Projection not null"); Assert.That(projection.ClassName, Is.EqualTo(name), "Projection class name"); CheckInfo(projection, name, authority, code); if (pp == null) { return; } Assert.That(projection.NumParameters, Is.EqualTo(pp.Count), "Number of projection parameters"); for (int i = 0; i < pp.Count; i++) { ProjectionParameter par = null; Assert.That(() => par = projection.GetParameter(pp[i].Item1), Throws.Nothing, $"Getting projection parameter '{pp[i].Item1}' throws."); Assert.That(par, Is.Not.Null, $"Projection parameter '{pp[i].Item1}' is null"); Assert.That(par.Name, Is.EqualTo(pp[i].Item1), $"Projection parameter '{par.Name}' name is not '{pp[i].Item1}'."); Assert.That(par.Value, Is.EqualTo(pp[i].Item2), $"Projection parameter value for '{par.Name}' name ({par.Value:R}) is not '{pp[i].Item2:R}'."); } }
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(System.Globalization.CultureInfo.InvariantCulture, "Projection {0} is not supported.",projection.AuthorityCode)); } return transform; }
private static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid, ILinearUnit unit) { List<ProjectionParameter> parameterList = new List<ProjectionParameter>(projection.NumParameters); for (int i = 0; i < projection.NumParameters; i++) parameterList.Add(projection.GetParameter(i)); parameterList.Add(new ProjectionParameter("semi_major", ellipsoid.SemiMajorAxis)); parameterList.Add(new ProjectionParameter("semi_minor", ellipsoid.SemiMinorAxis)); parameterList.Add(new ProjectionParameter("unit", unit.MetersPerUnit)); IMathTransform transform = null; switch (projection.ClassName.ToLower(CultureInfo.InvariantCulture).Replace(' ', '_')) { case "mercator": case "mercator_1sp": case "mercator_2sp": //1SP transform = new Mercator(parameterList); break; case "transverse_mercator": transform = new TransverseMercator(parameterList); break; case "albers": case "albers_conic_equal_area": transform = new AlbersProjection(parameterList); break; case "krovak": transform = new KrovakProjection(parameterList); break; case "lambert_conformal_conic": case "lambert_conformal_conic_2sp": case "lambert_conic_conformal_(2sp)": transform = new LambertConformalConic2SP(parameterList); break; default: throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.ClassName)); } return transform; }
private static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid, ILinearUnit unit) { var parameterList = new List <ProjectionParameter>(projection.NumParameters); for (var i = 0; i < projection.NumParameters; i++) { parameterList.Add(projection.GetParameter(i)); } //var toMeter = 1d/ellipsoid.AxisUnit.MetersPerUnit; if (parameterList.Find((p) => p.Name.ToLowerInvariant().Replace(' ', '_').Equals("semi_major")) == null) { parameterList.Add(new ProjectionParameter("semi_major", /*toMeter * */ ellipsoid.SemiMajorAxis)); } if (parameterList.Find((p) => p.Name.ToLowerInvariant().Replace(' ', '_').Equals("semi_minor")) == null) { parameterList.Add(new ProjectionParameter("semi_minor", /*toMeter * */ ellipsoid.SemiMinorAxis)); } if (parameterList.Find((p) => p.Name.ToLowerInvariant().Replace(' ', '_').Equals("unit")) == null) { parameterList.Add(new ProjectionParameter("unit", unit.MetersPerUnit)); } var operation = ProjectionsRegistry.CreateProjection(projection.ClassName, parameterList); /* * var mpOperation = operation as MapProjection; * if (mpOperation != null && projection.AuthorityCode !=-1) * { * mpOperation.Authority = projection.Authority; * mpOperation.AuthorityCode = projection.AuthorityCode; * } */ return(operation); /* * switch (projection.ClassName.ToLower(CultureInfo.InvariantCulture).Replace(' ', '_')) * { * case "mercator": * case "mercator_1sp": * case "mercator_2sp": * //1SP * transform = new Mercator(parameterList); * break; * case "transverse_mercator": * transform = new TransverseMercator(parameterList); * break; * case "albers": * case "albers_conic_equal_area": * transform = new AlbersProjection(parameterList); * break; * case "krovak": * transform = new KrovakProjection(parameterList); * break; * case "polyconic": * transform = new PolyconicProjection(parameterList); * break; * case "lambert_conformal_conic": * case "lambert_conformal_conic_2sp": * case "lambert_conic_conformal_(2sp)": * transform = new LambertConformalConic2SP(parameterList); * break; * default: * throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.ClassName)); * } * return transform; */ }
private static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid, ILinearUnit unit) { var parameterList = new List<ProjectionParameter>(projection.NumParameters); for (var i = 0; i < projection.NumParameters; i++) parameterList.Add(projection.GetParameter(i)); //var toMeter = 1d/ellipsoid.AxisUnit.MetersPerUnit; if (parameterList.Find((p) => p.Name.ToLowerInvariant().Replace(' ', '_').Equals("semi_major")) == null) parameterList.Add(new ProjectionParameter("semi_major", /*toMeter * */ellipsoid.SemiMajorAxis)); if (parameterList.Find((p) => p.Name.ToLowerInvariant().Replace(' ', '_').Equals("semi_minor")) == null) parameterList.Add(new ProjectionParameter("semi_minor", /*toMeter * */ellipsoid.SemiMinorAxis)); if (parameterList.Find((p) => p.Name.ToLowerInvariant().Replace(' ', '_').Equals("unit")) == null) parameterList.Add(new ProjectionParameter("unit", unit.MetersPerUnit)); var operation = ProjectionsRegistry.CreateProjection(projection.ClassName, parameterList); /* var mpOperation = operation as MapProjection; if (mpOperation != null && projection.AuthorityCode !=-1) { mpOperation.Authority = projection.Authority; mpOperation.AuthorityCode = projection.AuthorityCode; } */ return operation; /* switch (projection.ClassName.ToLower(CultureInfo.InvariantCulture).Replace(' ', '_')) { case "mercator": case "mercator_1sp": case "mercator_2sp": //1SP transform = new Mercator(parameterList); break; case "transverse_mercator": transform = new TransverseMercator(parameterList); break; case "albers": case "albers_conic_equal_area": transform = new AlbersProjection(parameterList); break; case "krovak": transform = new KrovakProjection(parameterList); break; case "polyconic": transform = new PolyconicProjection(parameterList); break; case "lambert_conformal_conic": case "lambert_conformal_conic_2sp": case "lambert_conic_conformal_(2sp)": transform = new LambertConformalConic2SP(parameterList); break; default: throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.ClassName)); } return transform; */ }
private static void WriteProjection(IProjection projection, IndentedTextWriter writer) { writer.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "PROJECTION[\"{0}\"],",projection.Name)); for (int i=0;i<projection.NumParameters; i++) { string paramName = projection.GetParameter(i).Name; double paramValue = projection.GetParameter(i).Value; writer.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "PARAMETER[\"{0}\",{1}],",paramName,paramValue)); } }