Replies: 2 comments 2 replies
-
Good idea. The Using some of the built-in datafrom geowombat.data import l8_224078_20200518_polygons, l8_224078_20200518_B4
import geowombat as gw
import geopandas as gpd The polygonsThese will be converted to points at the native cell resolution. If gpd.read_file(l8_224078_20200518_polygons).head()
name geometry
0 water POLYGON ((737544.502 -2795232.772, 737544.502 ...
1 crop POLYGON ((742517.658 -2798160.232, 743046.717 ...
2 tree POLYGON ((742435.360 -2801875.403, 742458.874 ...
3 developed POLYGON ((738903.667 -2811573.845, 738926.586 ... The extract functionThe with gw.open(l8_224078_20200518_B4) as src:
df = gw.extract(src, l8_224078_20200518_polygons)
print(df.head())
id point geometry name 1
0 0 0 POINT (737535.000 -2795205.000) water 6283
1 0 1 POINT (737565.000 -2795205.000) water 6294
2 0 2 POINT (737595.000 -2795205.000) water 6295
3 0 3 POINT (737625.000 -2795205.000) water 6284
4 0 4 POINT (737655.000 -2795205.000) water 6266 |
Beta Was this translation helpful? Give feedback.
-
Ok great. Thanks. Oddly the index didn't match my polygon index, odd...
I'll play around some more.
…On Tue, Feb 2, 2021 at 8:19 PM Jordan ***@***.***> wrote:
Following up on the previous comment...
The id column should be a column of integers. If id_column is specified
and the column has strings, extract() should fail. If id_column is not
specified (the default is id_column='id') and the column doesn't exist,
it will be created from the index values by:
if id_column not in df.columns.tolist():
df.loc[:, id_column] = df.index.values
If you want your own unique ids for each polygon, you could do:
from geowombat.data import l8_224078_20200518_polygonsimport geopandas as gpdfrom sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
df_poly = gpd.read_file(l8_224078_20200518_polygons)df_poly['unique'] = le.fit_transform(df_poly['name'])
gw.extract(src, df_poly, id_column='unique')
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#66 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABHR6VE4R7CXYUY4ONE67I3S5CQBPANCNFSM4W63CTOA>
.
|
Beta Was this translation helpful? Give feedback.
-
Running gw.extract with polygons the returned dataframe has
id | point | geometry | index
Just wondering how these are generated. None seems related to the polygon index. Maybe worth adding to docs?
Beta Was this translation helpful? Give feedback.
All reactions