java几何操作工具类

目录

一、介绍

二、工具类实现


一、介绍


为了能够更加方便的在java中操作几何对象,提高开发效果,编写了几何对象的操作工具类。

二、工具类实现


工具类具体如下。

public class GeometryToolUtil {

    private static WKTReader reader = new WKTReader();

    public static void main(String[] args) throws IOException, ParseException {
    }

    /**
     * wkt转Geometry
     *
     * @param wktStr
     * @return
     * @throws IOException
     * @throws ParseException
     */
    public static Geometry wktToGeom(String wktStr) throws IOException, ParseException {
        Geometry geometry = null;
        if (oConvertUtils.isNotEmpty(wktStr)) {
            geometry = reader.read(wktStr);
        }
        return geometry;
    }


    /**
     * 从wkt格式的坐标系定义中获取坐标系名称
     *
     * @param wkt wkt格式的坐标系定义
     * @return
     */
    public static String getCoordinateSystemName(String wkt) {
        try {
            CoordinateReferenceSystem coordinateReferenceSystem = CRS.parseWKT(wkt);
            return coordinateReferenceSystem.getName().getCode();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    /**
     * 创建空MultiPolygon
     *
     * @param srid
     * @return
     */
    public static MultiPolygon creatMultiPolygon_empty(int srid) {
        MultiPolygon multiPolygon = null;
        try {
            WKTReader reader = new WKTReader();
            multiPolygon = (MultiPolygon) reader.read("MULTIPOLYGON EMPTY");
            multiPolygon.setSRID(srid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return multiPolygon;
    }

    /**
     * 创建空point
     *
     * @param srid
     * @return
     */
    public static Point creatPoint_empty(int srid) {
        Point point = null;
        try {
            WKTReader reader = new WKTReader();
            point = (Point) reader.read("POINT EMPTY");
            point.setSRID(srid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return point;
    }

    /**
     * 判定几何类型是否为面/多面
     *
     * @param geometryType 几何类型
     * @return
     */
    public static boolean geomTypeIsPolygon(String geometryType) {
        if (geometryType.toLowerCase().equals("multipolygon") || geometryType.toLowerCase().equals("polygon")) {
            return true;
        }
        return false;
    }


    /**
     * 检查wkt是否为多面
     *
     * @param wkt
     * @return
     */
    public static boolean wktIsMultiPolygon(String wkt) {
        if (wkt.toLowerCase().startsWith("multipolygon")) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 检查wkt是否为面
     *
     * @param wkt
     * @return
     */
    public static boolean wktIsPolygon(String wkt) {
        if (wkt.toLowerCase().startsWith("polygon")) {
            return true;
        } else {
            return false;
        }
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

会跑的小鹿

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值