Select to view content in your preferred language

How to list files in a personal geodatabse in Pro.

387
1
01-19-2023 08:24 AM
AlfredBaldenweck
MVP Regular Contributor

Hi all,

I realize I can't do any sort of actual work (add to a map, geoprocess) with the contents of a personal geodatabase in Pro, but I was wondering if I could list its contents?

The reason I ask is because personal geodatabases are recognized by arcpy.listEnvironments(), so it seems like their contents should also be recognized, but I haven't been able to get it to work so far.

Is this possible at all?

 

Related: It'd be great if Esri added some sort of conversion for personal gdbs to file gdbs to Pro.

0 Kudos
1 Reply
Brian_Wilson
Regular Contributor II

Actually, they included support with Pro. They did not make it easy. I won't speculate on why.

Look for ogr2ogr.py on your computer. On mine it is in "C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/Lib/site-packages/osgeo_utils/samples". That program is the swiss army knife of file conversions.

See if your computer has the personal geodatabase support in it. Activate a conda environment and run python, for example

conda activate arcgispro-py3
cd "C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/Lib/site-packages/osgeo_utils/samples"
python ogrinfo.py --formats
.
.
My system lists 77 supported formats here. The ESRI ones listed are

  ESRI Shapefile -vector- (rw+v): ESRI Shapefile
  ESRIJSON -vector- (rov): ESRIJSON
  PGeo -vector- (ro): ESRI Personal GeoDatabase
  OpenFileGDB -vector- (rov): ESRI FileGDB

 

The ones you are interested in are the two database formats. Personal and FileGDB.

Older versions of GDAL (of which OGR is a member) support only reading FileGDB. Unfortunately that's what Esri gives you (see the "(rov)" which sadly means read-only.

You can read all details on the PGDB driver here: https://gdal.org/drivers/vector/pgeo.html

The FGDB information is here: https://gdal.org/drivers/vector/openfilegdb.html

If you want to be able to READ a PGDB and then WRITE to a FGDB you can update your copy of GDAL. It's probably incompatible with arcpy. But so what!! You have conda. You could do something like this

conda create --name=gdal python gdal
conda activate gdal
ogrinfo --version

Now you have gdal version 3.6 installed,  and also it installs ALL the commands for you not just the Python libraries. So you can directly run commands without having to load Python. (Like "ogrinfo --version" instead of "python ogrinfo.py --version")

If you run "ogrinfo --formats" again you will see " OpenFileGDB -vector- (rw+v): ESRI FileGDB" which means you now have a tool that can translate PGDB to FGDB and it took you about 3 minutes to install it. And it's free. (I won't speculate why Esri does not included it with Pro since it's free?)

The ogrinfo tool should be able to list the contents of a PGDB. I don't have one!!

Here is an example of running it on a FGDB.

ogrinfo TaxMaps.gdb
INFO: Open of `TaxMaps.gdb'
      using driver `OpenFileGDB' successful.
Layer: taxmap_anno (Multi Polygon)
Layer: seemap_anno (Multi Polygon)
Layer: bearing_anno (Multi Polygon)
Layer: taxlot_anno (Multi Polygon)
Layer: taxcode_anno (Multi Polygon)
Layer: PLSS (Multi Polygon)
Layer: Taxlots (Multi Polygon)
Layer: bearing_anno_aoi (Multi Polygon)
Layer: taxlot_anno_aoi (Multi Polygon)
Layer: Mapindex (Multi Polygon)
Layer: Reference_Lines (Multi Line String)
Layer: Taxlots_WM (Multi Polygon)

 

Once I know all the layers in the database, I can get details on one layer,

ogrinfo TaxMaps.gdb PLSS
INFO: Open of `TaxMaps.gdb'
      using driver `OpenFileGDB' successful.

Layer name: PLSS
Geometry: Multi Polygon
Feature Count: 1
Extent: (7351565.172900, 930222.284121) - (7357078.350066, 935707.477034)
Layer SRS WKT:
PROJCRS["NAD83(HARN) / Oregon North (ft)",
    BASEGEOGCRS["NAD83(HARN)",
        DATUM["NAD83 (High Accuracy Reference Network)",
            ELLIPSOID["GRS 1980",6378137,298.257222101,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4152]],
    CONVERSION["SPCS83 Oregon North zone (International feet)",
        METHOD["Lambert Conic Conformal (2SP)",

... and it goes on and on listing everything ...

 

Now that I know I can read a file geodatabase and I can get a list of layers, I can translate.

As I said above I DON'T HAVE ANY PGEO databases so I can't test it for you. In your case you would READ the PGEO and WRITE to whatever -- shapefile? UGH... I'd try going to a FGDB myself. This is just a test

Note the names are reversed, destination is first then source,

ogr2ogr -f "GeoJSON" plss.json TaxMaps.gdb PLSS

Note I have to give it the name of the layer (PLSS) in the FGDB as part of the source. This feature class has only one polygon in it, so I can dump the whole file here, 

ogrinfo plss.json PLSS
INFO: Open of `plss.json'
      using driver `GeoJSON' successful.

Layer name: PLSS
Geometry: Multi Polygon
Feature Count: 1
Extent: (7351565.172900, 930222.284121) - (7357078.350066, 935707.477034)
Layer SRS WKT:
PROJCRS["NAD83(HARN) / Oregon North (ft)",
    BASEGEOGCRS["NAD83(HARN)",
        DATUM["NAD83 (High Accuracy Reference Network)",
            ELLIPSOID["GRS 1980",6378137,298.257222101,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4152]],
    CONVERSION["SPCS83 Oregon North zone (International feet)",
        METHOD["Lambert Conic Conformal (2SP)",
            ID["EPSG",9802]],
        PARAMETER["Latitude of false origin",43.6666666666667,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8821]],
        PARAMETER["Longitude of false origin",-120.5,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8822]],
        PARAMETER["Latitude of 1st standard parallel",46,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8823]],
        PARAMETER["Latitude of 2nd standard parallel",44.3333333333333,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8824]],
        PARAMETER["Easting at false origin",8202099.738,
            LENGTHUNIT["foot",0.3048],
            ID["EPSG",8826]],
        PARAMETER["Northing at false origin",0,
            LENGTHUNIT["foot",0.3048],
            ID["EPSG",8827]]],
    CS[Cartesian,2],
        AXIS["easting (X)",east,
            ORDER[1],
            LENGTHUNIT["foot",0.3048]],
        AXIS["northing (Y)",north,
            ORDER[2],
            LENGTHUNIT["foot",0.3048]],
    USAGE[
        SCOPE["Engineering survey, topographic mapping."],
        AREA["United States (USA) - Oregon - counties of Baker; Benton; Clackamas; Clatsop; Columbia; Gilliam; Grant; Hood River; Jefferson; Lincoln; Linn; Marion; Morrow; Multnomah; Polk; Sherman; Tillamook; Umatilla; Union; Wallowa; Wasco; Washington; Wheeler; Yamhill."],
        BBOX[43.95,-124.17,46.26,-116.47]],
    ID["EPSG",2913]]
Data axis to CRS axis mapping: 1,2
AREA: String (0.0)
PERIMETER: Real (0.0)
PLS_: Integer (0.0)
PLS_ID: Integer (0.0)
TOWN: String (0.0)
RANGE: String (0.0)
SECTION: String (0.0)
QTR: String (0.0)
TR: String (0.0)
SYMBOL: Integer (0.0)
Shape_Length: Real (0.0)
Shape_Area: Real (0.0)
OGRFeature(PLSS):0
  AREA (String) = (null)
  PERIMETER (Real) = 21242.661
  PLS_ (Integer) = 79
  PLS_ID (Integer) = 33
  TOWN (String) = 8
  RANGE (String) = 9
  SECTION (String) = 18
  QTR (String) = B
  TR (String) = 8N9W
  SYMBOL (Integer) = 18
  Shape_Length (Real) = 21242.6608759667
  Shape_Area (Real) = 28202907.1147083
  MULTIPOLYGON (((7357078.35006562 935522.437992126,7356868.19389763 930222.284120739,7351565.17290026 930414.819881886,7351732.43339895 935325.079724416,7351745.4589895 935707.477034122,7353078.68208662 935661.216863513,7354411.90387139 935614.95800525,7355745.1269685 935568.698162735,7357078.35006562 935522.437992126)))