Created
July 20, 2020 20:43
-
-
Save mauforonda/7fee8d4e17efe53e23f29f415a8147af to your computer and use it in GitHub Desktop.
simplificar polígonos
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 geopandas as gpd | |
| import pandas as pd | |
| from shapely.geometry import shape | |
| def poligoncitos(input_csv, output_geojson, tolerance): | |
| ''' | |
| input_csv es el csv que exportas de flourish | |
| output_geojson es el resultado que puedes subir a flourish | |
| tolerance es un decimal que indica cuánto quieres simplificar los polígonos, un valor entre 0.001 y 0.01 | |
| ''' | |
| df = pd.read_csv(input_csv) | |
| df['geometry'] = df['geometry'].apply(lambda x: shape(eval(x))) | |
| crs = {'init': 'epsg:4326'} | |
| gdf = gpd.GeoDataFrame(df, crs=crs).set_geometry('geometry') | |
| gdf['geometry'] = gdf['geometry'].simplify(tolerance=tolerance) | |
| gdf.to_file(output_geojson, driver='GeoJSON') | |
| # ejemplo: | |
| # poligoncitos('Regions.1595273242088.csv', 'mapafeliz.geojson', 0.01) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment