public GeoPointDto Get(string key) { GeoPointDto result = new GeoPointDto(); string queryString = "select top(1) Location, createDate, SerialNumber from geoPoint where SerialNumber like (?) order by createDate desc"; IFieldsQueryCursor query2 = cache.Query(new SqlFieldsQuery(queryString, key)); var query3 = cache.QueryFields(new SqlFieldsQuery(queryString, key)); var resQ3 = query3.GetAll(); foreach (var item in resQ3) { var tempRow = item[0].ToString().Remove(0, 6).Replace("(", "").Replace(")", "").Split(" "); Coordinate c = Cartesian.CartesianToLatLong(double.Parse(tempRow[0]), double.Parse(tempRow[1]), double.Parse(tempRow[2])); var point = new Dto.Point() { elevation = 0, Latitude = c.Latitude.DecimalDegree, Longitude = c.Longitude.DecimalDegree }; result.Point = point; result.CreateDate = DateTime.Parse(item[1].ToString()); result.SerialNumber = item[2].ToString(); } return(result); }
private static void Run_Conversion_Passes(List <List <string> > Conversions) { //List of coordinates to test conversions against. List <double[]> coords = new List <double[]>(); coords.Add(new double[] { 39.5768, 72.4859 }); coords.Add(new double[] { -15.5768, 100.4859 }); coords.Add(new double[] { 65.25, -15.1859 }); coords.Add(new double[] { -80.659, -152.49 }); for (int x = 0; x < Conversions.Count; x++) { List <string> coordList = Conversions[x]; double lat = coords[x][0]; double lng = coords[x][1]; //0 = Decimal / Signed //1 = Decimal Degree //2 = Degree Decimal Minute //3 = Degree Minutes Seconds //4 = UTM //5 = MGRS //6 = Cartesian //7 = ECEF Coordinate c = new Coordinate(lat, lng); bool pass = true; Coordinate rc = new Coordinate(); for (int y = 0; y < 8; y++) { switch (y) { case 0: c.FormatOptions.Format = CoordinateFormatType.Decimal; if (c.ToString() != coordList[y]) { pass = false; } break; case 1: c.FormatOptions.Format = CoordinateFormatType.Decimal_Degree; if (c.ToString() != coordList[y]) { pass = false; } break; case 2: c.FormatOptions.Format = CoordinateFormatType.Degree_Decimal_Minutes; if (c.ToString() != coordList[y]) { pass = false; } rc = new Coordinate(); rc.Latitude = new CoordinatePart(c.Latitude.Degrees, c.Latitude.DecimalMinute, c.Latitude.Position); rc.Longitude = new CoordinatePart(c.Longitude.Degrees, c.Longitude.DecimalMinute, c.Longitude.Position); if (rc.Latitude.ToDouble() != c.Latitude.ToDouble()) { pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (rc.Longitude.ToDouble() != c.Longitude.ToDouble()) { pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 3: c.FormatOptions.Format = CoordinateFormatType.Degree_Minutes_Seconds; if (c.ToString() != coordList[y]) { pass = false; } rc = new Coordinate(); rc.Latitude = new CoordinatePart(c.Latitude.Degrees, c.Latitude.Minutes, c.Latitude.Seconds, c.Latitude.Position); rc.Longitude = new CoordinatePart(c.Longitude.Degrees, c.Longitude.Minutes, c.Longitude.Seconds, c.Longitude.Position); if (rc.Latitude.ToDouble() != c.Latitude.ToDouble()) { pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (rc.Longitude.ToDouble() != c.Longitude.ToDouble()) { pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 4: if (c.UTM.ToString() != coordList[y]) { pass = false; } UniversalTransverseMercator utm = new UniversalTransverseMercator(c.UTM.LatZone, c.UTM.LongZone, c.UTM.Easting, c.UTM.Northing); rc = UniversalTransverseMercator.ConvertUTMtoLatLong(utm); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } //SIGNED DEGREE METHOD double[] sd = UniversalTransverseMercator.ConvertUTMtoSignedDegree(utm); if (Math.Abs(sd[0] - c.Latitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(sd[1] - c.Longitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } //OVERLOAD METHOD utm = new UniversalTransverseMercator(c.UTM.LongZone + c.UTM.LatZone.ToString(), c.UTM.Easting, c.UTM.Northing); rc = UniversalTransverseMercator.ConvertUTMtoLatLong(utm); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 5: if (c.MGRS.ToString() != coordList[y]) { pass = false; } MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem(c.MGRS.LatZone, c.MGRS.LongZone, c.MGRS.Digraph, c.MGRS.Easting, c.MGRS.Northing); rc = MilitaryGridReferenceSystem.MGRStoLatLong(mgrs); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .0001) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .0001) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } //SIGNED DEGREE METHOD double[] sdM = MilitaryGridReferenceSystem.MGRStoSignedDegree(mgrs); if (Math.Abs(sdM[0] - c.Latitude.ToDouble()) >= .0001) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(sdM[1] - c.Longitude.ToDouble()) >= .0001) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } //OVERLOAD METHOD mgrs = new MilitaryGridReferenceSystem(c.MGRS.LongZone + c.MGRS.LatZone.ToString(), c.MGRS.Digraph, c.MGRS.Easting, c.MGRS.Northing); rc = MilitaryGridReferenceSystem.MGRStoLatLong(mgrs); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .0001) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .0001) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 6: if (c.Cartesian.ToString() != coordList[y]) { pass = false; } Cartesian cart = new Cartesian(c.Cartesian.X, c.Cartesian.Y, c.Cartesian.Z); rc = Cartesian.CartesianToLatLong(cart); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...Cartesian Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...Cartesian Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 7: string ec = c.ECEF.ToString().Replace(" km", "").Replace(",", ""); if (ec != coordList[y]) { pass = false; } ECEF ecef = new ECEF(c.ECEF.X, c.ECEF.Y, c.ECEF.Z); rc = ECEF.ECEFToLatLong(ecef); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } if (Math.Abs(rc.ECEF.GeoDetic_Height.Meters - c.ECEF.GeoDetic_Height.Meters) >= .00001) { pass = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; default: break; } } Pass.Write("Conversion Pass " + ((int)(x + 1)).ToString() + ": ", pass); } }
static void Coordinate_Convsersions_Tests() { Console.WriteLine(); //GATHER CONVERSIONS //Conversion lists must end in //** to signify end of list List <List <string> > Conversions = new List <List <string> >(); string[] coordStrings = File.ReadAllLines("Conversions.txt"); List <string> cList = new List <string>(); foreach (string c in coordStrings) { if (c == "//**") { Conversions.Add(cList); cList = new List <string>(); } else { cList.Add(c); } } //Conversion coords to test List <double[]> coords = new List <double[]>(); coords.Add(new double[] { 39.5768, 72.4859 }); coords.Add(new double[] { -15.5768, 100.4859 }); coords.Add(new double[] { 65.25, -15.1859 }); coords.Add(new double[] { -80.6586, -152.49 }); for (int x = 0; x < Conversions.Count; x++) { List <string> coordList = Conversions[x]; double lat = coords[x][0]; double lng = coords[x][1]; //0 = Decimal / Signed //1 = Decimal Degree //2 = Degree Decimal Minute //3 = Degree Minutes Seconds //4 = UTM //5 = MGRS //6 = Cartesian Coordinate c = new Coordinate(lat, lng); bool pass = true; Coordinate rc = new Coordinate(); for (int y = 0; y < 7; y++) { switch (y) { case 0: c.FormatOptions.Format = CoordinateFormatType.Decimal; if (c.ToString() != coordList[y]) { pass = false; } break; case 1: c.FormatOptions.Format = CoordinateFormatType.Decimal_Degree; if (c.ToString() != coordList[y]) { pass = false; } break; case 2: c.FormatOptions.Format = CoordinateFormatType.Degree_Decimal_Minutes; if (c.ToString() != coordList[y]) { pass = false; } rc = new Coordinate(); rc.Latitude = new CoordinatePart(c.Latitude.Degrees, c.Latitude.DecimalMinute, c.Latitude.Position, rc); rc.Longitude = new CoordinatePart(c.Longitude.Degrees, c.Longitude.DecimalMinute, c.Longitude.Position, rc); if (rc.Latitude.ToDouble() != c.Latitude.ToDouble()) { pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (rc.Longitude.ToDouble() != c.Longitude.ToDouble()) { pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 3: c.FormatOptions.Format = CoordinateFormatType.Degree_Minutes_Seconds; if (c.ToString() != coordList[y]) { pass = false; } rc = new Coordinate(); rc.Latitude = new CoordinatePart(c.Latitude.Degrees, c.Latitude.Minutes, c.Latitude.Seconds, c.Latitude.Position, rc); rc.Longitude = new CoordinatePart(c.Longitude.Degrees, c.Longitude.Minutes, c.Longitude.Seconds, c.Longitude.Position, rc); if (rc.Latitude.ToDouble() != c.Latitude.ToDouble()) { pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (rc.Longitude.ToDouble() != c.Longitude.ToDouble()) { pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 4: if (c.UTM.ToString() != coordList[y] && c.UTM.WithinCoordinateSystemBounds) { pass = false; } UniversalTransverseMercator utm = new UniversalTransverseMercator(c.UTM.LatZone, c.UTM.LongZone, c.UTM.Easting, c.UTM.Northing); rc = UniversalTransverseMercator.ConvertUTMtoLatLong(utm); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001 && c.UTM.WithinCoordinateSystemBounds) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001 && c.UTM.WithinCoordinateSystemBounds) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 5: if (c.MGRS.ToString() != coordList[y] && c.MGRS.WithinCoordinateSystemBounds) { pass = false; } MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem(c.MGRS.LatZone, c.MGRS.LongZone, c.MGRS.Digraph, c.MGRS.Easting, c.MGRS.Northing); rc = MilitaryGridReferenceSystem.MGRStoLatLong(mgrs); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .0001 && c.MGRS.WithinCoordinateSystemBounds) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .0001 && c.MGRS.WithinCoordinateSystemBounds) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 6: if (c.Cartesian.ToString() != coordList[y]) { pass = false; } Cartesian cart = new Cartesian(c.Cartesian.X, c.Cartesian.Y, c.Cartesian.Z); rc = Cartesian.CartesianToLatLong(cart); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...Cartesian Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...Cartesian Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; default: break; } } Write_Pass("Conversion Pass " + ((int)(x + 1)).ToString() + ": ", pass); } //UTM MGRS BOUNDARY CHECK bool p = true; Coordinate cr = new Coordinate(-79.99, 0); if (!cr.UTM.WithinCoordinateSystemBounds || !cr.MGRS.WithinCoordinateSystemBounds) { p = false; } cr.Latitude.DecimalDegree = -80; if (cr.UTM.WithinCoordinateSystemBounds || cr.MGRS.WithinCoordinateSystemBounds) { p = false; } cr.Latitude.DecimalDegree = 83.99; if (!cr.UTM.WithinCoordinateSystemBounds || !cr.MGRS.WithinCoordinateSystemBounds) { p = false; } cr.Latitude.DecimalDegree = 84; if (cr.UTM.WithinCoordinateSystemBounds || cr.MGRS.WithinCoordinateSystemBounds) { p = false; } Write_Pass("UTM MGRS BOUNDARY CHECK", p); }