gee-community/geemap

Getting type error when loading data from postgis via geemap.gdf_to_ee()

bormy opened this issue · 3 comments

Environment Information

Please run the following code on your computer and share the output with us so that we can better debug your issue:

Wed Nov 15 16:52:29 2023 +07

OS | Darwin | CPU(s) | 8 | Machine | arm64
Architecture | 64bit | RAM | 8.0 GiB | Environment | Jupyter
File system | apfs
Python 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:12:31) [Clang 14.0.6 ]
geemap | 0.29.0 | ee | 0.1.374 | ipyleaflet | 0.17.4
folium | 0.14.0 | jupyterlab | 4.0.8 | notebook | 7.0.6
ipyevents | 2.0.1 | geopandas | 0.14.0 | localtileserver | 0.7.1

Description

I try to load data from postgis. the error occurs when calling gdf_to_ee()
Invalid field type <class 'datetime.date'>

What I Did

try:
aoi = geemap.gdf_to_ee(gdf)
jjfast = geemap.gdf_to_ee(df)
m.addLayer(aoi,{}, "Cambodia Boundary")
m.addLayer(jjfast,{},"Deforest Detections")
m.centerObject(aoi, 8)
m
except Exception as error:
print('E: {}'.format(error))
pass

The error message already indicates that the issue is invalid field type. Did you look into that?

If you want others to help, make sure you provide complete source code and datasets that can reproduce the issue.

The error message already indicates that the issue is invalid field type. Did you look into that?

If you want others to help, make sure you provide complete source code and datasets that can reproduce the issue.

Invalid field type <class 'datetime.date'>

the above is the error message caught by the exception. I am not sure whether it is because of my data or the datetime.date datatype is not supported. Whilst, fetching data from database has no issue. I will look into the geemap source code

After my investigation, the error is because of the date format used in postgres and geopendas GeoDataFrame does expect 'dd-MM-YYYY' by default. Whilst the date returned from PostGIS is 'YYYY-MM-dd' *(it is the default format used in postgresSQL Date datetype).

the suggest solutions:

  1. update default DateStyle in postgresSQL server
  2. use to_char([date_field], 'dd-MM-YYYY') in select query