Skip to content

Commit

Permalink
allow root dir
Browse files Browse the repository at this point in the history
  • Loading branch information
bw4sz committed Jan 4, 2024
1 parent f99f9e6 commit 3a840f0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion deepforest/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,11 @@ def determine_geometry_type(df, verbose=True):

return geometry_type

def read_file(input):
def read_file(input, root_dir=None):
"""Read a file and return a geopandas dataframe
Args:
input: a path to a file or a pandas dataframe
root_dir: Optional directory to prepend to the image_path column
Returns:
df: a geopandas dataframe with the properly formatted geometry column
"""
Expand All @@ -382,6 +383,9 @@ def read_file(input):
elif isinstance(input, gpd.GeoDataFrame):
df = input.copy(deep=True)

if root_dir:
df["image_path"] = df["image_path"].apply(lambda x: os.path.join(root_dir, x))

if type(df) == pd.DataFrame:
# If the geometry column is present, convert to geodataframe directly
if "geometry" in df.columns:
Expand Down

0 comments on commit 3a840f0

Please sign in to comment.