/// <summary> /// MAPINFO={Col,Row}:{X,Y}:{ResolutionX,ResolutionY} /// </summary> /// <param name="mapInfoString"></param> /// <returns></returns> public static CoordEnvelope FromMapInfoString(string mapInfoString, Size size) { HdrMapInfo mapInfo = ParseMapInfo(mapInfoString); float LonSolution = (float)mapInfo.XYResolution.Longitude; float LatSolution = (float)mapInfo.XYResolution.Latitude; float MinLon = (float)mapInfo.BaseMapCoordinateXY.Longitude - LonSolution * (mapInfo.BaseRowColNumber.X - 1);/*ENVI pixel from 1*/ float MaxLat = (float)mapInfo.BaseMapCoordinateXY.Latitude + LatSolution * (mapInfo.BaseRowColNumber.Y - 1); float MaxLon = MinLon + LonSolution * size.Width; float MinLat = MaxLat - LatSolution * size.Height; return(new CoordEnvelope(MinLon, MaxLon, MinLat, MaxLat)); }
private static HdrMapInfo GetMapInfo(string prjName, string cX, string cY, string cLon, string cLat, string eLon, string eLat, string rLon, string erLon, string rLat, string erLat, string project, string units) { HdrMapInfo hdrMapInfo = new HdrMapInfo(); hdrMapInfo.Name = prjName; hdrMapInfo.BaseRowColNumber = new System.Drawing.Point(Convert.ToInt32(string.IsNullOrEmpty(cX) ? "-1" : (cX.IndexOf('.') == -1 ? cX : cX.Substring(0, cX.IndexOf('.')))), Convert.ToInt32(string.IsNullOrEmpty(cY) ? "-1" : (cY.IndexOf('.') == -1 ? cY : cY.Substring(0, cY.IndexOf('.'))))); hdrMapInfo.BaseMapCoordinateXY.Latitude = Convert.ToDouble(string.IsNullOrEmpty(cLat) ? "-1" : cLat) * (string.IsNullOrEmpty(eLat) ? 1 : Math.Pow(10, Convert.ToDouble(eLat)));; hdrMapInfo.BaseMapCoordinateXY.Longitude = Convert.ToDouble(string.IsNullOrEmpty(cLon) ? "-1" : cLon) * (string.IsNullOrEmpty(eLon) ? 1 : Math.Pow(10, Convert.ToDouble(eLon)));; hdrMapInfo.XYResolution.Latitude = Math.Round(Convert.ToDouble(string.IsNullOrEmpty(rLat) ? "-1" : rLat), 6) * (string.IsNullOrEmpty(erLat) ? 1 : Math.Pow(10, Convert.ToDouble(erLat))); hdrMapInfo.XYResolution.Longitude = Math.Round(Convert.ToDouble(string.IsNullOrEmpty(rLon) ? "-1" : rLon), 6) * (string.IsNullOrEmpty(erLon) ? 1 : Math.Pow(10, Convert.ToDouble(erLon))); hdrMapInfo.CoordinateType = project; hdrMapInfo.Units = units; return(hdrMapInfo); }
private static HdrMapInfo ParseMapInfo(string value) { if (string.IsNullOrEmpty(value)) { return(null); } string[] parts = value.Split(':'); if (parts.Length != 3) { return(null); } for (int i = 0; i < parts.Length; i++) { parts[i] = parts[i].Replace('{', ' ').Replace('}', ' ').Trim(); } string[] values = parts[0].Split(','); if (values.Length != 2) { return(null); } HdrMapInfo mapInfo = new HdrMapInfo(); mapInfo.BaseRowColNumber = new Point(int.Parse(values[0]), int.Parse(values[1])); values = parts[1].Split(','); if (values.Length != 2) { return(null); } mapInfo.BaseMapCoordinateXY = new HdrGeoPointCoord(double.Parse(values[0]), double.Parse(values[1])); values = parts[2].Split(','); if (values.Length != 2) { return(null); } mapInfo.XYResolution = new HdrGeoPointCoord(double.Parse(values[0]), double.Parse(values[1])); return(mapInfo); }