-
Notifications
You must be signed in to change notification settings - Fork 0
/
explore.py
76 lines (58 loc) · 1.87 KB
/
explore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 25 20:36:19 2019
@author: imartinez
"""
# %%
import geopandas as gpd
border_file = 'data/ESP_adm/ESP_adm0.shp'
border = gpd.read_file( border_file)
file = 'data/RT_GIPUZKOA/RT_GIPUZKOA/RT_VIARIA/rt_tramo_vial.shp'
df = gpd.read_file( file )
# %%
df.clase.unique()
clase_selection = [1001, 1002, 1005, 1003]
column_selection = ['clase','geometry']
df_filter = df[df.clase.isin(clase_selection)][column_selection]
df_filter.geometry = df_filter.geometry.simplify(tolerance=1, preserve_topology=False)
df_filter.to_csv('test.csv')
# %%
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(15,9),facecolor=('black'))
df_filter.plot(column='clase', cmap='spring', alpha=0.1, ax = ax)
border.plot(edgecolor='white', lw=1, facecolor='#161616', ax = ax)
ax.set_xlim((-3,-1.5))
ax.set_ylim((42.8,43.5))
#ax.axis('equal')
ax.axis('off')
# %% reduce shapefiles
from pathlib import Path
import geopandas as gpd
import gc
import os
for filename in Path('data/raw').glob('**/rt_tramo_vial.shp'):
print(filename)
df = gpd.read_file( filename )
clase_selection = [1001, 1002, 1005, 1003, 2000]
column_selection = ['clase','geometry']
df_filter = df[df.clase.isin(clase_selection)][column_selection]
df_filter.geometry = df_filter.geometry.simplify(tolerance=1, preserve_topology=False)
f_ = str(filename).split('/')
folder = 'data/processed/' + f_[2] + '/'; os.mkdir(folder)
df_filter.to_file(folder + f_[5])
gc.collect()
# %% join all reduced shapefiles
from pathlib import Path
import geopandas as gpd
import pandas as pd
import gc
import os
df_list = []
for filename in Path('data/processed').glob('**/rt_tramo_vial.shp'):
print(filename)
df = gpd.read_file( filename )
df_list.append(df)
gc.collect()
df_total = pd.concat(df_list)
df_total.to_file('spain.shp')