Skip to content

Instantly share code, notes, and snippets.

@vincentsarago
Created September 6, 2019 03:17
Show Gist options
  • Save vincentsarago/ae7f6a8e85f341ae335855b44f79b4d3 to your computer and use it in GitHub Desktop.
Save vincentsarago/ae7f6a8e85f341ae335855b44f79b4d3 to your computer and use it in GitHub Desktop.
import json
import click
import cligj
from shapely.geometry import shape, mapping
@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'])
f['geometry'] = mapping(geom.centroid)
print(json.dumps(f))
if __name__ == '__main__':
centroid()
@vincentsarago
Copy link
Author

ogr2ogr -f GeoJSON -t_srs EPSG:4326 conus_ard_grid_wgs84.geojson conus_ard_grid.shp
fio cat conus_ard_grid_wgs84.geojson | python centroid_ard.py | fio collect > conus_ard_grid_centroid.geojson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment