您的位置:首页 > Web前端

ArcGis 创建 FeatureClass

2016-03-09 16:12 447 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: