java GIS地理信息处理 geometry数据处理 GeomUtil

package com.xj.hhjk.common.util;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
import org.locationtech.jts.geom.Geometry;
import org.opengis.feature.simple.SimpleFeature;

/**
 * GeoJson对Geometry的创作工具
 * 
 * @author server
 *
 */
public class GeomUtil {

    public static String read(String path) throws IOException {
        SimpleFeatureCollection coll = readShp(new File(path)).getFeatures();
        SimpleFeatureIterator iters 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
可以使用JDBC连接mysql5.7,然后使用PreparedStatement对象将Geometry数据写入到mysql5.7,具体步骤如下: 1. 加载JDBC驱动程序:Class.forName("com.mysql.jdbc.Driver"); 2. 连接mysql5.7数据库:Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "password"); 3. 创建PreparedStatement对象:PreparedStatement ps = conn.prepareStatement("insert into table_name (geometry_column) values (?)"); 4. 将Geometry数据转换成byte数组:byte[] geometryBytes = geometry.toBinary(); 5. 将Geometry数据设置到PreparedStatement对象中:ps.setBytes(1, geometryBytes); 6. 执行插入操作:ps.executeUpdate(); 完整代码示例: ``` import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import com.vividsolutions.jts.geom.Geometry; public class GeometryToMysql { public static void main(String[] args) { String url = "jdbc:mysql://localhost:3306/test"; String user = "root"; String password = "password"; try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection(url, user, password); String sql = "insert into table_name (geometry_column) values (?)"; PreparedStatement ps = conn.prepareStatement(sql); // 将Geometry数据转换成byte数组 Geometry geometry = ...; byte[] geometryBytes = geometry.toBinary(); // 将Geometry数据设置到PreparedStatement对象中 ps.setBytes(1, geometryBytes); // 执行插入操作 ps.executeUpdate(); ps.close(); conn.close(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

长青风

赏一块,发大财!赏两块,惹人爱

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值