コード例 #1
0
    def test_format_feature(self):
        features = process.read_feature(self.ds_file_path)
        name, feature = features.next()

        assert feature is not None

        level = 1
        feature_json = json.loads(feature.ExportToJson())
        result = process.format_feature(feature, self.tolerance, level)

        assert result['properties']['osm_id'] == feature_json['id']
        assert result['properties']['name'] == feature_json['properties'].get(
            'name')
        assert result['properties']['name_en'] == feature_json[
            'properties'].get('name:en')
        assert result['properties']['iso3166'] == feature_json[
            'properties'].get('ISO3166-1')
        assert result['properties']['admin_level'] == level

        assert result['properties']['is_in_country'] is None
        assert result['properties']['parent_id'] is None
        assert result['properties']['is_simplified'] is None

        assert result['geometry'].ExportToJson() == feature.GetGeometryRef(
        ).ExportToJson()
        assert result['simplified_geometry'].ExportToJson(
        ) == process.simplify_geom(feature, self.tolerance).ExportToJson()
コード例 #2
0
    def test_format_feature(self):
        features = process.read_feature(self.ds_file_path)
        name, feature = features.next()

        assert feature is not None

        level = 1
        feature_json = json.loads(feature.ExportToJson())
        result = process.format_feature(feature, self.tolerance, level)

        assert result["properties"]["osm_id"] == feature_json["id"]
        assert result["properties"]["name"] == feature_json["properties"].get("name")
        assert result["properties"]["name_en"] == feature_json["properties"].get("name:en")
        assert result["properties"]["iso3166"] == feature_json["properties"].get("ISO3166-1")
        assert result["properties"]["admin_level"] == level

        assert result["properties"]["is_in_country"] is None
        assert result["properties"]["parent_id"] is None
        assert result["properties"]["is_simplified"] is None

        assert result["geometry"].ExportToJson() == feature.GetGeometryRef().ExportToJson()
        assert (
            result["simplified_geometry"].ExportToJson()
            == process.simplify_geom(feature, self.tolerance).ExportToJson()
        )
コード例 #3
0
    def test_simplify_geom(self):
        features = process.read_feature(self.ds_file_path_2)
        name, feature = features.next()

        assert feature is not None
        result = process.simplify_geom(feature, self.tolerance).ExportToJson()
        expected = feature.GetGeometryRef().SimplifyPreserveTopology(self.tolerance).ExportToJson()
        assert result == expected
コード例 #4
0
    def test_simplify_geom(self):
        features = process.read_feature(self.ds_file_path_2)
        name, feature = features.next()

        assert feature is not None
        result = process.simplify_geom(feature, self.tolerance).ExportToJson()
        expected = feature.GetGeometryRef().SimplifyPreserveTopology(
            self.tolerance).ExportToJson()
        assert result == expected
コード例 #5
0
    def test_intersects_spatially(self):
        features = process.read_feature(self.output_ancestor_file_path)
        name, parent_feature = features.next()

        assert parent_feature is not None

        child_features = process.read_feature(self.ds_file_path_2)
        name1, child_feature1 = child_features.next()
        name2, child_feature2 = child_features.next()

        feature_id = 0
        child_geom1 = child_feature1.GetGeometryRef()
        child_geom2 = child_feature2.GetGeometryRef()
        parent_geom = parent_feature.GetGeometryRef()

        ancestor_id = json.loads(parent_feature.ExportToJson()).get("properties").get("osm_id")

        assert process.intersects_spatially(parent_feature, child_geom1, feature_id) == ancestor_id
        assert process.intersects_spatially(child_feature1, child_geom2, feature_id) is None
コード例 #6
0
    def test_format_feature_read_iso3166_2(self):
        features = process.read_feature(self.ds_file_path_2)
        name, feature = features.next()

        assert feature is not None

        level = 1
        feature_json = json.loads(feature.ExportToJson())
        result = process.format_feature(feature, self.tolerance, level)

        assert result["properties"]["iso3166"] == feature_json["properties"].get("ISO3166-2")
コード例 #7
0
    def test_get_ancestor(self):
        ancestor = None
        child_features = process.read_feature(self.ds_file_path_2)
        name1, child_feature1 = child_features.next()

        data_source = ogr.Open(self.output_ancestor_file_path)
        if data_source:
            lyr = data_source.GetLayer(0)
            if lyr:
                ancestor = process.get_ancestor(lyr, child_feature1.GetGeometryRef())

        assert ancestor is not None
コード例 #8
0
    def test_format_feature_read_iso3166_2(self):
        features = process.read_feature(self.ds_file_path_2)
        name, feature = features.next()

        assert feature is not None

        level = 1
        feature_json = json.loads(feature.ExportToJson())
        result = process.format_feature(feature, self.tolerance, level)

        assert result['properties']['iso3166'] == feature_json[
            'properties'].get('ISO3166-2')
コード例 #9
0
    def test_get_ancestor(self):
        ancestor = None
        child_features = process.read_feature(self.ds_file_path_2)
        name1, child_feature1 = child_features.next()

        data_source = ogr.Open(self.output_ancestor_file_path)
        if data_source:
            lyr = data_source.GetLayer(0)
            if lyr:
                ancestor = process.get_ancestor(
                    lyr, child_feature1.GetGeometryRef())

        assert ancestor is not None
コード例 #10
0
    def test_intersects_spatially(self):
        features = process.read_feature(self.output_ancestor_file_path)
        name, parent_feature = features.next()

        assert parent_feature is not None

        child_features = process.read_feature(self.ds_file_path_2)
        name1, child_feature1 = child_features.next()
        name2, child_feature2 = child_features.next()

        feature_id = 0
        child_geom1 = child_feature1.GetGeometryRef()
        child_geom2 = child_feature2.GetGeometryRef()
        parent_geom = parent_feature.GetGeometryRef()

        ancestor_id = json.loads(
            parent_feature.ExportToJson()).get('properties').get('osm_id')

        assert process.intersects_spatially(parent_feature, child_geom1,
                                            feature_id) == ancestor_id
        assert process.intersects_spatially(child_feature1, child_geom2,
                                            feature_id) is None
コード例 #11
0
    def test_parse_features(self):
        level = 1
        country_id = 192830
        result = process.parse_features(
            self.ds_file_path_2, self.output_ancestor_file_path, self.tolerance, level, country_id
        )

        collection, simplified_collection = result.next()
        name, expected_ancestor = process.read_feature(self.output_ancestor_file_path).next()
        expected_ancestor_json = json.loads(expected_ancestor.ExportToJson())

        first_feature = collection["features"][0]
        assert first_feature["properties"]["is_simplified"] is None
        assert first_feature["properties"]["parent_id"] == expected_ancestor_json["properties"]["osm_id"]

        first_simplified_feature = simplified_collection["features"][0]
        assert first_simplified_feature["properties"]["is_simplified"] is True
        assert first_simplified_feature["properties"]["parent_id"] == expected_ancestor_json["properties"]["osm_id"]
コード例 #12
0
    def test_parse_features(self):
        level = 1
        country_id = 192830
        result = process.parse_features(self.ds_file_path_2,
                                        self.output_ancestor_file_path,
                                        self.tolerance, level, country_id)

        collection, simplified_collection = result.next()
        name, expected_ancestor = process.read_feature(
            self.output_ancestor_file_path).next()
        expected_ancestor_json = json.loads(expected_ancestor.ExportToJson())

        first_feature = collection['features'][0]
        assert first_feature['properties']['is_simplified'] is None
        assert first_feature['properties'][
            'parent_id'] == expected_ancestor_json['properties']['osm_id']

        first_simplified_feature = simplified_collection['features'][0]
        assert first_simplified_feature['properties']['is_simplified'] is True
        assert first_simplified_feature['properties'][
            'parent_id'] == expected_ancestor_json['properties']['osm_id']
コード例 #13
0
 def test_read_feature(self):
     features = process.read_feature(self.ds_file_path)
     assert features is not None
コード例 #14
0
 def test_read_feature(self):
     features = process.read_feature(self.ds_file_path)
     assert features is not None