Created
September 6, 2019 03:13
-
-
Save vincentsarago/09f84c1e9f4e2154a919692764595306 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Author
vincentsarago
commented
Sep 6, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment