Esempio n. 1
0
 def test_wkt_vectorize_one_wkt(self):
     max_points = GeoVectorizer.max_points(brt_wkt, osm_wkt)
     vectorized = []
     target_set = SOURCE_DATA['intersection_wkt']
     for index in range(len(target_set)):
         vectorized.append(
             GeoVectorizer.vectorize_wkt(target_set[index], max_points))
     self.assertEqual(len(target_set), len(brt_wkt))
Esempio n. 2
0
 def test_interpolate(self):
     interpolated = GeoVectorizer.interpolate(input_geom,
                                              len(input_geom) * 2)
     for index, _ in enumerate(interpolated):
         result = list(interpolated[index])
         expected = list(output_geom[index])
         self.assertListEqual(result,
                              expected,
                              msg='Lists differ at index %i' % index)
Esempio n. 3
0
    def test_wkt_vectorize_two_wkt(self):
        vectorized = []
        max_points = GeoVectorizer.max_points(brt_wkt, osm_wkt)
        for index in range(len(brt_wkt)):
            vectorized.append(
                GeoVectorizer.vectorize_two_wkts(brt_wkt[index],
                                                 osm_wkt[index], max_points))

        num_records = len(vectorized)
        num_points = len(vectorized[0])
        num_features = len(vectorized[0][0])

        self.assertEqual(num_records, 13)
        self.assertEqual(num_points, 47)
        self.assertEqual(num_features, GEO_VECTOR_LEN)

        for record in vectorized:
            points = [point for point in record if point[0] > 0]
            # Every first point should have a "render" code
            self.assertEqual(points[0][RENDER_INDEX], 1)
            # Every last point should have a "full stop" code
            self.assertEqual(points[-1][FULL_STOP_INDEX], 1)
training_data = pandas.read_csv(TOPOLOGY_TRAINING_CSV)
truncated_data = np.array([
    record for record in training_data.values
    if len(record[0] + ';' + record[1]) <= MAX_SEQUENCE_LEN
])
raw_training_set = training_data['brt_wkt'] + ';' + training_data['osm_wkt']
raw_target_set = training_data['intersection_wkt']
print(len(raw_training_set), 'data points in training set')

brt_wkt = truncated_data[:, 0]
osm_wkt = truncated_data[:, 1]
intersection_set = truncated_data[:, 2]
centroid_distance = truncated_data[:, 3]
geom_distance = truncated_data[:, 4]
brt_centroid = [
    GeoVectorizer.vectorize_wkt(point, 1) for point in truncated_data[:, 5]
]
osm_centroid = [
    GeoVectorizer.vectorize_wkt(point, 1) for point in truncated_data[:, 6]
]
brt_centroid_rd = [
    GeoVectorizer.vectorize_wkt(point, 1) for point in truncated_data[:, 7]
]
osm_centroid_rd = [
    GeoVectorizer.vectorize_wkt(point, 1) for point in truncated_data[:, 8]
]
intersection_surface = truncated_data[:, 9]

training_set = brt_wkt + ';' + osm_wkt
print(len(training_set), 'max length data points in training set')
Esempio n. 5
0
import numpy as np
from model.topoml_util.GeoVectorizer import GeoVectorizer
from shapely.geometry import Polygon
from shapely.wkt import loads

SET_SIZE = 100000
TRIANGLES = '../files/triangles.npz'


print('Creating triangles')
raw_training_vectors = np.random.normal(size=(SET_SIZE, 6, 2))
triangle_sets = np.array([[Polygon(point_set[0:3]).wkt, Polygon(point_set[3:]).wkt]
                          for point_set in raw_training_vectors])
max_points = GeoVectorizer.max_points(triangle_sets[:, 0], triangle_sets[:, 1])

print('Intersecting triangles and pruning')
intersection_area = []
intersection_vectors = []
for index, (a, b) in enumerate(triangle_sets):
    # if loads(a).intersection_surface_area(loads(b)).type == 'Polygon':  # constrain to actually intersecting
    intersection = loads(a).intersection(loads(b))
    intersection_area.append(intersection.area)
    intersection_vectors.append(GeoVectorizer.vectorize_wkt(intersection.wkt, 12))

training_vectors = np.reshape(raw_training_vectors, (SET_SIZE, 12))
(_, GEO_VECTOR_LEN) = np.array(training_vectors).shape
intersection_area = np.array(intersection_area)

print('Saving compressed numpy data file', TRIANGLES)

np.savez_compressed(
Esempio n. 6
0
 def test_decypher_gmm_geom(self):
     pred = gmm_output.prediction
     sample_size = 10
     points = GeoVectorizer(gmm_size=5).decypher_gmm_geom(
         pred, sample_size=sample_size)
     self.assertEqual(len(points), 40)
Esempio n. 7
0
 def test_decypher(self):
     self.maxDiff = None
     max_points = GeoVectorizer.max_points(brt_wkt, osm_wkt)
     target_vector = GeoVectorizer.vectorize_wkt(target_wkt[0], max_points)
     decyphered = GeoVectorizer.decypher(target_vector)
     self.assertEqual(decyphered, target_wkt[0])
Esempio n. 8
0
 def test_max_points(self):
     max_points = GeoVectorizer.max_points(brt_wkt, osm_wkt)
     self.assertEqual(max_points, 47)