FileGDB API for linux学习系列之五,获取对象的定义

FileGDB API for linux 提供了获取对象定义的函数,但是获取出来的结果都是以XML形式存在,对于表,FeatureClass,FeatureDataset等对象已经足够了,

以下的例子是获得各种对象定义的例子程序,包括Table, FeatureClass, FeatureDataset等等对象的定义。

#include 
#include 
#include <string>
#include 
#include 
#include 
#include 

#define EXT_FILEGDB_API _declspec(dllimport)
#pragma warning (disable : 4251)

#include "Geodatabase.h"
#include "GeodatabaseManagement.h"
#include "Table.h"
using namespace std;
using namespace FileGDBAPI;

Geodatabase geodatabase;
int main()
{
  
  // Create a new geodatabase in the current directory.
  long hr;

  // Re-open the geodatabase.
  if ((hr = OpenGeodatabase(L"../data/TestFileGDB.gdb", geodatabase)) != S_OK)
  {
    cout << "An error occurred while opening the geodatabase." << endl;
    cout << "Error code: " << hr << endl;
    return -1;
  }
  cout << "The geodatabase has been opened." << endl;

  Table table;
  if((hr = geodatabase.OpenTable(L"//TSType",table)) != S_OK)
  {
           cout << "An error occurred while open the table." << endl;
           cout << "Error code: " << hr <return -1;
  }

  std::string tableDef;
  if(S_OK == table.GetDefinition(tableDef))
  {
        cout << "the table TSType definition: " << tableDef << endl;
  }
  // Close the geodatabase before the delete.
  if((hr = geodatabase.CloseTable(table)) != S_OK)
  {
    cout << "An error occurred while closing the table." << endl;
    cout << "Error code: " << hr << endl;
    return -1;
  }
  std::string featuredatasetDef;
  if(S_OK == geodatabase.GetDatasetDefinition(L"//Drainage",L"Feature Dataset",featuredatasetDef))
  {
    cout << "the featuredataset Drainage definition is: " << featuredatasetDef << endl;
  }

  std::string featureclassDef;

  if(S_OK == geodatabase.GetDatasetDefinition(L"//Basin_1",L"Feature Class",featureclassDef))
  {
      cout << "the featureclass Catchment definition is:" << featureclassDef << endl;
  }
  
  if ((hr = CloseGeodatabase(geodatabase)) != S_OK)
  {
    cout << "An error occurred while closing the geodatabase." << endl;
    cout << "Error code: " << hr << endl;
    return -1;
  }
  return 0;
}
运行结果如下:
The geodatabase has been opened.
the table TSType definition: 
   
   xml version="1.0" encoding="UTF-8"?>
<DataElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:esri="http://www.esri.com/schemas/ArcGIS/10.0" xsi:type="esri:DETable">
  <CatalogPath>/TSType
    
    CatalogPath>
  <Name>TSType
     
     Name>
  <ChildrenExpanded>false
      
      ChildrenExpanded>
  <DatasetType>esriDTTable 
       DatasetType> <DSID>18 
        DSID> <Versioned>false 
         Versioned> <CanVersion>false 
          CanVersion> <ConfigurationKeyword/> <HasOID>true 
           HasOID> <OIDFieldName>OBJECTID 
            OIDFieldName> <Fields xsi:type="esri:Fields"> <FieldArray xsi:type="esri:ArrayOfField"> <Field xsi:type="esri:Field"> <Name>OBJECTID 
             Name> <Type>esriFieldTypeOID 
              Type> <IsNullable>false 
               IsNullable> <Length>4 
                Length> <Precision>0 
                 Precision> <Scale>0 
                  Scale> <Required>true 
                   Required> <Editable>false 
                    Editable> <AliasName>OBJECTID 
                     AliasName> <ModelName>OBJECTID 
                      ModelName>  
                       Field> <Field xsi:type="esri:Field"> <Name>TSTypeID 
                        Name> <Type>esriFieldTypeInteger 
                         Type> <IsNullable>true 
                          IsNullable> <Length>4 
                           Length> <Precision>0 
                            Precision> <Scale>0 
                             Scale> <AliasName>TSTypeID 
                              AliasName> <ModelName>TSTypeID 
                               ModelName>  
                                Field> <Field xsi:type="esri:Field"> <Name>Variable 
                                 Name> <Type>esriFieldTypeString 
                                  Type> <IsNullable>true 
                                   IsNullable> <Length>255 
                                    Length> <Precision>0 
                                     Precision> <Scale>0 
                                      Scale> <AliasName>Variable 
                                       AliasName> <ModelName>Variable 
                                        ModelName>  
                                         Field> <Field xsi:type="esri:Field"> <Name>Units 
                                          Name> <Type>esriFieldTypeString 
                                           Type> <IsNullable>true 
                                            IsNullable> <Length>20 
                                             Length> <Precision>0 
                                              Precision> <Scale>0 
                                               Scale> <AliasName>Units 
                                                AliasName> <ModelName>Units 
                                                 ModelName>  
                                                  Field> <Field xsi:type="esri:Field"> <Name>IsRegular 
                                                   Name> <Type>esriFieldTypeInteger 
                                                    Type> <IsNullable>true 
                                                     IsNullable> <Length>4 
                                                      Length> <Precision>0 
                                                       Precision> <Scale>0 
                                                        Scale> <AliasName>IsRegular 
                                                         AliasName> <ModelName>IsRegular 
                                                          ModelName> <Domain> <DomainName>AHBoolean 
                                                           DomainName> <FieldType>esriFieldTypeInteger 
                                                            FieldType> <MergePolicy>esriMPTDefaultValue 
                                                             MergePolicy> <SplitPolicy>esriSPTDefaultValue 
                                                              SplitPolicy> <Description/> <Owner/> <CodedValues xsi:type="esri:ArrayOfCodedValue"> <CodedValue xsi:type="esri:CodedValue"> <Name>True 
                                                               Name> <Code xsi:type="xs:int">1 
                                                                Code>  
                                                                 CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>False 
                                                                  Name> <Code xsi:type="xs:int">0 
                                                                   Code>  
                                                                    CodedValue>  
                                                                     CodedValues>  
                                                                      Domain>  
                                                                       Field> <Field xsi:type="esri:Field"> <Name>TSInterval 
                                                                        Name> <Type>esriFieldTypeInteger 
                                                                         Type> <IsNullable>true 
                                                                          IsNullable> <Length>4 
                                                                           Length> <Precision>0 
                                                                            Precision> <Scale>0 
                                                                             Scale> <AliasName>TSInterval 
                                                                              AliasName> <ModelName>TSInterval 
                                                                               ModelName> <Domain> <DomainName>TSIntervalType 
                                                                                DomainName> <FieldType>esriFieldTypeInteger 
                                                                                 FieldType> <MergePolicy>esriMPTDefaultValue 
                                                                                  MergePolicy> <SplitPolicy>esriSPTDefaultValue 
                                                                                   SplitPolicy> <Description/> <Owner/> <CodedValues xsi:type="esri:ArrayOfCodedValue"> <CodedValue xsi:type="esri:CodedValue"> <Name>1Minute 
                                                                                    Name> <Code xsi:type="xs:int">1 
                                                                                     Code>  
                                                                                      CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>2Minute 
                                                                                       Name> <Code xsi:type="xs:int">2 
                                                                                        Code>  
                                                                                         CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>3Minute 
                                                                                          Name> <Code xsi:type="xs:int">3 
                                                                                           Code>  
                                                                                            CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>4Minute 
                                                                                             Name> <Code xsi:type="xs:int">4 
                                                                                              Code>  
                                                                                               CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>5Minute 
                                                                                                Name> <Code xsi:type="xs:int">5 
                                                                                                 Code>  
                                                                                                  CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>10Minute 
                                                                                                   Name> <Code xsi:type="xs:int">6 
                                                                                                    Code>  
                                                                                                     CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>15Minute 
                                                                                                      Name> <Code xsi:type="xs:int">7 
                                                                                                       Code>  
                                                                                                        CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>20Minute 
                                                                                                         Name> <Code xsi:type="xs:int">8 
                                                                                                          Code>  
                                                                                                           CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>30Minute 
                                                                                                            Name> <Code xsi:type="xs:int">9 
                                                                                                             Code>  
                                                                                                              CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>1Hour 
                                                                                                               Name> <Code xsi:type="xs:int">10 
                                                                                                                Code>  
                                                                                                                 CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>2Hour 
                                                                                                                  Name> <Code xsi:type="xs:int">11 
                                                                                                                   Code>  
                                                                                                                    CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>3Hour 
                                                                                                                     Name> <Code xsi:type="xs:int">12 
                                                                                                                      Code>  
                                                                                                                       CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>4Hour 
                                                                                                                        Name> <Code xsi:type="xs:int">13 
                                                                                                                         Code>  
                                                                                                                          CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>6Hour 
                                                                                                                           Name> <Code xsi:type="xs:int">14 
                                                                                                                            Code>  
                                                                                                                             CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>8Hour 
                                                                                                                              Name> <Code xsi:type="xs:int">15 
                                                                                                                               Code>  
                                                                                                                                CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>12Hour 
                                                                                                                                 Name> <Code xsi:type="xs:int">16 
                                                                                                                                  Code>  
                                                                                                                                   CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>1Day 
                                                                                                                                    Name> <Code xsi:type="xs:int">17 
                                                                                                                                     Code>  
                                                                                                                                      CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>1Week 
                                                                                                                                       Name> <Code xsi:type="xs:int">18 
                                                                                                                                        Code>  
                                                                                                                                         CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>1Month 
                                                                                                                                          Name> <Code xsi:type="xs:int">19 
                                                                                                                                           Code>  
                                                                                                                                            CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>1Year 
                                                                                                                                             Name> <Code xsi:type="xs:int">20 
                                                                                                                                              Code>  
                                                                                                                                               CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>Other 
                                                                                                                                                Name> <Code xsi:type="xs:int">99 
                                                                                                                                                 Code>  
                                                                                                                                                  CodedValue>  
                                                                                                                                                   CodedValues>  
                                                                                                                                                    Domain>  
                                                                                                                                                     Field> <Field xsi:type="esri:Field"> <Name>DataType 
                                                                                                                                                      Name> <Type>esriFieldTypeInteger 
                                                                                                                                                       Type> <IsNullable>true 
                                                                                                                                                        IsNullable> <Length>4 
                                                                                                                                                         Length> <Precision>0 
                                                                                                                                                          Precision> <Scale>0 
                                                                                                                                                           Scale> <AliasName>DataType 
                                                                                                                                                            AliasName> <ModelName>DataType 
                                                                                                                                                             ModelName> <Domain> <DomainName>TSDataType 
                                                                                                                                                              DomainName> <FieldType>esriFieldTypeInteger 
                                                                                                                                                               FieldType> <MergePolicy>esriMPTDefaultValue 
                                                                                                                                                                MergePolicy> <SplitPolicy>esriSPTDefaultValue 
                                                                                                                                                                 SplitPolicy> <Description/> <Owner/> <CodedValues xsi:type="esri:ArrayOfCodedValue"> <CodedValue xsi:type="esri:CodedValue"> <Name>Instantaneous 
                                                                                                                                                                  Name> <Code xsi:type="xs:int">1 
                                                                                                                                                                   Code>  
                                                                                                                                                                    CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>Cumulative 
                                                                                                                                                                     Name> <Code xsi:type="xs:int">2 
                                                                                                                                                                      Code>  
                                                                                                                                                                       CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>Incremental 
                                                                                                                                                                        Name> <Code xsi:type="xs:int">3 
                                                                                                                                                                         Code>  
                                                                                                                                                                          CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>Average 
                                                                                                                                                                           Name> <Code xsi:type="xs:int">4 
                                                                                                                                                                            Code>  
                                                                                                                                                                             CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>Maximum 
                                                                                                                                                                              Name> <Code xsi:type="xs:int">5 
                                                                                                                                                                               Code>  
                                                                                                                                                                                CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>Minimum 
                                                                                                                                                                                 Name> <Code xsi:type="xs:int">6 
                                                                                                                                                                                  Code>  
                                                                                                                                                                                   CodedValue>  
                                                                                                                                                                                    CodedValues>  
                                                                                                                                                                                     Domain>  
                                                                                                                                                                                      Field> <Field xsi:type="esri:Field"> <Name>Origin 
                                                                                                                                                                                       Name> <Type>esriFieldTypeInteger 
                                                                                                                                                                                        Type> <IsNullable>true 
                                                                                                                                                                                         IsNullable> <Length>4 
                                                                                                                                                                                          Length> <Precision>0 
                                                                                                                                                                                           Precision> <Scale>0 
                                                                                                                                                                                            Scale> <AliasName>Origin 
                                                                                                                                                                                             AliasName> <ModelName>Origin 
                                                                                                                                                                                              ModelName> <Domain> <DomainName>TSOrigins 
                                                                                                                                                                                               DomainName> <FieldType>esriFieldTypeInteger 
                                                                                                                                                                                                FieldType> <MergePolicy>esriMPTDefaultValue 
                                                                                                                                                                                                 MergePolicy> <SplitPolicy>esriSPTDefaultValue 
                                                                                                                                                                                                  SplitPolicy> <Description/> <Owner/> <CodedValues xsi:type="esri:ArrayOfCodedValue"> <CodedValue xsi:type="esri:CodedValue"> <Name>Recorded 
                                                                                                                                                                                                   Name> <Code xsi:type="xs:int">1 
                                                                                                                                                                                                    Code>  
                                                                                                                                                                                                     CodedValue> <CodedValue xsi:type="esri:CodedValue"> <Name>Generated 
                                                                                                                                                                                                      Name> <Code xsi:type="xs:int">2 
                                                                                                                                                                                                       Code>  
                                                                                                                                                                                                        CodedValue>  
                                                                                                                                                                                                         CodedValues>  
                                                                                                                                                                                                          Domain>  
                                                                                                                                                                                                           Field>  
                                                                                                                                                                                                            FieldArray>  
                                                                                                                                                                                                             Fields> <CLSID>{7A566981-C114-11D2-8A28-006097AFF44E} 
                                                                                                                                                                                                              CLSID> <EXTCLSID/> <RelationshipClassNames xsi:type="esri:Names"/> <AliasName/> <ModelName>TSType 
                                                                                                                                                                                                               ModelName> <HasGlobalID>false 
                                                                                                                                                                                                                HasGlobalID> <GlobalIDFieldName/> <RasterFieldName/> <ExtensionProperties xsi:type="esri:PropertySet"> <PropertyArray xsi:type="esri:ArrayOfPropertySetProperty"/>  
                                                                                                                                                                                                                 ExtensionProperties> <ControllerMemberships xsi:type="esri:ArrayOfControllerMembership"/> <Indexes xsi:type="esri:Indexes"> <IndexArray xsi:type="esri:ArrayOfIndex"> <Index xsi:type="esri:Index"> <Name>FDO_OBJECTID 
                                                                                                                                                                                                                  Name> <IsUnique>true 
                                                                                                                                                                                                                   IsUnique> <IsAscending>true 
                                                                                                                                                                                                                    IsAscending> <FieldArray xsi:type="esri:ArrayOfField"> <Field xsi:type="esri:Field"> <Name>OBJECTID 
                                                                                                                                                                                                                     Name> <Type>esriFieldTypeOID 
                                                                                                                                                                                                                      Type> <IsNullable>false 
                                                                                                                                                                                                                       IsNullable> <Length>4 
                                                                                                                                                                                                                        Length> <Precision>0 
                                                                                                                                                                                                                         Precision> <Scale>0 
                                                                                                                                                                                                                          Scale> <Required>true 
                                                                                                                                                                                                                           Required> <Editable>false 
                                                                                                                                                                                                                            Editable> <AliasName>OBJECTID 
                                                                                                                                                                                                                             AliasName> <ModelName>OBJECTID 
                                                                                                                                                                                                                              ModelName>  
                                                                                                                                                                                                                               Field>  
                                                                                                                                                                                                                                FieldArray>  
                                                                                                                                                                                                                                 Index> <Index xsi:type="esri:Index"> <Name>G18TSTypeID 
                                                                                                                                                                                                                                  Name> <IsUnique>false 
                                                                                                                                                                                                                                   IsUnique> <IsAscending>true 
                                                                                                                                                                                                                                    IsAscending> <FieldArray xsi:type="esri:ArrayOfField"> <Field xsi:type="esri:Field"> <Name>TSTypeID 
                                                                                                                                                                                                                                     Name> <Type>esriFieldTypeInteger 
                                                                                                                                                                                                                                      Type> <IsNullable>true 
                                                                                                                                                                                                                                       IsNullable> <Length>4 
                                                                                                                                                                                                                                        Length> <Precision>0 
                                                                                                                                                                                                                                         Precision> <Scale>0 
                                                                                                                                                                                                                                          Scale> <AliasName>TSTypeID 
                                                                                                                                                                                                                                           AliasName> <ModelName>TSTypeID 
                                                                                                                                                                                                                                            ModelName>  
                                                                                                                                                                                                                                             Field>  
                                                                                                                                                                                                                                              FieldArray>  
                                                                                                                                                                                                                                               Index>  
                                                                                                                                                                                                                                                IndexArray>  
                                                                                                                                                                                                                                                 Indexes>  
                                                                                                                                                                                                                                                  DataElement> the featuredataset Drainage definition is: <DEFeatureDataset xsi:type='typens:DEFeatureDataset' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:typens='http://www.esri.com/schemas/ArcGIS/10.0'><CatalogPath>/Drainage 
                                                                                                                                                                                                                                                   CatalogPath><Name>Drainage 
                                                                                                                                                                                                                                                    Name><ChildrenExpanded>false 
                                                                                                                                                                                                                                                     ChildrenExpanded><DatasetType>esriDTFeatureDataset 
                                                                                                                                                                                                                                                      DatasetType><DSID>19 
                                                                                                                                                                                                                                                       DSID><Versioned>false 
                                                                                                                                                                                                                                                        Versioned><CanVersion>false 
                                                                                                                                                                                                                                                         CanVersion><ConfigurationKeyword> 
                                                                                                                                                                                                                                                          ConfigurationKeyword><Extent xsi:nil='true'/><SpatialReference xsi:type='typens:ProjectedCoordinateSystem'><WKT>PROJCS["Clarke_1866_Albers",GEOGCS["GCS_Clarke_1866",DATUM["D_Clarke_1866",SPHEROID["Clarke_1866",6378206.4,294.9786982]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",23.0],UNIT["Meter",1.0]] 
                                                                                                                                                                                                                                                           WKT><XOrigin>-16901099.99967755 
                                                                                                                                                                                                                                                            XOrigin><YOrigin>-6971999.9998109061 
                                                                                                                                                                                                                                                             YOrigin><XYScale>7812.4999927240415 
                                                                                                                                                                                                                                                              XYScale><ZOrigin>0 
                                                                                                                                                                                                                                                               400000

这段代码可以显示出Table和FeatureDataset的定义,但是在显示FeatureDataset定义的时候就会crash掉,非常郁闷,感觉像一个bug(也正常,毕竟是beta版呀)。已提交给American Engineer 了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值