diff --git a/3_Convert_CSV2SHP.ipynb b/3_Convert_CSV2SHP.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..a75b06f3e19ed63a861303ad3079630760f007ed --- /dev/null +++ b/3_Convert_CSV2SHP.ipynb @@ -0,0 +1,116 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "#!/opt/conda/bin/python\n", + "import pandas as pd\n", + "from geopandas import GeoDataFrame as gdf\n", + "import geopandas as gpd\n", + "from geopandas.tools import sjoin\n", + "import shapely\n", + "import fiona\n", + "# May have to conda install reree in termianl" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "file = '/projects/bobafett/Icesat2Gabon/Data/CSV/Gabon_IS2_ATL08.csv'" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "finished reading\n" + ] + } + ], + "source": [ + "data = pd.read_csv(file)\n", + "print('finished reading')" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "converted to points\n" + ] + } + ], + "source": [ + "points= gdf(data, geometry=gpd.points_from_xy(data.lon, data.lat))\n", + "print('converted to points')\n", + "\n", + "#ESRI WKT string from epsg.io\n", + "ESRI_WKT = 'GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]]'" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "finished\n" + ] + } + ], + "source": [ + "#points.to_file(filename='/projects/bobafett/Icesat2Gabon/Data/CSV/Gabon_IS2_ATL08.gpkg', layer='ICESAT2', driver='GPKG', crs_wkt=ESRI_WKT)\n", + "\n", + "points.to_file(filename='/projects/bobafett/Icesat2Gabon/Data/Shapefiles/Gabon_IS2_ATL08.shp', layer='ICESAT2', driver='ESRI Shapefile', crs_wkt=ESRI_WKT)\n", + "print('finished')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}