用java实现经纬度坐标度分秒与度批量转换
? ? ? ??
1、度轉(zhuǎn)度分秒算法
? ? ? ? 小數(shù)點(diǎn)后數(shù)字乘以60,再將得到的數(shù)的小數(shù)點(diǎn)后數(shù)字乘以60
? ? ? ? 例如:103.55685565
? ? ? ? 103.55685565 - 103 = 0.55685565
? ? ? ? 0.55685565 ?60 = 33.411339
? ? ? ? 0.411339 ?60 = 24.68034
? ? ? ? 結(jié)果為103度33份24.68034秒
?2、度分秒轉(zhuǎn)度算法
? ? ? ? 以度轉(zhuǎn)度分秒方式反算
? ? ? ? 例如:103度33份24.68034秒
? ? ? ? 24.68034 / 60 = 0.411339
? ? ? ? 33.411339 / 60 = 0.55685565
? ? ? ? 103 + ?0.55685565 = 103.55685565
? ? ? 有了轉(zhuǎn)換公式就可以做一個(gè)轉(zhuǎn)換工具,java實(shí)現(xiàn):
package convertBLH;import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.border.EmptyBorder;class frame1 extends JFrame{/*** */private static final long serialVersionUID = 1L;//輸入輸出框private JTextField textField1 = new JTextField(8);private JTextField textField2 = new JTextField(3);private JTextField textField3 = new JTextField(3);private JTextField textField4 = new JTextField(5);private JTextField textField5 = new JTextField(8);private JTextField textField6 = new JTextField(3);private JTextField textField7 = new JTextField(3);private JTextField textField8 = new JTextField(5);private JLabel label1 = new JLabel("度——————>度分秒");private JLabel label2 = new JLabel("度分秒——————>度");private JButton button1 = new JButton("轉(zhuǎn)換");private JButton button2 = new JButton("轉(zhuǎn)換");public frame1(){//設(shè)置窗體大小、位置JFrame frame = new JFrame("度分秒轉(zhuǎn)換工具");frame.setSize(600,300);frame.setLocationRelativeTo(null);//定義面板容器JPanel contentpanel = new JPanel();contentpanel.setBorder(new EmptyBorder(5,5,5,5));frame.add(contentpanel);contentpanel.setLayout(null);JPanel panel = new JPanel();panel.setBounds(0,0,580,380);contentpanel.add(panel);panel.setLayout(null);//度轉(zhuǎn)度分秒//設(shè)置標(biāo)簽label1.setBounds(220,10,200,28);panel.add(label1);//設(shè)置輸入文本框textField1.setBounds(50,50,80,28);panel.add(textField1);//設(shè)置輸出文本框textField2.setBounds(270,50,50,28);panel.add(textField2);textField3.setBounds(340,50,50,28);panel.add(textField3);textField4.setBounds(410,50,100,28);panel.add(textField4);//設(shè)置按鈕button1.setBounds(150,50,100,28);button1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {//計(jì)算textfield2需要顯示的數(shù)字Double iDouble = Double.parseDouble(textField1.getText());int i = iDouble.intValue();String string = String.valueOf(i);textField2.setText(string);//計(jì)算textfield3需要顯示的數(shù)字double j1 = iDouble - i;Double j2 = j1 * 60;int j3 = j2.intValue();textField3.setText(String.valueOf(j3));//計(jì)算textField4double k1 = j2 - j3;Double k2 = k1 * 60;textField4.setText(String.valueOf(k2));}});panel.add(button1);//度分秒轉(zhuǎn)度label2.setBounds(220,90,200,28);panel.add(label2);textField5.setBounds(50,130,50,28);panel.add(textField5);textField6.setBounds(120,130,50,28);textField7.setBounds(190,130,100,28);textField8.setBounds(430,130,80,28);panel.add(textField6);panel.add(textField7);panel.add(textField8);button2.setBounds(310,130,100,28);panel.add(button2);button2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {Double iDouble = Double.parseDouble(textField7.getText());iDouble = iDouble / 60;iDouble = Double.parseDouble(textField6.getText()) + iDouble;iDouble = iDouble / 60;iDouble = iDouble + Double.parseDouble(textField5.getText());textField8.setText(iDouble.toString());}});frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);} } public class ConvertBLH {public static void main(String[] args) {new frame1();} }運(yùn)行效果:
另外,筆者做了一個(gè)批量轉(zhuǎn)換工具,可讀取坐標(biāo)txt文件并自動(dòng)識(shí)別度分秒轉(zhuǎn)換方式,實(shí)現(xiàn)度與度分秒格式批量轉(zhuǎn)換。
轉(zhuǎn)換結(jié)果:
下載地址:鏈接:https://pan.baidu.com/s/1zwnjKlhtBoG2zuYQlIDeQw 提取碼:o32b
總結(jié)
以上是生活随笔為你收集整理的用java实现经纬度坐标度分秒与度批量转换的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java图像处理之自动对比度
- 下一篇: 图像处理直方图匹配-巴氏系数原理及实现