Skip to content

armgit / Aleph

Public Imported from GitHub
0

Give satellite imagery, terrain data, buildings, streetview photos to your LLM

Add best match flag

Belluxxa8d6febd506b
diff --git a/aleph.py b/aleph.py
index 1214509..7367e0f 100644
--- a/aleph.py
+++ b/aleph.py
@@ -53,6 +53,10 @@ def parser():
json_output(command)
def locations(command):
+ selection = command.add_mutually_exclusive_group()
+ selection.add_argument("--match", metavar="TYPE/ID", help="choose an OSM ID returned for an ambiguous name")
+ selection.add_argument("--best-match", action="store_true",
+ help="automatically select the geocoder's highest-ranked place")
group = command.add_mutually_exclusive_group(required=True)
group.add_argument("--at", nargs=2, type=float, metavar=("LAT", "LON"), help="coordinates")
group.add_argument("--place", help="place name, including city or country")
@@ -72,7 +76,6 @@ def parser():
source = locations(street)
source.add_argument("--pano-id", help="exact panorama ID")
source.add_argument("--street", help="named street to follow from end to end")
- street.add_argument("--match", metavar="TYPE/ID", help="choose an OSM ID returned for an ambiguous name")
street.add_argument("--stops", type=int, help="street positions (default: 10)")
street.add_argument("--view", choices=("forward", "backward", "left", "right", "both"),
help="street orientation; both saves left and right (default: forward)")
@@ -92,7 +95,6 @@ def parser():
source = locations(satellite)
source.add_argument("--bbox", nargs=4, type=float, metavar=("S", "W", "N", "E"))
source.add_argument("--tile", type=tile_coordinates, metavar="Z/X/Y")
- satellite.add_argument("--match", metavar="TYPE/ID", help="choose an OSM ID returned for an ambiguous name")
satellite.add_argument("--size", type=float, help="square width in meters around a point (default: 200)")
satellite.add_argument("--zoom", type=int, help="satellite zoom, 1–21 (default: 19)")
output(satellite)
@@ -207,9 +209,9 @@ def query(args, progress):
mode = "search" if args.query is not None else "reverse"
result = dict(command="resolve", mode=mode, status="complete", results=results)
else:
- if args.match and not (args.place or getattr(args, "street", None)):
- raise ValueError("--match requires --place or --street.")
- keys = ("at", "place", "match")
+ if (args.match or args.best_match) and not (args.place or getattr(args, "street", None)):
+ raise ValueError("--match and --best-match require --place or --street.")
+ keys = ("at", "place", "match", "best_match")
if args.command == "streetview":
if args.street is None and (args.stops is not None or args.view is not None
or args.route is not None or args.reverse):
@@ -285,6 +287,8 @@ def emit(result, as_json):
if as_json:
print(json.dumps(result, ensure_ascii=False, allow_nan=False))
elif result.get("folder"):
+ if place := result.get("place"):
+ print(f"Selected: {place['label']} ({place['id']})")
if result["command"] == "satellite":
print(f"Saved satellite image · {result['width']} × {result['height']} px")
print(result["path"])
diff --git a/docs/cli.md b/docs/cli.md
index 054fe2f..6fdd498 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -38,6 +38,14 @@ alephgeo satellite --tile 19/280337/194891 -o captures --json
Both commands accept `--place "Colosseum, Rome"` instead of `--at LAT LON`. If several places match, they are listed. Repeat the command with `--match` followed by your chosen result's `id`.
+Use `--best-match` to automatically choose the first result in the geocoder's ranking:
+
+```sh
+alephgeo satellite --place "Colosseum, Rome" --best-match
+```
+
+The selected name and ID appear in plain-text output and in the JSON `place` field. `--best-match` also works with `streetview --place` and `streetview --street`. It cannot be combined with `--match`; street branches still require `--route N` when ambiguous.
+
Street View finds the nearest panorama within 50 meters; change this with `--radius`. Results include the camera position, distance, viewing direction, and photo date when available.
For satellite images, `--size 200` requests a square 200 meters wide around your location. Use `--bbox SOUTH WEST NORTH EAST` for a rectangle.
diff --git a/src/places.py b/src/places.py
index d4673b6..9a66ca9 100644
--- a/src/places.py
+++ b/src/places.py
@@ -90,11 +90,11 @@ def geocode(client, *, query=None, at=None, limit=5, street=False, endpoint=GEOC
return results
-def choose(client, query, *, match=None, street=False, endpoint=GEOCODER):
+def choose(client, query, *, match=None, best_match=False, street=False, endpoint=GEOCODER):
candidates = geocode(client, query=query, street=street, endpoint=endpoint, limit=10)
if not candidates:
raise RequestError("place_not_found", "No matching place was found. Include a city or country.")
- if match is None and len(candidates) == 1:
+ if match is None and (best_match or len(candidates) == 1):
return candidates[0]
for candidate in candidates:
if candidate["id"] == match:
diff --git a/src/quick.py b/src/quick.py
index ce11ae0..0b89f45 100644
--- a/src/quick.py
+++ b/src/quick.py
@@ -25,15 +25,15 @@ def coverage(client, area, progress):
return list(found.values())
-def location(client, *, at=None, place=None, match=None, endpoint=places.GEOCODER):
+def location(client, *, at=None, place=None, match=None, best_match=False, endpoint=places.GEOCODER):
if at is not None:
return places.point(at), None
- selected = places.choose(client, place, match=match, endpoint=endpoint)
+ selected = places.choose(client, place, match=match, best_match=best_match, endpoint=endpoint)
return (selected["lat"], selected["lon"]), selected
def street_photos(client, output, progress, *, at=None, place=None, pano_id=None,
- street=None, match=None, endpoint=places.GEOCODER, route=None,
+ street=None, match=None, best_match=False, endpoint=places.GEOCODER, route=None,
reverse=False, stops=10, view="forward", heading=0, look_at=None,
pitch=0, fov=75, radius=50, image_format="jpg"):
streetview.validate_angle(heading, "heading")
@@ -47,7 +47,7 @@ def street_photos(client, output, progress, *, at=None, place=None, pano_id=None
selected_place, selected_route = None, None
gaps = []
if street is not None:
- selected_place = places.choose(client, street, match=match, street=True, endpoint=endpoint)
+ selected_place = places.choose(client, street, match=match, best_match=best_match, street=True, endpoint=endpoint)
selected_route = routes.resolve(client, selected_place, route=route, reverse=reverse, progress=progress)
points = selected_route["points"]
south, west, north, east = extent(points)
@@ -62,7 +62,8 @@ def street_photos(client, output, progress, *, at=None, place=None, pano_id=None
raise ValueError("Invalid panorama ID.")
samples = [dict(pano_id=pano_id, stop=1)]
else:
- requested, selected_place = location(client, at=at, place=place, match=match, endpoint=endpoint)
+ requested, selected_place = location(client, at=at, place=place, match=match,
+ best_match=best_match, endpoint=endpoint)
views = coverage(client, places.around(requested, radius * 2), progress)
nearest = min(views, key=lambda v: (distance(requested, (v["lat"], v["lon"])), v["pano_id"]), default=None)
samples = []
@@ -124,7 +125,7 @@ def street_photos(client, output, progress, *, at=None, place=None, pano_id=None
return result
-def satellite(client, output, progress, *, at=None, place=None, match=None,
+def satellite(client, output, progress, *, at=None, place=None, match=None, best_match=False,
endpoint=places.GEOCODER, bbox=None, tile=None, size=200, zoom=19):
if tile is not None:
zoom, x, y = tile
@@ -139,7 +140,8 @@ def satellite(client, output, progress, *, at=None, place=None, match=None,
elif bbox is not None:
area = bounds(bbox)
else:
- center, selected_place = location(client, at=at, place=place, match=match, endpoint=endpoint)
+ center, selected_place = location(client, at=at, place=place, match=match,
+ best_match=best_match, endpoint=endpoint)
area = places.around(center, size)
g = grid(area, zoom)
run = capture.plan(client, area, dict(include=["satellite"], satellite_zoom=zoom), progress)