Guest User

Untitled

a guest
Feb 22nd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. from multiprocessing import Pool
  2. import sys
  3. import fiona
  4. from fiona.transform import transform_geom
  5. from shapely.geometry import mapping, shape
  6. import json
  7.  
  8. def reproject(f, srs_crs, dest_crs):
  9. f['geometry'] = transform_geom(srs_crs, dest_crs, f['geometry'],
  10. antimeridian_cutting=True,
  11. precision=-1)
  12. return f
  13.  
  14. def buffer(f, v):
  15. f['geometry'] = mapping(shape(f['geometry']).buffer(v))
  16. return f
  17.  
  18. class Process:
  19. def __init__(self, **kwargs):
  20. self.__dict__.update(kwargs)
  21. def __call__(self, f):
  22. return reproject(buffer(reproject(f, self.crs, 'EPSG:3857'), 1E+5), 'EPSG:3857', 'EPSG:4326')
  23.  
  24. if __name__ == '__main__':
  25. pool = Pool()
  26. with fiona.open(sys.argv[1], 'r') as source:
  27. p = Process(crs=source.crs)
  28. res = pool.map(p, source)
  29. print json.dumps({
  30. 'type': 'FeatureCollection',
  31. 'features': res
  32. })
Add Comment
Please, Sign In to add comment