11import os
2+ from typing import Tuple
23
34from loguru import logger
45
56from pybind11_geobuf import rapidjson # noqa
67from pybind11_geobuf import Decoder , Encoder # noqa
8+ from pybind11_geobuf import is_subset_of as is_subset_of_impl # noqa
79from pybind11_geobuf import normalize_json as normalize_json_impl # noqa
810from pybind11_geobuf import pbf_decode as pbf_decode_impl # noqa
911
@@ -90,6 +92,10 @@ def normalize_json(
9092 sort_keys : bool = True ,
9193 precision : int = - 1 ,
9294 only_xy : bool = False ,
95+ denoise_double_0 : bool = True ,
96+ strip_geometry_z_0 : bool = True ,
97+ round_geojson_non_geometry : int = 3 ,
98+ round_geojson_geometry : Tuple [int , int , int ] = (8 , 8 , 3 ),
9399):
94100 logger .info (
95101 f"normalize_json { input_path } ({ __filesize (input_path ):,} bytes)"
@@ -116,6 +122,10 @@ def normalize_json(
116122 output_path ,
117123 indent = indent ,
118124 sort_keys = sort_keys ,
125+ denoise_double_0 = denoise_double_0 ,
126+ strip_geometry_z_0 = strip_geometry_z_0 ,
127+ round_geojson_non_geometry = round_geojson_non_geometry ,
128+ round_geojson_geometry = round_geojson_geometry ,
119129 ), f"failed to normalize json to { output_path } "
120130 logger .info (f"wrote to { output_path } ({ __filesize (output_path ):,} bytes)" )
121131
@@ -155,12 +165,6 @@ def round_trip(
155165 json2pb_use_python : bool = False ,
156166 pb2json_use_python : bool = False ,
157167):
158- """
159- _0.json
160- _1.pbf
161- _2.pbf.txt
162- _3.json
163- """
164168 assert path .endswith ((".json" , ".geojson" )) and os .path .isfile (path )
165169 path = os .path .abspath (path )
166170 output_dir = os .path .abspath (output_dir or os .path .dirname (path ))
@@ -200,13 +204,18 @@ def round_trip(
200204 logger .info (f"wrote to { opath } " )
201205
202206
207+ def is_subset_of (path1 : str , path2 : str ):
208+ assert is_subset_of_impl (path1 , path2 )
209+
210+
203211if __name__ == "__main__" :
204212 import fire
205213
206214 fire .core .Display = lambda lines , out : print (* lines , file = out )
207215 fire .Fire (
208216 {
209217 "geobuf2json" : geobuf2json ,
218+ "is_subset_of" : is_subset_of ,
210219 "json2geobuf" : json2geobuf ,
211220 "normalize_geobuf" : normalize_geobuf ,
212221 "normalize_json" : normalize_json ,
0 commit comments