diff --git a/public/common/common.py b/public/common/common.py index ac0c4a7..0a4e36b 100644 --- a/public/common/common.py +++ b/public/common/common.py @@ -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 \ No newline at end of file diff --git a/public/common/meta.json b/public/common/meta.json index 66cba1e..77626e2 100644 --- a/public/common/meta.json +++ b/public/common/meta.json @@ -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", @@ -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", diff --git a/public/common/utils.py b/public/common/utils.py index d072d0f..831506d 100644 --- a/public/common/utils.py +++ b/public/common/utils.py @@ -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): @@ -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