问题描述
我有以下查询:
select distance(GeomFromText('POINT(8 49)',4326),GeomFromText('LINESTRING(8.329969 49.919323,8.330181 49.919468)',4326))
这给我0.97度.但是我需要以米为单位,并且不知道要转换为哪个SRID.
this gives me 0.97 degrees. But I need it in meters and do not know which SRID to transform to.
有人可以给我一个例子,如何以米为单位获得空间的结果吗?
Can somebody give me an example how to get the result in meters for spatialite?
所有职位都在欧洲.
推荐答案
只需将以度为单位的值乘以111195
-此值为(Earth mean radius)*PI/180
-即地球表面上一个大圆度的平均长度,以米为单位'.
Just multiply the value in degrees by 111195
- this value is (Earth mean radius)*PI/180
- that is 'mean length of one great circle degree in meters on Earth's surface'.
使用此方法获得的结果在WGS84椭球的测地距离的1%以内.
The result obtained using this method is within 1% of the geodesic distance for the WGS84 ellipsoid.
编辑
好吧,我在上面的回答仍然代表着一个问题:如何将弧度转换为米长度",但这不是您要问的(应该问的).
OK, my answer above still stands for the question: "how to convert arcs in degrees into lengths in meters", however, it's not the question you asked (should have asked).
我还没有专业使用Spatialite,因此我假设您的示例查询确实返回了长度(以度为单位)".这不是真的.
I haven't used Spatialite professionally, so I assumed that your sample query indeed returns the 'length in degrees'. That's not true.
不幸的是,看来Spatialite无法从地理意义"上计算距离.尽管您的几何是使用SRID 4326定义的,但仍将它们视为在飞机上一样对待.
Unfortunately, it appears that Spatialite fails to calculate the distance in 'geographic sense'. Despite your geometries are defined with SRID 4326, it treats them as if they were on a plane.
这是一个简单的证明:
select Distance(GeomFromText('POINT(0 0)',4326),GeomFromText('POINT(3 4)',4326));
返回5.0
.
真可惜...
让我们看看您的原始查询:
Lets have a look at your original query:
select Distance(
GeomFromText('POINT(8 49)',4326),
GeomFromText('LINESTRING(8.329969 49.919323,8.330181 49.919468)',4326)
)
MS SQL Server中的等效查询:
An equivalent query in MS SQL Server:
SELECT (geography::STGeomFromText('POINT(8 49)', 4326)).STDistance(geography::STGeomFromText('LINESTRING(8.329969 49.919323,8.330181 49.919468)', 4326));
立即为您提供正确的结果:105006.59673084648
,以米为单位,而没有任何额外的麻烦.
gets you the correct result immediately: 105006.59673084648
, in meters, and without any extra brouhaha.
那么您对Spatialite的选择是什么?
So what are your options with Spatialite?
的确,正如您在评论中所说,一种选择是投影您的几何形状,然后进行计算.在欧洲使用SRID 3035也很有意义(如果您的位置主要在德国,我会考虑使用SRID 25832).
Indeed, as you said in comments, one option is to project your geometries, and calculate on those. Using SRID 3035 for Europe makes sense, too (if your locations are mostly in Germany, I'd consider SRID 25832).
select Distance(
Transform(GeomFromText('POINT(8 49)',4326),25832),
Transform(GeomFromText('LINESTRING(8.329969 49.919323,8.330181 49.919468)',4326),25832)
)
返回104969.401605453
.
关于您的其他示例(在注释中):
As to your other sample (in comments):
select distance(
Transform(GeomFromText('POINT(8.328957 49.920900)',4326),3035),
Transform(GeomFromText('POINT(8.339665 49.918000)',4326),3035)
)
有一种更简单的方法(如果您有两个POINT,而不是POINT和LINESTRING):使用POINT创建LINESTRING并使用GeodesicLength
函数,如下所示:
There's a simpler way to do it (if you have two POINTs, not a POINT and a LINESTRING): create a LINESTRING with your POINTs and use GeodesicLength
function, like this:
select GeodesicLength(GeomFromText('LINESTRING(8.328957 49.920900, 8.339665 49.918000)',4326))
它按预期返回833.910006698673
.
这篇关于以米为单位获取距离,而不是以Spatialite为单位获取距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!