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

Increase the BBOX size but keep the ratio (Lon/Lat)

我有一个由以下值定义的 Bbox:

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

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

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

一个解决方案是平移盒子,使其中心位于原点,将所有值乘以 1.5,然后再平移回来。这应该可以用一个ST_Affine(),但我懒得去研究细节。 :)

或许ST_Expand is what you're looking for. You could first calculate the area of the input bbox using ST_Area然后以输出为单位展开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 是您提供的,外部是使用 ST_Expand.

创建的

演示: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,ymin),c(xmax,ymax))
bearing3 <- geosphere::bearingRhumb(c(xmin,ymin),c(xmax,ymin))
bearing4 <- geosphere::bearingRhumb(c(xmax,ymax),c(xmin,ymin))
#new bbox points
########################## left und top
########################## right und top
########################## right und bottom
########################## left und bottom
p1<- geosphere::destPointRhumb(c(xmin,ymax), bearing1, 10000, r = 6378137)
p2<- geosphere::destPointRhumb(c(xmax,ymax), bearing2, 10000, r = 6378137)
p3<- geosphere::destPointRhumb(c(xmax,ymin), bearing3, 10000, r = 6378137)
p4<- geosphere::destPointRhumb(c(xmin,ymin), bearing4, 10000, r = 6378137)

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

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