zoukankan      html  css  js  c++  java
  • java操作oracle空间信息介绍

    转自:http://www.cdtarena.com/javapx/201307/9088.html

    sde是Spatial Database Engine简写,中文全称:空间数据库引擎。

    SDE是一种客户/服务器软件,可使空间数据在工业标准的数据库管理系统中存储、管理和快速查询检索。把GIS数据放在RDBMS中,但是一般的RDBMS都没有提供GIS的数据类型(如点、线、多边形、以及这些feature之间的拓扑关系和投影坐标等相关信息),RDBMS只提供了少量的数据类型支持:int,float,double,Blob,Long ,char等,一般都是数字,字符串和二进制数据几种。并且RDBMS不仅没有提取对GIS数据类型的存储,也没有提供对这些基础类型的操作(如:判断包含关系,相邻、相交、求差、距离、最短路径等)
    JAVA对sde操作,首先需要下载sde支持的jar包。jpe92_sdk.jar和jsde92_sdk.jar两个包,这两个包可以从安装的目录下找到。
    下面是java获的sde的链接代码:

     

    [java] view plaincopyprint?
    01./** 
    02.     * 连接sde服务 
    03.     * @return 
    04.     */  
    05.    public  SeConnection getConnection () {  
    06.        SeConnection conn = null ;  
    07.        try {  
    08.            conn = new SeConnection(SDE_SERVER_IP, SDE_PROT, SDE_DATEBASE_SID, SDE_USERNAME, SDE_PASSWORD);   
    09.        } catch (SeException e) {  
    10.            return null;  
    11.        }  
    12.        return conn;  
    13.    }  

    对sde数据进行添加,点线面的新增 


    [java] view plaincopyprint?
    01./** 
    02.     * 添加资源信息点到sde中 
    03.     * @param pointBean 坐标点 POJO 
    04.     * @param tbName    图层名称 
    05.     * @param String typeName 所画的类型 1 点 2 线 3 面 
    06.     * @return   Long   sde的id 
    07.     * @throws Exception 
    08.     */  
    09.    public Long addPointObject(PointBean pointBean, List columnList, String tableName, String typeName) throws Exception {  
    10.        SeLayer insertLayer = null;  
    11.        SeConnection conn = null;  
    12.        Long intsertRowID = null;  
    13.        SeInsert insert = null;  
    14.        try {  
    15.            conn = this.getConnection();  
    16.            insertLayer = new SeLayer( conn,  tableName, "SHAPE");  
    17.            if (insertLayer == null) {  
    18.                throw new Exception("找不到空间表:" + tableName);  
    19.            }  
    20.            conn.startTransaction();  
    21.            int arrayLength = columnList.size() + 1 ;  
    22.            String[] cols = new String[arrayLength];  
    23.            cols[0] = "SHAPE";  
    24.            for (int i = 0 ;i<columnList.size() ; i++) {  
    25.                ColumnBean columnBean = (ColumnBean)columnList.get(i);  
    26.                cols[i+1] = columnBean.getName();  
    27.            }  
    28.            insert = new SeInsert(conn);  
    29.            insert.intoTable(insertLayer.getName(), cols);  
    30.            insert.setWriteMode(true);  
    31.            SeCoordinateReference coordref = (SeCoordinateReference) insertLayer.getCoordRef();  
    32.            SeShape shape = new SeShape(coordref);  
    33.              
    34.            if ("1".equals(typeName)) {  
    35.                this.addPoint(pointBean, shape);  
    36.            } else if ("2".equals(typeName)) {  
    37.                this.addLine(pointBean, shape);  
    38.            } else if ("3".equals(typeName)) {  
    39.                this.addPolygon(pointBean, shape);  
    40.            }  
    41.            SeRow row = insert.getRowToSet();  
    42.            row.setShape(0, shape);  
    43.            for (int i = 0 ;i<columnList.size() ; i++) {  
    44.                ColumnBean columnBean = (ColumnBean)columnList.get(i);  
    45.                if (columnBean.getTypeObject() == 1) {  
    46.                    row.setNString(i+1, String.valueOf(columnBean.getValObject()));  
    47.                } else if (columnBean.getTypeObject() == 2) {  
    48.                    row.setInteger(i+1, Integer.parseInt(columnBean.getValObject().toString()));  
    49.                }else if (columnBean.getTypeObject() == 3) {  
    50.                    row.setDouble(i+1, Double.parseDouble(columnBean.getValObject().toString()));  
    51.                }   
    52.            }  
    53.            insert.execute();  
    54.            intsertRowID = new Long(insert.lastInsertedRowId().longValue());  
    55.            conn.commitTransaction();  
    56.        } catch (Exception ex) {  
    57.            ex.printStackTrace();  
    58.            conn.rollbackTransaction();  
    59.        } finally {  
    60.            if (insert != null) {  
    61.                insert.close();  
    62.            }  
    63.            if (conn != null) {  
    64.                conn.close();  
    65.            }  
    66.        }  
    67.        return intsertRowID;  
    68.    }  

    sde查询接口实现 


    [java] view plaincopyprint?
    01./** 
    02.     * 查询sde 
    03.     * @param productId 产品id 
    04.     * @throws SeException 
    05.     */  www.cdtarena.com
    06.    public SeQuery searchSde (Long productId, String tableName) throws SeException {  
    07.        SeConnection conn = getConnection();  
    08.        SeLayer layer = new SeLayer( conn,  tableName, "SHAPE");  
    09.        SeSqlConstruct sqlConstruct = new SeSqlConstruct(layer.getName());  
    10.        if (productId != null) {  
    11.            sqlConstruct.setWhere("yid="+productId.intValue());  
    12.        }  
    13.        String[] cols = null;  
    14.        if (tableName.equals("YU_AN_POINT") || tableName.equals("FANG_AN_POINT")) {  
    15.            cols = new String[4];  
    16.            cols[0] = new String("OBJECTID");  
    17.            cols[1] = layer.getSpatialColumn();  
    18.            cols[2] = new String("NAME");  
    19.            cols[3] = new String("IMAGETYPE");  
    20.        } else {  
    21.            cols = new String[3];  
    22.            cols[0] = new String("OBJECTID");  
    23.            cols[1] = layer.getSpatialColumn();  
    24.            cols[2] = new String("NAME");  
    25.        }  
    26.        System.out.println("cols.length : " + cols.length);  
    27.        SeQuery query = new SeQuery(conn, cols, sqlConstruct );  
    28.        query.prepareQuery();  
    29.        query.execute();  
    30.        return query;  
    31.    }  

    SDE信息删除操作 


    [java] view plaincopyprint?
    01./** 
    02.     *  
    03.     * 删除 通过列对应的值 
    04.     * @param id     值 
    05.     * @param column 列  
    06.     * @param tbName 表名 
    07.     * @throws SeException 
    08.     */  
    09.     public void deletePointObject(String id, String column, String tbName) throws SeException {  
    10.        SeConnection conn = null;  
    11.        SeLayer layer = null;  
    12.        SeDelete delete = null;  
    13.        try {  
    14.            conn = this.getConnection();  
    15.            layer = new SeLayer(conn, tbName, "SHAPE"); // 得到对应图层   
    16.            if (layer == null) {  
    17.                throw new Exception("找不到空间表:" + tbName);  
    18.            }  
    19.            conn.startTransaction();  
    20.            delete = new SeDelete(conn);  
    21.            delete.fromTable(layer.getName(), column + "='" + id+"'");  
    22.            conn.commitTransaction();  
    23.        } catch (Exception ex) {  
    24.            conn.rollbackTransaction();  
    25.        } finally {  
    26.            if (delete != null) {  
    27.                try {  
    28.                    delete.close();  
    29.                } catch (SeException e) {  
    30.                    e.printStackTrace();  
    31.                    throw e;  
    32.                } finally {  
    33.                    if (conn != null) {  
    34.                        conn.close();  
    35.                    }  
    36.                }  
    37.            }  
    38.        }  
    39.    }  

     

     

  • 相关阅读:
    array_map()与array_shift()搭配使用 PK array_column()函数
    Educational Codeforces Round 8 D. Magic Numbers
    hdu 1171 Big Event in HDU
    hdu 2844 poj 1742 Coins
    hdu 3591 The trouble of Xiaoqian
    hdu 2079 选课时间
    hdu 2191 珍惜现在,感恩生活 多重背包入门题
    hdu 5429 Geometric Progression 高精度浮点数(java版本)
    【BZOJ】1002: [FJOI2007]轮状病毒 递推+高精度
    hdu::1002 A + B Problem II
  • 原文地址:https://www.cnblogs.com/cdtarena/p/3174047.html
Copyright © 2011-2022 走看看