Skip to content

Commit

Permalink
add explode step to upload if the dataframe has only one row.
Browse files Browse the repository at this point in the history
on dissolved dataset, the creation of mbtiles takes ages.
  • Loading branch information
hambsch committed Jul 9, 2024
1 parent 0df3d4d commit c118454
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/guppy/endpoints/upload_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,14 @@ def create_preprocessed_layer_file(ext: str, file_location: str, sanitized_filen
is_mbtile = True
else:
df = gpd.read_file(tmp_file_location)
df['fid'] = df.index
df.to_crs(epsg=4326, inplace=True)
gpkg_loc = f"{cfg.deploy.content}/shapefiles/uploaded/{sanitized_layer_name}_{sanitized_filename}.gpkg"
if len(df) == 1: # explode if there is only one row
df = df.explode().reset_index(drop=True)
df['fid'] = df.index
gpkg_loc = f"{cfg.deploy.content}/shapefiles/uploaded/{sanitized_layer_name}_{sanitized_filename}_tmp.gpkg"
if 'bounds' not in df.columns:
df['bounds'] = df.geometry.envelope.to_wkt()
df.to_file(gpkg_loc, index=False)
df.to_file(gpkg_loc, index=False, layer=sanitized_layer_name, driver='GPKG')
to_mbtiles(sanitized_layer_name, gpkg_loc, file_location)
os.remove(tmp_file_location)
df.drop(columns=['geometry'], inplace=True)
Expand Down

0 comments on commit c118454

Please sign in to comment.