from pathlib import Path
import geopandas as gpd
from tree import Tree, Forest

def get_existing_forest(shp_input):
    print(f"Importing {shp_input}")
    df = gpd.read_file(shp_input)
    trees = []
    for tree_row in df.itertuples():
        point = tree_row.geometry
        trees.append(Tree(point.x, point.y,
                          description=tree_row.Bezeichnun,
                          diameter=tree_row.Kronenbrei,
                          type=tree_row.Baumart,
                          trunk_diameter=tree_row.Stammumfan,
                          height=tree_row.Baumhöhe,
                          source=Path(shp_input).name
                          ))
    return Forest(trees)

if __name__ == "__main__":
    print(repr(get_existing_forest('existing_trees/Trees_ideal_2_20240227.shp')))
