计算点与海岸之间的最小距离 [英] calculating minimum distance between a point and the coast

查看:160
本文介绍了计算点与海岸之间的最小距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取给定点与海岸之间的最小距离.我的例子是马德里到海岸的距离:

I am trying to get the minimum distance between a given point and the coast. My example is the distance of Madrid to the coast:

library(rgeos)
library(maptools)
coast <- readShapeLines("Natural_Earth_quick_start/10m_physical/ne_10m_coastline.shp")
MAD = readWKT("POINT(-3.716667 40.383333)")
gDistance(MAD,coast)
[1] 3.021808

我无法理解gDistance()返回的内容.文档说它是以投影为单位的.这是否意味着它是拉特隆度的?如何将其转换为公里?

I am having trouble understanding what gDistance() returns. The docs say it's in the units of the projection. Does that mean it is in latlong degrees? How can I convert that to kilometers?

推荐答案

gDistance(...)返回点和作为参数提供的特征集之间的最小笛卡尔(欧几里得)距离.由于地图是在长/纬度座标中,因此您获得的距离以度"为单位,例如

gDistance(...) returns the minimum Cartesian (Euclidean) distance between the point and feature set provided as arguments. Since your map is in long/lat coordinates, you get distance in "degrees", e.g.

d = sqrt {(long 1 -long 2 ) 2 +(lat 1 -lat 2 ) 2 }

d = sqrt { (long1 - long2)2 + (lat1 - lat2)2 }

其中long和lat以十进制度数表示.如前所述,这并不意味着什么,因为转换为平面距离(例如km)取决于您所在的位置.因此,我们需要将您的数据转换为在感兴趣区域中大致为平面的CRS.事实证明,适用于西班牙的CRS是 EPSG-2062 . EPSG-2062的投影字符串为:

where long and lat are in decimal degrees. As was pointed out, this doesn't mean much because converting to planar distance (say, km) depends on where you are. So we need to transform your data into a CRS which is approximately planar in the region of interest. It turns out that the appropriate CRS for Spain is EPSG-2062. The projection string for EPSG-2062 is:

+proj=lcc +lat_1=40 +lat_0=40 +lon_0=0 +k_0=0.9988085293 +x_0=600000 +y_0=600000 +a=6378298.3 +b=6356657.142669561 +pm=madrid +units=m +no_defs 

具有+units=m(米)的

.因此,我们需要将点(MAD)和边界重新投影到EPSG-2062.

which has +units=m (meters). So we need to reproject both the point (MAD) and the borders to EPSG-2062.

library(rgeos)
library(maptools)

epsg.2062 <- "+proj=lcc +lat_1=40 +lat_0=40 +lon_0=0 +k_0=0.9988085293 +x_0=600000 +y_0=600000 +a=6378298.3 +b=6356657.142669561 +pm=madrid +units=m +no_defs"
wgs.84    <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"

coast <- readShapeLines("ne_10m_coastline",CRS(wgs.84))
MAD   <- readWKT("POINT(-3.716667 40.383333)",p4s=CRS(wgs.84))
gDistance(MAD,coast)            # WGS-84 (long/lat) projection, units in "degrees"
# [1] 3.021808

coast.proj <- spTransform(coast,CRS(epsg.2062))
MAD.proj   <- spTransform(MAD,CRS(epsg.2062))
gDistance(MAD.proj,coast.proj)  #EPSG-2062 projection, units are in meters.
# [1] 305171.2

所以最小距离是〜305.2km.

So the minimum distance is ~305.2km.

最后,请注意,您的海岸线文件包含世界上所有的海岸线,因此,这是到一些海岸线的最小距离,不一定是西班牙海岸(尽管在这种情况下,它确实可以在西班牙的北部海岸).如果您的参考点非常靠近葡萄牙边界,那么最近的沿海点将是葡萄牙的西海岸.

Finally, note that your coastline file has all the coastlines of the world, so this is the minimum distance to some coastline, not necessarily the Spanish coast (although in this case it does turn out to be on the northern coast of Spain). If your reference point was very near the border with Portugal, the the nearest coastal point would be to the western coast of Portugal.

这篇关于计算点与海岸之间的最小距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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