0

I am new to geospatial data analysis, and I would also use just free and open-source Python packages to work with.

Now I try to create geodatabase (.gdb), but I can not find any appropriate Python package to do so, however there is some Python package to read .gdb files such as GDAL and Fiona as explained in this question but I am not sure (and can not find) any appropriate way to create a geodatabase (from scratch) using these packages.

Now my main questions are

  1. Except ArcGIS (and ArcPy) is there any other package to create a geodatabase?
  2. If the answer to question one is "YES", how can I create a geodatabase in Python?
Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Apr 12, 2024 at 11:15
6
  • 4
    The GDAL driver is read/write gdal.org/drivers/vector/openfilegdb.html. Commented Apr 12, 2024 at 11:35
  • 1
    "File geodatabase" isn't a file, it's a directory with scores to thousands of files. Creating a file geodatabase is trivial, and just gets you an empty container. Commented Apr 12, 2024 at 11:51
  • You're right, geodatabase is a directory, I will also edit it in my question text. But my main question is about creating a geodatabase whose content is some CSV files, and raster files together with point and polygon shape files. Commented Apr 12, 2024 at 12:03
  • The raster access with GDAL is read-only gdal.org/drivers/raster/openfilegdb.html#raster-openfilegdb. Are you forced to use some special ESRI tools, or could you just forget filegeodatabase and use free and open format like GeoPackage instead? Commented Apr 12, 2024 at 12:23
  • 1
    If the real question is about populating tables in the created file geodatabase (feature classes and rasters), then that should be the focus of the Question. Note that neither CSV files nor raster files are permitted in a FGDB -- the act of loading them changes the data into tables (which are only readable with tools that are file geodatabase aware, and even the Esri FGBD DLL doesn't support rasters). One exception is mosaic datasets, which reference the GeoTIFFs on disk where they reside. Commented Apr 12, 2024 at 15:39

2 Answers 2

2

I dont know about raster support, but you can create a file geodatabase by writing any table to it:

import geopandas as gpd
df = gpd.GeoDataFrame(geometry=gpd.points_from_xy(x=[1], y=[1]), crs=4326)
df.to_file(filename=r"C:\GIS\GIStest\a_new_database.gdb", layer="temptable", driver="OpenFileGDB")

Then you'll have to delete the table created.

answered Apr 12, 2024 at 13:10
0

If using gdal>=3.11, you can create gdb vector files (raster support is RO):

(v_django4_38) marcos@acacia:~$ ogr2ogr -of OpenFileGDB xx.gdb /usr/share/magics/10m/ne_10m_admin_1_states_provinces_lines.shp 
(v_django4_38) marcos@acacia:~$ ll xx.gdb
total 5344
drwxr-xr-x 2 marcos marcos 4096 jun 16 11:52 ./
drwxr-x---+ 130 marcos marcos 12288 jun 16 11:52 ../
-rw-rw-r-- 1 marcos marcos 366 jun 16 11:52 a00000001.gdbtable
-rw-rw-r-- 1 marcos marcos 4128 jun 16 11:52 a00000001.gdbtablx
-rw-rw-r-- 1 marcos marcos 2073 jun 16 11:52 a00000002.gdbtable
-rw-rw-r-- 1 marcos marcos 4128 jun 16 11:52 a00000002.gdbtablx
-rw-rw-r-- 1 marcos marcos 776 jun 16 11:52 a00000003.gdbtable
-rw-rw-r-- 1 marcos marcos 4128 jun 16 11:52 a00000003.gdbtablx
-rw-rw-r-- 1 marcos marcos 11029 jun 16 11:52 a00000004.gdbtable
-rw-rw-r-- 1 marcos marcos 4128 jun 16 11:52 a00000004.gdbtablx
-rw-rw-r-- 1 marcos marcos 1723 jun 16 11:52 a00000005.gdbtable
-rw-rw-r-- 1 marcos marcos 4128 jun 16 11:52 a00000005.gdbtablx
-rw-rw-r-- 1 marcos marcos 281 jun 16 11:52 a00000006.gdbtable
-rw-rw-r-- 1 marcos marcos 4128 jun 16 11:52 a00000006.gdbtablx
-rw-rw-r-- 1 marcos marcos 2281 jun 16 11:52 a00000007.gdbtable
-rw-rw-r-- 1 marcos marcos 4128 jun 16 11:52 a00000007.gdbtablx
-rw-rw-r-- 1 marcos marcos 116 jun 16 11:52 a00000009.gdbindexes
-rw-rw-r-- 1 marcos marcos 5154232 jun 16 11:52 a00000009.gdbtable
-rw-rw-r-- 1 marcos marcos 51232 jun 16 11:52 a00000009.gdbtablx
-rw-rw-r-- 1 marcos marcos 131094 jun 16 11:52 a00000009.spx
-rw-rw-r-- 1 marcos marcos 8 jun 16 11:52 gdb
-rw-rw-r-- 1 marcos marcos 400 jun 16 11:52 timestamps
(v_django4_38) marcos@acacia:~$ ogrinfo xx.gdb/
INFO: Open of `xx.gdb/'
 using driver `OpenFileGDB' successful.
Layer: ne_10m_admin_1_states_provinces_lines (Multi Line String)

QGIS opens this folder fine. The GDAL/OGR Python bindings should work too.

answered Jun 16 at 9:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.