-
Notifications
You must be signed in to change notification settings - Fork 0
/
strips.py
104 lines (81 loc) · 3.05 KB
/
strips.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# GEO1000 - Assignment 3
# Authors:
# Studentnumbers:
from geometry import Point, Rectangle
class Strip(object):
def __init__(self, rectangle):
"""Constructor. Inits a Strip instance with a Rectangle describing
its shape and an empty points list.
"""
self.rect = rectangle
self.points = []
class StripStructure(object):
def __init__(self, extent, no_strips):
"""Constructor. Inits a StripStructure instance with the correct
number of Strip instances and makes sure that the domain is
correctly divided over the strips.
"""
self.strips = []
# Extend this method,
# so that the right number of strip objects (with the correct extent)
# are appended to the strips list
pass
def find_overlapping_strips(self, shape):
"""Returns a list of strip objects for which their rectangle intersects
with the shape given.
Returns - list of Strips
"""
pass
def query(self, shape):
"""Returns a list of points that overlaps the given shape.
For this it first finds the strips that overlap the shape,
using the find_overlapping_strips method.
Then, all points of the selected strips are checked for intersection
with the query shape.
Returns - list of Points
"""
pass
def append_point(self, pt):
"""Appends a point object to the list of points of the correct strip
(i.e. the strip the Point intersects).
For this it first finds the strips that overlap the point,
using the find_overlapping_strips method.
In case multiple strips overlap the point, the point is added
to the strip with the left most coordinate.
Returns - None
"""
pass
def print_strip_statistics(self):
"""Prints:
* how many strips there are in the structure
And then, for all the strips in the structure:
* an id (starting at 1),
* the number of points in a strip,
* the lower left point of a strip and
* the upper right point of a strip.
Returns - None
"""
pass
def dumps_strips(self):
"""Dumps the strips of this structure to a str,
which (if saved in a text file) can be loaded as
delimited text layer in QGIS.
Returns - str
"""
lines = "strip;wkt\n"
for i, strip in enumerate(self.strips, start = 1):
t = "{0};{1}\n".format(i, strip.rect)
lines += t
return lines
def dumps_points(self):
"""Dumps the points of this structure to a str,
which (if saved in a text file) can be loaded as
delimited text layer in QGIS.
Returns - str
"""
lines = "strip;wkt\n"
for i, strip in enumerate(self.strips, start = 1):
for pt in strip.points:
t = "{0};{1}\n".format(i, pt)
lines += t
return lines