Select Test Building Set

This notebook extracts the coordinates of a set of buildings to be used for spatial-cimo test runs from a folder with shape files with point geometry.


In [ ]:
import geopandas as gpd
import pandas as pd
from pathlib import Path
%matplotlib inline

In [ ]:
DATA_FOLDER_PATH = Path('./data/')
RESULT_FILE_PATH = Path('./build/test_building_selection.csv')

Read all files


In [ ]:
data = None
for i, shape_file_path in enumerate(DATA_FOLDER_PATH.glob('*.shp')):
    shape_file_data = gpd.read_file(shape_file_path.as_posix())
    if data is None:
        data = shape_file_data
    else:
        data = data.append(shape_file_data)

In [ ]:
data.plot()

In [ ]:
data['x'] = [point.coords.xy[0][0] for point in data.geometry]
data['y'] = [point.coords.xy[1][0] for point in data.geometry]

Create a Selection


In [ ]:
selection = data[(data['x'] > 530000) & (data['x'] < 531000) & (data['y'] > 186000) & (data['y'] < 186400)]

In [ ]:
selection.plot()

In [ ]:
len(selection.index)

Normalise


In [ ]:
xy = pd.DataFrame({
        'x': [point.xy[0][0] for point in selection.geometry],
        'y': [point.xy[1][0] for point in selection.geometry]
        })

In [ ]:
xy.x = xy.x - xy.x.min() - (xy.x.max() - xy.x.min()) / 2
xy.y = xy.y - xy.y.min() - (xy.y.max() - xy.y.min()) / 2

In [ ]:
xy.plot(kind='scatter', x='x', y='y')

Export


In [ ]:
xy.to_csv(RESULT_FILE_PATH.as_posix())