1212from geoarrow .pyarrow .io import read_geoparquet_table
1313from obstore .store import S3Store
1414from omegaconf import OmegaConf
15+ from pyogrio import read_info
1516
1617
1718def load_config ():
@@ -107,6 +108,16 @@ def preview_file(bucket_cfg, bucket_name: str, path: str):
107108 """Preview file content based on extension."""
108109 ext = pathlib .Path (path ).suffix .lower ()
109110
111+ http_path = f"{ bucket_cfg .endpoint } /{ bucket_cfg .bucket } /{ path } "
112+ fs = create_fs (
113+ bucket_cfg .bucket or bucket_name ,
114+ bucket_cfg .endpoint ,
115+ bucket_cfg .get ("access_key" ),
116+ bucket_cfg .get ("secret_key" ),
117+ )
118+
119+ s3_path = f"s3://{ bucket_name } /{ path } "
120+
110121 try :
111122 if ext in (".png" , ".jpg" , ".jpeg" , ".gif" , ".webp" , ".svg" ):
112123 content = load_file_content (
@@ -119,40 +130,41 @@ def preview_file(bucket_cfg, bucket_name: str, path: str):
119130 st .image (content , caption = path )
120131
121132 elif ext == ".tif" :
122- full_path = f"{ bucket_cfg .endpoint } /{ bucket_cfg .bucket } /{ path } "
123133 m = leafmap .Map ()
124- m .add_cog_layer (full_path , palette = "viridis" , name = "Remote COG" )
134+ m .add_cog_layer (http_path , palette = "viridis" , name = "Remote COG" )
125135 m .to_streamlit ()
126136
127137 elif ext == ".parquet" :
128- # Use obstore fsspec filesystem
129- fs = create_fs (
130- bucket_cfg .bucket or bucket_name ,
131- bucket_cfg .endpoint ,
132- bucket_cfg .get ("access_key" ),
133- bucket_cfg .get ("secret_key" ),
134- )
138+ info = None
139+ # Read and display metadata using fiona
140+ try :
141+ info = read_info (http_path )
142+ except Exception as meta_err :
143+ st .info (f"Could not read metadata with PyOGRIO: { meta_err } " )
135144
136- full_path = f"s3://{ bucket_name } /{ path } "
145+ if info :
146+ with st .expander ("Show file metadata (PyOGRIO)" ):
147+ st .json (info )
137148
138- # Try to read as geoparquet
139- try :
140- with fs .open (full_path , "rb" ) as f :
141- gdf = ga .to_geopandas (read_geoparquet_table (f )).head (2000 )
142-
143- st .warning ("Only the first 2000 elements are previewed" )
144- m = leafmap .Map ()
145- geom_only = gdf [[gdf .geometry .name ]]
146- m .add_gdf (geom_only , layer_name = "Geometries" )
147- st .dataframe (gdf , width = "stretch" , height = 400 )
149+ if info ["crs" ]:
148150 try :
149- m .to_streamlit ()
151+ with fs .open (s3_path , "rb" ) as f :
152+ gdf = ga .to_geopandas (read_geoparquet_table (f )).head (2000 )
153+
154+ st .warning ("Only the first 2000 elements are previewed" )
155+ m = leafmap .Map ()
156+ geom_only = gdf [[gdf .geometry .name ]]
157+ m .add_gdf (geom_only , layer_name = "Geometries" )
158+ st .dataframe (gdf , width = "stretch" , height = 400 )
159+ try :
160+ m .to_streamlit ()
161+ except Exception as e :
162+ st .warning (f"Could not render map preview: { e } " )
150163 except Exception as e :
151- st .warning (f"Could not render map preview : { e } " )
152- except Exception as e :
153- with fs .open (full_path , "rb" ) as f :
164+ st .warning (f"Could not render as geospatial data : { e } " )
165+ else :
166+ with fs .open (s3_path , "rb" ) as f :
154167 table = pq .read_table (f )
155- st .warning (f"Could not render as geospatial data: { e } " )
156168 st .dataframe (table , width = "stretch" , height = 400 )
157169
158170 elif ext in (".txt" , ".md" , ".json" , ".yaml" , ".yml" , ".csv" , ".xml" ):
0 commit comments