Support VD
This commit is contained in:
21
api/s35_vd_gen.py
Normal file
21
api/s35_vd_gen.py
Normal 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)
|
||||
Reference in New Issue
Block a user