Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
Kangyu Wang committed Nov 30, 2019
0 parents commit 8b562de
Show file tree
Hide file tree
Showing 338 changed files with 210,588 additions and 0 deletions.
Binary file added Data.zip
Binary file not shown.
1 change: 1 addition & 0 deletions Data/Data/DAMSELFISH_distributions.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UTF-8
Binary file added Data/Data/DAMSELFISH_distributions.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions Data/Data/DAMSELFISH_distributions.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]
Binary file added Data/Data/DAMSELFISH_distributions.shp
Binary file not shown.
Binary file added Data/Data/DAMSELFISH_distributions.shx
Binary file not shown.
1 change: 1 addition & 0 deletions Data/Data/DAMSELFISH_distributions_SELECTION.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ISO-8859-1
Binary file added Data/Data/DAMSELFISH_distributions_SELECTION.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions Data/Data/DAMSELFISH_distributions_SELECTION.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Binary file added Data/Data/DAMSELFISH_distributions_SELECTION.shp
Binary file not shown.
Binary file added Data/Data/DAMSELFISH_distributions_SELECTION.shx
Binary file not shown.
Binary file added Europe_borders.zip
Binary file not shown.
1 change: 1 addition & 0 deletions Europe_borders/Europe_borders.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UTF-8
Binary file added Europe_borders/Europe_borders.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions Europe_borders/Europe_borders.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["degree",0.0174532925199433]]
Binary file added Europe_borders/Europe_borders.sbn
Binary file not shown.
Binary file added Europe_borders/Europe_borders.sbx
Binary file not shown.
Binary file added Europe_borders/Europe_borders.shp
Binary file not shown.
Binary file added Europe_borders/Europe_borders.shx
Binary file not shown.
1 change: 1 addition & 0 deletions Europe_borders/Europe_borders_epsg3035.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ISO-8859-1
Binary file added Europe_borders/Europe_borders_epsg3035.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions Europe_borders/Europe_borders_epsg3035.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["ETRS89_LAEA_Europe",GEOGCS["GCS_ETRS_1989",DATUM["D_ETRS_1989",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Azimuthal_Equal_Area"],PARAMETER["latitude_of_origin",52],PARAMETER["central_meridian",10],PARAMETER["false_easting",4321000],PARAMETER["false_northing",3210000],UNIT["Meter",1]]
Binary file added Europe_borders/Europe_borders_epsg3035.shp
Binary file not shown.
Binary file added Europe_borders/Europe_borders_epsg3035.shx
Binary file not shown.
20 changes: 20 additions & 0 deletions Excercise 1/create_geometries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 6 19:45:54 2019
@author: kangyuwang
"""
from shapely.geometry import Point, LineString, Polygon
def createPointGeom(x_coord, y_coord):
point=Point(x_coord, y_coord)
return point
def createLineGeom(list_point):
linestring=LineString(list_point)
return linestring
def createPolyGeom(x):
if type(x[0])==tuple:
polygon=Polygon(x)
if type(x[0])==Point:
polygon=Polygon([(p.x, p.y) for p in x])
return polygon
createPolyGeom(input2)
17 changes: 17 additions & 0 deletions Excercise 1/file_coords_to_geom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 6 20:47:11 2019
@author: kangyuwang
"""

import pandas as pd
import statistics as sta
from shapely.geometry import Point, LineString
data = pd.read_csv('C:/Users/kangyuwang/OneDrive/portfolio/python_geo/Excercise 1/travelTimes_2015_Helsinki.txt', sep=";", header = 0)
data['from_id']
coords=data.loc[:, ['from_x', 'from_y', 'to_x', 'to_y']]
orig_points=[Point(coords.iloc[n, 0], coords.iloc[n, 1]) for n in range(0, coords.shape[0])]
dest_points=[Point(coords.iloc[n, 2], coords.iloc[n, 3]) for n in range(0, coords.shape[0])]
lines=[LineString([orig_points[i], dest_points[i]]) for i in range(0, coords.shape[0])]
sta.mean(lines[i].length for i in range(0, coords.shape[0]))
22 changes: 22 additions & 0 deletions Excercise 1/read_attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 6 20:12:58 2019
@author: kangyuwang
"""
from shapely.geometry import Point, LineString, Polygon

def getCentroid(x):
return x.centroid

def getArea(x):
return x.area

def getLength(x):
if type(x)==LineString:
return x.length
if type(x)==Polygon:
return x.exterior.length
else:
raise Error("Error: LineString or Polygon geometries required!")

14,644 changes: 14,644 additions & 0 deletions Excercise 1/travelTimes_2015_Helsinki.txt

Large diffs are not rendered by default.

109 changes: 109 additions & 0 deletions Excercise 2/Excercise 2 P1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 9 22:37:02 2019
@author: kangyuwang
"""

import geopandas as gpd

from shapely.geometry import Polygon

import matplotlib.pyplot as plt


# X -coordinates

xcoords = [29.99671173095703, 31.58196258544922, 27.738052368164062, 26.50013542175293, 26.652359008789062, 25.921663284301758, 22.90027618408203, 23.257217407226562,

23.335693359375, 22.87444305419922, 23.08465003967285, 22.565473556518555, 21.452774047851562, 21.66388702392578, 21.065969467163086, 21.67659568786621,

21.496871948242188, 22.339998245239258, 22.288192749023438, 24.539581298828125, 25.444232940673828, 25.303749084472656, 24.669166564941406, 24.689163208007812,

24.174999237060547, 23.68471908569336, 24.000761032104492, 23.57332992553711, 23.76513671875, 23.430830001831055, 23.6597900390625, 20.580928802490234, 21.320831298828125,

22.398330688476562, 23.97638702392578, 24.934917449951172, 25.7611083984375, 25.95930290222168, 26.476804733276367, 27.91069221496582, 29.1027774810791, 29.29846954345703,

28.4355525970459, 28.817358016967773, 28.459857940673828, 30.028610229492188, 29.075136184692383, 30.13492774963379, 29.818885803222656, 29.640830993652344, 30.57735824584961,

29.99671173095703]



# Y -coordinates

ycoords = [63.748023986816406, 62.90789794921875, 60.511383056640625, 60.44499588012695, 60.646385192871094, 60.243743896484375, 59.806800842285156, 59.91944122314453,

60.02395248413086, 60.14555358886719, 60.3452033996582, 60.211936950683594, 60.56249237060547, 61.54027557373047, 62.59798049926758, 63.02013397216797,

63.20353698730469, 63.27652359008789, 63.525691986083984, 64.79915618896484, 64.9533920288086, 65.51513671875, 65.65470886230469, 65.89610290527344, 65.79151916503906,

66.26332092285156, 66.80228424072266, 67.1570053100586, 67.4168701171875, 67.47978210449219, 67.94589233398438, 69.060302734375, 69.32611083984375, 68.71110534667969,

68.83248901367188, 68.580810546875, 68.98916625976562, 69.68568420410156, 69.9363784790039, 70.08860778808594, 69.70597076416016, 69.48533630371094, 68.90263366699219,

68.84700012207031, 68.53485107421875, 67.69471740722656, 66.90360260009766, 65.70887756347656, 65.6533203125, 64.92096710205078, 64.22373962402344, 63.748023986816406]



# P1. Create a list of x and y coordinate pairs out of xcoords and ycoords

# ------------------------------------------------------------------------

# Coordinate pair can be either a tuple or a list.

# The first coordinate pair in the 'coordpairs' -list should look like: (29.99671173095703, 63.748023986816406)

# Hint: you might want to iterate over items in the lists using a for-loop



coordpairs = [(xcoords[i], ycoords[i]) for i in range(len(xcoords))]



# P2. Create a shapely Polygon using the 'coordpairs' -list

# ------------------------------------------------------------------------

poly =Polygon(coordpairs)




# P3. Create an empty GeoDataFrame

# ---------------------------------

geo =gpd.GeoDataFrame()



# P4. Insert our 'poly' -polygon into the 'geo' GeoDataFrame using a column name 'geometry'

# ------------------------------------------------------------------------------------------

# Hint: Take advantage of .loc -funtion

geo.loc[0,'geometry']=poly



# P5. Save the GeoDataFrame into a new Shapefile called 'polygon.shp'

# --------------------------------------------------------------------

# Note: you do not need to define the coordinate reference system at this time


geo.to_file("C:/Users/kangyuwang/OneDrive/portfolio/python_geo/Excercise 2/polygon.shp")


# P6. Plot the polygon using taking advantage of the .plot() -function in GeoDataFrame. Save a PNG figure out of your plot and upload it to your GitHub repository.

# -----------------------------------------------------------------------------------------------------------------------------------------------------------------
geo.plot()
plt.title("Map of Finland: WSG84")



39 changes: 39 additions & 0 deletions Excercise 2/Excercise 2 P2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 9 22:58:13 2019
@author: kangyuwang
"""

import pandas as pd
from shapely.geometry import Point, LineString, Polygon

data=pd.read_csv("C:/Users/kangyuwang/OneDrive/portfolio/python_geo/Excercise 2/some_posts.csv")
data['geometry']=None
for index, row in data.iterrows():
data.loc[index, 'geometry']=Point(row['lat'], row['lon'])

import geopandas as gpd
from fiona.crs import from_epsg
import matplotlib.pyplot plt
data_gdf=gpd.GeoDataFrame(data)
data_gdf.crs=from_epsg(4236)
data_gdf.to_file("C:/Users/kangyuwang/OneDrive/portfolio/python_geo/Excercise 2/Kruger_posts.shp")
data_gdf.plot()

data_gdf_proj=data_gdf.to_crs(epsg=32735)
data_gdf_proj_grp=data_gdf_proj.groupby('userid')
movements=gpd.GeoDataFrame()
for key, values in data_gdf_proj_grp:
values_sort=values.sort_values(by=['timestamp'])
if len(values_sort.index)>1:
line=LineString((values_sort.loc[values_sort.index[i], 'lat'], values_sort.loc[values_sort.index[i], 'lon']) for i in range(len(values_sort.index)))
movements=movements.append(pd.DataFrame(data={'geometry': [line], 'userid': [key], 'distance': line.length}), ignore_index=True)
else:
movements=movements.append(pd.DataFrame(data={'geometry': None, 'userid': [key], 'distance':None}), ignore_index=True)
movements_gdf=gpd.GeoDataFrame(movements)
movements_gdf.to_file("C:/Users/kangyuwang/OneDrive/portfolio/python_geo/Excercise 2/Some_movements.shp")
##answers to question
movements.loc[: ,'distance'].mean()
movements.loc[: ,'distance'].max()
movements.loc[: ,'distance'].min()
1 change: 1 addition & 0 deletions Excercise 2/Kruger_posts.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ISO-8859-1
Binary file added Excercise 2/Kruger_posts.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions Excercise 2/Kruger_posts.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOGCS["Hu Tzu Shan 1950",DATUM["D_Hu_Tzu_Shan",SPHEROID["International_1924",6378388,297]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Binary file added Excercise 2/Kruger_posts.shp
Binary file not shown.
Binary file added Excercise 2/Kruger_posts.shx
Binary file not shown.
1 change: 1 addition & 0 deletions Excercise 2/Some_movements.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ISO-8859-1
Binary file added Excercise 2/Some_movements.dbf
Binary file not shown.
Binary file added Excercise 2/Some_movements.shp
Binary file not shown.
Binary file added Excercise 2/Some_movements.shx
Binary file not shown.
Loading

0 comments on commit 8b562de

Please sign in to comment.