Skip to content

Commit

Permalink
Merge pull request #1 from openforis/master
Browse files Browse the repository at this point in the history
add a file downloader
  • Loading branch information
12rambau authored Dec 7, 2020
2 parents 573c349 + 88e35dd commit 7b34737
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 13 deletions.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# import_to_gee
UI to load files to earthengine

## About
This module is a 2 step wrapper to upload AOI to Google Earth Engine

![results](./doc/img/full_input.png)

## usage

### Step 1 (optional)

If your file is not yet available in your SEAPL folders, you can upload it using the first menu.

![import](./doc/img/import.png)

### step 2

Select a methode to define your AOI between :

- `draw a shape`: manually draw a shape on the map
- `Upload file` : Use a shapefile as an asset
- `Use point file` : Use a `.csv` file as an aoi asset. Point file need to have at least 3 columns (id, lattitude and longitude) but you can use any custom names.

Once you have selected your aoi, click the btn and your AOI will be updated as an asset and available for the others SEPAL modules.

> the file created in step 1 may not appear in the file selector. refresh the list by opening a folder
If the process is successful, your AOI will be displayed in green on the map.

![image](./doc/img/results.png)

## contribute
to install the project on your SEPAL account
```
$ git clone https://github.com/openforis/import_to_ee.git
```

please retreive the develop branch where all our developments live
```
$ git checkout --track origin/develop
```

please follow the contributing [guidelines](CONTRIBUTING.md).

2 changes: 1 addition & 1 deletion about_ui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"from sepal_ui import sepalwidgets as sw\n",
"\n",
"#create the Html body of your about section \n",
"ig_about = sw.TileAbout('README.md')\n",
"ig_about = sw.TileAbout('utils/about.md')\n",
"\n",
"#create a disclaimer\n",
"ig_disclaimer = sw.TileDisclaimer()"
Expand Down
Binary file added doc/img/full_input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/img/import.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/img/results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
125 changes: 125 additions & 0 deletions download_ui.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from sepal_ui import sepalwidgets as sw\n",
"from functools import partial\n",
"from ipyvuetify.extra import FileInput\n",
"import ipyvuetify as v\n",
"from pathlib import Path\n",
"import unidecode"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# output \n",
"import_output = sw.Alert().add_msg('import your file')\n",
"\n",
"# btn \n",
"import_btn = sw.Btn('import', icon = 'mdi-check', class_='mt-4')\n",
"\n",
"# create the input \n",
"input_file = FileInput(\n",
" multiple = False, \n",
" accept = \"image/png, image/jpeg, image/bmp\"\n",
")\n",
"\n",
"# create a file selector \n",
"id_ = 'aoi_widget'\n",
"title = \"Import a file\"\n",
"\n",
"ig_import = sw.Tile(\n",
" id_,\n",
" title,\n",
" btn=import_btn, \n",
" inputs=[input_file],\n",
" output=import_output\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def import_on_click(widget, data, event, output):\n",
" \n",
" # toggle the btn\n",
" widget.toggle_loading()\n",
" \n",
" output.add_msg('start the downlaod')\n",
" \n",
" # load the files\n",
" myfiles = input_file.get_files()\n",
" \n",
" # test the selection\n",
" if not len(myfiles):\n",
" output.add_msg('No file selected', 'error')\n",
" return widget.toggle_loading()\n",
" \n",
" # create the path \n",
" path = Path('~/downloads').expanduser().joinpath(unidecode.unidecode(myfiles[0]['name']))\n",
" if path.is_file():\n",
" output.add_msg('File already exists', 'error')\n",
" return widget.toggle_loading()\n",
" \n",
" src = myfiles[0]['file_obj'] \n",
" with path.open('wb') as dst:\n",
" content = bytes(src.read())\n",
" dst.write(content)\n",
" \n",
" output.add_msg(f'Download complete in {path}', 'success')\n",
" \n",
" return widget.toggle_loading()\n",
"\n",
"import_btn.on_event('click', partial(import_on_click, output = import_output))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ig_import"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
13 changes: 2 additions & 11 deletions ui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,19 @@
"ig_appBar = sw.AppBar('Import to Google Earth Engine')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#create a footer \n",
"ig_footer = sw.Footer()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#add tiles \n",
"%run 'download_ui.ipynb'\n",
"%run 'aoi_selector_ui.ipynb'\n",
"%run 'about_ui.ipynb'\n",
"\n",
"ig_content = [\n",
" ig_import,\n",
" ig_aoi,\n",
" ig_about,\n",
" ig_disclaimer\n",
Expand Down Expand Up @@ -100,7 +92,6 @@
"ig_app = sw.App(\n",
" tiles=ig_content, \n",
" appBar=ig_appBar, \n",
" footer=ig_footer, \n",
" navDrawer=ig_drawer\n",
").show_tile('aoi_widget')"
]
Expand Down
26 changes: 26 additions & 0 deletions utils/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
This module is a 2 step wrapper to upload AOI to Google Earth Engine

## usage

### Step 1 (optional)

If your file is not yet available in your SEAPL folders, you can upload it using the first menu.

![import](https://raw.githubusercontent.com/openforis/import_to_gee/master/doc/img/import.png)

### step 2

Select a methode to define your AOI between :

- `draw a shape`: manually draw a shape on the map
- `Upload file` : Use a shapefile as an asset
- `Use point file` : Use a `.csv` file as an aoi asset. Point file need to have at least 3 columns (id, lattitude and longitude) but you can use any custom names.

Once you have selected your aoi, click the btn and your AOI will be updated as an asset and available for the others SEPAL modules.

> the file created in step 1 may not appear in the file selector. refresh the list by opening a folder
If the process is successful, your AOI will be display in green on the map.

![image](https://raw.githubusercontent.com/openforis/import_to_gee/master/doc/img/results.png)

0 comments on commit 7b34737

Please sign in to comment.