internal void SetMembers(string [] Parameters) { _unit = GeoUnits.Unknown; _geographic = false; _lat_0 = 0.0; _lon_0 = 0.0; _x_0 = 0.0; _y_0 = 0.0; foreach (string parameter in Parameters) { string[] p = parameter.ToLower().Replace(" ", "").Split('='); if (p.Length < 2) { continue; } if (p[0] == "+units") { switch (p[1]) { case "m": _unit = GeoUnits.Meters; break; } } if (p[0] == "+proj") { switch (p[1]) { case "longlat": case "latlong": _geographic = true; if (_unit == GeoUnits.Unknown) { _unit = GeoUnits.DecimalDegrees; } break; } } if (p[0] == "+lon_0") { double.TryParse(p[1].Replace(".", ","), out _lon_0); } if (p[0] == "+lat_0") { double.TryParse(p[1].Replace(".", ","), out _lat_0); } if (p[0] == "+x_0") { double.TryParse(p[1].Replace(".", ","), out _x_0); } if (p[0] == "+y_0") { double.TryParse(p[1].Replace(".", ","), out _y_0); } } }
private double ToMeters(double val, GeoUnits unit, double phi, int dim) { // http://jumk.de/calc/index.shtml if (dim <= 0) { dim = 1; } switch (unit) { case GeoUnits.Unknown: return(val); case GeoUnits.Inches: return(val * Math.Pow(0.0254, dim)); case GeoUnits.Feet: return(val * Math.Pow(0.3048, dim)); case GeoUnits.Yards: return(val * Math.Pow(0.9144, dim)); case GeoUnits.Miles: return(val * Math.Pow(1609.344, dim)); case GeoUnits.NauticalMiles: return(val * Math.Pow(1852.01, dim)); case GeoUnits.Millimeters: return(val * Math.Pow(0.001, dim)); case GeoUnits.Centimeters: return(val * Math.Pow(0.01, dim)); case GeoUnits.Decimeters: return(val * Math.Pow(0.1, dim)); case GeoUnits.Meters: return(val); case GeoUnits.Kilometers: return(val * Math.Pow(1000.0, dim)); case GeoUnits.DegreesMinutesSeconds: case GeoUnits.DecimalDegrees: if (dim > 1) { return(0.0); } return(val / RAD2DEG * _R * Math.Cos(phi / RAD2DEG)); } return(0.0); }
public void SetSegmentLength(double length, GeoUnits unit) { if (txtSegmentLength.InvokeRequired) { SetSegmentLengthCallback d = new SetSegmentLengthCallback(SetSegmentLength); this.Invoke(d, new object[] { length, unit }); } else { txtSegmentLength.Text = length.ToString(); lblSegmentLenghtUnit.Text = unit.ToString(); } }
public void SetTotalArea(double length, GeoUnits unit) { if (txtTotalArea.InvokeRequired) { SetTotalAreaCallback d = new SetTotalAreaCallback(SetTotalArea); this.Invoke(d, new object[] { length, unit }); } else { txtTotalArea.Text = length.ToString(); lblTotalAreaUnit.Text = ((unit != GeoUnits.Unknown) ? "Square " : "") + unit.ToString(); } }
private double FromMeters(double val, GeoUnits unit, double phi, int dim) { if (dim <= 0) { dim = 1; } switch (unit) { case GeoUnits.Unknown: return(val); case GeoUnits.Inches: return(val * Math.Pow(39.37008, dim)); case GeoUnits.Feet: return(val * Math.Pow(3.28084, dim)); case GeoUnits.Yards: return(val * Math.Pow(1.09361, dim)); case GeoUnits.Miles: return(val * Math.Pow(0.000621371, dim)); case GeoUnits.NauticalMiles: return(val * Math.Pow(0.000539954, dim)); case GeoUnits.Millimeters: return(val * Math.Pow(1000.0, dim)); case GeoUnits.Centimeters: return(val * Math.Pow(100.0, dim)); case GeoUnits.Decimeters: return(val * Math.Pow(10.0, dim)); case GeoUnits.Meters: return(val); case GeoUnits.Kilometers: return(val * Math.Pow(0.001, dim)); case GeoUnits.DegreesMinutesSeconds: case GeoUnits.DecimalDegrees: if (Math.Cos(phi / RAD2DEG) == 0.0) { return(0.0); } return(val / (R * Math.Cos(phi / RAD2DEG)) * RAD2DEG); } return(0.0); }
private string Unit2String(GeoUnits unit) { switch (unit) { case GeoUnits.Unknown: return(unit.ToString()); case GeoUnits.Inches: return(unit.ToString()); case GeoUnits.Feet: return(unit.ToString()); case GeoUnits.Yards: return(unit.ToString()); case GeoUnits.Miles: return(unit.ToString()); case GeoUnits.NauticalMiles: return("Nautic Miles"); case GeoUnits.Millimeters: return(unit.ToString()); case GeoUnits.Centimeters: return(unit.ToString()); case GeoUnits.Decimeters: return(unit.ToString()); case GeoUnits.Meters: return(unit.ToString()); case GeoUnits.Kilometers: return(unit.ToString()); case GeoUnits.DecimalDegrees: return("Decimal Degrees"); case GeoUnits.DegreesMinutesSeconds: return("Degrees Minutes Seconds"); } return("???"); }
public GeoUnitsItem(GeoUnits unit) { _unit = unit; }
public double Convert(double val, GeoUnits from, GeoUnits to) { return(Convert(val, from, to, 1, 0.0)); }
public string[] Convert(string[] val, GeoUnits from, GeoUnits to, ISpatialParameters parameters) { if (val.Length != 2) { return(null); } double x = 0.0, y = 0.0, phi = 0.0; if (from == GeoUnits.DegreesMinutesSeconds) { // Umwandelt in double } else { if (!double.TryParse(val[0], out x)) { return(null); } if (!double.TryParse(val[1], out y)) { return(null); } } if (from == GeoUnits.DegreesMinutesSeconds || from == GeoUnits.DecimalDegrees) { if (parameters != null) { x += parameters.lon_0; y += parameters.lat_0; } phi = y; } else { if (parameters != null) { x -= Convert(parameters.x_0, parameters.Unit, from); y -= Convert(parameters.y_0, parameters.Unit, from); } } double Xm = ToMeters(x, from, phi, 1); double Ym = ToMeters(y, from, 0.0, 1); double Yt = FromMeters(Ym, to, 0.0, 1), Xt; if (to == GeoUnits.DegreesMinutesSeconds || to == GeoUnits.DecimalDegrees) { phi = Yt + ((parameters != null) ? parameters.lat_0 : 0.0); Xt = FromMeters(Xm, to, phi, 1) + ((parameters != null) ? parameters.lon_0 : 0.0); } else { Xt = FromMeters(Xm, to, 0.0, 1); } if (to == GeoUnits.DegreesMinutesSeconds) { return(new string[] { deg2GMS(Xt, 2), deg2GMS(Yt, 2) }); } else if (to == GeoUnits.DecimalDegrees) { Xt = Math.Round(Xt, 2); Yt = Math.Round(Yt, 2); return(new string[] { Xt.ToString(), Yt.ToString() }); } else { if (parameters != null) { Xt += Convert(parameters.x_0, parameters.Unit, to); Yt += Convert(parameters.y_0, parameters.Unit, to); } Xt = Math.Round(Xt, 2); Yt = Math.Round(Yt, 2); return(new string[] { String.Format("{0:+0.00;-0.00;}", Xt), String.Format("{0:+0.00;-0.00;}", Yt) }); } }
public double Convert(double val, GeoUnits from, GeoUnits to, int dim, double phi) { double m = ToMeters(val, from, phi, dim); return(FromMeters(m, to, phi, dim)); }
public double Convert(double val, GeoUnits from, GeoUnits to, int dim) { return(Convert(val, from, to, dim, 0.0)); }