Skip to content

Commit

Permalink
Add the ability to download all result bounding boxes as KML
Browse files Browse the repository at this point in the history
This implements part of issue #13.
  • Loading branch information
Homme Zwaagstra committed Mar 7, 2012
1 parent 1f5e344 commit 8cbfbd6
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 2 deletions.
2 changes: 2 additions & 0 deletions python/medin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ def wsgi_app():
app.addContentTypes(view, 'full', full_types)
rss = views.SOAPRequest(views.RSSResults())
atom = views.SOAPRequest(views.AtomResults())
kml = views.SOAPRequest(views.KMLResults())
result_formats = views.ResultFormat(app, {'rss': rss,
'kml': kml,
'atom': atom})

# search by country
Expand Down
7 changes: 7 additions & 0 deletions python/medin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,13 @@ def __init__(self):
super(AtomResults, self).__init__(['atom', 'catalogue', '%s.xml'], RESULT_SUMMARY,
content_type='application/atom+xml')

class KMLResults(Results):
def __init__(self):
from medin.dws import RESULT_SUMMARY

super(KMLResults, self).__init__(['kml', 'catalogue', '%s.xml'], RESULT_SUMMARY,
content_type='application/vnd.google-earth.kml+xml')

class AreaResults(object):

def __init__(self, app):
Expand Down
5 changes: 3 additions & 2 deletions templates/full/catalogue.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ <h3>Bookmark this search</h3>
% endif
</div>
<div class="right syndicate">
<a href="${script_root}/full/catalogue.rss${start_link()}" title="Subscribe to these results using RSS"><img alt="Subscribe" src="/images/feed-icon.gif" class="image_no_border"/> RSS</a>
<a href="${script_root}/full/catalogue.atom${start_link()}" title="Subscribe to these results using Atom"><img alt="Subscribe" src="/images/feed-icon.gif" class="image_no_border"/> Atom</a>
<a href="${script_root}/full/catalogue.rss${start_link()}" title="Subscribe to these results using RSS"><img alt="Subscribe using RSS" src="/images/feed-icon.gif" class="image_no_border"/> RSS</a>
<a href="${script_root}/full/catalogue.atom${start_link()}" title="Subscribe to these results using Atom"><img alt="Subscribe using Atom" src="/images/feed-icon.gif" class="image_no_border"/> Atom</a>
<a href="${script_root}/full/catalogue.kml${start_link()}" title="Subscribe to these results using Atom"><img alt="Subscribe using KML" src="/images/kml.png" class="image_no_border"/> KML</a>
</div>
</div>
</%def>
Expand Down
106 changes: 106 additions & 0 deletions templates/kml/catalogue/base.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<%doc>
Created by Homme Zwaagstra
Copyright (c) 2010 GeoData Institute
http://www.geodata.soton.ac.uk
geodata@soton.ac.uk
Unless explicitly acquired and licensed from Licensor under another
license, the contents of this file are subject to the Reciprocal
Public License ("RPL") Version 1.5, or subsequent versions as
allowed by the RPL, and You may not copy or use this file in either
source code or executable form, except in compliance with the terms
and conditions of the RPL.
All software distributed under the RPL is provided strictly on an
"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
IMPLIED, AND LICENSOR HEREBY DISCLAIMS ALL SUCH WARRANTIES,
INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT, OR
NON-INFRINGEMENT. See the RPL for specific language governing rights
and limitations under the RPL.
You can obtain a full copy of the RPL from
http://opensource.org/licenses/rpl1.5.txt or [email protected]
</%doc>\
<%namespace import="isoformat, content, description" file="/common/feeds.xml"/><%!
template_ = ""
%><?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
xmlns:opensearchgeo="http://a9.com/-/opensearch/extensions/geo/1.0/">
<Folder>
<name>MEDIN - ${title | x}</name>
<description>${description()}</description>
<opensearch:totalResults>${hits}</opensearch:totalResults>
<opensearch:startIndex>${start_index}</opensearch:startIndex>
<opensearch:itemsPerPage>${count}</opensearch:itemsPerPage>
<atom:updated>${isoformat(updated)}</atom:updated>
<atom:link rel="search" type="application/opensearchdescription+xml" href="${script_root}/opensearch/catalogue/${self.attr.template}.xml"/>
<atom:link rel="self" href="${resource_root}${query_string | x}" type="application/rss+xml"/>
<atom:link rel="alternate" href="${script_root}/${self.attr.template}/catalogue${query_string | x}" type="text/html"/>
<atom:link rel="alternate" href="${script_root}/${self.attr.template}/catalogue.atom${query_string | x}" type="application/atom+xml"/>
<atom:link rel="self" href="${resource_root}${query_string | x}" type="application/rss+xml"/>
% if first_link:
<atom:link rel="first" href="${resource_root}?${first_link['link'] | x}" type="application/rss+xml"/>
% else:
<atom:link rel="first" href="${resource_root}${query_string | x}" type="application/rss+xml"/>
% endif
% if prev_links:
<atom:link rel="previous" href="${resource_root}?${prev_links[-1]['link'] | x}" type="application/rss+xml"/>
% endif
% if next_links:
<atom:link rel="next" href="${resource_root}?${next_links[0]['link'] | x}" type="application/rss+xml"/>
% endif
% if last_link:
<atom:link rel="last" href="${resource_root}?${last_link['link'] | x}" type="application/rss+xml"/>
% endif
<opensearch:Query role="request" searchTerms="${search_term | x}" startIndex="${start_index}" count="${count}" />
<Style id="extentStyle">
<LineStyle>
<color>#ca0000ff</color>
<width>2.5</width>
</LineStyle>
<PolyStyle>
<color>#ca0000af</color>
<colorMode>normal</colorMode>
<fill>1</fill>
<outline>1</outline>
</PolyStyle>
</Style>
% for result in results:
<Placemark>
<name>${result['title'] | x}</name>
<styleUrl>#extentStyle</styleUrl>
<atom:updated>${isoformat(result['updated'])}</atom:updated>
<atom:link>${script_root}/${self.attr.template}/catalogue/${result['id'] | x}</atom:link>
<description>&lt;strong&gt;Catalogue entry:&lt;/strong&gt;&lt;a href=&quot;${script_root}/${self.attr.template}/catalogue/${result['id'] | x}&quot;&gt;${result['id'] | x}&lt;/a&gt;&lt;br/&gt;${content(result)}</description>
%if result['bbox']:
<Polygon>
<outerBoundaryIs>
<LinearRing>
<gx:altitudeMode>clampToSeaFloor</gx:altitudeMode>
<coordinates>${result['bbox'][0]},${result['bbox'][1]} ${result['bbox'][2]},${result['bbox'][1]} ${result['bbox'][2]},${result['bbox'][3]} ${result['bbox'][0]},${result['bbox'][3]} ${result['bbox'][0]},${result['bbox'][1]}</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
%endif
</Placemark>
% endfor
% if not results:
% if not hits:
<Placemark>
<name>No Results Found</name>
<description>The following search produced no results: ${search_term | x}</description>
</Placemark>
% else:
<Placemark>
<name>Results Out Of Range</name>
<description>The results specified are out of range of the original search. Try the beginning of the result set at ${resource_root}?${first_link['link'] | x}</description>
</Placemark>
% endif
% endif
</Folder>
</kml>
29 changes: 29 additions & 0 deletions templates/kml/catalogue/full.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%doc>
Created by Homme Zwaagstra
Copyright (c) 2010 GeoData Institute
http://www.geodata.soton.ac.uk
geodata@soton.ac.uk
Unless explicitly acquired and licensed from Licensor under another
license, the contents of this file are subject to the Reciprocal
Public License ("RPL") Version 1.5, or subsequent versions as
allowed by the RPL, and You may not copy or use this file in either
source code or executable form, except in compliance with the terms
and conditions of the RPL.
All software distributed under the RPL is provided strictly on an
"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
IMPLIED, AND LICENSOR HEREBY DISCLAIMS ALL SUCH WARRANTIES,
INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT, OR
NON-INFRINGEMENT. See the RPL for specific language governing rights
and limitations under the RPL.
You can obtain a full copy of the RPL from
http://opensource.org/licenses/rpl1.5.txt or [email protected]
</%doc>\
<%!
template = "full"
%>
<%inherit file="base.xml"/>
29 changes: 29 additions & 0 deletions templates/kml/catalogue/light.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%doc>
Created by Homme Zwaagstra
Copyright (c) 2010 GeoData Institute
http://www.geodata.soton.ac.uk
geodata@soton.ac.uk
Unless explicitly acquired and licensed from Licensor under another
license, the contents of this file are subject to the Reciprocal
Public License ("RPL") Version 1.5, or subsequent versions as
allowed by the RPL, and You may not copy or use this file in either
source code or executable form, except in compliance with the terms
and conditions of the RPL.
All software distributed under the RPL is provided strictly on an
"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
IMPLIED, AND LICENSOR HEREBY DISCLAIMS ALL SUCH WARRANTIES,
INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT, OR
NON-INFRINGEMENT. See the RPL for specific language governing rights
and limitations under the RPL.
You can obtain a full copy of the RPL from
http://opensource.org/licenses/rpl1.5.txt or [email protected]
</%doc>\
<%!
template = "light"
%>
<%inherit file="base.xml"/>
2 changes: 2 additions & 0 deletions templates/opensearch/catalogue/base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<Description>Search the MEDIN metadata catalogue using the ${self.attr.template} interface</Description>
<Tags>medin portal metadata marine</Tags>
<Contact>[email protected]</Contact>
<Url type="application/vnd.google-earth.kml+xml"
template="${script_root}/${self.attr.template}/catalogue.kml?q={searchTerms}&amp;c={count}&amp;i={startIndex}"/>
<Url type="application/atom+xml"
template="${script_root}/${self.attr.template}/catalogue.atom?q={searchTerms}&amp;c={count}&amp;i={startIndex}"/>
<Url type="application/rss+xml"
Expand Down

0 comments on commit 8cbfbd6

Please sign in to comment.