Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing get_tiles for target_number_tiles = 1 + using `fused.types... #717

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 4 additions & 5 deletions public/common/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@fused.udf
def udf(bounds: fused.types.Tile):
return bounds



def udf(bounds: fused.types.Bounds):
from utils import get_tiles
bbox = get_tiles(bounds)
return bbox
8 changes: 4 additions & 4 deletions public/common/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@
"pitch": 0,
"bearing": 0
},
"fused:gitUrl": "https://github.com/fusedio/udfs/tree/18af4ca41df678c4c9c9d3c04ede6a1c13555e54/public/common/",
"fused:gitUrl": "https://github.com/fusedio/udfs/tree/c0fd4960845d1ebc4ac86c93274a537029ec70c7/public/common/",
"fused:gitPath": "public/common",
"fused:gitRef": "18af4ca41df678c4c9c9d3c04ede6a1c13555e54",
"fused:gitRef": "c0fd4960845d1ebc4ac86c93274a537029ec70c7",
"fused:gitAuthorNames": [
"Sina Kashuk",
"Tyler Erickson",
Expand Down Expand Up @@ -150,8 +150,8 @@
"https://avatars.githubusercontent.com/u/1020496?v=4",
"https://avatars.githubusercontent.com/u/26461855?v=4"
],
"fused:gitLastModified": "2025-03-12T05:20:02+00:00",
"fused:gitShortUrl": "https://github.com/fusedio/udfs/tree/18af4ca/public/common/",
"fused:gitLastModified": "2025-03-14T08:55:58+00:00",
"fused:gitShortUrl": "https://github.com/fusedio/udfs/tree/c0fd496/public/common/",
"fused:explorerTab": "public",
"fused:gitRepo": "fusedio/udfs",
"fused:gitPullRequestBranch": "sina-patch-ce8537-add-dict-support-for-xyz",
Expand Down
40 changes: 19 additions & 21 deletions public/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,32 +1200,30 @@ def to_gdf(
import shapely
import pandas as pd
import mercantile
# Convert xyz dict to xyz array

# Convert xyz dict to list of 3: [x, y, z]
if isinstance(data, dict) and set(data.keys()) == {'x', 'y', 'z'}:
try:
data = [int(data['x']), int(data['y']), int(data['z'])]
except (ValueError, TypeError):
pass


if data is None or (isinstance(data, (list, tuple, np.ndarray)) and len(data) == 4):

data = [327, 791, 11] if data is None else data #if no data, get a tile in SF

if len(data) == 3: # Handle xyz tile coordinates
x, y, z = data
tile = mercantile.Tile(x, y, z)
bounds = mercantile.bounds(tile)
gdf = gpd.GeoDataFrame(
{"x": [x], "y": [y], "z": [z]},
geometry=[shapely.box(bounds.west, bounds.south, bounds.east, bounds.north)],
crs=4326
)
return gdf[['x', 'y', 'z', 'geometry']]

# If no data is passed, we set a tile in San Francisco
data = [327, 791, 11] if data is None else data

else: # Handle the bounds case specifically
return gpd.GeoDataFrame({}, geometry=[shapely.box(*data)], crs=crs or 4326)
if len(data) == 3: # Handling of X Y Z tile
x, y, z = data
tile = mercantile.Tile(x, y, z)
bounds = mercantile.bounds(tile)
gdf = gpd.GeoDataFrame(
{"x": [x], "y": [y], "z": [z]},
geometry=[shapely.box(bounds.west, bounds.south, bounds.east, bounds.north)],
crs=4326
)
return gdf[['x', 'y', 'z', 'geometry']]

if (isinstance(data, (list, tuple, np.ndarray)) and len(data) == 4): # Handling of fused.types.Bounds
return gpd.GeoDataFrame({}, geometry=[shapely.box(*data)], crs=crs or 4326)

if cols_lonlat:
if isinstance(data, pd.Series):
Expand Down Expand Up @@ -2742,7 +2740,7 @@ def get_tiles(

if target_num_tiles == 1:
tile = mercantile.bounding_tile(*bounds.total_bounds)
gdf = to_gdf((tile.x, tile.y, tile.z))
gdf = to_gdf([tile.x, tile.y, tile.z])
else:
zoom_level = (
zoom
Expand Down
Loading