保存几何元素到oracle spatial

来源:互联网 发布:传奇霸业数据汇总 编辑:程序博客网 时间:2024/05/01 08:51
Cuckoo Framework GIS扩展计划开始启动。
代码举例: 保存几何元素到oracle spatial
package org.cuckooframework.gis.utils;import java.sql.*;import org.cuckooframework.jdbc.JdbcWrapping;import oracle.spatial.geometry.JGeometry;import oracle.sql.STRUCT;public class OracleSpatialUtil {private JdbcWrapping jdbc = new JdbcWrapping();public void updatePoint(String tableName, String geoColName, String pkName,String pkValue, double[] coords) throws SQLException {Connection conn = null;PreparedStatement ps = null;try {conn = jdbc.getConnection();JGeometry j_geom = JGeometry.createPoint(coords, 1, 8307);ps = conn.prepareStatement("UPDATE  " + tableName + " SET "+ geoColName + "=? WHERE " + pkName + "='" + pkValue + "'");STRUCT obj = JGeometry.store(j_geom, conn);ps.setObject(1, obj);ps.execute();} finally {ps.close();conn.close();}}public void updateLine(String tableName, String geoColName, String pkName,String pkValue, double[] coords) throws SQLException {Connection conn = null;PreparedStatement ps = null;try {conn = jdbc.getConnection();JGeometry j_geom = JGeometry.createLinearLineString(coords, 2, 8307);ps = conn.prepareStatement("UPDATE  " + tableName + " SET "+ geoColName + "=? WHERE " + pkName + "='" + pkValue + "'");STRUCT obj = JGeometry.store(j_geom, conn);ps.setObject(1, obj);ps.execute();} finally {ps.close();conn.close();}}public static void main(String args[]) throws SQLException {/*double[] coords4line = { 117.291935, 31.858818, 117.288111, 31.857575,117.284476, 31.856351, 117.280028, 31.854988, 117.276361,31.85373, 117.269741, 31.851501, 117.269496, 31.852636,117.267003, 31.849165, 117.258803, 31.832658, 117.2534,31.824521, 117.249716, 31.819603, 117.232726, 31.798573,117.229846, 31.7951, 117.225706, 31.789038, 117.22038,31.782381, 117.218535, 31.781215, 117.213371, 31.784446,117.204668, 31.78445, 117.20463, 31.790516, 117.208053,31.799411, 117.210196, 31.810546, 117.210438, 31.820885,117.21759, 31.820121, 117.222768, 31.821911, 117.226048,31.821141, 117.226585, 31.81131, 117.226925, 31.800918,117.227045, 31.79821 };new OracleSpatialUtil().updateLine("geo_line", "geoloc", "tid", "1",coords4line);*/double[] coords4point = {117.276361,31.85373};new OracleSpatialUtil().updatePoint("geo_point", "geoloc", "tid", "5",coords4point);}}
原创粉丝点击