JTS:01 使用WKT格式数据

使用WKT格式数据

      • 版本
      • 代码

版本

org.locationtech.jts:jts-core:1.19.0
链接: github

代码

import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import org.locationtech.jts.io.WKTWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * WKT学习
 * @author LiHan
 * 2023年9月12日 11:03:46
 */
public class WKTStu {

    private static WKTReader wktReader;

    private static WKTWriter wktWriter;

    private static final Logger LOGGER = LoggerFactory.getLogger(WKTStu.class);

    public static void main(String[] args) {
        wktReader = new WKTReader();
        wktWriter = new WKTWriter();
        WKTStu wktStu = new WKTStu();
        wktStu.stu01();
    }

    /**
     * WKT 数据读取
     */
    public void stu00() {
        try {
            Geometry geometry = wktReader.read("POINT(114.413265 30.482731)");
            LOGGER.info("geometry类型: {}",geometry.getGeometryType());
            LOGGER.info("X: 位置{}", geometry.getCoordinate().getX());
            LOGGER.info("Y: 位置{}", geometry.getCoordinate().getY());
        } catch (ParseException e) {
            LOGGER.error("stu00 错误", e);
        }
    }

    /**
     * WKT 数据输出
     */
    public void stu01() {
        try {
            Geometry geometry = wktReader.read("POINT(114.413265 30.482731)");
            String str = wktWriter.write(geometry);
            LOGGER.info(str);
        } catch (ParseException e) {
            LOGGER.error("stu00 错误", e);
        }
    }
}

你可能感兴趣的:(JTS,JTS,GIS)