Feature data (geometries and attributes)
import ee
import geemap# Trigger the authentication flow.
ee.Authenticate()
# Initialize the library.
ee.Initialize(project='your-gee-project-id-here') Output
Creating geometries and attaching attributes¶
# Define a point (For example, a location in the Philippines)
point_geometry = ee.Geometry.Point([124.615, 8.445])
# Create a Feature by attaching data (like crop type) to that geometry
farm_feature = ee.Feature(point_geometry, {
'crop_type': 'Calamansi',
'farmer_name': 'Juan Dela Cruz',
'area_hectares': 2.5
})
# Request the data dictionary back from the server to view it
feature_data = farm_feature.getInfo()
print("Farm Feature Data:")
print(feature_data)Creating a Feature Collection from existing data¶
# Pure EE approach
import ee
import json
data_polygons = 'data/psa-geoshape-odk-020426.geojson'
with open(data_polygons) as f:
geojson = json.load(f)
farm_polygons = ee.FeatureCollection(geojson)# Easier geemap approach
import geemap
import pandas as pd
import geopandas as gpd
data_points = 'data/psa_geopts_odk_021026-edited.csv'
df = pd.read_csv(data_points)
gdf = gpd.GeoDataFrame(
df, geometry=gpd.points_from_xy(df["crop_location-Longitude"], df["crop_location-Latitude"]), crs="EPSG:4326"
)
geemap_farm_points = geemap.geopandas_to_ee(gdf)👨💻 TRY IT OUT
Try to load the psa_geopts_odk_021026-original.csv file.
⚠️ CAUTION
What’s wrong with the psa_geopts_odk_021026-original.csv file? What’s the solution?
# Write your solution hereShow your features on a map¶
m = geemap.Map()
m.add_layer(farm_feature, name="Farm Feature")
m.add_layer(farm_polygons, name="Farm Polygons")
m.add_layer(geemap_farm_points, name="Farm Points")
m.centerObject(point_geometry, 10)
m