12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package com.shkpr.service.alambizplugin.commtools;
- import org.locationtech.jts.geom.GeometryFactory;
- import org.locationtech.jts.geom.Point;
- import org.locationtech.jts.geom.PrecisionModel;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- /**
- * 地理工具类
- *
- * @author 欧阳劲驰
- * @since JDK1.8
- */
- public class GeomUtil {
- /**
- * geom工厂
- */
- private static final GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4490);
- /**
- * 地球半径
- */
- private static final int EARTH_RADIUS = 6378137;
- /**
- * 将米转换为度
- *
- * @param degrees 度
- * @return 对应的米
- */
- public static double convertDegreesToMeters(double degrees) {
- return degrees * (Math.PI / 180) * EARTH_RADIUS;
- }
- /**
- * 将米转换为度
- *
- * @param meters 米
- * @return 对应的度
- */
- public static double convertMetersToDegrees(double meters) {
- return meters / (Math.PI / 180 * EARTH_RADIUS);
- }
- /**
- * 经纬度的度转十进制
- * <p>如RMC(NMEA0183)协议报文:</p>
- * <blockquote><pre>$GNRMC,072905.00,A,3640.46260,N,11707.54950,E,000.0,000.0,050119,OK*24</pre></blockquote>
- * <p>则表示为:{@code [36.67438,117.12583]}</p>
- *
- * @param degrees 度
- * @param minutesIndex 分索引,如 {@code ddmm.mmmmm} 则为2
- * @return 十进制表示
- */
- public static double convertDegreesToDecimal(String degrees, int minutesIndex) {
- return Integer.parseInt(degrees.substring(0, minutesIndex)) +
- //分除60保留8位
- BigDecimal.valueOf(Float.parseFloat(degrees.substring(minutesIndex)))
- .divide(BigDecimal.valueOf(60), 8, RoundingMode.HALF_UP)
- .doubleValue();
- }
- /**
- * 判断点1是否在点2距离范围内
- *
- * @param point1 点1
- * @param point2 点2
- * @param distance 距离(米)
- * @return 判断状态
- */
- public static Boolean isWithinDistance(Point point1, Point point2, double distance) {
- return point1.isWithinDistance(point2, convertMetersToDegrees(distance));
- }
- }
|