[英]Offsetting polygons by meters with clipper
I would like to create buffered polygons of locations (towns, villages etc) in order to use them for searching in radius.我想创建位置(城镇、村庄等)的缓冲多边形,以便使用它们进行半径搜索。
This is what I would like to achieve (units for ilustration):这就是我想要实现的(用于 ilustration 的单位):
This is how I do it in pyclipper:这就是我在 pyclipper 中的做法:
import pyclipper
coordinates = # Array of lat,lng tuples
clipper_offset = pyclipper.PyclipperOffset()
coordinates = pyclipper.scale_to_clipper(coordinates)
clipper_offset.AddPath(coordinates, pyclipper.JT_ROUND,
pyclipper.ET_CLOSEDPOLYGON)
scaled_coordinates = clipper_offset.Execute(1000.0)
scaled_coordinates = pyclipper.scale_from_clipper(scaled_coordinates)
Number 1000.0 is arbitrary and my question is - how do I calculate the right offset ratio for Execute method, so that the offsetted polygon will approximately represent 10,20 and 50km radius ?数字 1000.0 是任意的,我的问题是 -如何计算 Execute 方法的正确偏移率,以便偏移的多边形大约代表 10,20 和 50km 半径?
Btw.顺便提一句。 is this the right approach to this problem ?
这是解决这个问题的正确方法吗?
The way that worked for me:对我有用的方式:
import pyclipper
coordinates = [(198,362),(220,330),(282,372),(260,404)] # Array of lat,lng tuples
clipper_offset = pyclipper.PyclipperOffset()
coordinates_scaled = pyclipper.scale_to_clipper(coordinates)
clipper_offset.AddPath(coordinates_scaled, pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON)
new_coordinates = clipper_offset.Execute(pyclipper.scale_to_clipper(10))
new_coordinates_scaled = pyclipper.scale_from_clipper(new_coordinates)
I mean:我的意思是:
new_coordinates = clipper_offset.Execute(pyclipper.scale_to_clipper(10))
new_coordinates = clipper_offset.Execute(pyclipper.scale_to_clipper(10))
10 or any other value that you need. 10 或您需要的任何其他值。
It based on baji answer that don't work for me它基于对我不起作用的 baji 答案
[ scale_to_clipper(x) => pyclipper.scale_to_clipper(x) ]
[ scale_to_clipper(x) => pyclipper.scale_to_clipper(x) ]
You need to also scale the applied offset (to the clipper function):您还需要缩放应用的偏移量(到裁剪器功能):
scaled_coordinates = clipper_offset.Execute(scale_to_clipper(1000.0))
pyclipper scales the input floats to 64 bit integers: http://www.angusj.com/delphi/clipper/documentation/Docs/Overview/Rounding.htm pyclipper 将输入浮点数缩放为 64 位整数: http ://www.angusj.com/delphi/clipper/documentation/Docs/Overview/Rounding.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.