Skip to content

Extract by point

Extract data of raster image from points

Import package

import geopandas as gpd
from Godream.geobox import extract_by_point
from Godream.plotimg import overlay_map

Explore Input data

raster = 'D:/DGEO/data/S2_image3.tif'
points = 'D:/DGEO/data/ppoint.geojson'
output_vector = 'D:/DGEO/data/ppoint_1.geojson'
gdf = gpd.read_file(points)
gdf.head()
geometry
0 POINT (100.38786 13.99795)
1 POINT (100.42939 14.00995)
2 POINT (100.41725 14.03318)
3 POINT (100.38942 14.01469)
4 POINT (100.36727 14.02073)
# display input file on interative map
overlay_map(vector_file= [points], raster_file=[raster])

123

Extract data by points

extract_by_point(raster, points, output_vector)
geometry band_1 band_2 band_3 band_4
0 POINT (100.38786 13.99795) 569.0 956.0 1062.0 2796.0
1 POINT (100.42939 14.00995) 659.0 1018.0 1086.0 3080.0
2 POINT (100.41725 14.03318) 606.0 967.0 1078.0 3102.0
3 POINT (100.38942 14.01469) 641.0 988.0 1078.0 2954.0
4 POINT (100.36727 14.02073) 766.0 1047.0 1146.0 2454.0
5 POINT (100.37963 14.01217) 597.0 942.0 1075.0 3165.0
6 POINT (100.36129 13.99269) 703.0 1090.0 1126.0 3046.0
7 POINT (100.39729 13.97719) 771.0 1085.0 1174.0 2787.0
8 POINT (100.37916 13.96268) 635.0 973.0 1113.0 3142.0
9 POINT (100.37298 13.96574) 598.0 953.0 1077.0 2666.0

Output

# Read the vector 
gdf = gpd.read_file(output_vector)

gdf.head()
band_1 band_2 band_3 band_4 geometry
0 569.0 956.0 1062.0 2796.0 POINT (100.38786 13.99795)
1 659.0 1018.0 1086.0 3080.0 POINT (100.42939 14.00995)
2 606.0 967.0 1078.0 3102.0 POINT (100.41725 14.03318)
3 641.0 988.0 1078.0 2954.0 POINT (100.38942 14.01469)
4 766.0 1047.0 1146.0 2454.0 POINT (100.36727 14.02073)