Exemple #1
0
    def test_multi_polygon(self):
        with tempfile.TemporaryDirectory("-allfed-spatial-test") as tempdir:
            filename = os.path.join(tempdir, "testfile.file")

            feature1 = Feature(
                MultiPolygon([
                    Polygon([(0, 0), (1, 1), (0, 1)]),
                    Polygon([(0, 0), (1, 1), (1, 0)])
                ]), complete_test_data_1)
            feature2 = Feature(
                MultiPolygon([
                    Polygon([(1, 1), (2, 2), (1, 2)]),
                    Polygon([(1, 1), (2, 2), (2, 1)])
                ]), complete_test_data_2)

            featuresToDisk = [feature1, feature2]

            geoms = [f.geom for f in featuresToDisk]
            data = [f.data for f in featuresToDisk]

            schema = featureIO.get_feature_schema(featuresToDisk[0])

            featureIO.write_shape(geoms, data, schema, filename)
            featuresFromDisk = featureIO.load_features(filename)
            self.FeaturesEqual(featuresFromDisk, featuresToDisk)
Exemple #2
0
    def test_bad_schema(self):
        with tempfile.TemporaryDirectory("-allfed-spatial-test") as tempdir:
            filename = os.path.join(tempdir, "testfile.file")

            feature = Feature(Point(0, 0), complete_test_data_1)

            featuresToDisk = [feature]

            geoms = [f.geom for f in featuresToDisk]
            data = [f.data for f in featuresToDisk]

            schema = {"This is": "not a schema"}

            with self.assertRaises(Exception):
                featureIO.write_shape(geoms, data, schema, filename)
Exemple #3
0
    def test_data_mismatch(self):
        with tempfile.TemporaryDirectory("-allfed-spatial-test") as tempdir:
            filename = os.path.join(tempdir, "testfile.file")

            feature1 = Feature(Point(0, 0), complete_test_data_1)
            feature2 = Feature(Point(1, 1), diff_schema_test_data)

            featuresToDisk = [feature1, feature2]

            geoms = [f.geom for f in featuresToDisk]
            data = [f.data for f in featuresToDisk]

            schema = featureIO.get_feature_schema(featuresToDisk[0])

            with self.assertRaises(ValueError):
                featureIO.write_shape(geoms, data, schema, filename)
Exemple #4
0
    def test_mixed_geom(self):
        with tempfile.TemporaryDirectory("-allfed-spatial-test") as tempdir:
            filename = os.path.join(tempdir, "testfile.file")

            feature1 = Feature(LineString([(0, 0), (1, 1)]),
                               complete_test_data_1)
            feature2 = Feature(Point(20, 20), complete_test_data_2)

            featuresToDisk = [feature1, feature2]

            geoms = [f.geom for f in featuresToDisk]
            data = [f.data for f in featuresToDisk]

            schema = featureIO.get_feature_schema(featuresToDisk[0])

            with self.assertRaises(fiona.errors.GeometryTypeValidationError):
                featureIO.write_shape(geoms, data, schema, filename)
Exemple #5
0
    def test_other_geom(self):
        """Other geometry is silently lost, no exceptions stop the process"""
        with tempfile.TemporaryDirectory("-allfed-spatial-test") as tempdir:
            filename = os.path.join(tempdir, "testfile.file")

            feature1 = Feature(LinearRing([(0, 0), (1, 1), (0, 1)]),
                               complete_test_data_1)

            featuresToDisk = [feature1]

            geoms = [f.geom for f in featuresToDisk]
            data = [f.data for f in featuresToDisk]

            schema = featureIO.get_feature_schema(featuresToDisk[0])

            featureIO.write_shape(geoms, data, schema, filename)
            featuresFromDisk = featureIO.load_features(filename)
            self.assertEqual(featuresFromDisk, [])
Exemple #6
0
    def test_data_unconvertable(self):
        with tempfile.TemporaryDirectory("-allfed-spatial-test") as tempdir:
            filename = os.path.join(tempdir, "testfile.file")

            feature1 = Feature(Point(0, 0), complete_test_data_1)
            feature2 = Feature(Point(1, 1),
                               diff_schema_unconvertable_float_test_data)

            featuresToDisk = [feature1, feature2]

            geoms = [f.geom for f in featuresToDisk]
            data = [f.data for f in featuresToDisk]

            schema = featureIO.get_feature_schema(featuresToDisk[0])

            featureIO.write_shape(geoms, data, schema, filename)
            featuresFromDisk = featureIO.load_features(filename)

            modifiedFeaturesFromDisk = featureIO.load_features(filename)
            modifiedFeaturesFromDisk[1].data["uniqueKey"] = math.nan

            self.assertFalse(math.isnan(featuresFromDisk[1].data["uniqueKey"]))
            self.assertEqual(featuresFromDisk[1].data["uniqueKey"], -(2**63))
            self.FeaturesEqual(modifiedFeaturesFromDisk, featuresToDisk)