根据坐标计算所在图幅


//根据坐标计算2.5万图幅号的公式。
int M1, M2, M3, M4, J1;
double J2, W;
W  = y;   //纬度
J1 = (int)x;  //经度度
J2 = x-J1;//经度秒

M1 = (int)(W*60/40);
M2 = J1-60;
M3 = (int)( (W*60/40-( (int)(W*60/40) ) ) *40/5);
M4 = (int)(J2*3600)/450;
    
char ss1[3],ss2[3],ss3[2],ss4[2];
_itoa(M1,ss1,10);
_itoa(M2,ss2,10);
_itoa(M3,ss3,10);
_itoa(M4,ss4,10);
CString M;
M  = ss1;
M += ss2;
M += ss3;
M += ss4;



//根据坐标计算5千图幅号的公式。
xMin=M2*3600+M4*450+60*3600;
xMax=xMin+450;
yMin=M1*2400+M3*300;
yMax=yMin+300;
    
double xx,yy;
xx = x*3600-xMin;
yy = y*3600-yMin;
int mapcode_1 = 3 + int(xx/225) - 2*int(yy/150);
xx = xx - int(xx/225)*225;
yy = yy - int(yy/150)*150;
int mapcode_05 = 3 + int(xx/112.5) - 2*int(yy/75);
CString strTemp;
strTemp.Format("%s_%d_%d", M, mapcode_1, mapcode_05);
'计算图幅 Option Explicit Type ArrayData Data() As String Count As Integer End Type Public Function getSheetNumber(strLat As String, strLon As String, ScaleID As String) As String Dim strLatErr As String, strLonErr As String Dim dblLatErr As String, dblLonErr As String Dim dblLat As Double, dblLon As Double Dim a As String, b As Integer, c As Integer, d As Integer Select Case ScaleID Case "A" '1:100W strLatErr = "4°00′00″": strLonErr = "6°00′00″" Case "B" '1:50W strLatErr = "2°00′00″": strLonErr = "3°00′00″" Case "C" '1:25W strLatErr = "1°00′00″": strLonErr = "1°30′00″" Case "D" '1:10W strLatErr = "00°20′00″": strLonErr = "00°30′00″" Case "E" '1:5W strLatErr = "00°10′00″": strLonErr = "00°15′00″" Case "F" '1:2.5W strLatErr = "00°05′00″": strLonErr = "00°07′30″" Case "G" '1:1W strLatErr = "00°02′30″": strLonErr = "00°03′45″" Case "H" '1:0.5W strLatErr = "00°01′15″": strLonErr = "00°01′52.5″" Case Else ' getSheetNumber = "比例尺代码错误" Exit Function End Select dblLatErr = changeToSecond(strLatErr): dblLonErr = changeToSecond(strLonErr) dblLat = changeToSecond(strLat): dblLon = changeToSecond(strLon) a = Chr(64 + Int(dblLat / changeToSecond("4°00′00″")) + 1) b = Int(dblLon / changeToSecond("6°00′00″") + 31) If ScaleID <> "A" Then c = changeToSecond("4°00′00″") / dblLatErr - Int(mMod(dblLat, changeToSecond("4°00′00″")) / dblLatErr) d = Int(mMod(dblLon, changeToSecond("6°00′00″")) / dblLonErr) + 1 getSheetNumber = a & b & ScaleID & Format(c, "000") & Format(d, "000") Else getSheetNumber = a & b End If End Function Private Function changeToSecond(strDeg As String) As Double Dim intD As Integer, intM As Integer, dblS As Double intD = Int(strOperate(strDeg, "°").Data(0)) dblS = CDbl(Left(strOperate(strDeg, "′").Data(1), Len(strOperate(strDeg, "′").Data(1)) - 1)) intM = Int(Left(strOperate(strDeg, "°").Data(1), 2)) changeToSecond = intD * 60 + intM + dblS / 60 End Function Private Function strOperate(ByVal strX As String, ByVal strA As String) As ArrayData '分割字符串 Dim i As Integer, j As Integer, k As Integer Dim cnt As Integer, strTemp As String If Trim(strA) <> "" Then strX = Trim(strX) strA = Trim(strA) strX = strX & strA For i = 1 To Len(strX) If Mid(strX, i, Len(Trim(strA))) = strA Then cnt = cnt + 1 i = i + Len(strA) - 1 End If Next i strOperate.Count = cnt ReDim strOperate.Data(cnt - 1) For j = 1 To Len(strX) If Mid(strX, j, Len(strA)) = strA Then strOperate.Data(k) = Left(strX, j - 1) strX = Trim(Right(strX, Len(strX) - Len(strOperate.Data(k)) - Len(strA))) k = k + 1 j = 0 End If Next j Else strX = Trim(strX) strTemp = strX For i = 1 To Len(strTemp) If Mid(strTemp, i, 1) = " " Then cnt = cnt + 1 strTemp = Trim(Right(strTemp, Len(strTemp) - i + 1)) i = 0 End If Next i strX = strX & " " strOperate.Count = cnt + 1 ReDim strOperate.Data(cnt) For i = 1 To Len(strX) If Mid(strX, i, 1) = " " Then strOperate.Data(j) = Left(strX, i - 1) strX = LTrim(Right(strX, Len(strX) - i + 1)) j = j + 1 i = 0 End If Next i End If End Function Private Function mMod(dblF As Double, dblS As Double) As Double Dim intM As Integer intM = Int(dblF / dblS) mMod = dblF - dblS * intM End Function Private Sub Form_Load() Text1 = getSheetNumber("39°22′30″", "114°33′45″", "A") Text1 = Text1 & vbCrLf & getSheetNumber("39°22′30″", "114°33′45″", "B") Text1 = Text1 & vbCrLf & getSheetNumber("39°22′30″", "114°33′45″", "C") Text1 = Text1 & vbCrLf & getSheetNumber("39°22′30″", "114°33′45″", "D") Text1 = Text1 & vbCrLf & getSheetNumber("39°22′30″", "114°33′45″", "E") Text1 = Text1 & vbCrLf & getSheetNumber("39°22′30″", "114°33′45″", "F") Text1 = Text1 & vbCrLf & getSheetNumber("39°22′30″", "114°33′45″", "G") Text1 = Text1 & vbCrLf & getSheetNumber("39°22′30″", "114°33′45″", "H") End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值