Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support conversion of attribute layers #30

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions fgdb_to_gpkg/fgdb_to_gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import fiona
import geopandas as gpd
import pandas
import pyogrio
from tqdm import tqdm


Expand Down Expand Up @@ -75,7 +77,8 @@ def convert_layer(
:param layer_list: list of existing layers in the GeoPackage
:type layer_list: List[str]

:param kwargs: additional keyword arguments for geopandas.to_file()
:param kwargs: additional keyword arguments for geopandas.to_file(). Note that these
are not applied to attribute layers.
"""
if not overwrite and fc in layer_list:
warnings.warn(
Expand All @@ -84,7 +87,11 @@ def convert_layer(
return

gdf = gpd.read_file(fgdb_path, layer=fc)
gdf.to_file(gpkg_path, driver="GPKG", layer=fc, index=False, mode="a", **kwargs)
if isinstance(gdf, pandas.DataFrame):
# Handle attribute layer
pyogrio.write_dataframe(gdf, gpkg_path, layer=fc, driver="GPKG", append=True)
else:
gdf.to_file(gpkg_path, driver="GPKG", layer=fc, index=False, mode="a", **kwargs)


def fgdb_to_gpkg(
Expand Down
Loading
Loading