|
|
|
@ -7,11 +7,14 @@ import fiona
|
|
|
|
|
import pandas as pd
|
|
|
|
|
from fiona.crs import from_epsg
|
|
|
|
|
from shapely.geometry import Point, mapping
|
|
|
|
|
import logging.config
|
|
|
|
|
|
|
|
|
|
logging.config.fileConfig("./src/logging.conf", disable_existing_loggers=False)
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
@click.command()
|
|
|
|
|
@click.argument('input_csv')
|
|
|
|
|
@click.argument('output_shp')
|
|
|
|
|
@click.option("--input-csv", required=True, help=".csv file to convert")
|
|
|
|
|
@click.option("--output-shp", required=True, help="where to store .shp file")
|
|
|
|
|
def sites_csv_to_shp(input_csv, output_shp):
|
|
|
|
|
"""
|
|
|
|
|
Converts our dataframe of sites to .shp to load in QGis
|
|
|
|
@ -19,30 +22,22 @@ def sites_csv_to_shp(input_csv, output_shp):
|
|
|
|
|
:param output_shp:
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
logger.info('Converting %s to %s', input_csv, output_shp)
|
|
|
|
|
df_sites = pd.read_csv(input_csv, index_col=[0])
|
|
|
|
|
|
|
|
|
|
schema = {
|
|
|
|
|
'geometry': 'Point',
|
|
|
|
|
'properties': {
|
|
|
|
|
'beach': 'str',
|
|
|
|
|
'site_id': 'str'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
with fiona.open(output_shp, 'w', crs=from_epsg(4326), driver='ESRI Shapefile', schema=schema) as output:
|
|
|
|
|
schema = {"geometry": "Point", "properties": {"beach": "str", "site_id": "str"}}
|
|
|
|
|
with fiona.open(output_shp, "w", crs=from_epsg(4326), driver="ESRI Shapefile", schema=schema) as output:
|
|
|
|
|
for index, row in df_sites.iterrows():
|
|
|
|
|
point = Point(row['lon'], row['lat'])
|
|
|
|
|
prop = {
|
|
|
|
|
'beach': row['beach'],
|
|
|
|
|
'site_id': index,
|
|
|
|
|
}
|
|
|
|
|
output.write({'geometry': mapping(point), 'properties': prop})
|
|
|
|
|
|
|
|
|
|
point = Point(row["lon"], row["lat"])
|
|
|
|
|
prop = {"beach": row["beach"], "site_id": index}
|
|
|
|
|
output.write({"geometry": mapping(point), "properties": prop})
|
|
|
|
|
logger.info('Done!')
|
|
|
|
|
|
|
|
|
|
@click.group()
|
|
|
|
|
def cli():
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
cli.add_command(sites_csv_to_shp)
|
|
|
|
|
cli()
|
|
|
|
|