Exemplo n.º 1
0
 def test_as_features(self, regions_half_squares):
     """Retrieve regions as feature dicts
     """
     rset = RegionSet('test', regions_half_squares)
     actual = rset.as_features()
     expected = [{
         'type': 'Feature',
         'properties': {
             'name': 'a'
         },
         'geometry': {
             'type':
             'Polygon',
             'coordinates': (((0.0, 0.0), (0.0, 1.0), (1.0, 1.0),
                              (1.0, 0.0), (0.0, 0.0)), )
         }
     }, {
         'type': 'Feature',
         'properties': {
             'name': 'b'
         },
         'geometry': {
             'type':
             'Polygon',
             'coordinates': (((0.0, 1.0), (0.0, 2.0), (1.0, 2.0),
                              (1.0, 1.0), (0.0, 1.0)), )
         }
     }]
     assert actual == expected
Exemplo n.º 2
0
    def test_serialise(self, regions):
        rset = RegionSet('test', regions)
        rset.description = 'my description'
        actual = rset.as_dict()
        expected = {'name': 'test', 'description': 'my description'}

        assert actual == expected
Exemplo n.º 3
0
def register(regions_half_triangles, regions_half_squares,
             regions_single_half_square, regions_rect):
    """Region register with regions pre-registered
    """
    register = NDimensionalRegister()
    register.register(RegionSet('half_triangles', regions_half_triangles))
    register.register(RegionSet('half_squares', regions_half_squares))
    register.register(
        RegionSet('single_half_square', regions_single_half_square))
    register.register(RegionSet('rect', regions_rect))
    alt = copy(regions_rect)
    register.register(RegionSet('rect_alt', alt))
    return register
Exemplo n.º 4
0
    def test_must_have_unique_names(self):
        with raises(AssertionError) as ex:
            RegionSet('test', [{
                'name': 'a',
                'feature': {
                    'type': 'Feature',
                    'properties': {
                        'name': 'a'
                    },
                    'geometry': {
                        'type': 'Polygon',
                        'coordinates': [[[0, 0], [0, 1], [1, 1], [1, 0]]]
                    }
                }
            }, {
                'name': 'a',
                'feature': {
                    'type': 'Feature',
                    'properties': {
                        'name': 'a'
                    },
                    'geometry': {
                        'type': 'Polygon',
                        'coordinates': [[[0, 1], [0, 2], [1, 2], [1, 1]]]
                    }
                }
            }])

        assert 'Region set must have uniquely named regions' in str(ex.value)
Exemplo n.º 5
0
 def test_centroids_as_features(self, regions_half_squares):
     """Retrieve centroids
     """
     actual = RegionSet('test',
                        regions_half_squares).centroids_as_features()
     expected = [
         {
             'type': 'Feature',
             'properties': {
                 'name': 'a'
             },
             'geometry': {
                 'type': 'Point',
                 'coordinates': (0.5, 0.5)
             }
         },
         {
             'type': 'Feature',
             'properties': {
                 'name': 'b'
             },
             'geometry': {
                 'type': 'Point',
                 'coordinates': (0.5, 1.5)
             }
         },
     ]
     assert actual == expected
Exemplo n.º 6
0
 def test_create(self, regions):
     rset = RegionSet('test', regions)
     assert rset.name == 'test'
     assert len(rset) == 3
     assert rset[0].name == 'unit'
     assert rset[1].name == 'half'
     assert rset[2].name == 'two'
Exemplo n.º 7
0
def test_proportion(regions):
    """Sense-check proportion calculator
    """
    region_set = RegionSet('regions', regions)

    assert region_set.get_proportion(0, region_set[0]) == 1

    assert region_set.get_proportion(0, region_set[1]) == 0.5
    assert region_set.get_proportion(1, region_set[0]) == 1

    assert region_set.get_proportion(0, region_set[2]) == 1
    assert region_set.get_proportion(2, region_set[0]) == 0.5
    assert region_set.get_proportion(1, region_set[2]) == 1
    assert region_set.get_proportion(2, region_set[1]) == 0.25
Exemplo n.º 8
0
 def test_get_names(self, regions):
     rset = RegionSet('test', regions)
     actual = rset.get_entry_names()
     expected = ['unit', 'half', 'two']
     assert actual == expected