Python TopoJSON:计算比例和偏移 问题:
给定绝对坐标,如何计算拓扑变换的Python TopoJSON:计算比例和偏移 问题:,python,math,geometry,geo,Python,Math,Geometry,Geo,给定绝对坐标,如何计算拓扑变换的比例和平移的理想值? 我想从这里开始: absolute = [ [-69.9009900990099, 12.451814888520133], [-69.9009900990099, 12.417091709170947], [-69.97299729972997, 12.43445329884554], [-70.00900090009, 12.486538067869319], [-70.081008100
比例和平移的理想值?
我想从这里开始:
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是一种存储地理特征的格式,非常类似于
为了节省空间(除其他技巧外),该格式使用上一点的相对整数偏移。例如,这是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看起来已经缩小了…:-) 这看起来像一个数学问题,当计算
比例
和平移
时,弧
列表已知吗?或者它是要计算的目标之一?scale
和translate
用于将[点(-69.9009900990099,12.451814888520133),点(-69.9009900990099,12.417091709170947),…]形式的绝对坐标转换为弧中由小整数组成的相对坐标。[点(30585901),点(0,-2),…]
。