SHCJ2BDJW.java
2.84 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
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 sqlUpdate = "UPDATE jjwgps_t_gjldb SET bdjw = GeomFromText(?),SHAPE = GeomFromText(?) 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("shape", rs.getString("SHAPE"));
map.put("id", rs.getInt("ID"));
list.add(map);
}
for(int i =0;i<list.size();i++) {
Map<String, Object> temp = list.get(i);
String lineString = temp.get("shape").toString();
/*String lineString = "LINESTRING (13532.5305161702 -3677.63275264995, 13433.22401617 -3881.74765264988)";*/
String arrayP[] = lineString.substring(lineString.indexOf("(")+1, lineString.length()-1).split(", ");
int id = Integer.parseInt(temp.get("id").toString());
String geometry = "";
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)
geometry = geometry + (location.getLng()+0.000727) + " " + (location.getLat() - 0.0000624);
else
geometry = geometry + (location.getLng()+0.000727) + " " + (location.getLat() - 0.0000624) + ",";
}
ps = null;
geometry = "LINESTRING(" + geometry +")";
ps = conn.prepareStatement(sqlUpdate);
ps.setString(1, geometry);
ps.setString(2, lineString);
ps.setInt(3, id);
int stauts = ps.executeUpdate();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}