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
- Except ArcGIS (and ArcPy) is there any other package to create a geodatabase?
- If the answer to question one is "YES", how can I create a geodatabase in Python?
-
4The GDAL driver is read/write gdal.org/drivers/vector/openfilegdb.html.user30184– user301842024年04月12日 11:35:50 +00:00Commented 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.Vince– Vince2024年04月12日 11:51:54 +00:00Commented 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.amin13afa– amin13afa2024年04月12日 12:03:24 +00:00Commented 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?user30184– user301842024年04月12日 12:23:33 +00:00Commented Apr 12, 2024 at 12:23
-
1If 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.Vince– Vince2024年04月12日 15:39:16 +00:00Commented Apr 12, 2024 at 15:39
2 Answers 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.
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.
Explore related questions
See similar questions with these tags.