微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

增加 BBOX 大小但保持比例 (Lon/Lat)

如何解决增加 BBOX 大小但保持比例 (Lon/Lat)

我有一个由以下值定义的 BBox

xmin: 11.555333537980914 
ymin: 47.76067947037518 
xmax: 11.995692579075694 
ymax: 48.281587762758136

我想增加这个 BBox 的大小但保持比例。 我尝试的一种方法是计算 BBox 的中点,并计算一个半径值增加 50% 的新 BBox。 问题是:比率丢失了。

如何将 BBox 的大小增加到 50% 但保持比例不变。

解决方法

也许 ST_Expand 正是您要找的。可以先用ST_Area计算输入bbox的面积,然后以输出为单位展开bbox。

SELECT            -- here you can play with different sizes
  ST_Expand(geom,ST_Area(geom)/2) 
FROM yourtable;

示例:

WITH j (geom) AS (
  SELECT ST_MakeEnvelope(11.555333537980914,47.76067947037518,11.995692579075694,48.281587762758136,4326)
)
SELECT 
  ST_Expand(geom,ST_Area(geom)/2) 
FROM j;

下图表示结果集。内部 bbox 是您提供的,而外部 bbox 是使用 ST_Expand 创建的。

enter image description here

演示:db<>fiddle

,

@Jim Jones 提供的答案非常有效。 PostGIS有什么不能做的吗? :)

我不想依赖 PostGIS

所以我试图用 R 解决这个问题。我的方法:

我延长 bbox 的每条对角线并计算该对角线的方位角。基于该数据,我计算了 bbox 的新边缘点。它有点工作,但 bbox 的左侧看起来有点小。我认为某处有错误,但我还不知道在哪里。

xmin<- 11.555333537980914 
ymin<- 47.76067947037518 
xmax<- 11.995692579075694 
ymax<- 48.281587762758136 

###calculate bearing clockwise of diagonal for each corner of the BBOX
######## right bottom,left und top
######## left and bottom,right and top 
######## left and top and right and bottom 
######## right and top,left and bottom 
##bearing(p1,p2,a=6378137,f=1/298.257223563)
bearing1 <- geosphere::bearingRhumb(c(xmax,ymin),c(xmin,ymax))
bearing2 <- geosphere::bearingRhumb(c(xmin,c(xmax,ymax))
bearing3 <- geosphere::bearingRhumb(c(xmin,ymin))
bearing4 <- geosphere::bearingRhumb(c(xmax,ymax),ymin))
#new bbox points
########################## left und top
########################## right und top
########################## right und bottom
########################## left und bottom
p1<- geosphere::destPointRhumb(c(xmin,bearing1,10000,r = 6378137)
p2<- geosphere::destPointRhumb(c(xmax,bearing2,r = 6378137)
p3<- geosphere::destPointRhumb(c(xmax,bearing3,r = 6378137)
p4<- geosphere::destPointRhumb(c(xmin,bearing4,r = 6378137)

data<-rbind.data.frame(p1,p3,p4)

xmin<-min(data$lon)
ymin<-min(data$lat)
xmax<-max(data$lon)
ymax<-max(data$lat)
cat(xmin,",ymin,xmax,ymax)

enter image description here

,

一种解决方案是平移盒子,使其中心位于原点,将所有内容乘以 1.5,然后再平移回来。这应该可以通过单个 ST_Affine() 实现,但我懒得计算细节。 :)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。