C++ AO读取一个shapefile文件的所有属性值
作者:网络转载 发布时间:[ 2014/3/7 9:37:57 ] 推荐标签:C++ 属性值
#include "stdafx.h"
#include "iostream.h"
#include "atlbase.h"
#include "comdef.h" 字串1
#pragma warning(push)
#pragma warning(disable : 4192)
#pragma warning(disable : 4146) 字串6
#import "esriSystem.olb"
raw_interfaces_only,
raw_native_types,
no_namespace,
named_guids, 字串7
exclude("OLE_COLOR", "OLE_HANDLE", "VARTYPE")
#import "esriGeometry.olb" raw_interfaces_only, raw_native_types, no_namespace, named_guids
#import "esriDataSourcesFile.olb" raw_interfaces_only, raw_native_types, no_namespace, named_guids
#import "esriGeoDatabase.olb" raw_interfaces_only, raw_native_types, no_namespace, named_guids
字串2
#pragma warning(pop)
字串5
//CString VariantToString1(VARIANT * va);
字串2
int main(int argc, char* argv[])
{
::CoInitialize(NULL);
字串1
IWorkspaceFactoryPtr pWSFactory(CLSID_ShapefileWorkspaceFactory);
IWorkspacePtr pWS;
// BSTR path;
// path = ::SysAllocString(L"C:\test");
HRESULT hr = pWSFactory->OpenFromFile(CComBSTR(L"C:\test\bj"),0,&pWS);
if (FAILED(hr) || pWS==NULL)
{
cerr<<"Failed to open the destination folder."<<endl;
return 1;
} 字串1
IFeatureWorkspacePtr pFWS(pWS);
IFeatureClassPtr pFClass;
pFWS->OpenFeatureClass (CComBSTR(L"bj_est1"),&pFClass);
字串3
IFeatureCursorPtr pFCursor;
pFClass->Search (NULL,VARIANT_TRUE,&pFCursor);
字串7
long lngFieldCount ;
IFieldsPtr pFields;
IFieldPtr pField;
pFCursor->get_Fields (&pFields);
pFields->get_FieldCount (&lngFieldCount); 字串4
IFeaturePtr pFeature;
pFCursor->NextFeature (&pFeature); 字串8
USES_CONVERSION; 字串9
long t;
CComBSTR bsValues;
CComVariant varValue;
esriFieldType esriFldType;
while (pFeature)
{
bsValues = CComBSTR(L" ");
for (t =0; t < lngFieldCount ; t++)
{
pFields->get_Field(t, &pField);
pField->get_Type(&esriFldType);
switch (esriFldType)
{
case (esriFieldTypeGeometry):
bsValues += CComBSTR(L"Shape ");
break;
default:
pFeature->get_Value(t, &varValue);
if (varValue.vt != VT_BSTR)
varValue.ChangeType(VT_BSTR); 字串4
bsValues += varValue.bstrVal;
bsValues += CComBSTR(L" ");
break;
}
} 字串3
// _bstr_t outString(bsValues,FALSE); //方法1:为控制台输出作准备
// cout << outString<<endl;
//方法2:也可以用OLE2A来进行转化,
//当然需要加上 USES_CONVERSION;
cout << OLE2A(bsValues)<< endl;
pFCursor->NextFeature (&pFeature);
} 字串6
pWSFactory=NULL;
pWS=NULL;
pFWS=NULL;
pFClass=NULL;
pFCursor=NULL;
pFields=NULL;
pField=NULL;
字串8
::CoUninitialize();
字串3
return 0;
} 字串5
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11