# 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/utils/shapelytools.py
# def endpoints_from_lines(lines):
# def vertices_from_lines(lines):
# def snapping_vertexis_from_lines(lines, closeness_limit):
# def prune_short_lines(lines, min_length):
# def neighbors(lines, of):
# def bend_towards(line, where, to):
# def snappy_endings(lines, max_distance):
# def nearest_neighbor_within(others, point, max_distance):
# def find_isolated_endpoints(lines):
# def closest_object(geometries, point):
# def project_point_to_line(point, line_start, line_end):
# def pairs(lst):
# def project_point_to_object(point, geometry):
# def one_linestring_per_intersection(lines):
# def linemerge(linestrings_or_multilinestrings):
# 
# Path: rivus/utils/skeletrontools.py
# def select_biggest_polygon_from_multipolygon(multi_polygon):
# def extract_lines_from_graph(graphs):
# def skeletonize(roads, buffer_length=60,
#                 dissolve_length=30,
#                 simplify_length=30,
#                 buffer_resolution=2,
#                 psg_length=150):


import os
import geopandas
from ..utils import pandashp
from ..utils import shapelytools
from ..utils import skeletrontools

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

# IN
streets_filename = 'streets.shp'
streets_filename_abs = os.path.join(work_dir, 'streets.shp')

# OUT
edge_apath = os.path.join(work_dir, 'edgeout.shp')
vertex_apath = os.path.join(work_dir, 'vertexout.shp')


streets = geopandas.read_file(streets_filename)
streets = streets.to_crs(epsg=EPSG_XY)  # EPSG:32632 == UTM Zone 32N (Germany!)

# filter away roads by type
road_types = ['motorway', 'motorway_link', 'primary', 'primary_link',
              'secondary', 'secondary_link', 'tertiary', 'tertiary_link',
              'residential', 'living_street', 'service', 'unclassified']
streets = streets[streets['type'].isin(road_types)]


skeleton = skeletrontools.skeletonize(streets,
                                      buffer_length=30,
                                      dissolve_length=15,
                                      simplify_length=30)

# 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/utils/shapelytools.py
# def endpoints_from_lines(lines):
# def vertices_from_lines(lines):
# def snapping_vertexis_from_lines(lines, closeness_limit):
# def prune_short_lines(lines, min_length):
# def neighbors(lines, of):
# def bend_towards(line, where, to):
# def snappy_endings(lines, max_distance):
# def nearest_neighbor_within(others, point, max_distance):
# def find_isolated_endpoints(lines):
# def closest_object(geometries, point):
# def project_point_to_line(point, line_start, line_end):
# def pairs(lst):
# def project_point_to_object(point, geometry):
# def one_linestring_per_intersection(lines):
# def linemerge(linestrings_or_multilinestrings):
# 
# Path: rivus/utils/skeletrontools.py
# def select_biggest_polygon_from_multipolygon(multi_polygon):
# def extract_lines_from_graph(graphs):
# def skeletonize(roads, buffer_length=60,
#                 dissolve_length=30,
#                 simplify_length=30,
#                 buffer_resolution=2,
#                 psg_length=150):


# Path: rivus/converter/streets_to_edge.py
import os
import geopandas
from ..utils import pandashp
from ..utils import shapelytools
from ..utils import skeletrontools


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

# IN
streets_filename = 'streets.shp'
streets_filename_abs = os.path.join(work_dir, 'streets.shp')

# OUT
edge_apath = os.path.join(work_dir, 'edgeout.shp')
vertex_apath = os.path.join(work_dir, 'vertexout.shp')


streets = geopandas.read_file(streets_filename)
streets = streets.to_crs(epsg=EPSG_XY)  # EPSG:32632 == UTM Zone 32N (Germany!)

# filter away roads by type
road_types = ['motorway', 'motorway_link', 'primary', 'primary_link',
              'secondary', 'secondary_link', 'tertiary', 'tertiary_link',
              'residential', 'living_street', 'service', 'unclassified']
streets = streets[streets['type'].isin(road_types)]


skeleton = skeletrontools.skeletonize(streets,
                                      buffer_length=30,
                                      dissolve_length=15,
                                      simplify_length=30)

skeleton = shapelytools.one_linestring_per_intersection(skeleton)