2

質問:

scale絶対座標が与えられた場合、topojsonトポロジ変換の理想値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

次に、絶対相対変換を記述する必要があります。これを行うには、 と の値を取得する必要がありscaleます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 に変換するのに苦労しています。私はマイクの作品が大好きですが、彼の js はすでに縮小されているように見えることがあります... :-)

4

0 に答える 0