我有一个脚本,它从 oracle 获取数据,将数据放入 pandas.DataFrame -> geopandas df 并导出到 geoJSON:
import cx_Oracle
import pandas as pd
import geopandas as gpd
from shapely.geometry import LineString
from shapely import wkb
from sqlalchemy import *
con = cx_Oracle.connect('argument/user@hoooooost/service_n')
#c = con.cursor()
forty_df = pd.read_sql('select * from schema.table where column = 40', con)
df = pd.DataFrame(forty_df)
gdf = gpd.GeoDataFrame(
df, geometry=gpd.points_from_xy(df.LON, df.LAT))
gdf.to_file("geocoder/forty.geojson", driver='GeoJSON') #problem line
#print(gdf.T.dtypes)
当我尝试运行脚本时,终端抛出:文件“
/home/user/raster_dir/gaspsenv/lib/python3.7/site-packages/geopandas/geodataframe.py", line 515, in to_file
to_file(self, filename, driver, schema, **kwargs)
File "/home/user/raster_dir/gaspsenv/lib/python3.7/site-packages/geopandas/io/file.py", line 130, in to_file
colxn.writerecords(df.iterfeatures())
File "/home/user/raster_dir/gaspsenv/lib/python3.7/site-packages/fiona/collection.py", line 342, in writerecords
self.session.writerecs(records, self)
File "fiona/ogrext.pyx", line 1195, in fiona.ogrext.WritingSession.writerecs
File "fiona/ogrext.pyx", line 412, in fiona.ogrext.OGRFeatureBuilder.build
ValueError: Invalid field type <class 'cx_Oracle.LOB'>
我发现它是 dtype 项目,因为我的所有列都是对象,而不是整数/字符串等。
我该怎么做才能修复它并使其正确导出?