private int CalZoomScale(CoorPoint tl, CoorPoint br) { CoordinateTransform coorConv = new CoordinateTransform(); for (int i = 21; i > 1; --i) { CoorPoint c2 = coorConv.CalLonLatRadToCoorPixel(tl.x, tl.y, i); CoorPoint c1 = coorConv.CalLonLatRadToCoorPixel(br.x, br.y, i); if ((c2.x - c1.x) < 1280 && c2.y - c1.y < 1280) { return(i); } } return(0); }
public Matrix GetMatrix() { if (rg == null || !rg.IsReadFinished()) { return(null); } CoordinateTransform ct = new CoordinateTransform(); CoorPoint lt = ct.CalLonLatDegToTwd97(rg.GetTopLeft.x, rg.GetTopLeft.y); CoorPoint rb = ct.CalLonLatDegToTwd97(rg.GetBottomRight.x, rg.GetBottomRight.y); Matrix m = new Matrix(1f, 0, 0, -1f, 0, 0); float xScale = 1280.0f / (float)(rb.x - lt.x); float yScale = 1280.0f / (float)(lt.y - rb.y); m.Scale(xScale, yScale); m.Translate((float)-lt.x, (float)-lt.y); return(m); }
public static void FillDataByRiverGrid(CoorPoint[,] inputCoor, DataGridView xv, DataGridView yv, DataGridView zv) { }
private CoorPoint GetTopLeft() { if(!rg.IsInMap()) { return new CoorPoint(rg.GetTopLeft.x, rg.GetTopLeft.y); } CoordinateTransform ct = new CoordinateTransform(); CoorPoint pt = new CoorPoint(); switch (bkImgType) { case BackgroundMapType.None: pt = ct.CalLonLatDegToTwd97(rg.GetTopLeft.x, rg.GetTopLeft.y); break; case BackgroundMapType.GoogleStaticMap: pt = ct.CalLonLatDegToTwd97(rg.GetTopLeft.x, rg.GetTopLeft.y); break; case BackgroundMapType.ImportImage: pt = topLeft; break; } return pt; }
public void SetMapBackground(string s, double e, double n, double w, double h) { if(s == null || s.Length == 0) { bkImgType = BackgroundMapType.None; DrawGrid(); PicBox.Refresh(); return; } importBmp = LoadBitmapWithoutLockFile(s); if (importBmp == null || importBmp.Width < 100 || importBmp.Height < 100) { bkImgType = BackgroundMapType.None; DrawGrid(); PicBox.Refresh(); return; } importBmp.SetResolution(96.0F, 96.0F); topLeft = new CoorPoint(e, n); bottomRight = new CoorPoint(e + w, n - h); bkImgType = BackgroundMapType.ImportImage; DrawGrid(); PicBox.Refresh(); }
public CoorPoint Twd97ToTwd67(CoorPoint coor97) { double x67 = coor97.x - 807.8 - A * coor97.x - B * coor97.y; double y67 = coor97.y + 248.6 - A * coor97.y - B * coor97.x; return new CoorPoint(x67, y67); }
public CoorPoint Twd67ToTwd97(CoorPoint coor67) { double x97 = coor67.x + 807.8 + A * coor67.x + B * coor67.y; double y97 = coor67.y - 248.6 + A * coor67.y + B * coor67.y; return new CoorPoint(x97, x97); }
private bool ConvertGrid(CoorPoint[,] grid) { _j = grid.GetLength(1); _i = grid.GetLength(0); maxX = double.MinValue; minX = double.MaxValue; maxY = double.MinValue; minY = double.MaxValue; foreach(CoorPoint pt in grid) { if (pt.x > maxX) maxX = pt.x; if (pt.x < minX) minX = pt.x; if (pt.y > maxY) maxY = pt.y; if (pt.y < minY) minY = pt.y; } //Finished read CoordinateTransform ct = new CoordinateTransform(); if (IsInMap()) { zoomScale = CalZoomScale(ct.CalTwd97ToLatLonCoorRad(maxX, maxY), ct.CalTwd97ToLatLonCoorRad(minX, minY)); } else { zoomScale = 1; } if (zoomScale == 0) { return false; } if (IsInMap()) { CoorPoint center = ct.CalTwd97ToLatLonCoorRad((maxX + minX) / 2, (maxY + minY) / 2); bottomRight = ct.CalCenterLatLonToOffsetPixelLonLat(center.x, center.y, 640, 640, zoomScale).RadToDegree(); topLeft = ct.CalCenterLatLonToOffsetPixelLonLat(center.x, center.y, -640, -640, zoomScale).RadToDegree(); centerPoint = center.RadToDegree(); } else { centerPoint = new CoorPoint((maxX + minX) / 2, (maxY + minY) / 2); bottomRight = new CoorPoint(maxX, minY); topLeft = new CoorPoint(minX, maxY); } return true; }
private int CalZoomScale(CoorPoint tl, CoorPoint br) { CoordinateTransform ct = new CoordinateTransform(); for (int i = 21; i > 1; --i) { CoorPoint c2 = ct.CalLonLatRadToCoorPixel(tl.x, tl.y, i); CoorPoint c1 = ct.CalLonLatRadToCoorPixel(br.x, br.y, i); if ((c2.x - c1.x) < 1280 && c2.y - c1.y < 1280) { return i; } } return 0; }
public bool ReadInputGridData(DataGridView dx, DataGridView dy, DataGridView dz, int x, int y) { try { _j = y; _i = x; if (inputCoor == null || (inputCoor.GetLength(0) != _i && inputCoor.GetLength(1) != _j)) { inputCoor = new CoorPoint[_i, _j]; } int xyZeroCount = 0; for (int i = 0; i < _i; ++i) { for (int j = 0; j < _j; ++j) { string s1 = dx[j, i].Value as string; string s2 = dy[j, i].Value as string; string s3 = dz[j, i].Value as string; if ((s1 == null && s2 == null) || (s1.Length == 0 && s2.Length == 0)) { if(++xyZeroCount > 1) { return false; } } inputCoor[i, j] = new CoorPoint(Convert.ToDouble(s1), Convert.ToDouble(s2), Convert.ToDouble(dz[j, i].Value ?? 0)); if (inputCoor[i, j].x > maxX) maxX = inputCoor[i, j].x; if (inputCoor[i, j].x < minX) minX = inputCoor[i, j].x; if (inputCoor[i, j].y > maxY) maxY = inputCoor[i, j].y; if (inputCoor[i, j].y < minY) minY = inputCoor[i, j].y; } } } catch { return false; } ConvertGrid(inputCoor); return true; }
public bool ReadInputFile(string path) { const int MaxLineWord = 5; try { System.IO.StreamReader file = new System.IO.StreamReader(path); char[] charSeparators = new char[] { '\t', ' ' }; string line = file.ReadLine(); string[] words = line.Split(charSeparators, MaxLineWord); _j = Convert.ToInt32(words[0]); _i = Convert.ToInt32(words[1]); inputCoor = new CoorPoint[_i, _j]; int i = 0, j = _j - 1; while ((line = file.ReadLine()) != null) { words = line.Split(charSeparators, MaxLineWord); inputCoor[i, j] = new CoorPoint(Convert.ToDouble(words[0]), Convert.ToDouble(words[1])); if (words.Length > 3) { //Have Z data inputCoor[i, j].z = Convert.ToDouble(words[3]); } if (inputCoor[i, j].x > maxX) maxX = inputCoor[i, j].x; if (inputCoor[i, j].x < minX) minX = inputCoor[i, j].x; if (inputCoor[i, j].y > maxY) maxY = inputCoor[i, j].y; if (inputCoor[i, j].y < minY) minY = inputCoor[i, j].y; if (--j < 0) { j = _j - 1; ++i; } if (i == _i) { break; } } ConvertGrid(inputCoor); } catch (Exception e) { MessageBox.Show(e.Message); return false; } return true; }
public bool ReadInputFile(string path) { const int MaxLineWord = 3; try { System.IO.StreamReader file = new System.IO.StreamReader(path); char[] charSeparators = new char[] { '\t', ' ' }; string line = file.ReadLine(); string[] words = line.Split(charSeparators, MaxLineWord); _j = Convert.ToInt32(words[0]); _i = Convert.ToInt32(words[1]); inputCoor = new CoorPoint[_i, _j]; int i = 0, j = _j - 1; while ((line = file.ReadLine()) != null) { words = line.Split(charSeparators, MaxLineWord); inputCoor[i, j] = new CoorPoint(Convert.ToDouble(words[0]), Convert.ToDouble(words[1])); if (inputCoor[i, j].x > maxX) { maxX = inputCoor[i, j].x; } if (inputCoor[i, j].x < minX) { minX = inputCoor[i, j].x; } if (inputCoor[i, j].y > maxY) { maxY = inputCoor[i, j].y; } if (inputCoor[i, j].y < minY) { minY = inputCoor[i, j].y; } if (--j < 0) { j = _j - 1; ++i; } if (i == _i) { break; } } //Finished read CoordinateTransform coorConv = new CoordinateTransform(); //CoorPoint topLeft = coorConv.CalTwd97ToLatLonCoorRad(maxX, maxY); //CoorPoint bottomRight = coorConv.CalTwd97ToLatLonCoorRad(minX, minY); zoomScale = CalZoomScale(coorConv.CalTwd97ToLatLonCoorRad(maxX, maxY), coorConv.CalTwd97ToLatLonCoorRad(minX, minY)); if (zoomScale == 0) { return(false); } CoorPoint center = coorConv.CalTwd97ToLatLonCoorRad((maxX + minX) / 2, (maxY + minY) / 2); bottomRight = coorConv.CalCenterLatLonToOffsetPixelLonLat(center.x, center.y, 640, 640, zoomScale).RadToDegree(); topLeft = coorConv.CalCenterLatLonToOffsetPixelLonLat(center.x, center.y, -640, -640, zoomScale).RadToDegree(); centerPoint = center.RadToDegree(); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } return(true); }