Skip to content

Commit

Permalink
Support raster overviews (#140)
Browse files Browse the repository at this point in the history
Co-authored-by: Javier Goizueta <jgoizueta@gmail.com>
Co-authored-by: juanrmn <jgonzalez@cartodb.com>
  • Loading branch information
3 people committed Jun 21, 2024
1 parent 8838790 commit 035fe4f
Show file tree
Hide file tree
Showing 10 changed files with 498 additions and 39 deletions.
11 changes: 9 additions & 2 deletions raster_loader/cli/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ def upload(

# create default table name if not provided
if table is None:
table = get_default_table_name(file_path if is_local_file else urlparse(file_url).path, band)
table = get_default_table_name(
file_path if is_local_file else urlparse(file_url).path, band
)

credentials = None
if token is not None:
Expand Down Expand Up @@ -170,7 +172,12 @@ def upload(
@click.option("--dataset", help="The name of the dataset.", required=True)
@click.option("--table", help="The name of the table.", required=True)
@click.option("--limit", help="Limit number of rows returned", default=10)
@click.option("--token", help="An access token to authenticate with.", required=False, default=None)
@click.option(
"--token",
help="An access token to authenticate with.",
required=False,
default=None,
)
def describe(project, dataset, table, limit, token):
credentials = None
if token is not None:
Expand Down
42 changes: 33 additions & 9 deletions raster_loader/cli/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@ def snowflake(args=None):
@click.option("--account", help="The Swnoflake account.", required=True)
@click.option("--username", help="The username.", required=False, default=None)
@click.option("--password", help="The password.", required=False, default=None)
@click.option("--token", help="An access token to authenticate with.", required=False, default=None)
@click.option(
"--token",
help="An access token to authenticate with.",
required=False,
default=None,
)
@click.option("--role", help="The role to use for the file upload.", default=None)
@click.option("--file_path", help="The path to the raster file.", required=False, default=None)
@click.option("--file_url", help="The path to the raster file.", required=False, default=None)
@click.option(
"--file_path", help="The path to the raster file.", required=False, default=None
)
@click.option(
"--file_url", help="The path to the raster file.", required=False, default=None
)
@click.option("--database", help="The name of the database.", required=True)
@click.option("--schema", help="The name of the schema.", required=True)
@click.option("--table", help="The name of the table.", default=None)
Expand Down Expand Up @@ -102,8 +111,12 @@ def upload(
get_block_dims,
)

if (token is None and (username is None or password is None)) or all(v is not None for v in [token, username, password]):
raise ValueError("Either --token or --username and --password must be provided.")
if (token is None and (username is None or password is None)) or all(
v is not None for v in [token, username, password]
):
raise ValueError(
"Either --token or --username and --password must be provided."
)

if file_path is None and file_url is None:
raise ValueError("Either --file_path or --file_url must be provided.")
Expand All @@ -126,7 +139,9 @@ def upload(

# create default table name if not provided
if table is None:
table = get_default_table_name(file_path if is_local_file else urlparse(file_url).path, band)
table = get_default_table_name(
file_path if is_local_file else urlparse(file_url).path, band
)

connector = SnowflakeConnection(
username=username,
Expand Down Expand Up @@ -180,16 +195,25 @@ def upload(
@click.option("--account", help="The Swnoflake account.", required=True)
@click.option("--username", help="The username.", required=False, default=None)
@click.option("--password", help="The password.", required=False, default=None)
@click.option("--token", help="An access token to authenticate with.", required=False, default=None)
@click.option(
"--token",
help="An access token to authenticate with.",
required=False,
default=None,
)
@click.option("--role", help="The role to use for the file upload.", default=None)
@click.option("--database", help="The name of the database.", required=True)
@click.option("--schema", help="The name of the schema.", required=True)
@click.option("--table", help="The name of the table.", required=True)
@click.option("--limit", help="Limit number of rows returned", default=10)
def describe(account, username, password, token, role, database, schema, table, limit):

if (token is None and (username is None or password is None)) or all(v is not None for v in [token, username, password]):
raise ValueError("Either --token or --username and --password must be provided.")
if (token is None and (username is None or password is None)) or all(
v is not None for v in [token, username, password]
):
raise ValueError(
"Either --token or --username and --password must be provided."
)

fqn = f"{database}.{schema}.{table}"
connector = SnowflakeConnection(
Expand Down
2 changes: 1 addition & 1 deletion raster_loader/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self):
"You can make your raster compatible "
"by converting it using the following command:\n"
"gdalwarp -of COG -co TILING_SCHEME=GoogleMapsCompatible "
"-co COMPRESS=DEFLATE -co OVERVIEWS=NONE -co ADD_ALPHA=NO "
"-co COMPRESS=DEFLATE -co OVERVIEWS=IGNORE_EXISTING -co ADD_ALPHA=YES "
"-co RESAMPLING=NEAREST -co BLOCKSIZE=512 "
"<input_raster>.tif <output_raster>.tif"
)
Expand Down
Loading

0 comments on commit 035fe4f

Please sign in to comment.