Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/ImazonSadGoogle/Deforestati…
Browse files Browse the repository at this point in the history
…onAnalysisTool
  • Loading branch information
Dave Thau committed Mar 13, 2012
2 parents efa77f6 + fc9bb0c commit 9ae211d
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 11 deletions.
13 changes: 12 additions & 1 deletion src/application/models.py
Expand Up @@ -173,7 +173,13 @@ class Cell(db.Model):
done = db.BooleanProperty(default=False);
last_change_by = db.UserProperty()
last_change_on = db.DateTimeProperty(auto_now=True)

compare_view = db.StringProperty(default='four')
map_one_layer_status = db.StringProperty(default='"Brazil Legal Amazon","false","Brazil Municipalities Public","false","Brazil States Public","false","Brazil Federal Conservation Unit Public","false","Brazil State Conservation Unit Public","false","LANDSAT/L7_L1T","false","SMA","false","RGB","false","NDFI t0","false","NDFI t1","false","NDFI analysis","true","True color RGB141","false","False color RGB421","false","F color infrared RGB214","false","Validated polygons","true",*')
map_two_layer_status = db.StringProperty(default='"Brazil Legal Amazon","false","Brazil Municipalities Public","false","Brazil States Public","false","Brazil Federal Conservation Unit Public","false","Brazil State Conservation Unit Public","false","LANDSAT/L7_L1T","false","SMA","false","RGB","false","NDFI t0","true","NDFI t1","false","NDFI analysis","true","True color RGB141","false","False color RGB421","false","F color infrared RGB214","false","Validated polygons","true",*')
map_three_layer_status = db.StringProperty(default='"Brazil Legal Amazon","false","Brazil Municipalities Public","false","Brazil States Public","false","Brazil Federal Conservation Unit Public","false","Brazil State Conservation Unit Public","false","LANDSAT/L7_L1T","false","SMA","false","RGB","false","NDFI t0","false","NDFI t1","true","NDFI analysis","true","True color RGB141","false","False color RGB421","false","F color infrared RGB214","false","Validated polygons","true",*')
map_four_layer_status = db.StringProperty(default='"Brazil Legal Amazon","false","Brazil Municipalities Public","false","Brazil States Public","false","Brazil Federal Conservation Unit Public","false","Brazil State Conservation Unit Public","false","Terrain","true","Satellite","false","Hybrid","false","Roadmap","false","LANDSAT/L7_L1T","true","NDFI t0","false","True color RGB141","false","False color RGB421","false","F color infrared RGB214","false",*')


@staticmethod
def get_cell(report, x, y, z):
q = Cell.all()
Expand Down Expand Up @@ -301,6 +307,11 @@ def as_dict(self):
'ndfi_low': self.ndfi_low,
'ndfi_high': self.ndfi_high,
'ndfi_change_value': self.ndfi_change_value,
'compare_view':self.compare_view,
'map_one_layer_status': self.map_one_layer_status,
'map_two_layer_status': self.map_two_layer_status,
'map_three_layer_status': self.map_three_layer_status,
'map_four_layer_status': self.map_four_layer_status,
'done': self.done,
'latest_change': t,
'added_by': by,
Expand Down
5 changes: 5 additions & 0 deletions src/application/resources/report.py
Expand Up @@ -145,6 +145,11 @@ def update(self, report_id, id):
data = json.loads(request.data)
cell.ndfi_low = float(data['ndfi_low'])
cell.ndfi_high = float(data['ndfi_high'])
cell.compare_view = str(data['compare_view'])
cell.map_one_layer_status = str(data['map_one_layer_status'])
cell.map_two_layer_status = str(data['map_two_layer_status'])
cell.map_three_layer_status = str(data['map_three_layer_status'])
cell.map_four_layer_status = str(data['map_four_layer_status'])
cell.done = data['done']
cell.last_change_by = users.get_current_user()
cell.put()
Expand Down
5 changes: 4 additions & 1 deletion src/application/views.py
Expand Up @@ -66,6 +66,10 @@ def get_or_create_user():
u.put()
return u

@app.route('/')
def start():
return redirect('/analysis')

@app.route('/analysis')
@login_required
def home(cell_path=None):
Expand All @@ -92,7 +96,6 @@ def home(cell_path=None):



@app.route('/')
@app.route('/vis')
@login_required
def vis():
Expand Down
2 changes: 1 addition & 1 deletion src/content/templates/_header.html
Expand Up @@ -10,8 +10,8 @@
</div>

<ul id="tabs">
<li id="report"><a href="/vis">report</a></li>
<li id="analysis"><a href="/analysis">analysis</a></li>
<li id="report"><a href="/vis">report</a></li>
</ul>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/content/templates/vis/_header.html
Expand Up @@ -9,8 +9,8 @@
<div style="color: #666;font-family: arial;font-size: 11px;white-space: nowrap;">Powered By <span style="font-size: 12px;font-weight: bold;"><a href="http://google.org/earthengine" style="color:#444;text-decoration:none;"><img src="http://www.google.com/images/logos/google_logo_powered_by.png" style="border:none;vertical-align:middle;" /> Earth Engine</a></div>
</div>
<ul id="tabs">
<li id="report"><a href="/vis">report</a></li>
<li id="analysis"><a href="/analysis">analysis</a></li>
<li id="analysis"><a href="/analysis">analysis</a></li>
<li id="report"><a href="/vis">report</a></li>
</ul>
</div>
</div>
Expand Down
215 changes: 211 additions & 4 deletions src/static/js/app.js
Expand Up @@ -202,22 +202,221 @@ $(function() {
this.map.adjustSize();
this.compare_layout = this.$("#compare_layout_2").show();
this.compare_maps = [];
this.compare_maps.push(this.get_map("#map_half"));
this.compare_maps.push(this.get_map("#map_half"));
},

status_layer_map_save: function(number){
var cell = this.gridstack.current_cell;
if(number === 'one') {
cell.set({'map_one_layer_status':this.status_layer_map(this.map)});
cell.save();
}else if(number === 'two') {
cell.set({'map_one_layer_status':this.status_layer_map(this.map)});
var map2 = this.compare_maps[0];
cell.set({'map_two_layer_status':this.status_layer_map(map2)});
cell.save();
} else if(number === 'four'){
cell.set({'map_one_layer_status':this.status_layer_map(this.map)});
var map2 = this.compare_maps[0];
cell.set({'map_two_layer_status':this.status_layer_map(map2)});
map2 = this.compare_maps[1];
cell.set({'map_three_layer_status':this.status_layer_map(map2)});
map2 = this.compare_maps[2];
cell.set({'map_four_layer_status':this.status_layer_map(map2)});
cell.save();
}
},

get_status_layer_map: function(number){
if(number === 'one') {
var cell = this.gridstack.current_cell;
var layers = cell.get('map_one_layer_status');
while(layers!='*'){
var layer = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var flag = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var lay = this.map.layers.get_by_name(layer);
if(lay) {
if(flag==='true'){
lay.set_enabled(true);
}else{
lay.set_enabled(false);
}
}
}
}else if(number === 'two') {
var cell = this.gridstack.current_cell;
var layers = cell.get('map_one_layer_status');
while(layers!='*'){
var layer = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var flag = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var lay = this.map.layers.get_by_name(layer);
if(lay) {
if(flag==='true'){
lay.set_enabled(true);
}else{
lay.set_enabled(false);
}
}
}
layers = "";
layers = cell.get('map_two_layer_status');
var map2 = this.compare_maps[0];
while(layers!='*'){
var layer = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var flag = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var lay = map2.layers.get_by_name(layer);
if(lay) {
if(flag==='true'){
lay.set_enabled(true);
}else{
lay.set_enabled(false);
}
}
}
} else if(number === 'four'){
var cell = this.gridstack.current_cell;
var layers = cell.get('map_one_layer_status');
while(layers!='*'){
var layer = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var flag = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var lay = this.map.layers.get_by_name(layer);
if(lay) {
if(flag==='true'){
lay.set_enabled(true);
}else{
lay.set_enabled(false);
}
}
}
layers = "";
layers = cell.get('map_two_layer_status');
var map2 = this.compare_maps[0];
while(layers!='*'){
var layer = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var flag = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var lay = map2.layers.get_by_name(layer);
if(lay) {
if(flag==='true'){
lay.set_enabled(true);
}else{
lay.set_enabled(false);
}
}
}
layers = "";
layers = cell.get('map_three_layer_status');
var map2 = this.compare_maps[1];
while(layers!='*'){
var layer = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var flag = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var lay = map2.layers.get_by_name(layer);
if(lay) {
if(flag==='true'){
lay.set_enabled(true);
}else{
lay.set_enabled(false);
}
}
}
layers = "";
layers = cell.get('map_four_layer_status');
var map2 = this.compare_maps[2];
while(layers!='*'){
var layer = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var flag = layers.slice(layers.indexOf("\"")+1,layers.indexOf("\","));
layers = layers.slice(layers.indexOf(",")+1);
var lay = map2.layers.get_by_name(layer);
if(lay) {
if(flag==='true'){
lay.set_enabled(true);
}else{
lay.set_enabled(false);
}
}
}
}
},

status_layer_map: function(map_name){
// enable layer, amazonas bounds
/*
* id{1} name{Brazil Legal Amazon}
* id{2} name{Brazil Municipalities Public}
* id{3} name{Brazil States Public}
* id{4} name{Brazil Federal Conservation Unit Public}
* id{5} name{Brazil State Conservation Unit Public}
* id{6} name{Terrain} this's not saving
* id{7} name{Satellite} this's not saving
* id{8} name{Hybrid} this's not saving
* id{9} name{Roadmap} this's not saving
* id{9affcec73a8b645dc4974ff4da8830f0} name{LANDSAT/L7_L1T}
* id{f69b3bb6add9276eef4d0ab158de74e8} name{NDFI t0}
* id{?} name{True color RGB141}
* id{?} name{False color RGB421}
* id{?} name{F color infrared RGB214}
*
*/
var arraylayer = new Array("Brazil Legal Amazon","Brazil Municipalities Public","Brazil States Public","Brazil Federal Conservation Unit Public",
"Brazil State Conservation Unit Public","LANDSAT/L7_L1T","SMA","RGB","NDFI t0","NDFI t1","NDFI analysis","True color RGB141","False color RGB421",
"F color infrared RGB214","Validated polygons");
var save_status_layer="";
for(var num=0; num<arraylayer.length;num++){
var lay = map_name.layers.get_by_name(arraylayer[num]);
if(lay) {
if(lay.get_enabled()){
if(num==(arraylayer.length-1)){
save_status_layer += "\""+arraylayer[num]+"\",\""+lay.get_enabled()+"\",*";
}else{
save_status_layer += "\""+arraylayer[num]+"\",\""+lay.get_enabled()+"\",";
}
}else{
if(num==(arraylayer.length-1)){
save_status_layer += "\""+arraylayer[num]+"\",\""+lay.get_enabled()+"\",*";
}else{
save_status_layer += "\""+arraylayer[num]+"\",\""+lay.get_enabled()+"\",";
}
}
}
}
return save_status_layer;
},


compare_view_save: function(num) {
var cell = this.gridstack.current_cell;
cell.set({'compare_view':num});
cell.save();
},

compare_view: function(compare_type) {
var self = this;
var compare_type_view = compare_type;
this.map.close_layer_editor();
if(compare_type !== 'one') {

if(this.compare_layout !== null) {
this.compare_view('one');
this.compare_view_save('one');
}
// el gran putiferio
if(compare_type === 'two') {
this.compare_two();
this.compare_two();
this.compare_view_save('two');
} else {
this.compare_four();
this.compare_view_save('four');
}
this.map.crosshair(true);
_.each(this.compare_maps, function(m) {
Expand All @@ -243,6 +442,7 @@ $(function() {
});
});
} else {
this.compare_view_save('one');
//restore
this.map.el.css({width: '100%'});
this.map.adjustSize();
Expand Down Expand Up @@ -290,6 +490,7 @@ $(function() {
//update slider with current cell values
var cell = this.gridstack.current_cell;
this.polygon_tools.ndfi_range.set_values(cell.get('ndfi_low'), cell.get('ndfi_high'));
this.compare_view(cell.get('compare_view'));
//cell done!
this.overview.set_note_count(this.gridstack.current_cell.get('note_count'));
this.overview.set_ndfi(this.gridstack.current_cell.get('ndfi_change_value'));
Expand All @@ -301,6 +502,7 @@ $(function() {
this.editing_router = new EditingToolsRuoter({
app: this
});
this.get_status_layer_map(cell.get('compare_view'));
},

cell_done: function() {
Expand All @@ -316,7 +518,12 @@ $(function() {
this.active_report.fetch();
},

go_back: function() {
go_back: function() {
//alert(this.status_layer_map(this.map));
console.log(this.compare_type_view);
this.status_layer_map_save(this.compare_type_view);
//this.status_layer_map_save('two');
//this.get_status_layer_map('one');
var p = this.gridstack.current_cell.parent_cell();
this.to_cell(p.get('z'), p.get('x'), p.get('y'));
router.navigate('cell/' + p.get('z') + "/" + p.get('x') + "/" + p.get('y'));
Expand Down
11 changes: 9 additions & 2 deletions src/static/js/models/layers.js
Expand Up @@ -14,7 +14,7 @@ var LayerModel = Backbone.Model.extend({
}
if(this.get('enabled') === true) {
this.set_enabled(true);
}
}
},

set_enabled: function(b) {
Expand All @@ -23,8 +23,15 @@ var LayerModel = Backbone.Model.extend({
this.set({'enabled': this.enabled});
this.trigger('change', this);
}
}
},

get_enabled: function() {
if(this.get('enabled') === true) {
return true;
}else{
return false;
}
}
});

// this layer needs to update the tile url when
Expand Down

0 comments on commit 9ae211d

Please sign in to comment.