Skip to content

Commit

Permalink
export admin level2
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau committed Dec 9, 2021
1 parent 7639687 commit 165476b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
1 change: 1 addition & 0 deletions component/tile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .download_tile import *
from .tile_tile import *
from .export_tile import *
41 changes: 41 additions & 0 deletions component/tile/export_tile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import ipyvuetify as v
from traitlets import Int
from sepal_ui import aoi
from sepal_ui import mapping as sm

from component.message import cm


class ExportTile(aoi.AoiTile):
"""adapt the AoiTile object for this specifi usage"""

ready = Int(0).tag(sync=True)

def __init__(self, **kwargs):
"""add a download behaviour for admin areas"""

# set the accepted methods
kwargs["methods"] = ["ADMIN2", "DRAW", "SHAPE", "POINTS"]

# call the constructor
super().__init__(**kwargs)

# set the title
self.set_title(cm.to_gee.title)

# add js behaviour
self.view.observe(self.export_data, "updated")

def export_data(self, *args):
"""trigger the exportation to Earth Engine"""

if self.view.model.method == "ADMIN2":

self.view.model.export_to_asset()

# update the message
self.view.alert.add_msg("The AOI have been exported to GEE.", "success")

self.ready += 1

return
6 changes: 3 additions & 3 deletions component/widget/link_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def __init__(self, tile):

super().__init__(value=False, max_width="600px", children=[self.card])

self.tile.observe(self.fire_dialog, "updated")
self.tile.observe(self.fire_dialog, "ready")

def fire_dialog(self, link):

# the toggle btn has changed let's see if it's for a good reason
if self.tile.alert.type == "success":
if self.tile.view.alert.type == "success":

self.value = True
self.link.v_model = self.tile.model.asset_name.replace(
self.link.v_model = self.tile.view.model.dst_asset_id.replace(
"projects/earthengine-legacy/assets/", ""
)

Expand Down
12 changes: 4 additions & 8 deletions download_ui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
"metadata": {},
"outputs": [],
"source": [
"from sepal_ui import aoi\n",
"from component import tile\n",
"from component import widget\n",
"\n",
"from component.message import cm"
"from component import widget"
]
},
{
Expand All @@ -30,8 +27,7 @@
"outputs": [],
"source": [
"# create the tile\n",
"ig_export = aoi.AoiTile(methods=[\"DRAW\", \"SHAPE\", \"POINTS\"])\n",
"ig_export.set_title(cm.to_gee.title)\n",
"ig_export = tile.ExportTile()\n",
"\n",
"# this tile will only be displayed if voila is launch from this notebook\n",
"ig_export"
Expand All @@ -43,7 +39,7 @@
"metadata": {},
"outputs": [],
"source": [
"ig_dialog = widget.LinkDialog(ig_export.view)\n",
"ig_dialog = widget.LinkDialog(ig_export)\n",
"ig_dialog"
]
}
Expand All @@ -64,7 +60,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down

1 comment on commit 165476b

@12rambau
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix #26

Please sign in to comment.