Select to view content in your preferred language

SQLite Tables to File Geodatabase Feature Classes

147
4
Friday
Labels (3)
Clubdebambos
MVP Regular Contributor

I have received an SQLite database that is a bit different than what I am used to. It seems that the data is in tables rather that "feature classes", see image below...

Clubdebambos_0-1746795547649.png

 

I was expecting more like the below for example...

Clubdebambos_1-1746795574755.png

 

At a guess, it seems that the data is in the first table and the the other two help define geometry and srs for that table.

My usage of SQLite is limited. Has anyone experienced the above and have a solution for me for how to extract as a feature class?

Cheers,

Glen 

 

~ learn.finaldraftmapping.com
0 Kudos
4 Replies
AyanPalit
Esri Regular Contributor

@Clubdebambos I would check with the source of SQLite database on GIS format. Looks like a non-ArcGIS format; once you know the format, there should be some conversion tools for ArcGIS.

If it is a proprietary format, figuring out the relationship between relational tables to build the spatial objects could be tricky and not worth your time.   

Ayan Palit | Principal Consultant Esri
0 Kudos
Luke_Pinner
MVP Regular Contributor

That SQLite db looks like a spatialite DB which is something GDAL/OGR can read.

The arcgispro-py3 env includes the GDAL/OGR (osgeo.gdal / osgeo.ogr) library, so may have the GDAL commandline tools (I'm not at my work computer, so can't check). 

If you have og2ogr available, you could convert the SQLite DB to a File GeoDatabase with something like (untested):

ogr2ogr -of OpenFileGDB output.gdb input.sqlite

 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If you are able to post any of the data, that would help community members provide more in-depth responses.  If you can't share any of the data, can you truncate the tables and at least share an empty SQLite package that has the schema?

0 Kudos
Clubdebambos
MVP Regular Contributor

Thank you all for your replies.

I ended up using ArcPy. There is a field in the table called geom that is a "blob" type. I extracted the blob to bytes and used ArcPy to convert FromWKB which produces a Geometry object. I could then reconstruct the Feature Class in a File Geodatabase.

import arcpy

## path to SQLite Table
sqlite_fc = "path/to/sqlite/fc_name"

## Path to pre-prepared Feature Class
out_fc = "path/to/output_gdb/fc_name"

## open up an InsertCursor for the out_fc
with arcpy.da.InsertCursor(out_fc, ["name", "SHAPE@"]) as i_cursor:
    ## use the SearchCursor on the sqlite_fc
    with arcpy.da.SearchCursor(sqlite_fc, ["name", "geom"]) as s_cursor:
        ## for each record
        for row in s_cursor:
            ## get the blob and convert to Geometry object
            geom = arcpy.FromWKB(row[1].tobytes())
            ## insert into the out_fc
            i_cursor.insertRow([row[0], geom])

 

~ learn.finaldraftmapping.com
0 Kudos