【问题标题】:Increase the BBOX size but keep the ratio (Lon/Lat)增加 BBOX 大小但保持比例 (Lon/Lat)
【发布时间】:2021-07-09 07:12:43
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: postgresql geometry gis geospatial postgis


    【解决方案1】:

    也许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 是您提供的,外层是使用 ST_Expand 创建的。

    演示:db<>fiddle

    【讨论】:

    • 非常感谢!我用 R 中的解决方案更新了我的问题。但解决方案不完整,因为新框在左侧看起来有点小。
    • @Andreas 我很高兴它有帮助。尝试计算两个 bbox 的面积并检查数字是否匹配 - 先前在球体上计算的数据的平面表示可能会变得“视觉上不准确”。欢呼
    • 我明白了 :) 这是有道理的。我会检查的。
    • @Andreas 考虑发布您的最新更新作为答案。顺便说一句 +1
    • 添加为答案。仅供参考,您的答案和我的需要相同的运行时间。
    【解决方案2】:

    @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)
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • “中心在原点”是什么意思?
      • 为简单起见,让我们看一下一维情况。假设你有 xmin=10,xmax=11,所以 xcenter 是 10.5。将 x 平移 -10.5,所以现在你有 (-0.5, 0.5)。乘以 1.5,得到 (-0.75, 0.75)。翻译回来,给予 (9.75, 11.25)。
      • (显然,在纬度/经度空间处理箱子有点雷区——当心两极!——但我想你知道...)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-05
      • 2018-03-01
      • 1970-01-01
      • 2015-01-31
      • 1970-01-01
      相关资源
      最近更新 更多