Beispiel #1
0
 def test_wrong_driver(self):
     """Verify failure when a bad driver string is used."""
     from pygeoprocessing.testing import create_vector_on_disk
     from pygeoprocessing.testing.sampledata import SRS_WILLAMETTE
     filename = os.path.join(self.workspace, 'foo')
     with self.assertRaises(AssertionError):
         create_vector_on_disk([], SRS_WILLAMETTE.projection,
                               vector_format='foobar', filename=filename)
Beispiel #2
0
 def test_wrong_field_type(self):
     """Verify failure when a bad field type string is used."""
     from pygeoprocessing.testing import create_vector_on_disk
     from pygeoprocessing.testing.sampledata import SRS_WILLAMETTE
     polygons = []
     fields = {'foo': 'bar'}
     filename = os.path.join(self.workspace, 'foo')
     with self.assertRaises(AssertionError):
         create_vector_on_disk(polygons, SRS_WILLAMETTE.projection, fields,
                               filename=filename)
Beispiel #3
0
 def test_mismatched_geoms_attrs(self):
     """Verify a crash when an attribute is missing from a field."""
     from pygeoprocessing.testing import create_vector_on_disk
     from pygeoprocessing.testing.sampledata import SRS_COLOMBIA
     polygons = [
         Polygon([(0, 0), (1, 0), (0.5, 1), (0, 0)]),
     ]
     fields = {'foo': 'int'}
     attrs = []
     filename = os.path.join(self.workspace, 'foo')
     with self.assertRaises(AssertionError):
         create_vector_on_disk(polygons, SRS_COLOMBIA.projection, fields,
                               attrs, filename=filename)
Beispiel #4
0
    def test_autogen_filename_geojson(self):
        """Verify that vectors can be created at a tempfile."""
        from pygeoprocessing.testing import create_vector_on_disk
        from pygeoprocessing.testing.sampledata import SRS_COLOMBIA

        polygons = [
            Polygon([(0, 0), (1, 0), (0.5, 1), (0, 0)]),
        ]
        try:
            # Have the new vector be created in the workspace
            old_tempdir = tempfile.tempdir
            tempfile.tempdir = self.workspace
            create_vector_on_disk(polygons, SRS_COLOMBIA.projection)
        finally:
            tempfile.tempdir = old_tempdir
Beispiel #5
0
    def test_basic_vector_creation(self):
        """Verify we can create a vector with basic configuration options."""
        from pygeoprocessing.testing import create_vector_on_disk
        from pygeoprocessing.testing.sampledata import SRS_COLOMBIA

        polygons = [
            Polygon([(0, 0), (1, 0), (0.5, 1), (0, 0)]),
        ]
        filename = os.path.join(self.workspace, 'foo')
        create_vector_on_disk(polygons, SRS_COLOMBIA.projection,
                              filename=filename)

        vector = ogr.Open(filename)
        layer = vector.GetLayer()
        features = layer.GetFeatureCount()
        self.assertEqual(features, 1)
 def create_vector(*args, **kwargs):
     from pygeoprocessing.testing import create_vector_on_disk
     from pygeoprocessing.testing.sampledata import SRS_WILLAMETTE
     defaults = {
         'geometries': [Point(0, 0)],
         'projection': SRS_WILLAMETTE.projection,
     }
     defaults.update(kwargs)
     return create_vector_on_disk(*args, **defaults)