0

I have a file geodatabase that contains polygons as feature classes. Here is the description of my dataset. It contains vegetation data for each polygon.

I have found this Python script online that reads the domains from the geodatabase. And this seems to work fine.

from __future__ import print_function
import json
import xml.etree.ElementTree as ET
import ogr

gdb_path = r'S_USA.EVMid_R05_CentralCoast.gdb' ds = ogr.Open(gdb_path) res = ds.ExecuteSQL('select * from GDB_Items') res.CommitTransaction()

for i in range(0, res.GetFeatureCount()): item = json.loads( res.GetNextFeature().ExportToJson())['properties']['Definition'] if item: xml = ET.fromstring(item) if xml.tag == 'GPCodedValueDomain2': print(xml.find('DomainName').text) print(xml.find('Description').text) print(xml.find('FieldType').text)

        for table in xml.iter('CodedValues'):
            for child in table:
                print(child.find('Code').text, child.find('Name').text)
        print()

    if xml.tag == 'GPRangeDomain2':
        print(xml.find('DomainName').text)
        print(xml.find('Description').text)
        print(xml.find('FieldType').text)
        print(xml.find('MinValue').text)
        print(xml.find('MaxValue').text)

But I want to view each separate polygon and its associated attributes (including the boundary of the polygon itself) so that, given a coordinate, I am able to view the bounding polygon and therefore fetch the vegetation data associated with a given coordinate. Apologies if my terminology is wrong, I am new to GIS. But as I understand, I wish to view the feature classes. How can I do this using Python GDAL?

Vince
  • 20,017
  • 15
  • 45
  • 64
Hdot
  • 141
  • 1
  • 6
  • Welcome to GIS SE! Are you looking to join the polygon attributes with your point feature class, or a spatial join operation? I am confused about how you wish to use the "bounding" polygon. Could you please provide more details on your desired end-product? – Aaron Nov 01 '20 at 15:56
  • Firstly I would just like to query for each polygon feature class. I.e. I want to return every polygon in the set along with the polygons associated attributes. And secondly, I would like to find the polygon in which given a point feature (a coordinate somewhere in the space) exists, a spatial join. – Hdot Nov 01 '20 at 16:57
  • Thanks for the clarification. Do you have a point feature class you are using for your sample locations? – Aaron Nov 01 '20 at 17:29
  • No, I don't, only the dataset linked. Is it not possible to check if an (x,y) coordinate sits inside one of the polygons? – Hdot Nov 01 '20 at 17:33
  • apologies if this is all vague. I'm having a hard time finding useful resources to help me understand how this stuff works. – Hdot Nov 01 '20 at 17:33
  • It is possible to sample the polygons using either coordinates or a point feature class. I find it easier to generate a list of sample locations as a point feature class and then run a spatial join. However, you can iterate through a list of coords and perform the same operation. I guess it all depends on how you are using the data. If summarizing data, the point feature class is preferable, if querying a location as some sort of web service, maybe a coordinate is preferable. – Aaron Nov 01 '20 at 17:44
  • I am wanting to query the location like a web service. How can I do this? Or how can I find some good resources to help me understand how this works? Thank you for your help – Hdot Nov 01 '20 at 17:48
  • If you could please explain how I could do this in an answer I would accept it? – Hdot Nov 02 '20 at 09:19
  • What you are describing sounds like a select by location operation. Here is a related post that uses geopandas which should be helpful: https://gis.stackexchange.com/q/279670/8104 – Aaron Nov 02 '20 at 16:11

0 Answers0