From 5f1b179c7d115069a94ced908c6c3fde90806eed Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Sun, 10 Sep 2023 18:35:30 -0400 Subject: [PATCH] Add GitHub Actions for checking PR file size --- .github/workflows/check_file_size.yml | 38 +++++ docs/notebooks/74_map_tiles_to_geotiff.ipynb | 151 ++---------------- .../notebooks/74_map_tiles_to_geotiff.ipynb | 151 ++---------------- leafmap/common.py | 25 +-- setup.py | 7 + 5 files changed, 87 insertions(+), 285 deletions(-) create mode 100644 .github/workflows/check_file_size.yml diff --git a/.github/workflows/check_file_size.yml b/.github/workflows/check_file_size.yml new file mode 100644 index 0000000000..fef0bb3494 --- /dev/null +++ b/.github/workflows/check_file_size.yml @@ -0,0 +1,38 @@ +name: Check Pull Request File Size + +on: + pull_request: + paths: + - "**" + +jobs: + check_file_size: + runs-on: ubuntu-latest + + steps: + - name: Check File Size + id: check_file_size + uses: actions/checkout@v3 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: "18" + + - name: Get Changed Files + id: get_changed_files + run: | + echo "::set-output name=changed_files::$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})" + shell: bash + + - name: Check File Size + id: check_size + run: | + for file in ${{ steps.get_changed_files.outputs.changed_files }}; do + file_size=$(stat -c %s "$file") + if [ $file_size -gt 2000000 ]; then + echo "File $file exceeds the 2MB limit with a size of $(($file_size / 1000000)) MB" + exit 1 + fi + done + shell: bash diff --git a/docs/notebooks/74_map_tiles_to_geotiff.ipynb b/docs/notebooks/74_map_tiles_to_geotiff.ipynb index 4eaa7eb9d0..eb0ec6a650 100644 --- a/docs/notebooks/74_map_tiles_to_geotiff.ipynb +++ b/docs/notebooks/74_map_tiles_to_geotiff.ipynb @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -28,7 +28,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -44,24 +44,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "64179897fd044c98a924b5fc03c04dc7", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Map(center=[20, 0], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_text…" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "m = leafmap.Map()\n", "m" @@ -76,7 +61,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -90,87 +75,17 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Download TMS tiles and create a GeoTIFF file. First, let's try OpenStreetMap." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Downloaded image 1/15\n", - "Downloaded image 2/15\n", - "Downloaded image 3/15\n", - "Downloaded image 4/15\n", - "Downloaded image 5/15\n", - "Downloaded image 6/15\n", - "Downloaded image 7/15\n", - "Downloaded image 8/15\n", - "Downloaded image 9/15\n", - "Downloaded image 10/15\n", - "Downloaded image 11/15\n", - "Downloaded image 12/15\n", - "Downloaded image 13/15\n", - "Downloaded image 14/15\n", - "Downloaded image 15/15\n", - "Saving GeoTIFF. Please wait...\n", - "Image saved to osm.tif\n" - ] - } - ], - "source": [ - "leafmap.map_tiles_to_geotiff('osm.tif', bbox, zoom=13, source='OpenStreetMap', quiet=False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![](https://i.imgur.com/ft597DD.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Try Google Satellite." + "Download map tiles and create a GeoTIFF file. First, let's try Esri world imagery basemap." ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, + "id": "fd118011", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Downloaded image 1/15\n", - "Downloaded image 2/15\n", - "Downloaded image 3/15\n", - "Downloaded image 4/15\n", - "Downloaded image 5/15\n", - "Downloaded image 6/15\n", - "Downloaded image 7/15\n", - "Downloaded image 8/15\n", - "Downloaded image 9/15\n", - "Downloaded image 10/15\n", - "Downloaded image 11/15\n", - "Downloaded image 12/15\n", - "Downloaded image 13/15\n", - "Downloaded image 14/15\n", - "Downloaded image 15/15\n", - "Saving GeoTIFF. Please wait...\n", - "Image saved to satellite.tif\n" - ] - } - ], + "outputs": [], "source": [ - "leafmap.map_tiles_to_geotiff('satellite.tif', bbox, zoom=13, source='Satellite')" + "leafmap.map_tiles_to_geotiff('satellite.tif', bbox, zoom=13, source='Esri.WorldImagery')" ] }, { @@ -180,53 +95,13 @@ "![](https://i.imgur.com/ILYunA9.png)" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Try OpenTopoMap." - ] - }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "source = 'https://a.tile.opentopomap.org/{z}/{x}/{y}.png'" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Downloaded image 1/15\n", - "Downloaded image 2/15\n", - "Downloaded image 3/15\n", - "Downloaded image 4/15\n", - "Downloaded image 5/15\n", - "Downloaded image 6/15\n", - "Downloaded image 7/15\n", - "Downloaded image 8/15\n", - "Downloaded image 9/15\n", - "Downloaded image 10/15\n", - "Downloaded image 11/15\n", - "Downloaded image 12/15\n", - "Downloaded image 13/15\n", - "Downloaded image 14/15\n", - "Downloaded image 15/15\n", - "Saving GeoTIFF. Please wait...\n", - "Image saved to topo.tif\n" - ] - } - ], - "source": [ - "leafmap.map_tiles_to_geotiff('topo.tif', bbox, zoom=13, source=source)" + "leafmap.map_tiles_to_geotiff('topo.tif', bbox, zoom=13, source='OpenTopoMap')" ] }, { @@ -253,7 +128,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.11.5" } }, "nbformat": 4, diff --git a/examples/notebooks/74_map_tiles_to_geotiff.ipynb b/examples/notebooks/74_map_tiles_to_geotiff.ipynb index 4eaa7eb9d0..eb0ec6a650 100644 --- a/examples/notebooks/74_map_tiles_to_geotiff.ipynb +++ b/examples/notebooks/74_map_tiles_to_geotiff.ipynb @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -28,7 +28,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -44,24 +44,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "64179897fd044c98a924b5fc03c04dc7", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Map(center=[20, 0], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_text…" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "m = leafmap.Map()\n", "m" @@ -76,7 +61,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -90,87 +75,17 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Download TMS tiles and create a GeoTIFF file. First, let's try OpenStreetMap." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Downloaded image 1/15\n", - "Downloaded image 2/15\n", - "Downloaded image 3/15\n", - "Downloaded image 4/15\n", - "Downloaded image 5/15\n", - "Downloaded image 6/15\n", - "Downloaded image 7/15\n", - "Downloaded image 8/15\n", - "Downloaded image 9/15\n", - "Downloaded image 10/15\n", - "Downloaded image 11/15\n", - "Downloaded image 12/15\n", - "Downloaded image 13/15\n", - "Downloaded image 14/15\n", - "Downloaded image 15/15\n", - "Saving GeoTIFF. Please wait...\n", - "Image saved to osm.tif\n" - ] - } - ], - "source": [ - "leafmap.map_tiles_to_geotiff('osm.tif', bbox, zoom=13, source='OpenStreetMap', quiet=False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![](https://i.imgur.com/ft597DD.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Try Google Satellite." + "Download map tiles and create a GeoTIFF file. First, let's try Esri world imagery basemap." ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, + "id": "fd118011", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Downloaded image 1/15\n", - "Downloaded image 2/15\n", - "Downloaded image 3/15\n", - "Downloaded image 4/15\n", - "Downloaded image 5/15\n", - "Downloaded image 6/15\n", - "Downloaded image 7/15\n", - "Downloaded image 8/15\n", - "Downloaded image 9/15\n", - "Downloaded image 10/15\n", - "Downloaded image 11/15\n", - "Downloaded image 12/15\n", - "Downloaded image 13/15\n", - "Downloaded image 14/15\n", - "Downloaded image 15/15\n", - "Saving GeoTIFF. Please wait...\n", - "Image saved to satellite.tif\n" - ] - } - ], + "outputs": [], "source": [ - "leafmap.map_tiles_to_geotiff('satellite.tif', bbox, zoom=13, source='Satellite')" + "leafmap.map_tiles_to_geotiff('satellite.tif', bbox, zoom=13, source='Esri.WorldImagery')" ] }, { @@ -180,53 +95,13 @@ "![](https://i.imgur.com/ILYunA9.png)" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Try OpenTopoMap." - ] - }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "source = 'https://a.tile.opentopomap.org/{z}/{x}/{y}.png'" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Downloaded image 1/15\n", - "Downloaded image 2/15\n", - "Downloaded image 3/15\n", - "Downloaded image 4/15\n", - "Downloaded image 5/15\n", - "Downloaded image 6/15\n", - "Downloaded image 7/15\n", - "Downloaded image 8/15\n", - "Downloaded image 9/15\n", - "Downloaded image 10/15\n", - "Downloaded image 11/15\n", - "Downloaded image 12/15\n", - "Downloaded image 13/15\n", - "Downloaded image 14/15\n", - "Downloaded image 15/15\n", - "Saving GeoTIFF. Please wait...\n", - "Image saved to topo.tif\n" - ] - } - ], - "source": [ - "leafmap.map_tiles_to_geotiff('topo.tif', bbox, zoom=13, source=source)" + "leafmap.map_tiles_to_geotiff('topo.tif', bbox, zoom=13, source='OpenTopoMap')" ] }, { @@ -253,7 +128,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.11.5" } }, "nbformat": 4, diff --git a/leafmap/common.py b/leafmap/common.py index 250b6f4e6d..f9d99b111b 100644 --- a/leafmap/common.py +++ b/leafmap/common.py @@ -9117,6 +9117,10 @@ def map_tiles_to_geotiff( source = xyz_tiles[source.upper()]["url"] elif isinstance(source, str) and source.startswith("http"): pass + elif isinstance(source, str): + tiles = basemap_xyz_tiles() + if source in tiles: + source = tiles[source].url else: raise ValueError( 'source must be one of "OpenStreetMap", "ROADMAP", "SATELLITE", "TERRAIN", "HYBRID", or a URL' @@ -10351,15 +10355,18 @@ def images_to_tiles( for index, image in enumerate(images): name = names[index] - if image.startswith("http") and image.endswith(".tif"): - url = cog_tile(image, **kwargs) - tile = ipyleaflet.TileLayer(url=url, name=name, **kwargs) - elif image.startswith("http"): - url = stac_tile(image, **kwargs) - tile = ipyleaflet.TileLayer(url=url, name=name, **kwargs) - else: - tile = get_local_tile_layer(image, layer_name=name, **kwargs) - tiles[name] = tile + try: + if image.startswith("http") and image.endswith(".tif"): + url = cog_tile(image, **kwargs) + tile = ipyleaflet.TileLayer(url=url, name=name, **kwargs) + elif image.startswith("http"): + url = stac_tile(image, **kwargs) + tile = ipyleaflet.TileLayer(url=url, name=name, **kwargs) + else: + tile = get_local_tile_layer(image, layer_name=name, **kwargs) + tiles[name] = tile + except Exception as e: + print(image, e) return tiles diff --git a/setup.py b/setup.py index 3fa26ea1a3..cfcb73b05f 100644 --- a/setup.py +++ b/setup.py @@ -44,6 +44,13 @@ "sql": ["psycopg2", "sqlalchemy"], "apps": ["streamlit-folium", "voila", "solara"], "vector": ["geopandas", "osmnx"], + "ai": [ + "geopandas", + "osmnx", + "localtileserver", + "rastervision", + "pytorch-lightning", + ], } requirements = []