Skip to content

Commit

Permalink
Merge pull request #30 from brandones/attribute-layers
Browse files Browse the repository at this point in the history
Support conversion of attribute layers
  • Loading branch information
philiporlando authored Nov 23, 2024
2 parents cf0b7d0 + cf7fb11 commit 321c480
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 63 deletions.
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

0 comments on commit 321c480

Please sign in to comment.