I am reading and writing a layer to an ESRI File GDB that contains text fields. Standard text fields are stored as objects by GeoPandas. When the GDB is read the text fields have an unlimited length (or 65536 to be exact). However, I want to write the file so it has a field width character limit of 255 or less.
I have tried several solutions such as:
gdf = gdf.convert_dtypes(convert_string=True)
gdf["text_col"] = gdf["text_col"].astype(str)
gdf["text_col"] = pd.Series(df["text_col"], dtype="S255")
The only solution so far that changed the field length is to convert the column to "S255" dtype. However this writes the column as a byte-string resulting in the addition of b'' in the column values, making it unsuitable for analysis.
So how can I write text columns using GeoPandas to an ESRI FileGDB layer with a dtype of char(255) (or similar) that is visible when inspecting the field metadata in QGIS or ArcGIS.
GeoPandas version: 1.0.1
Snippet to replicate.
import geopandas as gpd
from shapely.geometry import Point
data = {
'name': ['Location 1', 'Location 2', 'Location 3'],
'description': [
'This is a description for location 1.',
'This is a description for location 2.',
'This is a description for location 3.'
],
'geometry': [Point(4.895168, 52.370216), Point(4.904139, 52.367573), Point(4.899431, 52.379189)]
}
gdf = gpd.GeoDataFrame(data, crs="EPSG:4326")
gdf.to_file("test.gdb", driver='OpenFileGDB')