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).

  • Are you working with a table or a feature class located within a geodatabase? My initial thought is the you should read data into a GeoPandas geodataframe. That way you will be able to interact with the attributes as you would with Pandas. More here: geopandas.org/io.html – Aaron Dec 7 '20 at 18:43
  • @Aaron I believe so. I have a .gdb file with a bunch of data, pipelines being one layer, and I would like to know how to save that layer to a csv and preserve location data/how location data is managed within that. GeoPandas looks like a good place to start, I'll check it out, thank you. – mathwiz97 Dec 7 '20 at 18:47
  • ...also, what do you intend to do with the csv after converting? There may be a more efficient approach than to use intermediate CSV files. – Aaron Dec 7 '20 at 20:14

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 

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.