def test_dump(): fp = io.StringIO() point = Point(1, 1) geojson1 = '{\n "type": "Point",\n "coordinates": [\n 1.0,\n 1.0\n ]\n}' geojson2 = '{\n "coordinates": [\n 1.0,\n 1.0\n ],\n "type": "Point"\n}' with fp: dump(point, fp, indent=1) assert fp.getvalue() == geojson1 or fp.getvalue() == geojson2
def main(args): numpy_pc = np.load(args.input) numpy_pc = numpy_pc.astype('f8') logging.info("Converting numpy point cloud to geometries") if numpy_pc.shape[1] == 4: with open(args.config) as f: config = json.load(f) geometries = get_geometries(numpy_pc, config['filtered_classes'], **config['np2geom']) with open(args.out, "w") as f: dump(geometries, f, indent=2) else: print( "Error! Numpy file does not have class information. Except shape to be (X, 4)" )
import json import sys import shapely_geojson from shapely.geometry import GeometryCollection, shape from shapely.ops import cascaded_union if __name__ == "__main__": with open(sys.argv[1]) as f: features = json.load(f)['features'] polygons = [shape(feature["geometry"]).buffer(10/111111.0) for feature in features] polygon = cascaded_union(polygons) with open(sys.argv[2], 'w') as f: shapely_geojson.dump(polygon, f)
def save_shapely(shape, fname, uid="", alg='polylidar'): feature = Feature(shape, properties={'uid': uid, 'alg': alg}) with open(fname, "w") as f: dump(feature, f, indent=2)