Last active
April 1, 2025 13:20
-
-
Save fralc/73a64f8384dcc7c6412a113286ed44d9 to your computer and use it in GitHub Desktop.
Geopandas `gdf.sample_points()` x sorting proof
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 numpy as np | |
| import matplotlib.pyplot as plt | |
| import pandas as pd | |
| from shapely.geometry import Polygon | |
| polygon = Polygon(((0, 0), (0, 1), (5, 1), (5, 0))) | |
| polygon_gdf = gpd.GeoDataFrame({'geometry': [polygon]}, geometry='geometry') | |
| points = polygon_gdf.sample_points(size=1000) | |
| # ax = polygon_gdf.boundary.plot() | |
| # points.plot(ax=ax, alpha=.5) | |
| points = points.explode().reset_index() | |
| # points = points.explode().sample(frac=1).reset_index() # sampling tackle the x-along issue | |
| points['sorter'] = np.arange(0, points.shape[0]) | |
| ax1 = points.plot(column='sorter', cmap='gist_ncar') | |
| # ax2 = points.geometry.x.plot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment