SHCJ2BDJW.java 6.1 KB
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();
		}
	}

}