问题描述
在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
...然后计算线串上点与点之间的距离.您最终可以通过将原始协调参考系从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)
有关距离的更多讨论,您可以在下面查看geotools用户站点.它是其中之一
And more discussion about distance you can check the geotools user site below..it's one of them
这篇关于使用geotools API在WGS84 crs中线段和点之间的最短距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!