From 322a976f7a629815f3e0fee2fec7886d9c09e4e5 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Tue, 25 Sep 2018 22:01:09 +0100 Subject: [PATCH] Fix get_test_polygons script --- .gitignore | 2 +- etl/get_test_polygons.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a5744ad6..09a54536 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ app/start.sh etl/cache/* etl/images/* etl/*.geojson -etl/*.txt +etl/*.csv diff --git a/etl/get_test_polygons.py b/etl/get_test_polygons.py index aa9a2b82..544fa33a 100644 --- a/etl/get_test_polygons.py +++ b/etl/get_test_polygons.py @@ -8,6 +8,8 @@ Then run: """ # -*- coding: utf-8 -*- import os +import subprocess + import osmnx # configure logging/caching @@ -28,7 +30,9 @@ fig, ax = osmnx.plot_buildings(gdf_proj, bgcolor='#333333', color='w', figsize=( filename='test_buildings_preview', dpi=600) # save -test_data_file = os.path.join(os.path.dirname(__file__), 'test_buildings.csv') +test_dir = os.path.dirname(__file__) +test_data_geojson = str(os.path.join(test_dir, 'test_buildings.geojson')) +subprocess.run(["rm", test_data_geojson]) gdf_to_save = gdf_proj.reset_index( )[ @@ -38,5 +42,13 @@ gdf_to_save = gdf_proj.reset_index( gdf_to_save.rename( columns={'index': 'fid'} ).to_file( - test_data_file, driver='CSV' + test_data_geojson, driver='GeoJSON' ) + +# convert to CSV +test_data_csv = str(os.path.join(test_dir, 'test_buildings.csv')) +subprocess.run(["rm", test_data_csv]) +subprocess.run(["ogr2ogr", "-f", "CSV", test_data_csv, test_data_geojson, "-lco", "GEOMETRY=AS_WKT"]) + +# add SRID for ease of loading to PostgreSQL +subprocess.run(["sed", "-i", "s/^\"POLYGON/\"SRID=3857;POLYGON/", test_data_csv])