使用geotools API在WGS84 crs中线段和点之间的最短距离 [英] Shortest distance between a line segment and a point in WGS84 crs using geotools api

查看:886
本文介绍了使用geotools API在WGS84 crs中线段和点之间的最短距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在geotools中,您可以使用Geometry类中的距离功能找到两个几何之间的距离.没有几何的Point子类,但是没有Geometry的线段子类.但是,有LineSegment类是从LineString派生的,而LineString不是Geometry类的子类.我尝试使用JTS,但它似乎仅适用于笛卡尔坐标系.

In geotools you can find distance between two geometries using the distance function in Geometry class. There is a Point subclass of Geometry but no line segment subclass of Geometry. There is however LineSegment class which derives from LineString which is not subclass of Geometry class. I tried using JTS but it appears as JTS is only for Cartesian coordinate system.

问题:如何以WGS84 crs找到LineSegment和一个点之间的最短距离(以米为单位).

Question: How to find shortest distance (in meters) between a LineSegment and a Point in WGS84 crs.

请注意:我知道在不使用geotools的情况下,SO上有可用的答案.由于我们在项目中使用了geotools,因此代码的可维护性非常重要,因此我想在geotools中做到这一点.

Please note: I know there are answers available on SO for doing this without using geotools. Since we are using geotools in our project and code maintainability is very important I want to do it in geotools.

推荐答案

在我看来,您必须同时使用点和线串的geotools将WGS84坐标转换为TM坐标.这是我的博客中有关CRS类的示例代码地质工具

In my opinion, you have to convert WGS84 coords to TM coords using geotools both point and linestring..Here is some example code of my blog about CRS class of geotools

http://blog.naver.com/tommybee/50154157186

...然后计算线串上点与点之间的距离. 您最终可以通过将原始协调参考系从TM(Transverse Meractor)转换为WGS84来获得结果.

... then calculate the distance between point and point on linestring. you can finally get the result by converting the original coordination reference system as a WGS84 from TM(Transverse Meractor)

https ://github.com/geotools/geotools/blob/master/docs/src/main/java/org/geotools/jts/SnapToLine.java

有关距离的更多讨论,您可以在下面查看geotools用户站点.它是其中之一

And more discussion about distance you can check the geotools user site below..it's one of them

http://osgeo-org.1560.x6.nabble.com/position-on-LineString-that-is-closest-to-Point-td4322083.html

这篇关于使用geotools API在WGS84 crs中线段和点之间的最短距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆