Exemplo n.º 1
0
    def test_add_single(self, vector_client):
        vector_client = mock.MagicMock()
        fc = FeatureCollection('foo', vector_client=vector_client)

        feature = Feature(geometry=POINT, properties={})

        fc.add(feature)
        vector_client.create_features.assert_called_once_with(
            'foo', [
                dict(geometry=getattr(feature.geometry, '__geo_interface__',
                                      feature.geometry),
                     properties=feature.properties)
            ])
Exemplo n.º 2
0
    def test_add_bulk_and_update_with_id(self, vector_client):
        def create_features(product_id, attributes):
            return DotDict(data=[
                dict(id=attr['properties']['id'], attributes=attr)
                for attr in attributes
            ])

        vector_client.create_features.side_effect = create_features

        fc = FeatureCollection('foo', vector_client=vector_client)

        features = [
            Feature(geometry=POINT, properties=dict(id='bar')),
            Feature(geometry=POINT, properties=dict(id='bar2'))
        ]

        modified_features = fc.add(features)

        vector_client.create_features.assert_called_once_with(
            'foo', [
                dict(
                    geometry=getattr(features[0].geometry, '__geo_interface__',
                                     features[0].geometry),
                    properties=features[0].properties),
                dict(
                    geometry=getattr(features[1].geometry, '__geo_interface__',
                                     features[1].geometry),
                    properties=features[1].properties),
            ])

        for f in modified_features:
            # the side_effect above uses properties.id instead of uuid
            self.assertEqual(f.id, f.properties.id)
Exemplo n.º 3
0
    def test_add_single(self, vector_client):
        vector_client = mock.MagicMock()
        fc = FeatureCollection("foo", vector_client=vector_client)

        feature = Feature(geometry=POINT, properties={})

        fc.add(feature)
        vector_client.create_features.assert_called_once_with(
            "foo",
            [
                dict(
                    geometry=getattr(feature.geometry, "__geo_interface__",
                                     feature.geometry),
                    properties=feature.properties,
                )
            ],
            fix_geometry="accept",
        )
Exemplo n.º 4
0
    def test_add_bulk_and_update_with_id(self, vector_client):
        def create_features(product_id, attributes, fix_geometry="accept"):
            return DotDict(data=[
                dict(id=attr["properties"]["id"], attributes=attr)
                for attr in attributes
            ])

        vector_client.create_features.side_effect = create_features

        fc = FeatureCollection("foo", vector_client=vector_client)

        features = [
            Feature(geometry=POINT, properties=dict(id="bar")),
            Feature(geometry=POINT, properties=dict(id="bar2")),
        ]

        modified_features = fc.add(features)

        vector_client.create_features.assert_called_once_with(
            "foo",
            [
                dict(
                    geometry=getattr(features[0].geometry, "__geo_interface__",
                                     features[0].geometry),
                    properties=features[0].properties,
                ),
                dict(
                    geometry=getattr(features[1].geometry, "__geo_interface__",
                                     features[1].geometry),
                    properties=features[1].properties,
                ),
            ],
            fix_geometry="accept",
        )

        for f in modified_features:
            # the side_effect above uses properties.id instead of uuid
            assert f.id == f.properties.id
Exemplo n.º 5
0
    geometry={
        "type": "Polygon",
        "coordinates": [
            [
                [-105.86975097656249, 36.94550173495345],
                [-104.930419921875, 36.94550173495345],
                [-104.930419921875, 37.70120736474139],
                [-105.86975097656249, 37.70120736474139],
                [-105.86975097656249, 36.94550173495345],
            ]
        ],
    },
    properties={"foo": "bar"},
)

fc.add([feature])

################################################
# Search for features in this product intersecting an aoi using
# :meth:`FeatureCollection.filter <descarteslabs.vectors.featurecollection.FeatureCollection.filter>`
# and :meth:`FeatureCollection.features <descarteslabs.vectors.featurecollection.FeatureCollection.features>`.

aoi = {
    "type": "Polygon",
    "coordinates": [
        [
            [-105.194091796875, 36.88181755936464],
            [-104.765625, 36.88181755936464],
            [-104.765625, 37.13404537126446],
            [-105.194091796875, 37.13404537126446],
            [-105.194091796875, 36.88181755936464],