TransWikia.com

.gdbtable file type, how GIS reads it, and how to batch-convert it to a CSV?

Geographic Information Systems Asked by mathwiz97 on December 10, 2020

TL;DR: How do I convert .gdbtable to .csv in Python? Where is the location data in the attribute table?

Using QGIS 3.14. I have a data type which I’m unfamiliar with, a GDB table it appears. The exact dataset I’m working with is a directory which contains various files which look like a0000000b.gdbtable so illegible to me but when I drag the whole directory in QGIS it imports all the data perfectly. Now, I’m not a QGIS or even a GIS person so I want this data to be stored and handled in Python, but I have no idea how to even begin and I couldn’t find a library or anything to work with. I found this post but it’s outdated and also it’s for .gdb files which are not the same (right?). Now, I could open the attribute table and export as CSV but two problems with that:

  1. I need this process to be automatic (i.e. using a GIS API or Python) such that it doesn’t depend on GIS software as this needs to be done several times a week with new data being downloaded

  2. The attribute table doesn’t appear to have any information about how to draw the layer, and of course that’s something I’d want to preserve. More to follow:

For context the data is oil and gas pipelines so each row in the attribute table is a separate pipeline however these are the attribute table headers:

[OBJECTID, PipelineID, Country, CountryISO, Region, Basin, OnOffshore, Environment, Status, Contents, UpdatedDate, CreatedDate, Symbol, SHAPE_Length]

So seemingly no location info however QGIS knows exactly where each pipeline is and shows it on the map. How does it know, where is the location data stored, and what is the type of data here exactly? A shapefile? Polygon? Multiple concatenated lines? List of points for each pipeline that are then drawn connected? I’m not sure if you could tell without actually having access to the data, which I could provide a sample if necessary.

I can clear up anything that doesn’t make sense, I am new to GIS and this data type (which is why I’m trying to do this in Python).

One Answer

I would recommend using GeoPandas for this where you can read Esri geodatabases (and many, many other formats) as a GeoDataframe. If you are familiar with Pandas, the dataframe is a very useful tabular data structure for analysis. Geopandas builds on this by adding a GeoSeries to the tabular data structure.

Here is how to read a featureclass from a geodatabase and convert it to either CSV or GeoJSON format:

import geopandas as gpd

gdb = '/path/to/your/geodatabase.gdb'

fc = gpd.read_file(gdb, layer='pipelines')

# Write to CSV 
fc.to_csv('/path/to/out_csv.csv')

# Write to GeoJSON
fc.to_file('/path/to/out_geojson.geojson', driver='GeoJSON')

Answered by Aaron on December 10, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP