/// <summary> /// 取图形范围 /// </summary> /// <param name="adfMinBound"></param> /// <param name="adfMaxBound"></param> /// <param name="param4"></param> /// <returns></returns> private RectLatLng GetShapeRect(double[] adfMinBound, double[] adfMaxBound, Matrix param4) { double minX, minY, maxX, maxY; minX = adfMinBound[0]; minY = adfMinBound[1]; var minZone = (int)minX / 1000000; minX = minX - minZone * 1000000; maxX = adfMaxBound[0]; maxY = adfMaxBound[1]; var maxZone = (int)maxX / 1000000; maxX = maxX - maxZone * 1000000; // 坐标转换(不要加大数) var minXY = LinearTransformation.Transform(new HorizontalCoordinate(minX, minY), param4); var maxXY = LinearTransformation.Transform(new HorizontalCoordinate(maxX, maxY), param4); var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; // 再转成经纬度(加上大数,因为需要计算投影带号) double lat, lng; projection.LongitudeOfOrigin = minZone * 3; projection.Reverse(minXY.X, minXY.Y, out lat, out lng); var minLB = new GeocentricCoordinate(lat, lng); projection.LongitudeOfOrigin = maxZone * 3; projection.Reverse(maxXY.X, maxXY.Y, out lat, out lng); var maxLB = new GeocentricCoordinate(lat, lng); // 取得图形范围用于显示 var rect = new RectLatLng(maxLB.Latitude.Digital, minLB.Longitude.Digital, maxLB.Longitude.Digital - minLB.Longitude.Digital, maxLB.Latitude.Digital - minLB.Latitude.Digital); return(rect); }
private RectLatLng GetShapeRect(double[] adfMinBound, double[] adfMaxBound) { double minX, minY, maxX, maxY; minX = adfMinBound[0]; minY = adfMinBound[1]; var minZone = (int)minX / 1000000; minX = minX - minZone * 1000000; maxX = adfMaxBound[0]; maxY = adfMaxBound[1]; var maxZone = (int)maxX / 1000000; maxX = maxX - maxZone * 1000000; var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; double lat, lng; projection.LongitudeOfOrigin = minZone * 3; projection.Reverse(minX, minY, out lat, out lng); var minLB = new GeocentricCoordinate(lat, lng); projection.LongitudeOfOrigin = maxZone * 3; projection.Reverse(maxX, maxY, out lat, out lng); var maxLB = new GeocentricCoordinate(lat, lng); // 取得图形范围用于显示 var rect = new RectLatLng(maxLB.Latitude.Digital, minLB.Longitude.Digital, maxLB.Longitude.Digital - minLB.Longitude.Digital, maxLB.Latitude.Digital - minLB.Latitude.Digital); return(rect); }
private PointLatLng GetPoint(double x, double y) { var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; var zone = (int)x / 1000000; x = x - zone * 1000000; // 根据x,y获取经纬度 double lat, lng; projection.LongitudeOfOrigin = zone * 3; projection.Reverse(x, y, out lat, out lng); return(new PointLatLng(lat, lng)); }
/// <summary> /// 获取转换后的点 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="param4"></param> /// <returns></returns> private PointLatLng GetTransformedPoint(double x, double y, Matrix param4) { var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; var zone = (int)x / 1000000; x = x - zone * 1000000; // 坐标转换(不要加大数) var sourceCoordinate = new HorizontalCoordinate(x, y); var targetCoordinate = LinearTransformation.Transform(sourceCoordinate, param4); // 再转成经纬度(加上大数,因为需要计算投影带号) double lat, lng; projection.LongitudeOfOrigin = zone * 3; projection.Reverse(targetCoordinate.X, targetCoordinate.Y, out lat, out lng); return(new PointLatLng(lat, lng)); }
private void xy2lbToolStripMenuItem_Click(object sender, EventArgs e) { var dialog = new OpenFileDialog(); dialog.Filter = "Excel 97-2003 工作簿(*.xls)|*.xls"; if (dialog.ShowDialog() == DialogResult.OK) { var xlsFileName = dialog.FileName; try { var workbook = ExtendSheet.GetWorkbook(xlsFileName); var sheet = workbook.GetSheetAt(0); if (sheet == null) { return; } var columnXIndex = ExtendSheet.SearchColumn(sheet, "X"); var columnYIndex = ExtendSheet.SearchColumn(sheet, "Y"); var columnBIndex = ExtendSheet.SearchColumn(sheet, "纬度"); if (columnBIndex < 0) { columnBIndex = sheet.GetRow(0).LastCellNum; sheet.GetRow(0).CreateCell(columnBIndex).SetCellValue("纬度"); } var columnLIndex = ExtendSheet.SearchColumn(sheet, "经度"); if (columnLIndex < 0) { columnLIndex = sheet.GetRow(0).LastCellNum; sheet.GetRow(0).CreateCell(columnLIndex).SetCellValue("经度"); } for (int i = 1; i <= sheet.LastRowNum; i++) { var row = sheet.GetRow(i); var xCell = row.GetCell(columnXIndex); var yCell = row.GetCell(columnYIndex); if (xCell == null || yCell == null) { return; } var lCell = row.GetCell(columnLIndex); var bCell = row.GetCell(columnBIndex); if (lCell == null) { lCell = row.CreateCell(columnLIndex); } if (bCell == null) { bCell = row.CreateCell(columnBIndex); } var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; var x = xCell.NumericCellValue; var y = yCell.NumericCellValue; var zone = (int)x / 1000000; projection.LongitudeOfOrigin = zone * 3; x = x - zone * 1000000; double lat, lng; projection.Reverse(x, y, out lat, out lng); var point = new GeocentricCoordinate(lat, lng); lCell.SetCellValue(point.Longitude.ToString()); bCell.SetCellValue(point.Latitude.ToString()); } using (FileStream fs = File.Open(xlsFileName, FileMode.Open, FileAccess.Write)) { workbook.Write(fs); System.Diagnostics.Process.Start("explorer.exe", Path.GetDirectoryName(xlsFileName)); } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }