用户输入地理点语法验证

问题描述 投票:0回答:1

我正在尝试在 java 项目中使用地理点。 我开始研究良好的实践,开始研究 GeoTols,它似乎是 java 的参考。

我想做的是验证用户输入的地理点。 用户输入是 JSON 文件。所以我正在解析文件,我想找到一些可以验证语法的东西,并且可能存在这个坐标上的点。

我在GeoTools中找不到它(可能是我搜索错误)。 谢谢!

java gis geo geotools
1个回答
0
投票

验证坐标应根据参考坐标系确定。可以像wgs84bounds一样访问epsg.io,使用下面的代码判断坐标是否在对应的区间内。

package org.example;


import org.geotools.referencing.CRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.cs.CoordinateSystemAxis;

/**
 * @author Arjen10
 * @date 2023/9/15 下午4:55
 */
public class Test2 {

    public static void main(String[] args) throws Exception {
        CoordinateReferenceSystem decode = CRS.decode("EPSG:4326", true);
        CoordinateSystem coordinateSystem = decode.getCoordinateSystem();
        CoordinateSystemAxis axis = coordinateSystem.getAxis(0);
        CoordinateSystemAxis axis1 = coordinateSystem.getAxis(1);
        double maximumValue = axis.getMaximumValue();
        double maximumValue1 = axis1.getMaximumValue();
        double minimumValue = axis.getMinimumValue();
        double minimumValue1 = axis1.getMinimumValue();
        System.out.println("wg84 maxX " + maximumValue);
        System.out.println("wg84 maxY " + maximumValue1);
        System.out.println("wg84 minX " + minimumValue);
        System.out.println("wg84 minY " + minimumValue1);
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.