public void GetSketchPointInfo(int index, ref double[] adfX, ref double[] adfY, ref double[] adfZ) { var marker = m_pointOverlay.Markers[index]; var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; projection.LongitudeOfOrigin = Math.Round(marker.Position.Lng / 3) * 3; projection.Forward(marker.Position.Lat, marker.Position.Lng, out adfX[0], out adfY[0]); adfX[0] = adfX[0] + projection.LongitudeOfOrigin / 3 * 1000000; }
/// <summary> /// 构建不同的投影变换方法 /// </summary> /// <param name="projection"></param> /// <param name="ellipsoid"></param> /// <param name="unit"></param> /// <returns></returns> private static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid, ILinearUnit unit) { List <ProjectionParameter> parameterList = new List <ProjectionParameter>(projection.NumParameters); for (int i = 0; i < projection.NumParameters; i++) { parameterList.Add(projection.GetParameter(i)); } parameterList.Add(new ProjectionParameter("semi_major", ellipsoid.SemiMajorAxis)); //长轴 parameterList.Add(new ProjectionParameter("semi_minor", ellipsoid.SemiMinorAxis)); //短轴 parameterList.Add(new ProjectionParameter("unit", unit.MetersPerUnit)); //单位弧度 IMathTransform transform = null; switch (projection.ClassName.ToLower(CultureInfo.InvariantCulture).Replace(' ', '_')) { case "mercator": case "mercator_1sp": case "mercator_2sp": //1SP transform = new Mercator(parameterList); break; case "transverse_mercator": transform = new TransverseMercator(parameterList); break; case "gauss_kruger": //高斯克吕格投影 transform = new GaussKrugerProjection(parameterList); break; case "albers": case "albers_conic_equal_area": transform = new AlbersProjection(parameterList); break; case "krovak": transform = new KrovakProjection(parameterList); break; case "lambert_conformal_conic": case "lambert_conformal_conic_2sp": case "lambert_conic_conformal_(2sp)": transform = new LambertConformalConic2SP(parameterList); break; default: throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.ClassName)); } return(transform); }
/// <summary> /// 打开KVS文件 /// </summary> /// <param name="kvsFileName">文件名</param> /// <param name="sourceCoordinates"></param> /// <param name="targetCoordinates"></param> public static void Open(string kvsFileName, out List <HorizontalCoordinate> sourceCoordinates, out List <HorizontalCoordinate> targetCoordinates) { sourceCoordinates = new List <HorizontalCoordinate>(); targetCoordinates = new List <HorizontalCoordinate>(); var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; var document = new XmlDocument(); document.Load(kvsFileName); var root = document.DocumentElement; foreach (XmlNode coordinateNode in root.ChildNodes) { foreach (XmlNode node in coordinateNode.ChildNodes) { double lng = double.MinValue, lat = double.MinValue; foreach (XmlNode lbNode in node.ChildNodes) { switch (lbNode.Name.ToLower()) { case "longitude": lng = Convert.ToDouble(lbNode.InnerText.Trim()); break; case "latitude": lat = Convert.ToDouble(lbNode.InnerText.Trim()); break; } } projection.LongitudeOfOrigin = (int)Math.Round(lng / 3) * 3; double E, N; projection.Forward(lat, lng, out E, out N); switch (node.Name.ToLower()) { case "source": sourceCoordinates.Add(new HorizontalCoordinate(E, N)); break; case "target": targetCoordinates.Add(new HorizontalCoordinate(E, N)); break; } } } }
public void GetSketchPolygonInfo(int index, ref double[] adfX, ref double[] adfY, ref double[] adfZ) { var polygon = m_polygonOverlay.Polygons[index]; var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; for (int i = 0; i < polygon.Points.Count; i++) { projection.LongitudeOfOrigin = Math.Round(polygon.Points[i].Lng / 3) * 3; projection.Forward(polygon.Points[i].Lat, polygon.Points[i].Lng, out adfX[i], out adfY[i]); adfX[i] = adfX[i] + projection.LongitudeOfOrigin / 3 * 1000000; } }
public void GetSketchPointInfo(int index, ref double[] adfX, ref double[] adfY, ref double[] adfZ, Matrix param4) { var marker = m_pointOverlay.Markers[index]; var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; projection.LongitudeOfOrigin = Math.Round(marker.Position.Lng / 3) * 3; projection.Forward(marker.Position.Lat, marker.Position.Lng, out adfX[0], out adfY[0]); var sourceCoordinate = new HorizontalCoordinate(adfX[0], adfY[0]); var targetCoordinate = LinearTransformation.Transform(sourceCoordinate, param4); adfX[0] = targetCoordinate.X + projection.LongitudeOfOrigin / 3 * 1000000; adfY[0] = targetCoordinate.Y; }
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="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); }
public void GetSketchPolygonInfo(int index, ref double[] adfX, ref double[] adfY, ref double[] adfZ, Matrix param4) { var polygon = m_polygonOverlay.Polygons[index]; var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; for (int i = 0; i < polygon.Points.Count; i++) { projection.LongitudeOfOrigin = Math.Round(polygon.Points[i].Lng / 3) * 3; projection.Forward(polygon.Points[i].Lat, polygon.Points[i].Lng, out adfX[i], out adfY[i]); var sourceCoordinate = new HorizontalCoordinate(adfX[i], adfY[i]); var targetCoordinate = LinearTransformation.Transform(sourceCoordinate, param4); adfX[i] = targetCoordinate.X + projection.LongitudeOfOrigin / 3 * 1000000; adfY[i] = targetCoordinate.Y; } }
/// <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 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 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); } } }