AnswerBun.com

Selecting polygon feature classes with one record in Oracle geodatabase using SQL query?

Geographic Information Systems Asked by Mich on November 6, 2020

I have an Oracle Enterprise geodatabase with many feature classes. I would like a SQL query to find all the polygon feature classes with only one record in its table. So far, I can only query all the feature classes.

  SELECT * 
  FROM SDE.GDB_ITEMS items INNER JOIN SDE.GDB_ITEMTYPES itemtypes ON items.Type = itemtypes.UUID
  WHERE itemtypes.Name = 'Feature Class' 

One Answer

Several parts are involved:

  • getting all the tables from the database (used code from the answer https://stackoverflow.com/a/9954833/3346915)
  • reading geodatabase metadata (in your question body)
  • filtering using the where clause to include only those tables that are of feature class type and their shape type are of polygon (parsing XML is involved).

This code would work on SQL Server:

SELECT 
    TableName = t.NAME,
    TableSchema = s.Name,
    RowCounts = p.rows
FROM 
    sys.tables t
INNER JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID 
    AND i.index_id = p.index_id
WHERE 
    t.name in (
        (SELECT PARSENAME(items.Name,1)
          FROM SDE.GDB_ITEMS items INNER JOIN SDE.GDB_ITEMTYPES itemtypes 
          ON items.Type = itemtypes.UUID
          WHERE itemtypes.Name = 'Feature Class' and 
                Definition.value('(/DEFeatureClassInfo/ShapeType)[1]', 
                'varchar(max)') = 'esriGeometryPolygon'))   
    and t.is_ms_shipped = 0 
    and p.rows = 1

GROUP BY
    t.NAME, s.Name, p.Rows
ORDER BY 
    s.Name, t.Name

The results:

    TableName           TableSchema      RowCounts
--  ------------------  -------------  -----------
 0  ND_1226_DIRTYAREAS  dbo                      1
 1  REDLINING           dbo                      1
 2  SS_WORKAREAS        dbo                      1
 3  T_1_DIRTYAREAS      dbo                      1

Answered by Alex Tereshenkov on November 6, 2020

Add your own answers!

Related Questions

Multi-field labeling of shapefile with PyQGIS?

1  Asked on December 2, 2020 by ennine

   

QGIS 3 Deleting Neighbour Points

0  Asked on December 2, 2020 by l-w

   

Convert UTM zone into EPSG code

3  Asked on December 2, 2020 by andrew-einhorn

         

How to Handle Proxies within Carto’s Python Import API framework

1  Asked on December 1, 2020 by cambriancatalyst

         

PyQGIS: DLL load failed while importing _core. Environment path?

2  Asked on December 1, 2020 by pyqgis_newbie

       

How to setup CRS for QField

1  Asked on December 1, 2020 by sigwood

     

TIMESAT Quality Data

0  Asked on December 1, 2020 by mateusz-lisiecki

         

Map two sf objects on one map with mapview

2  Asked on December 1, 2020

     

ECW and GeoPackage

0  Asked on December 1, 2020 by cristian-ibba

     

multi-multi point pgrouting functions

1  Asked on December 1, 2020 by columbo25

   

How to remove memory layer from memory?

2  Asked on December 1, 2020 by anon1234

     

Ask a Question

Get help from others!

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