Skip to content

Commit

Permalink
BGDIDIC-643: aerialimages bucket migration clean-up
Browse files Browse the repository at this point in the history
with the completion of the migration of the aerialimages bucket to
service-stac the followwing clean-up can be done in the api:
* remove /luftbilder/viewer.html endpoint and related templates
* remove deprecated attributes from the models of
    * ch.swisstopo.lubis-luftbilder_schwarzweiss
    * ch.swisstopo.lubis-luftbilder_infrarot
    * ch.swisstopo.lubis-luftbilder_farbe
    * ch.swisstopo.luftbilder_schraegaufnahmen
    * ch.swisstopo.lubis-terrestrische_aufnahmen
* clean-up / consolidate models
* clean-up / consolidate makos
  • Loading branch information
ltclm committed Oct 30, 2024
1 parent 46adede commit c942ea0
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 1,534 deletions.
1 change: 0 additions & 1 deletion chsdi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def datetime_adapter(obj, request):
config.add_route('htmlPopup', '/rest/services/{map}/MapServer/{layerId}/{featureId}/htmlPopup', request_method=request_method)
config.add_route('iframeHtmlPopup', '/rest/services/{map}/MapServer/{layerId}/{featureId}/iframeHtmlPopup', request_method=request_method)
config.add_route('extendedHtmlPopup', '/rest/services/{map}/MapServer/{layerId}/{featureId}/extendedHtmlPopup', request_method=request_method)
config.add_route('luftbilder', '/luftbilder/viewer.html', request_method=request_method)
config.add_route('historicalmaps', '/historicalmaps/viewer.html', request_method=request_method)
config.add_route('checker', '/checker', request_method=request_method)
config.add_route('checker_dev', '/checker_dev', request_method=request_method)
Expand Down
52 changes: 17 additions & 35 deletions chsdi/models/vector/lubis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,75 +10,70 @@

class LuftbilderBase:
__table_args__ = ({'schema': 'public', 'autoload': False})
__template__ = 'templates/htmlpopup/lubis.mako'
__returnedGeometry__ = 'the_geom_footprint'
__timeInstant__ = 'bgdi_flugjahr'
__label__ = 'flugdatum'
id = Column('ebkey', Unicode, primary_key=True)
filename = Column('filename', Unicode)
inventarnummer = Column('inventarnummer', Integer)
bildnummer = Column('bildnummer', Unicode)
flugdatum = Column('flugdatum', Unicode)
firma = Column('firma', Unicode)
filmart = Column('filmart', Unicode)
bgdi_flugjahr = Column('bgdi_flugjahr', Integer)
orientierung = Column('orientierung', Boolean)
rotation = Column('rotation', Integer)
orthophoto = Column('orthophoto', Unicode)
originalsize = Column('originalsize', Unicode)
x = Column('x', Integer)
y = Column('y', Integer)
flughoehe = Column('flughoehe', Integer)
ort = Column('ort', Unicode)
massstab = Column('massstab', Integer)
filesize_mb = Column('filesize_mb', Unicode)
bgdi_imagemode = Column('bgdi_imagemode', Unicode)
the_geom_footprint = Column('the_geom_footprint', Geometry2D)
the_geom = Column(Geometry2D)


class LuftbilderBaseStac(LuftbilderBase):
class LuftbilderBaseDritte(LuftbilderBase):
__template__ = 'templates/htmlpopup/lubis.mako'
inventarnummer = Column('inventarnummer', Integer)
bildnummer = Column('bildnummer', Unicode)
orientierung = Column('orientierung', Boolean)
rotation = Column('rotation', Integer)
ort = Column('ort', Unicode)
massstab = Column('massstab', Integer)
filesize_mb = Column('filesize_mb', Unicode)


class LuftbilderBaseSwisstopo(LuftbilderBase):
__template__ = 'templates/htmlpopup/lubis_stac.mako'
ebkey_old = Column('ebkey_old', Unicode)
feature_id = Column('feature_id', Unicode)
acquired = Column('acquired', Date)
film_type = Column('film_type', Unicode)
orthofilename = Column('orthofilename', Unicode)
filename = Column('filename', Unicode)
e = Column('e', Numeric)
n = Column('n', Numeric)
z = Column('z', Numeric)


class LuftbilderSwisstopoFarbe(Base, LuftbilderBaseStac, Vector):
class LuftbilderSwisstopoFarbe(Base, LuftbilderBaseSwisstopo, Vector):
__tablename__ = 'luftbilder_swisstopo_color'
__bodId__ = 'ch.swisstopo.lubis-luftbilder_farbe'
image_height = Column('image_height', Integer)
image_width = Column('image_width', Integer)

register('ch.swisstopo.lubis-luftbilder_farbe', LuftbilderSwisstopoFarbe)


class LuftbilderSwisstopoIr(Base, LuftbilderBaseStac, Vector):
__extended_info__ = True
class LuftbilderSwisstopoIr(Base, LuftbilderBaseSwisstopo, Vector):
__tablename__ = 'luftbilder_swisstopo_ir'
__bodId__ = 'ch.swisstopo.lubis-luftbilder_infrarot'
image_height = Column('image_height', Integer)
image_width = Column('image_width', Integer)

register('ch.swisstopo.lubis-luftbilder_infrarot', LuftbilderSwisstopoIr)


class LuftbilderSwisstopoSw(Base, LuftbilderBaseStac, Vector):
class LuftbilderSwisstopoSw(Base, LuftbilderBaseSwisstopo, Vector):
__tablename__ = 'luftbilder_swisstopo_bw'
__bodId__ = 'ch.swisstopo.lubis-luftbilder_schwarzweiss'
image_height = Column('image_height', Integer)
image_width = Column('image_width', Integer)

register('ch.swisstopo.lubis-luftbilder_schwarzweiss', LuftbilderSwisstopoSw)


class LuftbilderDritteFirmen(Base, LuftbilderBase, Vector):
class LuftbilderDritteFirmen(Base, LuftbilderBaseDritte, Vector):
__tablename__ = 'luftbilder_dritte_firmen'
__bodId__ = 'ch.swisstopo.lubis-luftbilder-dritte-firmen'
contact = Column('contact', Unicode)
Expand All @@ -89,7 +84,7 @@ class LuftbilderDritteFirmen(Base, LuftbilderBase, Vector):
register('ch.swisstopo.lubis-luftbilder-dritte-firmen', LuftbilderDritteFirmen)


class LuftbilderDritteKantone(Base, LuftbilderBase, Vector):
class LuftbilderDritteKantone(Base, LuftbilderBaseDritte, Vector):
__tablename__ = 'luftbilder_dritte_kantone'
__bodId__ = 'ch.swisstopo.lubis-luftbilder-dritte-kantone'
contact = Column('contact', Unicode)
Expand Down Expand Up @@ -139,23 +134,16 @@ class LuftbilderSchraegaufnahmen(Base, Vector):
__template__ = 'templates/htmlpopup/lubis_schraegaufnahmen.mako'
__bodId__ = 'ch.swisstopo.lubis-luftbilder_schraegaufnahmen'
__timeInstant__ = 'bgdi_flugjahr'
__extended_info__ = True
# Composite labels
__label__ = 'flightdate'
id = Column('ebkey', Unicode, primary_key=True)
ebkey_old = Column('ebkey_old', Unicode)
inventory_number = Column('inventory_number', Unicode)
flightdate = Column('flightdate', Unicode)
medium_format = Column('medium_format', Unicode)
filesize_mb = Column('filesize_mb', Unicode)
filename = Column('filename', Unicode)
filmart = Column('filmart', Unicode)
stereo_couple = Column('stereo_couple', Unicode)
bgdi_flugjahr = Column('bgdi_flugjahr', Integer)
x = Column('x', Integer)
y = Column('y', Integer)
contact = Column('contact', Unicode)
contact_email = Column('contact_email', Unicode)
the_geom = Column(Geometry2D)

register('ch.swisstopo.lubis-luftbilder_schraegaufnahmen', LuftbilderSchraegaufnahmen)
Expand All @@ -168,12 +156,10 @@ class LuftbilderTerrA(Base, Vector):
__bodId__ = 'ch.swisstopo.lubis-terrestrische_aufnahmen'
__timeInstant__ = 'bgdi_flugjahr'
__returnedGeometry__ = 'the_geom_footprint'
__extended_info__ = True
__label__ = 'flugdatum'
id = Column('inventory_number', Unicode, primary_key=True)
inventarnummer_old = Column('inventarnummer_old', Unicode)
inventarnummer = Column('objectid', Integer)
image_number = Column('image_number', Integer)
flugdatum = Column('bgdi_flugdatum', Unicode)
bgdi_flugjahr = Column('year', Integer)
filmart = Column('filmart', Unicode)
Expand All @@ -182,12 +168,8 @@ class LuftbilderTerrA(Base, Vector):
base_uuid = Column('base_uuid', Unicode)
x = Column('easting', Numeric)
y = Column('northing', Numeric)
medium_format = Column('format', Unicode)
filesize_mb = Column('filesize_mb', Unicode)
filename = Column('filename', Unicode)
bgdi_imagemode = Column('bgdi_imagemode', Unicode)
image_height = Column('image_height', Integer)
image_width = Column('image_width', Integer)
smapshot_id = Column('smapshot_id', Integer)
the_geom_footprint = Column('the_geom_footprint', Geometry2D)
the_geom = Column(Geometry2D)
Expand Down
189 changes: 1 addition & 188 deletions chsdi/templates/htmlpopup/lubis.mako
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<%inherit file="base.mako"/>
<%namespace name="lubis_map" file="../luftbilder/lubis_map.mako"/>

<%!
import datetime
Expand All @@ -15,43 +14,11 @@ except ImportError:
def br(text):
return text.replace('\n', markupsafe.Markup('<br />'))
def determinePreviewUrl(tileUrlBasePath, ebkey):
tileUrlBasePath = tileUrlBasePath
def getPreviewImageUrl(ebkey):
return tileUrlBasePath + '/' + ebkey + '/quickview.jpg'
def getZeroTileUrl(ebkey):
return tileUrlBasePath + '/' + ebkey + '/1/0/0.jpg'
headers = {'Referer': 'http://admin.ch'}
url = getPreviewImageUrl(ebkey)
#testing these 2 url could be done more python like
if not h.resource_exists(url, headers):
url = getZeroTileUrl(ebkey)
return url
def date_to_str(datum):
try:
return datetime.datetime.strptime(datum.strip(), "%Y%m%d").strftime("%d-%m-%Y")
except:
return request.translate('None') + request.translate('Datenstand')
def get_viewer_url(request, params):
f = {
'width': params[0],
'height': params[1],
'title': params[2].encode('utf8'),
'bildnummer': params[3],
'datenherr': params[4].encode('utf8'),
'layer': params[5].encode('utf8'),
'lang': params[6],
'rotation': params[7]
}
return route_url('luftbilder', request) + '?' + urlencode(f)
%>

<%def name="table_body(c, lang)">
Expand All @@ -61,35 +28,7 @@ tt_lubis_ebkey = c['layerBodId'] + '.' + 'id'
lang = lang if lang in ('fr','it','en') else 'de'
c['stable_id'] = True
request = context.get('request')
aerialimages_data_host = request.registry.settings['aerialimages_data_host']
tileUrlBasePath = aerialimages_data_host + '/tiles'
preview_url = determinePreviewUrl(tileUrlBasePath, c['featureId'])
image_width = c['attributes']['image_width'] if 'image_width' in c['attributes'] else None
image_height = c['attributes']['image_height'] if 'image_height' in c['attributes'] else None
image_rotation = c['attributes']['rotation'] if 'rotation' in c['attributes'] else None
if image_width is None or image_height is None:
wh = h.imagesize_from_metafile(tileUrlBasePath, c['featureId'])
image_width = wh[0]
image_height = wh[1]
if image_rotation is None:
image_rotation = 0
datum = date_to_str(c['attributes']['flugdatum'])
params = (
image_width,
image_height,
_('ch.swisstopo.lubis-luftbilder-dritte-kantone.ebkey'),
c['featureId'],
c['attributes']['firma'],
c['layerBodId'],
lang,
image_rotation)
viewer_url = get_viewer_url(request, params)
%>
<tr>
<td class="cell-left">${_(tt_lubis_ebkey)}</td>
Expand All @@ -111,15 +50,7 @@ viewer_url = get_viewer_url(request, params)
</tr>
% endif
% if preview_url != "" and image_width != None:
<tr>
<td class="cell-left">${_('tt_lubis_Quickview')}</td>
<td>
<a href="${viewer_url}" target="_blank"><img src="${preview_url}" alt="quickview"></a>
</td>
</tr>
% elif str(c['attributes'].get('doi_link', '-')).startswith('http'):
% if str(c['attributes'].get('doi_link', '-')).startswith('http'):
<tr>
<td class="cell-left">${_('tt_lubis_Quickview')}</td>
<td><a href="${c['attributes']['doi_link']}" target="_blank">${c['attributes']['doi_link']}</a></td></tr>
Expand Down Expand Up @@ -155,121 +86,3 @@ viewer_url = get_viewer_url(request, params)
</tr>
% endif
</%def>


<%def name="extended_info(c, lang)">
<%
c['stable_id'] = True
protocol = request.scheme
c['baseUrl'] = h.make_agnostic(''.join((protocol, '://', request.registry.settings['geoadminhost'])))
topic = request.matchdict.get('map')
lang = request.lang
aerialimages_data_host = request.registry.settings['aerialimages_data_host']
tileUrlBasePath = aerialimages_data_host + '/tiles'
preview_url = determinePreviewUrl(tileUrlBasePath, c['featureId'])
filesize_mb = '-'
filename = c['attributes']['filename']
if filename:
filesize_mb = c['attributes']['filesize_mb']
endif
orientierung = '-'
if c['attributes']['orientierung']:
orientierung = 'True'
endif
datum = date_to_str(c['attributes']['flugdatum'])
image_width = c['attributes']['image_width'] if 'image_width' in c['attributes'] else None
image_height = c['attributes']['image_height'] if 'image_height' in c['attributes'] else None
image_rotation = c['attributes']['rotation'] if 'rotation' in c['attributes'] else None
if image_width is None or image_height is None:
wh = h.imagesize_from_metafile(tileUrlBasePath, c['featureId'])
image_width = wh[0]
image_height = wh[1]
if image_rotation is None:
image_rotation = 0
params = (
image_width,
image_height,
_('tt_lubis_ebkey'),
c['featureId'],
c['attributes']['firma'],
c['layerBodId'],
lang,
image_rotation)
viewer_url = get_viewer_url(request, params)
%>
<title>${_('tt_lubis_ebkey')}: ${c['featureId']}</title>
<body onload="init()">
<table class="table-with-border kernkraftwerke-extended">
<tr><th class="cell-left">${_('tt_lubis_ebkey')}</th> <td>${c['featureId'] or '-'}</td></tr>
<tr><th class="cell-left">${_('tt_lubis_inventarnummer')}</th> <td>${c['attributes']['inventarnummer'] or '-'}</td></tr>
<tr><th class="cell-left">${_('tt_lubis_Flugdatum')}</th> <td>${datum or '-'}</td></tr>
<tr><th class="cell-left">${_('tt_lubis_flughoehe')}</th> <td>${c['attributes']['flughoehe'] or '-'}</td></tr>
<tr><th class="cell-left">${_('tt_lubis_massstab')}</th> <td>1:${c['attributes']['massstab'] or '-'}</td></tr>
<tr><th class="cell-left">${_('tt_lubis_y')}</th> <td>${c['attributes']['x'] or '-'}</td></tr>
<tr><th class="cell-left">${_('tt_lubis_x')}</th> <td>${c['attributes']['y'] or '-'}</td></tr>
<tr><th class="cell-left">${_('tt_lubis_Filmart')}</th> <td>${c['attributes']['filmart'] or '-'}</td></tr>
% if 'contact_image_url' in c['attributes'] and c['attributes']['contact_image_url']:
<tr>
<th class="cell-left">${_('tt_lubis_url_canton')}</th>
<td><a href="${c['attributes']['contact_image_url']}" target="_blank">${c['attributes']['contact_image_url']}</a></td>
</tr>
% endif
<tr><th class="cell-left">${_('tt_lubis_originalsize')}</th> <td>${c['attributes']['originalsize'] or '-'}</td></tr>
<tr><th class="cell-left">${_('tt_lubis_filesize_mb')}</th> <td>${filesize_mb or '-'}</td></tr>
<tr><th class="cell-left">${_('tt_lubis_bildpfad')}</th>
% if filename and filename.startswith('http'):
<td><a href="${filename or '-'}" target="_blank">${filename or '-'}</a></td></tr>
% else:
<td>${filename or '-'}</td></tr>
% endif
% if str(c['attributes'].get('doi_link', '')).startswith('http'):
<tr><th class="cell-left">DOI Link</th> <td><a href="${c['attributes']['doi_link']}" target="_blank">${c['attributes']['doi_link']}</a></td></tr>
% endif
<tr><th class="cell-left">${_('tt_lubis_orthophoto')}</th> <td>${c['attributes']['orthophoto'] or '-'}</td></tr>
<tr><th class="cell-left">${_('tt_lubis_orientierung')}</th> <td>${orientierung or '-'}</td></tr>
<tr><th class="cell-left">${_('tt_lubis_rotation')}</th> <td>${c['attributes']['rotation'] or '-'}</td></tr>
% if 'contact_web' in c['attributes']:
<tr class="chsdi-no-print">
<th class="cell-left">${_('tt_lubis_bildorder')}</th>
<td>${c['attributes']['contact'] | br } <br /> ${c['attributes']['contact_email']} <br /><a href="${c['attributes']['contact_web']}" target="_blank">${c['attributes']['contact_web']}</a></td>
</tr>
% endif
</table>
<br>
<div class="chsdi-map-container table-with-border">
<iframe src="${''.join((c['baseUrl'], '/embed.html', '?', c['layerBodId'], '=', str(c['featureId']), '&lang=', lang, '&topic=', topic,'&bgLayer=ch.swisstopo.pixelkarte-grau'))}" width='580' height='300' style="width: 100%;" frameborder='0' style='border:0'></iframe>
</div>
<br>
% if preview_url != "" and image_width != None:
<div class="chsdi-map-container table-with-border" >
<div id="lubismap"></div>
</div>
% endif
<br>
<script type="text/javascript">
function init() {
% if preview_url != "" and image_width != None:
${lubis_map.init_map(c['featureId'], image_width, image_height, image_rotation, 'lubismap', aerialimages_data_host)}
%endif
}
</script>
</body>
</%def>


<%def name="extended_resources(c, lang)">
<script type="text/javascript" src="${h.get_loaderjs_url(request, '3.18.2')}"></script>
</%def>
Loading

0 comments on commit c942ea0

Please sign in to comment.