text stringlengths 0 1.47k |
|---|
# CJK-capable fonts, tried in order; GEO_FONT can point at any other font file. |
_FONT_PATHS = ( |
"C:/Windows/Fonts/msyh.ttc", "C:/Windows/Fonts/msyhbd.ttc", |
"C:/Windows/Fonts/simhei.ttf", "C:/Windows/Fonts/simsun.ttc", |
"/System/Library/Fonts/STHeiti Medium.ttc", "/System/Library/Fonts/Hiragino Sans GB.ttc", |
"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", |
) |
def _font(size: int): |
for p in (os.environ.get("GEO_FONT", "").strip(), *_FONT_PATHS): |
if not p: |
continue |
try: |
return ImageFont.truetype(p, size) |
except Exception: |
continue |
return ImageFont.load_default() |
def sheet(items: list[dict], out: Path, cols: int = 3, tw: int = 480, th: int = 360, |
cache: Path | None = None, proxy: str | None = None) -> None: |
"""items: [{id, heading, pitch?, fov?, label?}] → numbered contact sheet.""" |
def one(it): |
return render(it["id"], it["heading"], it.get("pitch", 10), it.get("fov", 80), cache=cache, proxy=proxy) |
with ThreadPoolExecutor(12) as ex: |
ims = list(ex.map(one, items)) |
rows = (len(items) + cols - 1) // cols |
S = Image.new("RGB", (cols * tw, rows * th), "black") |
d = ImageDraw.Draw(S) |
f = _font(16) |
for i, (it, im) in enumerate(zip(items, ims)): |
x, y = (i % cols) * tw, (i // cols) * th |
S.paste(im.convert("RGB").resize((tw, th)), (x, y)) |
text = it.get("label") or f"{i}: …{it['id'][-9:]} h{it['heading']:.0f}" |
d.rectangle([x, y, x + tw, y + 22], fill="black") |
d.text((x + 4, y + 2), text, fill="yellow", font=f) |
S.save(out, quality=88) |
def _neg_coords(argv: list[str]) -> list[str]: |
"""argparse treats negative coordinates like -1.45,-48.5 as option names; prefixing a space makes them plain values (float ignores the space). Needed for every puzzle in the southern or western hemisphere.""" |
return [" " + a if re.match(r"^-\d[\d.]*(,-?[\d.]+)+$", a) else a for a in argv] |
def main() -> None: |
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) |
ap.add_argument("--proxy", help=PROXY_HELP) |
ap.add_argument("--cache", type=Path, default=Path(".geo-cache/pano")) |
sub = ap.add_subparsers(dest="cmd", required=True) |
n = sub.add_parser("near") |
n.add_argument("latlon") |
i = sub.add_parser("info") |
i.add_argument("id") |
s = sub.add_parser("scan") |
s.add_argument("center") |
s.add_argument("--radius", type=float, default=250) |
s.add_argument("--step", type=float, default=20) |
s.add_argument("--out", type=Path, required=True) |
r = sub.add_parser("render") |
r.add_argument("id") |
r.add_argument("--heading", type=float, required=True) |
r.add_argument("--pitch", type=float, default=10) |
r.add_argument("--fov", type=float, default=80) |
r.add_argument("--out", type=Path, required=True) |
sh = sub.add_parser("sheet") |
g = sh.add_mutually_exclusive_group(required=True) |
g.add_argument("--ids", help="comma-separated panoids") |
g.add_argument("--panos", type=Path, help="JSON output of scan") |
g.add_argument("--spec", type=Path, help="JSON list [{id, heading, pitch, fov, label}]") |
sh.add_argument("--heading", type=float, help="one heading for all") |
sh.add_argument("--headings", help="render these headings at every point, comma-separated, e.g. 0,60,120,180,240,300 (look around from a single point)") |
sh.add_argument("--toward", help="lat,lon: each point faces this target") |
sh.add_argument("--offset", type=float, default=0, help="angle added on top of the toward bearing") |
sh.add_argument("--pitch", type=float, default=10) |
sh.add_argument("--fov", type=float, default=80) |
sh.add_argument("--within", help="lat,lon,radius in meters: only points inside this circle") |
sh.add_argument("--road", help="only points whose road name contains these characters (the road field in scan output); comma-separated for several") |
sh.add_argument("--spread", type=float, help="thinning: minimum meters between neighboring points") |
sh.add_argument("--limit", type=int, default=12, help="max cells per contact sheet; extra cells go to more pages automatically") |
sh.add_argument("--out", type=Path, required=True) |
sp = sub.add_parser("sample", help="random street-view sample contact sheet of a candidate city/area: compare the styles of municipal fixtures such as guardrails, streetlights, bus stops, curbs") |
sp.add_argument("--bbox", required=True, help="south,west,north,east (urban area)") |
sp.add_argument("--n", type=int, default=24, help="how many points to sample") |
sp.add_argument("--spread", type=float, default=300, help="minimum spacing between two points, m") |
sp.add_argument("--seed", type=int, default=1) |
sp.add_argument("--skip", default="隧道,高速,高架,匝道,立交", help="skip points whose road name contains these characters, comma-separated (default: tunnel, expressway, elevated road, ramp, interchange)") |
sp.add_argument("--heading-offset", type=float, default=0, help="extra degrees to turn from the along-road direction (90 = look at the roadside)") |
sp.add_argument("--include-unnamed", action="store_true", help="also take points without a road name (internal roads of residential compounds, campuses); skipped by default") |
sp.add_argument("--out", type=Path, required=True) |
for parser in (n, i, s, r, sh, sp): |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.