Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import json
  2.  
  3. import click
  4. import cligj
  5.  
  6. from shapely.geometry import shape, mapping, MultiPolygon
  7. from shapely.affinity import translate
  8.  
  9.  
  10. @click.command()
  11. @click.pass_context
  12. @cligj.features_in_arg
  13. @cligj.sequence_opt
  14. def centroid(ctx, features, sequence):
  15. """Get Centroid."""
  16. for f in features:
  17. geom = shape(f['geometry'])
  18. if f["properties"]["RINGS_OK"] == 2:
  19. geom = MultiPolygon(
  20. [
  21. translate(g, xoff=360) if g.bounds[0] < 0 else g for g in geom
  22. ]
  23. )
  24. centroid = geom.centroid
  25. if centroid.x > 180:
  26. centroid = translate(centroid, xoff=-360)
  27. f['geometry'] = mapping(centroid)
  28. print(json.dumps(f))
  29.  
  30. # centroid = geom.centroid
  31. # f['geometry'] = mapping(centroid)
  32.  
  33.  
  34. if __name__ == '__main__':
  35. centroid()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement