📄 detachhandle.java
字号:
package mapcenter.weihu;
import java.sql.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import com.mapinfo.dp.*;
import com.mapinfo.dp.util.*;
import com.mapinfo.util.*;
import com.mapinfo.mapj.*;
import mapcenter.service.*;
public class DetachHandle extends Thread implements ActionListener{
private static Log log = LogFactory.getLog("WebGIS");
private Connection conn = null;
private JProgressBar progBar;
private JLabel progLabel;
private JButton runButton;
private MapJ myMap;
public DetachHandle(MapHandle mapHandle)throws Exception{
this.myMap = mapHandle.getMapJ();
}
public void mapDetach()throws Exception{
try{
progLabel.setText("正在靖空归一化数据......");
progBar.setValue(20);
progBar.setString("20%");
conn = ConnDBFactory.getInstance().getConnection();
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.execute("delete from gui_yi_hua");
conn.commit(); stmt.close();
//========= 循环每一个注册图层 ===================
String[] layerName = MapContext.getLayerParameter();
for(int i=0; i<layerName.length; i++){
FeatureLayer layer = myMap.getLayers().getLayer(layerName[i]);
TableInfo tabInfo = layer.getTableInfo();
ArrayList columnNames = new ArrayList();
for (int a=0;a<tabInfo.getColumnCount();a++){
columnNames.add(tabInfo.getColumnName(a));
}
FeatureSet featureSet = layer.searchAll(columnNames,null);
RewindableFeatureSet reFeatureSet = new RewindableFeatureSet(featureSet);
if(reFeatureSet == null){continue;}
//========= 循环处理每个图元记录 =================
Feature feature = null;
PreparedStatement preStmt = conn.prepareStatement("Insert Into gui_yi_hua(txbh,centerx,centery,feature_type,feature_key,mingcheng,dizhi,mingchengpinyin,dizhipinyin) Values(?,?,?,?,?,?,?,?,?)");
while((feature=reFeatureSet.getNextFeature()) != null){
//生成基本要素
int columnIndex = tabInfo.getColumnIndex("MapInfo_ID");
String featureKey = feature.getAttribute(columnIndex).getString();
String txbh = layerName[i]+"&"+featureKey;
DoublePoint centerPoint = feature.getGeometry().getBounds().center();
String centerX = String.valueOf(centerPoint.x);
String centerY = String.valueOf(centerPoint.y);
String name="", address="", namePinYin="", addressPinYin="";
//生成名称拼音
if(columnNames.contains("名称")){
columnIndex = tabInfo.getColumnIndex("名称");
name = feature.getAttribute(columnIndex).getString();
namePinYin = name;
}
//生成地址拼音
if(columnNames.contains("地址")){
columnIndex = tabInfo.getColumnIndex("地址");
address = feature.getAttribute(columnIndex).getString();
addressPinYin = address;
}
//数据库增加一行记录
preStmt.setString(1,txbh);
preStmt.setString(2,centerX);
preStmt.setString(3,centerY);
preStmt.setString(4,layerName[i]);
preStmt.setString(5,featureKey);
preStmt.setString(6,name);
preStmt.setString(7,address);
preStmt.setString(8,namePinYin);
preStmt.setString(9,addressPinYin);
preStmt.addBatch();
progLabel.setText("正在处理"+layerName[i]+"图层");
progBar.setValue(50);
progBar.setString("50%");
}//结束循环每个图元
preStmt.executeBatch();
preStmt.close();
reFeatureSet.dispose();
}//结束循环每个图层
conn.commit();
progLabel.setText("完成归一化操作");
progBar.setValue(100);
runButton.setEnabled(true);
}catch(Exception e){
log.error(e);
}finally{
try{conn.close();}catch(Exception e){}
}
}
public void actionPerformed(ActionEvent parm1){
try{
runButton = (JButton)parm1.getSource();
runButton.setEnabled(false);
this.progLabel = (JLabel)runButton.getClientProperty("Label");
this.progBar = (JProgressBar)runButton.getClientProperty("jprog");
this.start();
}catch(Exception e){log.error(e);}
}
public void run(){
try{
this.mapDetach();
}catch(Exception e){log.error(e);}
}
public static void main(String[] args){
try{
Connection conn = ConnDBFactory.getInstance().getConnection();
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("select count(*) as aaa from an_qing_xin_xi_father_his");
rs.next();
int count = rs.getInt(1);
System.out.println(count);
}catch(Exception e){e.printStackTrace();}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -