SHCJ2BDJW.java
6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package com.bsth.util.Geo;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.bsth.util.JWDUtil;
import com.bsth.util.TransGPS;
import com.bsth.util.TransGPS.Location;
import com.bsth.util.db.DBUtils_MS;
public class SHCJ2BDJW {
public static void main(String[] args) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
/*String sqlSelect = "SELECT b.SHAPESTRING as SHAPE , b.id as ID FROM jjwgps_t_gjldb b where SHAPESTRING is not null order by b.ldbh asc ";*/
/*String sqlSelect = "select s.id,s.descriptions from bsth_c_station s order by s.id asc ";*/
String sqlSelect = "select s.id,s.x,s.y from bsth_c_station s where id >=26882 order by s.id asc";
/*String sqlSelect = "SELECT s.id,s.descriptions FROM bsth_c_section s order by s.id asc ";*/
/*String sqlUpdate = "UPDATE bsth_c_section SET csection_vector = ST_GeomFromText(?) , bsection_vector=ST_GeomFromText(?) , gsection_vector=ST_GeomFromText(?) where id = ?";*/
String sqlUpdate = "UPDATE bsth_c_station SET b_jwpoints= ? , g_lonx=? , g_laty=? where id = ?";
List<Map<String, Object>> list = new ArrayList<>();
try {
conn = DBUtils_MS.getConnection();
ps = conn.prepareStatement(sqlSelect);
rs = ps.executeQuery();
while (rs.next()) {
Map<String, Object> map = new HashMap<String, Object>();
/*map.put("descriptions", rs.getString("descriptions"));*/
map.put("x", rs.getString("x"));
map.put("y", rs.getString("y"));
map.put("id", rs.getInt("id"));
list.add(map);
}
for(int i =0;i<list.size();i++) {
Map<String, Object> temp = list.get(i);
// POINT (8229.30921617 -933.16425265)
//String lineString = temp.get("descriptions").toString();
Double lng = Double.parseDouble(temp.get("x").toString());
Double lat = Double.parseDouble(temp.get("y").toString());
Map map_2 = JWDUtil.ConvertSHToJW(lng,lat);
String b_jwpoints = "";
Float g_lonx=0.0f,g_laty=0.0f;
int id = Integer.parseInt(temp.get("id").toString());
g_lonx = Float.parseFloat(map_2.get("x").toString());
g_laty = Float.parseFloat(map_2.get("y").toString());
Location location = TransGPS.LocationMake(Float.parseFloat(map_2.get("x").toString()), Float.parseFloat(map_2.get("y").toString()));
location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location));
b_jwpoints = (location.getLng()+0.000727) + " " + (location.getLat() - 0.0000624);
//String arrayP[] = lineString.substring(lineString.indexOf("(")+1, lineString.length()-1).split(", ");
/*String arrayP[] = lineString.substring(lineString.indexOf("(")+1, lineString.length()-1).split(" ");
String b_jwpoints = "";
Float g_lonx=0.0f,g_laty=0.0f,x=0.0f,y=0.0f;*/
/*Double lng = Double.parseDouble(arrayP[0]);
Double lat = Double.parseDouble(arrayP[1]);
x = Float.parseFloat(arrayP[0]);
y = Float.parseFloat(arrayP[1]);
// WGS84
Map map_2 = JWDUtil.ConvertSHToJW(lng,lat);
g_lonx = Float.parseFloat(map_2.get("x").toString());
g_laty = Float.parseFloat(map_2.get("y").toString());
Location location = TransGPS.LocationMake(Float.parseFloat(map_2.get("x").toString()), Float.parseFloat(map_2.get("y").toString()));
location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location));
b_jwpoints = (location.getLng()+0.000727) + " " + (location.getLat() - 0.0000624);*/
//b_jwpoints = (location.getLng()) + " " + (location.getLat());
/* String csection_vector="",bsection_vector="",gsection_vector="";
for(int k =0;k<arrayP.length;k++) {
String arrayXY[] = arrayP[k].split(" ");
Double lng = Double.parseDouble(arrayXY[0]);
Double lat = Double.parseDouble(arrayXY[1]);
Map map_2 = JWDUtil.ConvertSHToJW(lng,lat);
Location location = TransGPS.LocationMake(Float.parseFloat(map_2.get("x").toString()), Float.parseFloat(map_2.get("y").toString()));
location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location));
if(k==arrayP.length-1) {
bsection_vector = bsection_vector + (location.getLng()+0.000727) + " " + (location.getLat() - 0.0000624);
csection_vector = csection_vector + arrayXY[0] + " " + arrayXY[1];
gsection_vector = gsection_vector + map_2.get("x").toString() + " " + map_2.get("y").toString();
}else {
bsection_vector = bsection_vector + (location.getLng()+0.000727) + " " + (location.getLat() - 0.0000624) + ",";
csection_vector = csection_vector + arrayXY[0] + " " + arrayXY[1] +",";
gsection_vector = gsection_vector + map_2.get("x").toString() + " " + map_2.get("y").toString()+",";
}
}*/
ps = null;
//bsection_vector = "LINESTRING(" + bsection_vector +")";
//csection_vector = "LINESTRING(" + csection_vector +")";
//gsection_vector = "LINESTRING(" + gsection_vector +")";
ps = conn.prepareStatement(sqlUpdate);
// String sqlUpdate = "UPDATE bsth_c_section SET csection_vector = ? , bsection_vector=? , gsection_vector=? where id = ?";
//ps.setString(1, csection_vector);
//ps.setString(2, bsection_vector);
//ps.setString(3, gsection_vector);
//ps.setInt(4, id);
//int stauts = ps.executeUpdate();
// String sqlUpdate = "UPDATE bsth_c_station SET b_jwpoints = ?1 , g_lonx=?2 , g_laty=?3 , x = ?4 , y = ?5 where id = ?6";
/*ps.setString(1, b_jwpoints);
ps.setFloat(2, g_lonx);
ps.setFloat(3, g_laty);
ps.setFloat(4, x);
ps.setFloat(5, y);
ps.setFloat(6, id);*/
ps.setString(1, b_jwpoints);
ps.setFloat(2, g_lonx);
ps.setFloat(3, g_laty);
ps.setFloat(4, id);
int stauts = ps.executeUpdate();
System.out.println(stauts);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}