Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GabonMangroves
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Boba Fett
GabonMangroves
Commits
99af6d5c
Commit
99af6d5c
authored
4 years ago
by
Boba Fett
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
eb6b9f2f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
3_Convert_CSV2SHP.ipynb
+116
-0
116 additions, 0 deletions
3_Convert_CSV2SHP.ipynb
with
116 additions
and
0 deletions
3_Convert_CSV2SHP.ipynb
0 → 100644
+
116
−
0
View file @
99af6d5c
{
"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
}
%% Cell type:code id: tags:
```
python
#!/opt/conda/bin/python
import
pandas
as
pd
from
geopandas
import
GeoDataFrame
as
gdf
import
geopandas
as
gpd
from
geopandas.tools
import
sjoin
import
shapely
import
fiona
# May have to conda install reree in termianl
```
%% Cell type:code id: tags:
```
python
file
=
'
/projects/bobafett/Icesat2Gabon/Data/CSV/Gabon_IS2_ATL08.csv
'
```
%% Cell type:code id: tags:
```
python
data
=
pd
.
read_csv
(
file
)
print
(
'
finished reading
'
)
```
%% Output
finished reading
%% Cell type:code id: tags:
```
python
points
=
gdf
(
data
,
geometry
=
gpd
.
points_from_xy
(
data
.
lon
,
data
.
lat
))
print
(
'
converted to points
'
)
#ESRI WKT string from epsg.io
ESRI_WKT
=
'
GEOGCS[
"
GCS_WGS_1984
"
,DATUM[
"
D_WGS_1984
"
,SPHEROID[
"
WGS_1984
"
,6378137,298.257223563]],PRIMEM[
"
Greenwich
"
,0],UNIT[
"
Degree
"
,0.017453292519943295]]
'
```
%% Output
converted to points
%% Cell type:code id: tags:
```
python
#points.to_file(filename='/projects/bobafett/Icesat2Gabon/Data/CSV/Gabon_IS2_ATL08.gpkg', layer='ICESAT2', driver='GPKG', crs_wkt=ESRI_WKT)
points
.
to_file
(
filename
=
'
/projects/bobafett/Icesat2Gabon/Data/Shapefiles/Gabon_IS2_ATL08.shp
'
,
layer
=
'
ICESAT2
'
,
driver
=
'
ESRI Shapefile
'
,
crs_wkt
=
ESRI_WKT
)
print
(
'
finished
'
)
```
%% Output
finished
%% Cell type:code id: tags:
```
python
```
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment