91 lines
3.2 KiB
Python
91 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""Отрисовка плана участка по site-layout.json (вид сверху).
|
||
|
||
Все размеры берутся из JSON: меняем числа — перерисовываем картинку.
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
import os
|
||
|
||
from PIL import Image, ImageDraw, ImageFont
|
||
|
||
W, H = 1500, 1050
|
||
PAD = 70
|
||
|
||
|
||
def font(size: int):
|
||
try:
|
||
return ImageFont.truetype("segoeui.ttf", size)
|
||
except Exception:
|
||
return ImageFont.load_default()
|
||
|
||
|
||
def main() -> None:
|
||
here = os.path.dirname(os.path.abspath(__file__))
|
||
data = json.load(open(os.path.join(here, "site-layout.json"), encoding="utf-8"))
|
||
|
||
pts = []
|
||
for plot in data["plots"]:
|
||
pts += [tuple(p) for p in plot["polygon_m"]]
|
||
minx = min(p[0] for p in pts)
|
||
maxx = max(p[0] for p in pts)
|
||
miny = min(p[1] for p in pts)
|
||
maxy = max(p[1] for p in pts)
|
||
|
||
spanx = maxx - minx or 1
|
||
spany = maxy - miny or 1
|
||
scale = min((W - 2 * PAD) / spanx, (H - 2 * PAD) / spany)
|
||
|
||
def sx(x):
|
||
return PAD + (x - minx) * scale
|
||
|
||
def sy(y):
|
||
return PAD + (y - miny) * scale
|
||
|
||
img = Image.new("RGB", (W, H), (247, 248, 250))
|
||
d = ImageDraw.Draw(img)
|
||
|
||
# участки
|
||
for plot in data["plots"]:
|
||
poly = [(sx(x), sy(y)) for x, y in plot["polygon_m"]]
|
||
d.polygon(poly, fill=(255, 255, 255), outline=(196, 60, 60), width=4)
|
||
cx = sum(p[0] for p in poly) / len(poly)
|
||
cy = sum(p[1] for p in poly) / len(poly)
|
||
d.text((cx - 60, cy - 10), plot["cadastral"], fill=(150, 60, 60), font=font(22))
|
||
if plot.get("approx"):
|
||
d.text((cx - 60, cy + 18), "(контур примерный)", fill=(150, 120, 120), font=font(15))
|
||
|
||
# дом
|
||
h = data["house"]
|
||
hx, hy = h["x_m"], h["y_m"]
|
||
d.rectangle([sx(hx), sy(hy), sx(hx + h["w_m"]), sy(hy + h["d_m"])],
|
||
fill=(222, 232, 226), outline=(70, 92, 82), width=3)
|
||
d.text((sx(hx) + 10, sy(hy) + 8), "ДОМ", fill=(60, 84, 74), font=font(24))
|
||
d.text((sx(hx) + 10, sy(hy) + 38), "15,05 × 8,0 м", fill=(70, 76, 84), font=font(18))
|
||
|
||
# парковка
|
||
p = data["parking"]
|
||
d.rectangle([sx(p["x_m"]), sy(p["y_m"]), sx(p["x_m"] + p["w_m"]), sy(p["y_m"] + p["h_m"])],
|
||
fill=(214, 226, 242), outline=(60, 96, 160), width=3)
|
||
d.text((sx(p["x_m"]) + 8, sy(p["y_m"]) + 6), "ПАРКОВКА", fill=(50, 86, 150), font=font(18))
|
||
if p.get("status") == "to-measure":
|
||
d.text((sx(p["x_m"]) + 8, sy(p["y_m"]) + 30), "перемерить", fill=(90, 110, 140), font=font(15))
|
||
|
||
# ориентация
|
||
d.text((W // 2 - 40, 18), "ЗАПАД", fill=(120, 126, 136), font=font(24))
|
||
d.text((W // 2 - 60, H - 42), "ВОСТОК", fill=(120, 126, 136), font=font(24))
|
||
d.text((W - 130, H // 2 - 16), "СЕВЕР", fill=(120, 126, 136), font=font(24))
|
||
d.text((24, H // 2 - 16), "ЮГ", fill=(120, 126, 136), font=font(24))
|
||
|
||
d.text((24, 18), "План участка 242:1331 + 244:1348 — параметрическая схема",
|
||
fill=(38, 42, 50), font=font(24))
|
||
|
||
out = os.path.join(here, "site-plan-param.png")
|
||
img.save(out)
|
||
print("готово:", out)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|