forked from QuantCrimAtLeeds/PredictCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample1.py
More file actions
46 lines (37 loc) · 1.12 KB
/
Copy pathexample1.py
File metadata and controls
46 lines (37 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import csv
import open_cp.data
import geopandas as gpd
import pyproj
import dateutil.parser
def row_to_datetime(row):
datetime_string = row[1]
return dateutil.parser.parse(datetime_string)
proj = pyproj.Proj({"init" : "epsg:2790"})
def row_to_coords(row):
x = float(row[5])
y = float(row[4])
return proj(x, y)
def load_points():
with open("example.csv") as file:
reader = csv.reader(file)
header = next(reader)
# Assume the header is correct
times = []
xcoords = []
ycoords = []
for row in reader:
times.append(row_to_datetime(row))
x, y = row_to_coords(row)
xcoords.append(x)
ycoords.append(y)
# Maybe `times` is not sorted.
times, xcoords, ycoords = open_cp.data.order_by_time(times, xcoords, ycoords)
return open_cp.data.TimedPoints.from_coords(times, xcoords, ycoords)
def load_geometry():
frame = gpd.read_file("SouthSide")
return frame.geometry[0]
geo = load_geometry()
print(geo.geom_type)
data = load_points()
print(data, data.number_data_points)
print(data.timestamps[0])