Beispiel #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)
Beispiel #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)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #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]
            featureIO.write_features(featuresToDisk, filename)
            featuresFromDisk = featureIO.load_features(filename)
            self.assertEqual(featuresFromDisk, [])
Beispiel #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)
Beispiel #7
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)
Beispiel #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"]))