2

问题:

给定绝对坐标,我如何计算拓扑变换scale拓扑变换的理想值?translate

我想从这个出发:

absolute = [
     [-69.9009900990099, 12.451814888520133],
     [-69.9009900990099, 12.417091709170947],
     [-69.97299729972997, 12.43445329884554],
     [-70.00900090009, 12.486538067869319],
     [-70.08100810081008, 12.538622836893097],
     [-70.08100810081008, 12.590707605916876],
     [-70.04500450045005, 12.608069195591469],
     [-70.00900090009, 12.55598442656769],
     [-69.93699369936994, 12.469176478194726],
     [-69.9009900990099, 12.451814888520133],
]

对此:

scale = [0.036003600360036005, 0.017361589674592462]
translate = [-180, -89.99892578124998]

relative = [[3058, 5901], [0, -2], [-2, 1], [-1, 3], [-2, 3], [0, 3], [1, 1], 
     [1, -3], [2, -5], [1, -1]]

我得到了相对到绝对的转换工作:

def arc_to_coordinates(topology, arc):
    scale = topology['transform']['scale']
    translate = topology['transform']['translate']

    x = 0
    y = 0
    coordinates = []

    for point in arc:
        x += point[0]
        y += point[1]
        coordinates.append([
            x * scale[0] + translate[0],
            y * scale[1] + translate[1] 
        ])

    return coordinates

现在我需要编写绝对到相对的转换。为此,有必要获取scaleand的值translate,我被卡住了。

关于 topojson

topojson 是一种存储地理特征的格式,类似于geojson

为了节省空间(以及其他技巧),该格式使用相对于前一点的整数偏移量。例如,这是 Aruba 的 topojson 文件:

{
  "type": "Topology",
  "transform": {
    "scale": [0.036003600360036005, 0.017361589674592462],
    "translate": [-180, -89.99892578124998]
  },
  "objects": {
    "aruba": {
      "type": "Polygon",
      "arcs": [[0]],
      "id": 533
    }
  },
  "arcs": [
    [[3058, 5901], [0, -2], [-2, 1], [-1, 3], [-2, 3], [0, 3], [1, 1], 
     [1, -3], [2, -5], [1, -1]]
  ]
}

与 GeoJSON 功能相同的信息如下所示:

{
    "type" : "Feature",
    "id" : 533,
    "properties" : {},
    "geometry" : {
        "type" : "Polygon",
        "coordinates" : [[
                 [-69.9009900990099, 12.451814888520133], 
                 [-69.9009900990099, 12.417091709170947], 
                 [-69.97299729972997, 12.43445329884554], 
                 [-70.00900090009, 12.486538067869319], 
                 [-70.08100810081008, 12.538622836893097], 
                 [-70.08100810081008, 12.590707605916876], 
                 [-70.04500450045005, 12.608069195591469], 
                 [-70.00900090009, 12.55598442656769], 
                 [-69.93699369936994, 12.469176478194726], 
                 [-69.9009900990099, 12.451814888520133]
            ]]
    }
}

很容易看出前者比后者更紧凑。我的绝对相对功能正在工作:

>>> arc_to_coordinates(topology, topology['arcs'][0])
[[-69.9009900990099, 12.451814888520133],
 [-69.9009900990099, 12.417091709170947],
 [-69.97299729972997, 12.43445329884554],
 [-70.00900090009, 12.486538067869319],
 [-70.08100810081008, 12.538622836893097],
 [-70.08100810081008, 12.590707605916876],
 [-70.04500450045005, 12.608069195591469],
 [-70.00900090009, 12.55598442656769],
 [-69.93699369936994, 12.469176478194726],
 [-69.9009900990099, 12.451814888520133]]

[更新]

我相信算法在这个文件的某个地方,但我很难将 JS 翻译成 Python。我喜欢 Mike 的工作,但有时他的 js 看起来已经缩小了...... :-)

4

0 回答 0