Support VD

This commit is contained in:
WQY\qiong
2023-05-17 21:12:05 +08:00
parent 2cab278c9f
commit 4e14b9398d
7 changed files with 400 additions and 9 deletions

21
api/s35_vd_gen.py Normal file
View File

@@ -0,0 +1,21 @@
from .s32_region_util import calculate_boundary, inflate_boundary
from .s35_vd_cal import *
from .s35_vd import get_all_virtual_district_ids
from .batch_exe import execute_batch_command
def generate_virtual_district(name: str, centers: list[str]) -> ChangeSet:
cs = ChangeSet()
for id in get_all_virtual_district_ids(name):
cs.delete({'type': 'virtual_district', 'id': id})
vds = calculate_virtual_district(name, centers)['virtual_districts']
for vd in vds:
center = vd['center']
nodes = vd['nodes']
boundary = calculate_boundary(name, nodes)
boundary = inflate_boundary(name, boundary)
cs.add({ 'type': 'virtual_district', 'id': f"VD_{center}", 'boundary': boundary, 'center': center, 'nodes': nodes })
return execute_batch_command(name, cs)