From 0a3047fd78e5a41b327fba3af272121e76510d7a Mon Sep 17 00:00:00 2001 From: Adam Cox Date: Tue, 18 Aug 2026 15:32:14 -0500 Subject: [PATCH] update footprints output for atlascope --- ohmg/extensions/atlascope.py | 39 ++++++++++++++++++++++++---- ohmg/extensions/loc_sanborn.py | 1 + ohmg/extensions/views.py | 46 ++++++++++++---------------------- 3 files changed, 51 insertions(+), 35 deletions(-) diff --git a/ohmg/extensions/atlascope.py b/ohmg/extensions/atlascope.py index 82f9372f..b082bc1a 100644 --- a/ohmg/extensions/atlascope.py +++ b/ohmg/extensions/atlascope.py @@ -1,21 +1,24 @@ import json -from django.conf import settings +import topojson from django.contrib.gis.geos import GEOSGeometry, MultiPolygon from ninja import Schema from ..core.models import LayerSet +from ..places.models import Place def generate_atlascope_properties(layerset: LayerSet): return { "identifier": layerset.map.identifier, - "publisherShort": "Sanborn", + "publisherShort": layerset.map.publisher + if layerset.map.publisher + else layerset.map.creator, "year": layerset.map.year, - "bibliographicEntry": "_Richards standard atlas of the town of Greenfield_ (Richards Map Company, 1918)", + "bibliographicEntry": f"Fire Insurance Map of {layerset.map.title} (Sanborn Map Company)", "source": { - "type": "tilejson", - "url": f"{settings.SITEURL.rstrip('/')}/map/{layerset.map.identifier}/{layerset.category.slug}/tilejson", + "type": "xyz", + "url": f"{layerset.xyz_tiles_url}/{{z}}/{{x}}/{{y}}.png", }, "catalogPermalink": f"https://loc.gov/item/{layerset.map.identifier}", "heldBy": ["Library of Congress"], @@ -36,6 +39,32 @@ def generate_atlascope_geometry(layerset: LayerSet): return {"type": "MultiPolygon", "coordinates": []} +def generate_atlascope_footprints(place: Place, override_data_name: str = None): + maps = sorted(place.map_set.all().exclude(hidden=True), key=lambda x: x.year) + + features = [] + for map in maps: + ls = map.get_layerset("main-content") + if ls and ls.xyz_tiles_url: + feature = AtlascopeLayersetFeature.from_orm(ls).dict() + features.append(feature) + + topo = topojson.Topology( + { + "type": "FeatureCollection", + "features": features, + } + ) + topo_json = json.loads(topo.to_json()) + + ## allow override of the data property name in the topojson + if override_data_name: + topo_json["objects"][override_data_name] = topo_json["objects"]["data"] + del topo_json["objects"]["data"] + + return topo_json + + class AtlascopeLayersetFeature(Schema): type: str = "Feature" properties: dict diff --git a/ohmg/extensions/loc_sanborn.py b/ohmg/extensions/loc_sanborn.py index 374404a8..f7af6c48 100644 --- a/ohmg/extensions/loc_sanborn.py +++ b/ohmg/extensions/loc_sanborn.py @@ -66,6 +66,7 @@ def parse(self): "identifier": identifier, "title": parsed_item.title, "creator": "Sanborn Map Company", + "publisher": "Sanborn Map Company", "year": parsed_item.year, "month": parsed_item.month, "locale": self.input_data["locale"], diff --git a/ohmg/extensions/views.py b/ohmg/extensions/views.py index 56a7941c..3f8af820 100644 --- a/ohmg/extensions/views.py +++ b/ohmg/extensions/views.py @@ -1,6 +1,3 @@ -import json - -import topojson from django.http import JsonResponse from django.views import View @@ -8,7 +5,7 @@ from ohmg.core.models import Map from ohmg.core.utils import full_reverse -from .atlascope import AtlascopeLayersetFeature +from .atlascope import generate_atlascope_footprints from .iiif import IIIFResource @@ -53,29 +50,18 @@ def get(self, request, mapid, layerset_category): class AtlascopeDataView(View): def get(self, request, place, operation): - if operation == "footprints": - maps = sorted(place.map_set.all().exclude(hidden=True), key=lambda x: x.year) - ls = [i.get_layerset("main-content") for i in maps] - - features = [ - AtlascopeLayersetFeature.from_orm(i).dict() for i in ls if i and i.mosaic_geotiff - ] - - feature_collection = { - "type": "FeatureCollection", - "name": f"{place.slug}-volume-extents", - "features": features, - } - topo = topojson.Topology(feature_collection) - topo_json = json.loads(topo.to_json()) - - ## extra key needed for atlascope detroit - if place.slug == "detroit-mi": - topo_json["objects"]["detroit-volume-extents"] = topo_json["objects"]["data"] - return JsonResponse(topo_json) - - elif operation == "coverages": - return JsonResponse([{"name": str(place), "center": place.get_center()}], safe=False) - - else: - return JsonResponseNotFound("invalid operation. must be 'footprints' or 'coverages'") + data_name = request.GET.get("data-name") + match operation: + case "footprints": + topo_json = generate_atlascope_footprints(place, override_data_name=data_name) + return JsonResponse(topo_json) + + case "coverages": + return JsonResponse( + [{"name": str(place), "center": place.get_center()}], safe=False + ) + + case _: + return JsonResponseNotFound( + "invalid operation. must be 'footprints' or 'coverages'" + )