Skip to content

Instantly share code, notes, and snippets.

@dersteppenwolf
Last active June 28, 2019 14:31
Show Gist options
  • Save dersteppenwolf/02e62bfb597f7c0db069ff054dd848b4 to your computer and use it in GitHub Desktop.
Save dersteppenwolf/02e62bfb597f7c0db069ff054dd848b4 to your computer and use it in GitHub Desktop.
Conversión de Filegeodatabase a Geopackage utilizando Python y Arcpy
#-*- coding: UTF-8 -*-
import logging, os
import arcpy
from arcpy import env
################################################################################
################################################################################
if __name__ == "__main__":
logging.info("************************************************************************************************")
logging.info("Inicio Programa")
logging.debug("export_fgdb_to_geopackage ")
################################################################################
## Parametros generales
################################################################################
output_folder = "G:\\temp\\"
features = []
fgdb = 'G:\\data\\my_data.gdb'
output_gpkg = "my_data.gpkg"
logging.debug("** fgdb:" + fgdb)
logging.debug("** output_folder:" + output_folder)
# Execute CreateSQLiteDatabase
output_gpkg = os.path.join(output_folder, output_gpkg)
if os.path.isfile(output_gpkg):
os.remove(output_gpkg)
arcpy.CreateSQLiteDatabase_management(output_gpkg, 'GEOPACKAGE_1.2')
features = []
env.workspace = fgdb
# List all feature classes in feature datasets
datasets = arcpy.ListDatasets("","featuredataset")
if datasets:
for fds in datasets:
logging.debug("***********************************")
logging.debug("Dataset:"+fds)
featureclasses = arcpy.ListFeatureClasses("*","",fds)
for f in featureclasses:
logging.debug("feature:"+f)
features.append( fgdb + '\\'+fds + '\\' + f )
logging.debug("***********************************")
# features outside datasets
featureclasses = arcpy.ListFeatureClasses()
if featureclasses:
for f in featureclasses:
logging.debug("feature:"+f)
features.append( fgdb + '/' + f )
logging.debug( "Convirtiendo %i feature classes a geopackage" % len(features))
logging.debug( str(features) )
for feature in features:
logging.debug("Convirtiendo a Geopackage : feature "+ feature )
arcpy.FeatureClassToGeodatabase_conversion(feature, output_gpkg)
logging.info("Fin Programa")
logging.info("************************************************************************************************")
################################################################################
################################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment