Skip to content

Commit

Permalink
use GEE tile fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Thannarot committed Oct 2, 2020
1 parent 9f03c84 commit 9d63cdd
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 81 deletions.
24 changes: 12 additions & 12 deletions forest_monitor/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class ForestMonitor():
ee.Initialize(settings.EE_CREDENTIALS)

# image collection
TREE_CANOPY = ee.ImageCollection('projects/servir-mekong/yearly_primitives_smoothed/tree_canopy')
TREE_HEIGHT = ee.ImageCollection('projects/servir-mekong/yearly_primitives_smoothed/tree_height')
TREE_CANOPY = ee.ImageCollection('projects/servir-mekong/UMD/tree_canopy')
TREE_HEIGHT = ee.ImageCollection('projects/servir-mekong/UMD/tree_height')
PRIMARY_FOREST = ee.ImageCollection('projects/servir-mekong/yearly_primitives_smoothed/primary_forest')

# geometries
Expand Down Expand Up @@ -125,7 +125,7 @@ def _apply_tree_canopy_definition(img):

return {
'eeMapId': str(map_id['mapid']),
'eeMapToken': str(map_id['token'])
'eeMapURL': str(map_id['tile_fetcher'].url_format)
}

# -------------------------------------------------------------------------
Expand All @@ -134,7 +134,7 @@ def tree_height(self,
get_image = False,
for_download = False,
year = None,
tree_height_definition = 5,
tree_height_definition = 5,
):

if not year:
Expand Down Expand Up @@ -170,7 +170,7 @@ def _apply_tree_height_definition(img):

return {
'eeMapId': str(map_id['mapid']),
'eeMapToken': str(map_id['token'])
'eeMapURL': str(map_id['tile_fetcher'].url_format)
}

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -201,14 +201,14 @@ def primary_forest(self, get_image=False, year=None):

return {
'eeMapId': str(map_id['mapid']),
'eeMapToken': str(map_id['token'])
'eeMapURL': str(map_id['tile_fetcher'].url_format)
}

# -------------------------------------------------------------------------
@staticmethod
def _get_combined_img_coll():

years = ee.List.sequence(2000, 2018)
years = ee.List.sequence(2000, 2019)
date_ymd = ee.Date.fromYMD

def addBands(year):
Expand Down Expand Up @@ -280,7 +280,7 @@ def forest_gain(self,

return {
'eeMapId': str(map_id['mapid']),
'eeMapToken': str(map_id['token'])
'eeMapURL': str(map_id['tile_fetcher'].url_format)
}

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -328,7 +328,7 @@ def forest_loss(self,

return {
'eeMapId': str(map_id['mapid']),
'eeMapToken': str(map_id['token'])
'eeMapURL': str(map_id['tile_fetcher'].url_format)
}

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -390,7 +390,7 @@ def forest_change(self,

return {
'eeMapId': str(map_id['mapid']),
'eeMapToken': str(map_id['token'])
'eeMapURL': str(map_id['tile_fetcher'].url_format)
}

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -431,7 +431,7 @@ def forest_extend(self,

return {
'eeMapId': str(map_id['mapid']),
'eeMapToken': str(map_id['token'])
'eeMapURL': str(map_id['tile_fetcher'].url_format)
}

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -587,7 +587,7 @@ def download_to_drive(self,
print ('past %d seconds' % (i * settings.EE_TASK_POLL_FREQUENCY))
i += 1
time.sleep(settings.EE_TASK_POLL_FREQUENCY)

# Make a copy (or copies) in the user's Drive if the task succeeded
state = task.status()['state']
if state == ee.batch.Task.State.COMPLETED:
Expand Down
8 changes: 4 additions & 4 deletions landcover_viewer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def get_landcover(self, classes=range(0, 21), year=2016, download=False):

return {
'eeMapId': str(map_id['mapid']),
'eeMapToken': str(map_id['token'])
'eeMapURL': str(map_id['tile_fetcher'].url_format)
}

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -558,7 +558,7 @@ def get_primitive(self, index=0, year=2016, download=False):

return {
'eeMapId': str(map_id['mapid']),
'eeMapToken': str(map_id['token'])
'eeMapURL': str(map_id['tile_fetcher'].url_format)
}

# -------------------------------------------------------------------------
Expand All @@ -579,7 +579,7 @@ def get_probability(self, year=2017, download=False):
})
return {
'eeMapId': str(map_id['mapid']),
'eeMapToken': str(map_id['token'])
'eeMapURL': str(map_id['tile_fetcher'].url_format)
}

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -738,5 +738,5 @@ def get_composite(self, year=2017):

return {
'eeMapId': str(map_id['mapid']),
'eeMapToken': str(map_id['token'])
'eeMapURL': str(map_id['tile_fetcher'].url_format)
}
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@
// Callbacks for Parameters (forest canopy, change, loss etc)
var parameterChangeSuccessCallback = function (name, data, slider, message) {
MapService.removeGeoJson(map);
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, name);
var mapType = MapService.getMapType(name, data.eeMapURL);
loadMap(name, mapType);
slider.slider('setValue', 1);
showSuccessAlert(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
$scope.showLoader = false;
};


/**
* Starts the Google Earth Engine application. The main entry point.
*/
Expand Down Expand Up @@ -315,7 +316,7 @@
};
LandCoverService.getLandCoverMap(parameters)
.then(function (data) {
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type);
var mapType = MapService.getMapType(type, data.eeMapURL);
loadMap(type, mapType);
$timeout(function () {
showInfoAlert('The map data shows the landcover data for ' + $scope.sliderYear);
Expand Down Expand Up @@ -799,7 +800,7 @@
var type = 'primitivemap';
MapService.removeGeoJson(map);
MapService.clearLayer(map, type);
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type);
var mapType = MapService.getMapType(type, data.eeMapURL);
loadMap(type, mapType);
$timeout(function () {
showInfoAlert('Showing ' + getPrimitiveLabel(index) + ' primitive layer for ' + $scope.sliderYear);
Expand Down Expand Up @@ -831,7 +832,7 @@
var type = 'probabilitymap';
MapService.removeGeoJson(map);
MapService.clearLayer(map, type);
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type);
var mapType = MapService.getMapType(type, data.eeMapURL);
var checked = $('#probability-map-checkbox').prop('checked');
loadMap(type, mapType);
if (checked) {
Expand Down Expand Up @@ -866,7 +867,7 @@
var type = 'compositemap';
MapService.removeGeoJson(map);
MapService.clearLayer(map, type);
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type);
var mapType = MapService.getMapType(type, data.eeMapURL);
var checked = $('#composite-map-checkbox').prop('checked');
loadMap(type, mapType);
if (checked) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@

LandCoverService.getLandCoverMap(parameters)
.then(function (data) {
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type);
var mapType = MapService.getMapType(type, data.eeMapURL);
loadMap(type, mapType);
$timeout(function () {
showInfoAlert('The map data shows the landcover data for ' + $scope.sliderYear);
Expand Down Expand Up @@ -710,7 +710,7 @@
.then(function (data) {
MapService.removeGeoJson(map);
MapService.clearLayer(map, 'primitivemap');
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, 'primitivemap');
var mapType = MapService.getMapType('primitivemap', data.eeMapURL);
loadMap('primitivemap', mapType);
$timeout(function () {
showInfoAlert('Showing ' + getPrimitiveLabel(index) + ' primitive layer for ' + $scope.sliderYear);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@

LandCoverService.getLandCoverMap(parameters)
.then(function (data) {
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type);
var mapType = MapService.getMapType(type, data.eeMapURL);
loadMap(type, mapType);
$timeout(function () {
showInfoAlert('The map data shows the landcover data for ' + $scope.sliderYear);
Expand Down Expand Up @@ -712,7 +712,7 @@
.then(function (data) {
MapService.removeGeoJson(map);
MapService.clearLayer(map, 'primitivemap');
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, 'primitivemap');
var mapType = MapService.getMapType('primitivemap', data.eeMapURL);
loadMap('primitivemap', mapType);
$timeout(function () {
showInfoAlert('Showing ' + getPrimitiveLabel(index) + ' primitive layer for ' + $scope.sliderYear);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@

LandCoverService.getLandCoverMap(parameters)
.then(function (data) {
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type);
var mapType = MapService.getMapType(type, data.eeMapURL);
loadMap(type, mapType);
$timeout(function () {
showInfoAlert('The map data shows the landcover data for ' + $scope.sliderYear);
Expand Down Expand Up @@ -694,7 +694,7 @@
.then(function (data) {
MapService.removeGeoJson(map);
MapService.clearLayer(map, 'primitivemap');
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, 'primitivemap');
var mapType = MapService.getMapType('primitivemap', data.eeMapURL);
loadMap('primitivemap', mapType);
$timeout(function () {
showInfoAlert('Showing ' + getPrimitiveLabel(index) + ' primitive layer for ' + $scope.sliderYear);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@

LandCoverService.getLandCoverMap(parameters)
.then(function (data) {
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type);
var mapType = MapService.getMapType(type, data.eeMapURL);
loadMap(type, mapType);
$timeout(function () {
showInfoAlert('The map data shows the landcover data for ' + $scope.sliderYear);
Expand Down Expand Up @@ -729,7 +729,7 @@
.then(function (data) {
MapService.removeGeoJson(map);
MapService.clearLayer(map, 'primitivemap');
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, 'primitivemap');
var mapType = MapService.getMapType('primitivemap', data.eeMapURL);
loadMap('primitivemap', mapType);
$timeout(function () {
showInfoAlert('Showing ' + getPrimitiveLabel(index) + ' primitive layer for ' + $scope.sliderYear);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@

LandCoverService.getLandCoverMap(parameters)
.then(function (data) {
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type);
var mapType = MapService.getMapType(type, data.eeMapURL);
loadMap(type, mapType);
$timeout(function () {
showInfoAlert('The map data shows the landcover data for ' + $scope.sliderYear);
Expand Down Expand Up @@ -676,7 +676,7 @@
.then(function (data) {
MapService.removeGeoJson(map);
MapService.clearLayer(map, 'primitivemap');
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, 'primitivemap');
var mapType = MapService.getMapType('primitivemap', data.eeMapURL);
loadMap('primitivemap', mapType);
$timeout(function () {
showInfoAlert('Showing ' + getPrimitiveLabel(index) + ' primitive layer for ' + $scope.sliderYear);
Expand Down Expand Up @@ -780,7 +780,7 @@
.then(function (data) {
MapService.removeGeoJson(map);
MapService.clearLayer(map, 'probabilitymap');
var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, 'probabilitymap');
var mapType = MapService.getMapType('probabilitymap', data.eeMapURL);
var checked = $('#probability-map-checkbox').prop('checked');
loadMap('probabilitymap', mapType);
if (checked) {
Expand Down
19 changes: 10 additions & 9 deletions landcoverportal/static/app/services/map-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,20 @@
}
};

service.getMapType = function (mapId, mapToken, type) {
service.getMapType = function (type, eeMapURL) {
var eeMapOptions = {
getTileUrl: function (tile, zoom) {
var url = 'https://earthengine.googleapis.com/map/';
url += [mapId, zoom, tile.x, tile.y].join('/');
url += '?token=' + mapToken;
getTileUrl: function (tile, zoom) {
var url = eeMapURL.replace('{x}', tile.x)
.replace('{y}', tile.y)
.replace('{z}', zoom);
return url;
},
tileSize: new google.maps.Size(256, 256),
opacity: 1.0,
name: type
tileSize: new google.maps.Size(256, 256),
name: type,
opacity: 1.0
};
return new google.maps.ImageMapType(eeMapOptions);
var mapType = new google.maps.ImageMapType(eeMapOptions);
return mapType
};

service.getPolygonBoundArray = function (array) {
Expand Down
6 changes: 1 addition & 5 deletions landcoverportal/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@
{% cms_toolbar %}

<!-- CMS Menu -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
{% show_menu 0 100 100 100 %}
</ul>
</div>


{% block navigation_container %} {% endblock navigation_container %}

Expand Down
Loading

0 comments on commit 9d63cdd

Please sign in to comment.