简体   繁体   中英

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

多边形半径

This is how I do it in 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 ?

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

10 or any other value that you need.

It based on baji answer that don't work for me

[ 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM