1

I am new to code and using Earth Engine Python API. I converted a shapefile to a GeoJSON. I need to convert my geojson file to a feature collection and upload it into my Google Earth Engine repository. I am using this code (check picture), however I get an error that says

EEException: Invalid GeoJSON geometry.

I then use a GeoJSON online validator tool, and it seems like my file is valid and the geometry type is a point. My GeoJSON is a feature collection with more than 3000 points. How can I overcome this? I added a block with my code, and screenshots of the GeoJSON file.

Code

# Specify the Google Drive file ID of the shapefile
file_id = '1iA9L6tn0dwVlABPngFAgjRxd8xXET1c4'
file_path = '/content/drive/My Drive/Colab Notebooks/Data/TrainingSet_SabieCroc/Training_setSc.shp'
url = f'https://drive.google.com/uc?id={file_id}'

# Read the shapefile into a GeoDataFrame
training_data = gpd.read_file(file_path)

#print (training_data)

# Convert the GeoDataFrame to GeoJSON and save it
geojson_path = '/content/drive/My Drive/Colab Notebooks/Data/TrainingSet_SabieCroc/Training_setSc.geojson'
training_data.to_file(geojson_path, driver='GeoJSON')

# Read the GeoJSON file as a dictionary
with open(geojson_path, 'r') as f:
    geojson_data = json.load(f)

# Convert the GeoJSON file to a feature collection
training_set= ee.FeatureCollection(geojson_data)

#Specify the asset ID where you want to upload the feature collection
#asset_id = 'projects/thandeka-skosana/assets/training_set'

# Export the feature collection to an Earth Engine asset
#export_task = ee.batch.Export.table.toAsset(
    #collection=training_set,
    #description='Export Training Set',
    #assetId=asset_id
#)

# Start the export task
#export_task.start()

snapshot of geojson

geojson geometry

3
  • 1
    Please put code and data in your Question as text, not screenshots. You don't want to require those who want to help you to retype all your code and data. Commented Feb 15, 2024 at 16:24
  • It looks like your points have Z coordinates, but ee.Geometry.Point only supports X and Y. You'll need to remove the Z coordinates from the GeoDataFrame before turning it into a FeatureCollection. Commented Feb 15, 2024 at 17:16
  • @AaronZuspan I did remove the Z coordinates but it still didn't work. Thanks for trying to help. Commented Feb 21, 2024 at 11:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.