private static void WriteGeographicCoordinateSystem(GeographicCoordinateSystem geogrCoordSystem) { // +proj=longlat +ellps=clrk80 +towgs84=-294.7,-200.1,525.5,0,0,0,0 +no_defs #region Ellipsoid Ellipsoid ellipsoid = geogrCoordSystem.HorizontalDatum.Ellipsoid; double majorAxis, minorAxis, invFlattening; string ellps = ProjDB.SpheroidByName(ellipsoid.Name, out majorAxis, out minorAxis, out invFlattening); if (ellps != String.Empty && majorAxis == ellipsoid.SemiMajorAxis && minorAxis == ellipsoid.SemiMinorAxis) { _p4parameters.Add(new P4Parameter("+ellps", ellps)); } else { _p4parameters.Add(new P4Parameter("+a", ellipsoid.SemiMajorAxis.ToString(_nhi))); _p4parameters.Add(new P4Parameter("+b", ellipsoid.SemiMinorAxis.ToString(_nhi))); } #endregion #region WGS84 WGS84ConversionInfo wgs84 = geogrCoordSystem.HorizontalDatum.WGS84Parameters; if (wgs84.IsInUse) { _p4parameters.Add(new P4Parameter("+towgs84", String.Format("{0},{1},{2},{3},{4},{5},{6}", wgs84.Dx.ToString(_nhi), wgs84.Dy.ToString(_nhi), wgs84.Dz.ToString(_nhi), wgs84.Ex.ToString(_nhi), wgs84.Ey.ToString(_nhi), wgs84.Ez.ToString(_nhi), wgs84.Ppm.ToString(_nhi)))); } #endregion }
public GeodeticDatum(string name) { ProjDB db = new ProjDB(ProjDBTables.datums); Parameter = db.GetDatumParameters(name); db.Dispose(); Name = name; }
private static void WriteProjectedCoordinateSystem(ProjectedCoordinateSystem projCoordSystem) { string projP4 = ProjDB.ProjectionP4ByName(projCoordSystem.Projection.Name); if (projP4 == String.Empty) { throw new NotImplementedException("Unknown projection " + projCoordSystem.Projection.Name); } _p4parameters.Add(new P4Parameter("+proj", projP4)); WriteGeographicCoordinateSystem(projCoordSystem.GeographicCoordinateSystem); for (int i = 0; i < projCoordSystem.Projection.NumParameters; i++) { ProjectionParameter projParameter = projCoordSystem.Projection.GetParameter(i); switch (projParameter.Name.ToLower()) { case "latitude_of_origin": case "latitude_of_center": _p4parameters.Add(new P4Parameter("+lat_0", projParameter.Value.ToString(_nhi))); break; case "central_meridian": case "longitude_of_origin": case "longitude_of_center": _p4parameters.Add(new P4Parameter("+lon_0", projParameter.Value.ToString(_nhi))); break; case "scale_factor": _p4parameters.Add(new P4Parameter("+k", projParameter.Value.ToString(_nhi))); break; case "false_easting": _p4parameters.Add(new P4Parameter("+x_0", projParameter.Value.ToString(_nhi))); break; case "false_northing": _p4parameters.Add(new P4Parameter("+y_0", projParameter.Value.ToString(_nhi))); break; case "azimuth": _p4parameters.Add(new P4Parameter("+alpha", projParameter.Value.ToString(_nhi))); break; case "standard_parallel_1": _p4parameters.Add(new P4Parameter("+lat_1", projParameter.Value.ToString(_nhi))); break; case "standard_parallel_2": _p4parameters.Add(new P4Parameter("+lat_2", projParameter.Value.ToString(_nhi))); break; } } }
private static Ellipsoid ReadEllipsoid(string [] parameters, LinearUnit unit) { string ellps = ParameterValue(parameters, "+ellps"); if (ellps != null) { double majorAxis, minorAxis, invFlattening; string name = ProjDB.SpheroidByP4(ellps, out majorAxis, out minorAxis, out invFlattening); if (name == String.Empty) { throw new NotSupportedException(String.Format("Ellipsoid {0} is not implemented.", ellps)); } string a = ParameterValue(parameters, "+a"); string b = ParameterValue(parameters, "+b"); if (a != null) { majorAxis = double.Parse(a); } if (b != null) { minorAxis = double.Parse(b); } if (a != null && b != null) { if (majorAxis == minorAxis) { invFlattening = 0; } else { invFlattening = minorAxis / (majorAxis - minorAxis); } } return(new Ellipsoid(majorAxis, minorAxis, invFlattening, true, unit, String.Empty, string.Empty, string.Empty, name, string.Empty, string.Empty)); } else { string a = ParameterValue(parameters, "+a"); string b = ParameterValue(parameters, "+b"); if (a != null && b != null) { return(new Ellipsoid( double.Parse(a, _nhi), double.Parse(b, _nhi), 0, false, unit)); } } return(null); }
internal static ISpatialReference FromID_(string id) { ProjDB db = new ProjDB(); string parameters = db.GetParameters(id); string descr = db.GetDescription(id); SpatialReference ret = new SpatialReference(id, descr, parameters, null); string pgWKT = db.GetPgWkt(id); if (!String.IsNullOrEmpty(pgWKT)) { string axisX = db.GetQoutedWKTParameter(pgWKT, "AXIS[\"X\"", ",", "]"); string axisY = db.GetQoutedWKTParameter(pgWKT, "AXIS[\"Y\"", ",", "]"); switch (axisX) { case "NORTH": ret.Gml3AxisX = AxisDirection.North; break; case "EAST": ret.Gml3AxisX = AxisDirection.East; break; case "SOUTH": ret.Gml3AxisX = AxisDirection.South; break; case "WEST": ret.Gml3AxisX = AxisDirection.West; break; } switch (axisY) { case "NORTH": ret.Gml3AxisY = AxisDirection.North; break; case "EAST": ret.Gml3AxisY = AxisDirection.East; break; case "SOUTH": ret.Gml3AxisY = AxisDirection.South; break; case "WEST": ret.Gml3AxisY = AxisDirection.West; break; } } return(ret); }
public SpatialReference(string name, IGeodeticDatum datum) { _ID = name; ProjDB db = new ProjDB(); this.Parameters = db.GetParameters(_ID).Split(' '); _description = db.GetDescription(_ID); db.Dispose(); _datum = datum; _sParams.SetMembers(this.Parameters); }
public SpatialReference(string name) { _ID = name; ProjDB db = new ProjDB(ProjDBTables.projs); this.Parameters = db.GetParameters(_ID).Split(' '); _description = db.GetDescription(_ID); if (this.Datum != null) { this.Datum.Name = db.GetDatumName(_ID); } db.Dispose(); _sParams.SetMembers(this.Parameters); }
private static PrimeMeridian ReadPrimeMeridian(string[] parameters) { string pm = ParameterValue(parameters, "+pm"); if (pm == null) { pm = ""; } double longitude; string name = ProjDB.PrimeMeridianByP4(pm, out longitude); return(new PrimeMeridian( name, new AngularUnit(Math.PI / 180.0), longitude)); }
private void FormSpatialReferenceSystems_Load(object sender, System.EventArgs e) { ProjDB db = new ProjDB(_table); DataTable tab = (_table == ProjDBTables.projs) ? db.GetTable(_filter) : db.GetDatumTable(_filter); if (tab == null) { MessageBox.Show(db.errMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } BuildList(tab); db.Dispose(); }
private void btnQuery_Click(object sender, System.EventArgs e) { ProjDB db = new ProjDB(_table); DataTable tab; if (_table == ProjDBTables.projs) { tab = db.GetTable("(PROJ_ID like '%" + txtWhere.Text + "%' OR PROJ_DESCRIPTION like '%" + txtWhere.Text + "%')" + ((_filter != String.Empty) ? " AND (" + _filter + ")" : "")); } else { tab = db.GetDatumTable("DATUM_Name like '%" + txtWhere.Text + "%'"); } db.Dispose(); if (tab == null) { MessageBox.Show(db.errMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } BuildList(tab); }
private static ProjectedCoordinateSystem ReadProjectedCoordinateSystem(string[] parameters) { // +proj=tmerc +lat_0=0 +lon_0=-62 +k=0.999500 +x_0=400000 +y_0=0 +ellps=clrk80 +towgs84=725,685,536,0,0,0,0 +units=m +no_defs string projParam = ParameterValue(parameters, "+proj"); string projName = ProjDB.ProjectionNameByP4(projParam); List <ProjectionParameter> projParameters = new List <ProjectionParameter>(); if (projParam.ToLower() == "utm" && projName.ToLower() == "transverse_mercator") { projParameters.Add(new ProjectionParameter("scale_factor", 0.9996)); projParameters.Add(new ProjectionParameter("false_easting", 500000.0)); } foreach (string p4param in parameters) { string val; string p4 = Parameter(p4param, out val); double v; if (!double.TryParse(val, NumberStyles.Number, _nhi, out v)) { continue; } switch (p4) { case "+lat_0": projParameters.Add(new ProjectionParameter("latitude_of_origin", v)); break; case "+lon_0": projParameters.Add(new ProjectionParameter("longitude_of_origin", v)); projParameters.Add(new ProjectionParameter("central_meridian", v)); break; case "+k": projParameters.Add(new ProjectionParameter("scale_factor", v)); break; case "+x_0": projParameters.Add(new ProjectionParameter("false_easting", v)); break; case "+y_0": projParameters.Add(new ProjectionParameter("false_northing", v)); break; case "+alpha": projParameters.Add(new ProjectionParameter("azimuth", v)); break; case "+lat_1": projParameters.Add(new ProjectionParameter("standard_parallel_1", v)); break; case "+lat_2": projParameters.Add(new ProjectionParameter("standard_parallel_2", v)); break; case "+zone": projParameters.Add(new ProjectionParameter("Central_Meridian", -177.0 + 6 * (v - 1))); break; } } Projection proj = new Projection(projName, projParameters.ToArray(), "", "", "", ""); GeographicCoordinateSystem geogrCoordSystem = ReadGeographicCoordinateSystem(parameters); AxisInfo[] axis = { new AxisInfo("Easting", AxisOrientation.East), new AxisInfo("Northing", AxisOrientation.North) }; ProjectedCoordinateSystem projCoordSystem = new ProjectedCoordinateSystem( geogrCoordSystem.HorizontalDatum, axis, geogrCoordSystem, new LinearUnit(1.0, String.Empty, String.Empty, String.Empty, "metre", String.Empty, String.Empty), proj); projCoordSystem.Name = "Unknown"; return(projCoordSystem); }
internal static ISpatialReference FromID_(string id) { ProjDB db = new ProjDB(); string parameters = db.GetParameters(id); string descr = db.GetDescription(id); SpatialReference ret = new SpatialReference(id, descr, parameters, null); string pgWKT = db.GetPgWkt(id); if (!String.IsNullOrEmpty(pgWKT)) { string axisX = db.GetQoutedWKTParameter(pgWKT, "AXIS[\"X\"", ",", "]"); string axisY = db.GetQoutedWKTParameter(pgWKT, "AXIS[\"Y\"", ",", "]"); if (String.IsNullOrWhiteSpace(axisX) && String.IsNullOrWhiteSpace(axisY)) { if (ret.Parameters.Contains("+proj=utm")) { ret.Gml3AxisX = AxisDirection.East; ret.Gml3AxisY = AxisDirection.North; } else if (ret.SpatialParameters.IsGeographic) // 4326 => X-Axis to north => tested with QGIS!! { ret.Gml3AxisX = AxisDirection.North; ret.Gml3AxisY = AxisDirection.East; } } else { switch (axisX) { case "NORTH": ret.Gml3AxisX = AxisDirection.North; break; case "EAST": ret.Gml3AxisX = AxisDirection.East; break; case "SOUTH": ret.Gml3AxisX = AxisDirection.South; break; case "WEST": ret.Gml3AxisX = AxisDirection.West; break; } switch (axisY) { case "NORTH": ret.Gml3AxisY = AxisDirection.North; break; case "EAST": ret.Gml3AxisY = AxisDirection.East; break; case "SOUTH": ret.Gml3AxisY = AxisDirection.South; break; case "WEST": ret.Gml3AxisY = AxisDirection.West; break; } } } return(ret); }