Пример #1
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]
            with self.assertRaises(fiona.errors.GeometryTypeValidationError):
                featureIO.write_features(featuresToDisk, filename)
Пример #2
0
    def test_point(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), complete_test_data_2)

            featuresToDisk = [feature1, feature2]
            featureIO.write_features(featuresToDisk, filename)
            featuresFromDisk = featureIO.load_features(filename)
            self.FeaturesEqual(featuresFromDisk, featuresToDisk)
Пример #3
0
    def test_different_schema(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(LineString([(2, 2), (3, 3)]),
                               diff_schema_test_data)

            featuresToDisk = [feature1, feature2]
            with self.assertRaises(ValueError):
                featureIO.write_features(featuresToDisk, filename)
Пример #4
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]
            featureIO.write_features(featuresToDisk, filename)
            featuresFromDisk = featureIO.load_features(filename)
            self.assertEqual(featuresFromDisk, [])
Пример #5
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]
            featureIO.write_features(featuresToDisk, filename)
            featuresFromDisk = featureIO.load_features(filename)
            self.FeaturesEqual(featuresFromDisk, featuresToDisk)
Пример #6
0
    def test_different_schema_unconvertable_string(self):
        """Note that the string value is dropped and a default of 0 is used"""
        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(LineString([(2, 2), (3, 3)]),
                               diff_schema_unconvertable_string_test_data)

            featuresToDisk = [feature1, feature2]
            featureIO.write_features(featuresToDisk, filename)

            featuresFromDisk = featureIO.load_features(filename)

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

            self.assertNotEqual(featuresFromDisk[1].data["uniqueKey"], "NaN")
            self.assertEqual(featuresFromDisk[1].data["uniqueKey"], 0)
            self.FeaturesEqual(modifiedFeaturesFromDisk, featuresToDisk)
Пример #7
0
    def test_different_schema_convertable_float(self):
        """Note that the float is converted to an int"""
        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(LineString([(2, 2), (3, 3)]),
                               diff_schema_convertable_float_test_data)

            featuresToDisk = [feature1, feature2]
            featureIO.write_features(featuresToDisk, filename)

            featuresFromDisk = featureIO.load_features(filename)

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

            self.assertNotEqual(featuresFromDisk[1].data["uniqueKey"], 3.5)
            self.assertEqual(featuresFromDisk[1].data["uniqueKey"], 3)
            self.FeaturesEqual(modifiedFeaturesFromDisk, featuresToDisk)
Пример #8
0
    def test_different_schema_unconvertable_float(self):
        """Note that the NaN value is dropped,
		it seems like int_64(1<<64) is used
		i.e. -(2**63), the minimum 64 bit int value
		
		odd given that we map to int:16,
		TODO: maybe we should be mapping to int:64 instead"""
        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(LineString([(2, 2), (3, 3)]),
                               diff_schema_unconvertable_float_test_data)

            featuresToDisk = [feature1, feature2]
            featureIO.write_features(featuresToDisk, filename)

            featuresFromDisk = featureIO.load_features(filename)

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