Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
args: ["--maxkb=500"]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.12.0
rev: 26.1.0
hooks:
- id: black-jupyter

Expand All @@ -27,6 +27,6 @@ repos:
]

- repo: https://github.com/kynan/nbstripout
rev: 0.8.2
rev: 0.9.0
hooks:
- id: nbstripout
20 changes: 6 additions & 14 deletions docs/maplibre/dashboard.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,30 @@
"\n",
"# Customize dialog\n",
"tw.set_help_title(\"About this dashboard\")\n",
"tw.set_help_content(\n",
" widgets.HTML(\n",
" \"\"\"\n",
"tw.set_help_content(widgets.HTML(\"\"\"\n",
" <p><b>Shortcuts</b></p>\n",
" <ul>\n",
" <li>1 / 2 / 3 — switch tabs</li>\n",
" <li>R — refresh</li>\n",
" <li>? — help</li>\n",
" </ul>\n",
" \"\"\"\n",
" )\n",
")\n",
" \"\"\"))\n",
"\n",
"m = leafmap.Map(\n",
" projection=\"globe\", style=\"liberty\", sidebar_visible=True, height=\"800px\"\n",
")\n",
"m.create_container()\n",
"\n",
"home_tab = widgets.HTML(\n",
" \"\"\"\n",
"home_tab = widgets.HTML(\"\"\"\n",
" <h1>Welcome to the Leafmap Visualization Dashboard</h1>\n",
" <p>This is the home tab.</p>\n",
" <img src=\"https://assets.gishub.org/images/geog-312.png\" width=\"100%\">\n",
" \"\"\"\n",
")\n",
" \"\"\")\n",
"\n",
"settings_tab = widgets.HTML(\n",
" \"\"\"\n",
"settings_tab = widgets.HTML(\"\"\"\n",
" <h1>Settings</h1>\n",
" <p>This is the settings tab.</p>\n",
" \"\"\"\n",
")\n",
" \"\"\")\n",
"\n",
"tw.set_tab_content(0, home_tab)\n",
"tw.set_tab_content(1, m.container)\n",
Expand Down
1 change: 0 additions & 1 deletion docs/notebooks/92_maplibre.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,6 @@
"from maplibre import Layer, LayerType, Map, MapOptions\n",
"from maplibre.sources import GeoJSONSource\n",
"\n",
"\n",
"bg_layer = Layer(\n",
" type=LayerType.BACKGROUND,\n",
" id=\"background\",\n",
Expand Down
1 change: 0 additions & 1 deletion docs/workshops/HGAC_2024.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2814,7 +2814,6 @@
"source": [
"import numpy as np\n",
"\n",
"\n",
"# Generate the icon data\n",
"width = 64 # The image will be 64 pixels square\n",
"height = 64\n",
Expand Down
74 changes: 23 additions & 51 deletions leafmap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,16 +1115,10 @@ def create_code_cell(code: str = "", where: str = "below") -> None:
# pass

encoded_code = (base64.b64encode(str.encode(code))).decode()
display(
Javascript(
"""
display(Javascript("""
var code = IPython.notebook.insert_cell_{0}('code');
code.set_text(atob("{1}"));
""".format(
where, encoded_code
)
)
)
""".format(where, encoded_code)))


def local_tile_pixel_value(
Expand Down Expand Up @@ -12915,13 +12909,11 @@ def init_duckdb_tiles(
# Data is already in Web Mercator, don't transform
# Use VIEW for Parquet files only if user requested it
table_or_view = "VIEW" if (is_parquet and use_view) else "TABLE"
con.execute(
f"""
con.execute(f"""
CREATE {table_or_view} IF NOT EXISTS {table_name} AS
SELECT {select_clause}{geom_col_source} as {geom_column}
FROM {source_table};
"""
)
""")
if not quiet:
view_note = " (using view)" if (is_parquet and use_view) else ""
print(
Expand All @@ -12931,15 +12923,13 @@ def init_duckdb_tiles(
# Data needs transformation to Web Mercator
# Use VIEW for Parquet files only if user requested it
table_or_view = "VIEW" if (is_parquet and use_view) else "TABLE"
con.execute(
f"""
con.execute(f"""
CREATE {table_or_view} IF NOT EXISTS {table_name} AS
SELECT
{select_clause}
ST_Transform(ST_GeomFromWKB(ST_AsWKB({geom_col_source})), '{transform_from_crs}', 'EPSG:{srid}', true) as {geom_column}
FROM {source_table};
"""
)
""")
if not quiet:
view_note = " (using view)" if (is_parquet and use_view) else ""
print(
Expand All @@ -12955,13 +12945,11 @@ def init_duckdb_tiles(
)
# Use VIEW for Parquet files only if user requested it
table_or_view = "VIEW" if (is_parquet and use_view) else "TABLE"
con.execute(
f"""
con.execute(f"""
CREATE {table_or_view} IF NOT EXISTS {table_name} AS
SELECT {select_clause}{geom_col_source} as {geom_column}
FROM {source_table};
"""
)
""")
if not quiet:
view_note = " (using view)" if (is_parquet and use_view) else ""
print(
Expand All @@ -12985,13 +12973,11 @@ def init_duckdb_tiles(
# For Parquet, we already have the source_table and geom_col_source from above
# Use VIEW for Parquet files only if user requested it
table_or_view = "VIEW" if use_view else "TABLE"
con.execute(
f"""
con.execute(f"""
CREATE {table_or_view} IF NOT EXISTS {table_name} AS
SELECT {select_clause}{geom_col_source} as {geom_column}
FROM {source_table};
"""
)
""")
else:
# First, get column names and types to exclude geometry and complex types
temp_result = con.execute(
Expand Down Expand Up @@ -13041,13 +13027,11 @@ def init_duckdb_tiles(
else:
select_clause = ""

con.execute(
f"""
con.execute(f"""
CREATE TABLE IF NOT EXISTS {table_name} AS
SELECT {select_clause}"{geom_col_source}" as {geom_column}
FROM ST_Read('{input_path}');
"""
)
""")
con.commit()
if not quiet:
view_or_table = "view" if (is_parquet and use_view) else "table"
Expand Down Expand Up @@ -13286,17 +13270,15 @@ def get_tile(z, x, y):
if properties is None:
# Get column names and types, filtering for MVT-compatible types
# ST_AsMVT only supports: VARCHAR, FLOAT, DOUBLE, INTEGER, BIGINT, BOOLEAN
columns = con.execute(
f"""
columns = con.execute(f"""
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = '{table_name}'
AND column_name != '{geom_column}'
AND data_type IN ('VARCHAR', 'FLOAT', 'DOUBLE', 'INTEGER', 'BIGINT', 'BOOLEAN',
'SMALLINT', 'TINYINT', 'UBIGINT', 'UINTEGER', 'USMALLINT', 'UTINYINT',
'HUGEINT', 'REAL', 'TEXT')
"""
).fetchall()
""").fetchall()
prop_list = [col[0] for col in columns]
else:
prop_list = properties
Expand Down Expand Up @@ -14520,13 +14502,11 @@ def vector_to_parquet_batch(

try:
# Execute the conversion
conn.execute(
f"""
conn.execute(f"""
COPY (
SELECT * FROM ST_Read('{file}')
) TO '{parquet_file}' (FORMAT PARQUET)
"""
)
""")
except Exception as e:
print(f"Error converting {base_name}: {str(e)}")

Expand Down Expand Up @@ -14588,13 +14568,11 @@ def vector_to_gpkg_batch(

try:
# Execute the conversion
conn.execute(
f"""
conn.execute(f"""
COPY (
SELECT * FROM ST_Read('{file}')
) TO '{gpkg_file}' (FORMAT GDAL, DRIVER 'GPKG')
"""
)
""")
except Exception as e:
print(f"Error converting {base_name}: {str(e)}")

Expand Down Expand Up @@ -14654,13 +14632,11 @@ def vector_to_geojson_batch(input_dir, output_dir=None, file_ext=".shp", **kwarg

try:
# Execute the conversion
conn.execute(
f"""
conn.execute(f"""
COPY (
SELECT * FROM ST_Read('{file}')
) TO '{gpkg_file}' (FORMAT GDAL, DRIVER 'GeoJSON')
"""
)
""")
except Exception as e:
print(f"Error converting {base_name}: {str(e)}")

Expand Down Expand Up @@ -15063,11 +15039,9 @@ def split_parquet_by_geometries(
read_str = f"ST_Read('{input_vector}')"

# Get all state IDs from the parquet file
state_ids = con.execute(
f"""
state_ids = con.execute(f"""
SELECT {column} FROM {read_str}
"""
).fetchall()
""").fetchall()

state_ids.sort()

Expand Down Expand Up @@ -16697,9 +16671,7 @@ def generate_index_html(directory: str, output: str = "index.html") -> None:
<body>
<h1>Index of {directory}</h1>
<ul>
""".format(
directory=directory
)
""".format(directory=directory)

# Add each file to the HTML list
for file in files:
Expand Down
Loading