# Path: rivus/utils/pandashp.py
# def read_shp(filename):
# def write_shp(filename, dataframe, write_index=True):
# def match_vertices_and_edges(vertices, edges, vertex_cols=('Vertex1', 'Vertex2')):
# def find_closest_edge(polygons, edges, to_attr='index', column='nearest'):
# def bounds(df):
# def total_bounds(df):


import geopandas
import pandas as pd
import shutil
import os
from ..utils import pandashp as pdshp

# Consts
inp_dir = os.path.normpath(r"C:\Users\Kristof\GIT\Masterarbeit\rivus\data\haag15")
out_dir = os.path.normpath(r"C:\Users\Kristof\GIT\Masterarbeit\rivus\data\haag15")
EPSG_XY = 32632

# IN
buildings_apath = os.path.join(inp_dir, 'building.shp')
edge_apath = os.path.join(inp_dir, 'edge.shp')

# OUT
to_edge_apath = os.path.join(out_dir, 'to_edge.shp')
buildings_mapped_apath = os.path.join(out_dir, 'building_w_nearest.shp')

# DO
# read
buildings = geopandas.read_file(buildings_apath)
edge = geopandas.read_file(edge_apath)

# buildings.head()
# edge.head()

# project to UTM zone 33N (=EPSG:32600 + zone number for north)
buildings = buildings.to_crs(epsg=EPSG_XY)
edge = edge.to_crs(epsg=EPSG_XY)

# find closest edge

# Path: rivus/utils/pandashp.py
# def read_shp(filename):
# def write_shp(filename, dataframe, write_index=True):
# def match_vertices_and_edges(vertices, edges, vertex_cols=('Vertex1', 'Vertex2')):
# def find_closest_edge(polygons, edges, to_attr='index', column='nearest'):
# def bounds(df):
# def total_bounds(df):


# Path: rivus/converter/building_to_edge.py
import geopandas
import pandas as pd
import shutil
import os
from ..utils import pandashp as pdshp


# Consts
inp_dir = os.path.normpath(r"C:\Users\Kristof\GIT\Masterarbeit\rivus\data\haag15")
out_dir = os.path.normpath(r"C:\Users\Kristof\GIT\Masterarbeit\rivus\data\haag15")
EPSG_XY = 32632

# IN
buildings_apath = os.path.join(inp_dir, 'building.shp')
edge_apath = os.path.join(inp_dir, 'edge.shp')

# OUT
to_edge_apath = os.path.join(out_dir, 'to_edge.shp')
buildings_mapped_apath = os.path.join(out_dir, 'building_w_nearest.shp')

# DO
# read
buildings = geopandas.read_file(buildings_apath)
edge = geopandas.read_file(edge_apath)

# buildings.head()
# edge.head()

# project to UTM zone 33N (=EPSG:32600 + zone number for north)
buildings = buildings.to_crs(epsg=EPSG_XY)
edge = edge.to_crs(epsg=EPSG_XY)

# find closest edge

to_edge = pdshp.find_closest_edge(buildings, edge, to_attr='Edge')