ArcGis 创建 FeatureClass

ArcGis 创建 FeatureClass C++代码

   bool CreateNewFeatureClass( CString strFeatureClassName, IFeatureWorkspacePtr pFeatureWorkspace )
   {
    IFieldsPtr  ipFields( CLSID_Fields );
    IFieldsEditPtr ipFieldsEdit = ipFields; 
    IFieldEditPtr  pFieldEdit;  
    IWorkspaceDomainsPtr pWorkspaceDomain(pFeatureWorkspace);
    IDomainPtr pDomain;

    // Field:OBJECTID
    IFieldPtr  pField1( CLSID_Field ); 
    pFieldEdit = (IFieldEditPtr)pField1;
    pFieldEdit->PutName( _T("OBJECTID") );
    pFieldEdit->PutAliasName( _T("OBJECTID") );
    pFieldEdit->PutType( **esriFieldTypeOID** );
    if(FAILED(ipFieldsEdit->AddField( pField1 )))
        return nullptr;

    // Field:SHAPE
    IFieldPtr  pField2( CLSID_Field ); 
    pFieldEdit = ( IFieldEditPtr )pField2;
    pFieldEdit->PutName( _T("SHAPE") );
    pFieldEdit->PutAliasName( _T("Shape") );
    pFieldEdit->PutType( esriFieldTypeGeometry );
    pFieldEdit->putref_GeometryDef( createGeometryDefine( esriGeometryPoint,  esriSRGeoCS_WGS1984 ) );
    if(FAILED(ipFieldsEdit->AddField( pField2 )))
        return nullptr;
    // 其他Field
    .......
    IFeatureClassPtr  ipFeatureClass; 
    HRESULT  hr = pFeatureWorkspace->CreateFeatureClass( CComBSTR( strFeatureClassName ) ,ipFields , NULL , NULL , esriFTSimple , CComBSTR( L"SHAPE" ) , NULL , &ipFeatureClass ) ;
}


IGeometryDefPtr    createGeometryDefine ( esriGeometryType geometryDefine, esriSRGeoCSType geocsType )
{
    ISpatialReferenceFactory2Ptr  ipSpaRefFact2( CLSID_SpatialReferenceEnvironment ); 
    IGeographicCoordinateSystemPtr  ipGeoCoordSys;
    ipSpaRefFact2->CreateGeographicCoordinateSystem( geocsType ,&ipGeoCoordSys);  
    ISpatialReferencePtr ipSRef = ipGeoCoordSys; 

    IGeometryDefPtr  ipGeoDef( CLSID_GeometryDef );
    IGeometryDefEditPtr  ipGeoDefEdit = ipGeoDef; 
    ipGeoDefEdit->put_GeometryType( geometryDefine );  
    ipGeoDefEdit->putref_SpatialReference(ipSRef);    

    return ipGeoDef; 
}

你可能感兴趣的:(ArcGis,开发,arcgis,c++,cstring)