Skip to content

Commit

Permalink
Merge branch 'release-4.8.14'
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomarrocoli committed Jun 16, 2022
2 parents bc8e8b8 + 5bdf2c1 commit 157c7e9
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 23 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### 4.8.14
- Added global statistics download
- Fixed PAME file downloads
- Limited map zoom on global WMS layer
- Updated external API calls to work after API changes
- Stopped trying to load geom into memory and use extent to determine whether PA is point or polygon
- Fixed region links on search results
- Minor text changes
-
### 4.8.13
- Removed MPA download option
- Changed Mapbox basemap to most recent version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,10 @@ $cards-squares-width-tablet: 48%;

&:before { @include border-radius; }
}

&__title {
overflow-wrap: break-word;
text-align: center;
}
}
}
5 changes: 5 additions & 0 deletions app/controllers/global_statistics_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class GlobalStatisticsController < ApplicationController
def download
send_file GlobalStatistic.latest_csv, type: 'text/csv', disposition: 'attachment'
end
end
6 changes: 2 additions & 4 deletions app/controllers/pame_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ class PameController < ApplicationController
filters: []
}.to_json

# Format for this date is: Year-MON (4 digits-3 chars)
UPDATED_AT = "2020-DEC".freeze

def index
@table_attributes = PameEvaluation::TABLE_ATTRIBUTES.to_json
@filters = PameEvaluation.filters_to_json
Expand All @@ -26,10 +23,11 @@ def list
end

def download
last_update = PameEvaluation.last_csv_update_date.strftime('%Y-%^b')
send_data PameEvaluation.to_csv(params.to_json), {
type: "text/csv; charset=utf-8; header=present",
disposition: "attachment",
filename: "protectedplanet-pame-#{UPDATED_AT}.csv" }
filename: "protectedplanet-pame-#{last_update}.csv" }
end
end

3 changes: 2 additions & 1 deletion app/controllers/protected_areas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def show

@map_options = {
map: {
boundsUrl: @protected_area.extent_url
boundsUrl: @protected_area.extent_url,
maxZoom: 0
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/map_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def all_services_for_point_query

def country_extent_url (iso3)
{
url: "https://data-gis.unep-wcmc.org/server/rest/services/GADM_EEZ_Layer/FeatureServer/0/query?where=iso_ter+%3D+%27#{iso3}%27&returnGeometry=false&returnExtentOnly=true&outSR=4326&f=pjson",
url: "https://data-gis.unep-wcmc.org/server/rest/services/GADM_EEZ_Layer/FeatureServer/0/query?where=iso_ter+%3D+#{iso3}&returnGeometry=false&returnExtentOnly=true&outSR=4326&f=pjson",
padding: 5
}
end
Expand Down
1 change: 1 addition & 0 deletions app/javascript/components/map/default-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const MAP_OPTIONS_DEFAULT = {
attributionControl: false,
preserveDrawingBuffer: true, // needed for PDF rendering
zoom: 1.3,
maxZoom: 10 // Maximum zoom where tiles are cached for the web-map service
//bounds: [[-180, -90], [180, 90]],
//boundingISO: ISO3,
//boundingRegion; Name e.g. Europe,
Expand Down
5 changes: 5 additions & 0 deletions app/models/global_statistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ def self.green_list_stats
self.instance.send(column_name)
end
end

def self.latest_csv
global_statistics_csvs = Dir.glob("#{Rails.root}/lib/data/seeds/global_statistics*")
global_statistics_csvs.sort.last
end
end
6 changes: 6 additions & 0 deletions app/models/pame_evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ def self.to_csv(json = nil)

generate_csv(where_statement, restricted_where_statement)
end

def self.last_csv_update_date
pame_data_csvs = Dir.glob("#{Rails.root}/lib/data/seeds/pame_data*")
latest_pame_csv = pame_data_csvs.sort.last.split('_').last
latest_pame_csv.split('.').first.to_date
end
end


9 changes: 6 additions & 3 deletions app/models/protected_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ def arcgis_layer
end

def arcgis_query_string
"/query?where=wdpaid+%3D+%27#{wdpa_id}%27&geometryType=esriGeometryEnvelope&returnGeometry=true&f=geojson"
"/query?where=wdpaid+%3D+#{wdpa_id}&geometryType=esriGeometryEnvelope&returnGeometry=true&f=geojson"
end

def extent_url
{
url: "#{arcgis_layer}/query?where=wdpaid+%3D+%27#{wdpa_id}%27&returnGeometry=false&returnExtentOnly=true&outSR=4326&f=pjson",
url: "#{arcgis_layer}/query?where=wdpaid+%3D+#{wdpa_id}&returnGeometry=false&returnExtentOnly=true&outSR=4326&f=pjson",
padding: 0.2
}
end
Expand All @@ -254,7 +254,10 @@ def is_whs?
private

def is_point?
the_geom.geometry_type.type_name.match('Point').present?
@is_point ||= begin
extent = bounds
extent[0][0] == extent[1][0] && extent[0][1] == extent[1][1]
end
end

def bounding_box_query
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/search/areas_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def sites

def geo_hash(geo_type, areas, total=0)
areas = areas.present? ? areas.first(9) : []
geo_type_locale = geo_type == 'site' ? 'area-types.wdpa' : "geo-types.#{geo_type.pluralize}"
geo_type_locale = "geo-types.#{geo_type.pluralize}"
{
geoType: geo_type,
title: I18n.t("global.#{geo_type_locale}"),
Expand Down
2 changes: 2 additions & 0 deletions app/serializers/search/base_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def url(obj)
protected_area_path(obj.wdpa_id)
elsif obj.is_a?(Country)
country_path(iso: obj.iso_3)
elsif obj.is_a?(Region)
region_path(iso: obj.iso)
else
'#'
end
Expand Down
1 change: 1 addition & 0 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<section class="container spacer-small--top">
<%= render partial: "partials/cards/facts", locals: { cards: @site_facts } %>
<p class="p-larger no-margin--top"><span class="bold">Statistics updated: </span><%= @update_date %></p>
<%= link_to('Download latest global statistics', global_statistics_download_path) %>
</section>

<%= render partial: "partials/search/protected-areas", locals: { config: @config_search_areas } %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/partials/messages/_message-citation.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="card--message">
<h2>citation</h2>
<p>UNEP-WCMC (<%= Date.today.year %>). Protected Area Profile for <%= title %> from the World Database of Protected Areas, <%= Date.today.strftime("%B %Y") %>. Available at: <a href="/">www.protectedplanet.net</a></p>
<p>UNEP-WCMC (<%= Date.today.year %>). Protected Area Profile for <%= title %> from the World Database on Protected Areas, <%= Date.today.strftime("%B %Y") %>. Available at: <a href="/">www.protectedplanet.net</a></p>
</div>
1 change: 1 addition & 0 deletions config/locales/global/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ en:
geo-types:
countries: Countries
regions: Regions
sites: Protected Areas and OECMs
logos:
iucn: IUCN logo
pp: Protected Planet logo
Expand Down
10 changes: 5 additions & 5 deletions config/locales/home/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ en:
facts:
-
theme: terrestrial
title: Terrestrial protected area coverage
title: Terrestrial and inland waters protected area coverage
-
theme: marine
title: Marine protected area coverage
-
theme: oecm
title: Terrestrial protected area & OECM coverage
title: Terrestrial and inland waters protected area & OECM coverage
-
theme: oecm
title: Marine protected area & OECM coverage
Expand All @@ -34,14 +34,14 @@ en:
icon: area
categories:
-
title: Marine Protected Areas
title: Marine Protected Areas and OECMs
slug: /marine-protected-areas
filter: 'marine'
-
title: Terrestrial Protected Areas
title: Terrestrial and Inland Waters Protected Areas and OECMs
slug:
filter: 'terrestrial'
-
title: Green Listed Protected Areas
title: Green Listed Protected Areas and OECMs
slug: /green-list
filter: 'is_green_list'
4 changes: 2 additions & 2 deletions config/locales/map/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ en:
greenlist_marine:
title: Marine Green Listed Protected Areas
terrestrial_wdpa:
title: Terrestrial Protected Areas
title: Terrestrial and Inland Waters Protected Areas
marine_wdpa:
title: Marine Protected Areas
oecm_marine:
title: Other effective area-based conservation measures
oecm:
title: Other effective area-based conservation measures
title: Discover Protected Areas
title: Discover Protected Areas and OECMs
title_oecm: Discover OECMs
disclaimer:
heading: Map Disclaimer
Expand Down
2 changes: 1 addition & 1 deletion config/locales/search/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ en:
filter-group-type:
title: Type
options:
terrestrial: Terrestrial
terrestrial: Terrestrial and inland waters
marine: Marine
geo-types:
region: Regions
Expand Down
4 changes: 2 additions & 2 deletions config/locales/stats/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ en:
total: Total marine and coastal area
coverage_terrestrial:
covered: Land area covered
title_wdpa: Terrestrial protected area coverage
title_wdpa_oecm: Terrestrial protected area & OECM coverage
title_wdpa: Terrestrial and inland waters protected area coverage
title_wdpa_oecm: Terrestrial and inland waters protected area & OECM coverage
total: Total land area
coverage-chart-smallprint: The graph excludes status years with no information reported (STATUS_YR = 0).
countries: Number of countries
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
get '/country/:iso/compare(/:iso_to_compare)', to: 'country#compare', as: 'compare_countries'
get '/country/:iso/protected_areas', to: 'country#protected_areas', as: 'country_protected_areas'

get '/global_statistics_download', to: 'global_statistics#download'

# JSON endpoints
get '/downloads/poll', to: 'downloads#poll', as: 'download_poll'
resources :downloads, only: [:show, :create, :update]
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/download/queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ module Queries
:metadataid, :data_title, :resp_party,
:year, :update_yr, :char_set,
:ref_system, :scale, :lineage,
:citation, :disclaimer, :language
:citation, :disclaimer, :language,
:verifier
]

def self.for_points extra_columns={}
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/wdpa/global_stats_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ def self.import
CSV.foreach(latest_global_statistics_csv, headers: true) do |row|
field = row['type']
value = parse_value(row['value'])
attrs.merge!("#{field}": value)

# The global_statistics csv can now be downloaded so a methodology url has been added
# to the end of the spreadsheet. We need to not add this line to the attributes.
attrs.merge!("#{field}": value) if field.present?
end

stats = GlobalStatistic.first_or_initialize(attrs)
Expand Down

0 comments on commit 157c7e9

Please sign in to comment.