Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import click
- import cligj
- from shapely.geometry import shape, mapping, MultiPolygon
- from shapely.affinity import translate
- @click.command()
- @click.pass_context
- @cligj.features_in_arg
- @cligj.sequence_opt
- def centroid(ctx, features, sequence):
- """Get Centroid."""
- for f in features:
- geom = shape(f['geometry'])
- if f["properties"]["RINGS_OK"] == 2:
- geom = MultiPolygon(
- [
- translate(g, xoff=360) if g.bounds[0] < 0 else g for g in geom
- ]
- )
- centroid = geom.centroid
- if centroid.x > 180:
- centroid = translate(centroid, xoff=-360)
- f['geometry'] = mapping(centroid)
- print(json.dumps(f))
- # centroid = geom.centroid
- # f['geometry'] = mapping(centroid)
- if __name__ == '__main__':
- centroid()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement