Skip to content

Commit ced4c16

Browse files
committed
Merge remote-tracking branch 'origin/sample-landscan-data'
2 parents 29b98f5 + 4cfee98 commit ced4c16

6 files changed

Lines changed: 171 additions & 0 deletions

File tree

ansible/roles/dataqs/tasks/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@
114114
command: "{{ app_code_dir }}/venvs/geonode/bin/python {{app_code_dir}}/venvs/geonode/src/dataqs/dataqs/cmap/cmap.py"
115115
ignore_errors: yes
116116

117+
- include: geoserver_permissions.yml
118+
119+
- name: Create the landscan layer
120+
command: "{{ app_code_dir }}/venvs/geonode/bin/python {{app_code_dir}}/venvs/geonode/src/dataqs/dataqs/landscan/landscan.py"
121+
ignore_errors: yes
122+
117123
- name: Django updatelayers
118124
django_manage: command=updatelayers
119125
app_path={{app_code_dir}}/{{app_name}}

ansible/roles/dataqs/templates/dataq_settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
'dataqs.hifld',
3737
'dataqs.gistemp',
3838
'dataqs.cmap',
39+
'dataqs.landscan',
3940
)
4041

4142
# CELERY SETTINGS

dataqs/landscan/__init__.py

Whitespace-only changes.

dataqs/landscan/landscan.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
###############################################################################
5+
# Copyright Kitware Inc. and Epidemico Inc.
6+
#
7+
# Licensed under the Apache License, Version 2.0 ( the "License" );
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
###############################################################################
19+
import os
20+
from urllib import urlretrieve
21+
import zipfile
22+
23+
import gdal
24+
25+
from dataqs.helpers import style_exists
26+
from dataqs.processor_base import GeoDataProcessor
27+
28+
script_dir = os.path.dirname(os.path.realpath(__file__))
29+
30+
31+
class LandscanProcessor(GeoDataProcessor):
32+
"""
33+
Class for processing sample Landscan data
34+
"""
35+
36+
layer = "landscan"
37+
description = "LandScan 2011 Global Population Project"
38+
39+
def get_landscan(self):
40+
"""
41+
Downloads the sample landscan image for Cyprus
42+
"""
43+
44+
url = "http://web.ornl.gov/sci/landscan/" + \
45+
"landscan2011/LS11sample_Cyprus.zip"
46+
47+
zip_dir = os.path.join(self.tmp_dir, "landscan.zip")
48+
urlretrieve(url, zip_dir)
49+
50+
# Open up the zip file
51+
zip_ref = zipfile.ZipFile(zip_dir, 'r')
52+
landscan_dir = os.path.join(self.tmp_dir, "landscan")
53+
zip_ref.extractall(landscan_dir)
54+
zip_ref.close()
55+
56+
return landscan_dir
57+
58+
def convert_landscan(self, landscan_dir):
59+
"""
60+
Converts arcgrid into a tiff file
61+
"""
62+
63+
# Important
64+
# The directory which holds the .adf files
65+
# needs to be found here
66+
67+
for subdir, dirs, files in os.walk(landscan_dir):
68+
for d in dirs:
69+
direc = os.listdir(os.path.join(subdir, d))
70+
if set([f.endswith('.adf') for f in direc]) == {True}:
71+
grid_dir = os.path.join(subdir, d)
72+
73+
src_ds = gdal.Open(grid_dir)
74+
proj = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'
75+
src_ds.SetProjection(proj)
76+
driver = gdal.GetDriverByName("GTiff")
77+
78+
# Output to new format
79+
tiff_output = os.path.join(self.tmp_dir, "landscan.tiff")
80+
driver.CreateCopy(tiff_output, src_ds, 0)
81+
82+
return tiff_output
83+
84+
def import_landscan(self, landscan_tiff):
85+
"""
86+
Imports landscan to geonode
87+
"""
88+
89+
self.post_geoserver(landscan_tiff, self.layer)
90+
if not style_exists(self.layer):
91+
with open(os.path.join(
92+
script_dir, 'resources/landscan.sld')) as sld:
93+
self.set_default_style(self.layer,
94+
self.layer, sld.read())
95+
self.update_geonode(self.layer, title=self.layer,
96+
store=self.layer,
97+
description=self.description)
98+
self.truncate_gs_cache(self.layer)
99+
100+
def run(self):
101+
"""
102+
Retrieve and process Landscan sample data
103+
"""
104+
105+
landscan_dir = self.get_landscan()
106+
landscan_tiff = self.convert_landscan(landscan_dir)
107+
self.import_landscan(landscan_tiff)
108+
109+
if __name__ == '__main__':
110+
processor = LandscanProcessor()
111+
processor.run()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?><sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
2+
<sld:NamedLayer>
3+
<sld:Name>Landscan</sld:Name>
4+
<sld:UserStyle>
5+
<sld:Name>Landscan</sld:Name>
6+
<sld:Title>Population</sld:Title>
7+
<sld:FeatureTypeStyle>
8+
<sld:Name>name</sld:Name>
9+
<sld:Rule>
10+
<sld:RasterSymbolizer>
11+
<sld:ColorMap>
12+
<sld:ColorMapEntry color="#0FF01E" opacity="1" quantity="0" label="0"/>
13+
<sld:ColorMapEntry color="#11DAF0" opacity="1" quantity="25" label="25"/>
14+
<sld:ColorMapEntry color="#1515E8" opacity="1" quantity="50" label="50"/>
15+
<sld:ColorMapEntry color="#E9D715" opacity="1" quantity="100" label="100"/>
16+
<sld:ColorMapEntry color="#F19109" opacity="1" quantity="500" label="500"/>
17+
<sld:ColorMapEntry color="#F41B0F" opacity="1" quantity="1000" label="1000"/>
18+
</sld:ColorMap>
19+
</sld:RasterSymbolizer>
20+
</sld:Rule>
21+
</sld:FeatureTypeStyle>
22+
</sld:UserStyle>
23+
</sld:NamedLayer>
24+
</sld:StyledLayerDescriptor>

dataqs/landscan/tasks.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
###############################################################################
5+
# Copyright Kitware Inc. and Epidemico Inc.
6+
#
7+
# Licensed under the Apache License, Version 2.0 ( the "License" );
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
###############################################################################
19+
20+
from __future__ import absolute_import
21+
22+
from celery import shared_task
23+
from dataqs.landscan.landscan import LandscanProcessor
24+
25+
26+
@shared_task
27+
def landscan_task():
28+
processor = LandscanProcessor()
29+
processor.run()

0 commit comments

Comments
 (0)