ArcgisOpr CXX0030

这个错误我是找了好多天才找到了

 

AE(ArcgisEngine)在用VC环境进行开发时,对license的初始化失败,

并在VC的编译输出窗口中提示Could not bind to a valid ArcGIS installation

是因为VC没找到Arcgis Engine的安装位置,参考官网的介绍(好不容易找到的)

http://help.arcgis.com/EN/sdk/10.0/ArcObjects_NET/conceptualhelp/index.html#//000100000nmm000000

Loading an ArcGIS runtime

Stand-alone ArcGIS applications must locate an appropriate ArcGIS product installation before any ArcObjects code (including license initialization) is called. You must decide what runtime is needed for the application. This must be done whether the license initialization is carried out using the LicenseControl or by using the AoInitialize class. The application programming interfaces (APIs) used to bind to the ArcGIS runtime are in IArcGISVersion in the ArcGISVersionLib namespace. To bind to the runtime, make a call to the LoadVersion method. See the following code example:

 

对于独立的Arcgis 应用程序必须先绑定一个runtime,方法如下

// Load the ArcGISVersion library.

// This code is commonly placed in the StdAfx.h header file.

//这段代码放到stdafx.h里(或者放到主要的头文件中)

#import "libid:6FCCEDE0-179D-4D12-B586-58C88D26CA78" raw_interfaces_only no_implementation

--------------------------------------分割线--------------------------------------------------------------

// The following code can be used to bind to ArcGIS Engine Runtime:

//下面的代码要加在::AoInitialize(NULL);之后,IAoInitializePtr ipInit(CLSID_AoInitialize);之前

ArcGISVersionLib::IArcGISVersionPtr ipVer(__uuidof(ArcGISVersionLib ::VersionManager));

VARIANT_BOOL succeeded;

if (FAILED(ipVer->LoadVersion(ArcGISVersionLib::esriArcGISEngine, L "10.0", &succeeded))) ‍

return 0;

------------------------------

例如 main.cpp

#import "libid:6FCCEDE0-179D-4D12-B586-58C88D26CA78" raw_interfaces_only no_implementation

‍#include <ArcSDK.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
int LocateTheArcgisVersion()
{
ArcGISVersionLib::IArcGISVersionPtr ipVer(__uuidof(ArcGISVersionLib::VersionManager));
VARIANT_BOOL succeeded;
if (FAILED(ipVer->LoadVersion(ArcGISVersionLib::esriArcGISEngine, L"10.0",&succeeded)))
return 0;
return 1;
}
int main(int argc, char **argv)
{

::AoInitialize(NULL);
LocateTheArcgisVersion();
// ArcGIS Engine licensing
IAoInitializePtr ipInit(CLSID_AoInitialize);
esriLicenseStatus status;

ipInit->Initialize(esriLicenseProductCodeEngine,&status);
if(status == esriLicenseCheckedOut)
{
cout<<"lisense ok"; 
}


::AoUninitialize();
system("PAUSE");
AoExit(0);
return 0;
}



我是使用的ArcGIS Desktop 10开发的,所以我的代码如下:

stdafx.h:

[cpp]  view plain copy
  1. // stdafx.h : 标准系统包含文件的包含文件,  
  2. // 或是经常使用但不常更改的  
  3. // 特定于项目的包含文件  
  4.   
  5. #pragma once  
  6.   
  7. #ifndef _SECURE_ATL  
  8. #define _SECURE_ATL 1  
  9. #endif  
  10.   
  11. #ifndef VC_EXTRALEAN  
  12. #define VC_EXTRALEAN        // 从 Windows 头中排除极少使用的资料  
  13. #endif  
  14.   
  15. // 如果您必须使用下列所指定的平台之前的平台,则修改下面的定义。  
  16. // 有关不同平台的相应值的最新信息,请参考 MSDN。  
  17. #ifndef WINVER              // 允许使用特定于 Windows XP 或更高版本的功能。  
  18. #define WINVER 0x0501       // 将此值更改为相应的值,以适用于 Windows 的其他版本。  
  19. #endif  
  20.   
  21. #ifndef _WIN32_WINNT        // 允许使用特定于 Windows XP 或更高版本的功能。  
  22. #define _WIN32_WINNT 0x0501 // 将此值更改为相应的值,以适用于 Windows 的其他版本。  
  23. #endif                        
  24.   
  25. #ifndef _WIN32_WINDOWS      // 允许使用特定于 Windows 98 或更高版本的功能。  
  26. #define _WIN32_WINDOWS 0x0410 // 将它更改为适合 Windows Me 或更高版本的相应值。  
  27. #endif  
  28.   
  29. #ifndef _WIN32_IE           // 允许使用特定于 IE 6.0 或更高版本的功能。  
  30. #define _WIN32_IE 0x0600    // 将此值更改为相应的值,以适用于 IE 的其他版本。值。  
  31. #endif  
  32.   
  33. #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS  // 某些 CString 构造函数将是显式的  
  34.   
  35. // 关闭 MFC 对某些常见但经常可放心忽略的警告消息的隐藏  
  36. #define _AFX_ALL_WARNINGS  
  37.   
  38. #include <afxwin.h>         // MFC 核心组件和标准组件  
  39. #include <afxext.h>         // MFC 扩展  
  40.   
  41.   
  42. #include <afxdisp.h>        // MFC 自动化类  
  43.   
  44.   
  45.   
  46. #ifndef _AFX_NO_OLE_SUPPORT  
  47. #include <afxdtctl.h>     // MFC 对 Internet Explorer 4 公共控件的支持  
  48. #endif  
  49. #ifndef _AFX_NO_AFXCMN_SUPPORT  
  50. #include <afxcmn.h>           // MFC 对 Windows 公共控件的支持  
  51. #endif // _AFX_NO_AFXCMN_SUPPORT  
  52.   
  53.   
  54.   
  55.   
  56.   
  57.   
  58.   
  59.   
  60.   
  61. #ifdef _UNICODE  
  62. #if defined _M_IX86  
  63. #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")  
  64. #elif defined _M_IA64  
  65. #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")  
  66. #elif defined _M_X64  
  67. #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")  
  68. #else  
  69. #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")  
  70. #endif  
  71. #endif  
  72.   
  73.   
  74. #import "libid:6FCCEDE0-179D-4D12-B586-58C88D26CA78" raw_interfaces_only no_implementation  

初始化:

ArcgisOpr.cpp:

[cpp]  view plain copy
  1. #include "stdafx.h"  
  2. #include "ArcgisOpr.h"  
  3.   
  4. ArcgisOpr::ArcgisOpr(void)  
  5. {  
  6.     m_pAo = NULL;  
  7.     m_pFcls = NULL;  
  8.     m_pFwks = NULL;  
  9.     m_isOpen = 0;  
  10.     m_clsType = esriGeometryNull;  
  11.   
  12. }  
  13.   
  14. ArcgisOpr::~ArcgisOpr(void)  
  15. {  
  16.     CloseFeatureClass();  
  17.     CoUninitialize();  
  18.   
  19. }  
  20. int ArcgisOpr::LocateTheArcgisVersion()  
  21. {  
  22.     ArcGISVersionLib::IArcGISVersionPtr ipVer(__uuidof(ArcGISVersionLib::VersionManager));  
  23.     VARIANT_BOOL succeeded;  
  24.     if (FAILED(ipVer->LoadVersion(ArcGISVersionLib::esriArcGISDesktop, L"10.0",&succeeded)))  
  25.         return 0;  
  26.     return 1;  
  27. }  
  28.   
  29. long ArcgisOpr::InitFcls(const char* pszWSFilePath)  
  30. {  
  31.     TCHAR strPath[100] = {0};  
  32.     HRESULT hr = S_FALSE;  
  33.     esriLicenseStatus esriLice = esriLicenseUnavailable;      
  34.     BSTR bstrPath = NULL;  
  35.     IWorkspacePtr ipWksPtr = NULL;  
  36.     IWorkspaceFactoryPtr ipWksFtyPtr = NULL;  
  37.   
  38.     //com组建初始化  
  39.     CoInitialize(NULL);  
  40.     LocateTheArcgisVersion();  
  41.   
  42. /* 
  43.     ::AoInitialize(NULL); 
  44.     LocateTheArcgisVersion(); 
  45.     // ArcGIS Engine licensing 
  46.     IAoInitializePtr ipInit(CLSID_AoInitialize); 
  47.     esriLicenseStatus status; 
  48.  
  49.     ipInit->Initialize(esriLicenseProductCodeEngine,&status); 
  50.     if(status == esriLicenseCheckedOut) 
  51.     { 
  52.         cout<<"lisense ok";  
  53.     } 
  54.  
  55.  
  56.     ::AoUninitialize(); 
  57.     system("PAUSE"); 
  58.     AoExit(0); 
  59.     return 0; 
  60. */  
  61.     //初始化AO组件的license  
  62.     m_pAo.CreateInstance(CLSID_AoInitialize);  
  63.     hr = m_pAo->Initialize(esriLicenseProductCodeArcInfo,&esriLice);  
  64.   
  65.     //建立ACCESS数据库工作区间工厂  
  66.     hr = ipWksFtyPtr.CreateInstance(CLSID_ShapefileWorkspaceFactory);  
  67.     if (FAILED(hr))  
  68.     {  
  69.         return(0);  
  70.     }  
  71.     //获取工作区  
  72.     bstrPath  = _com_util::ConvertStringToBSTR(pszWSFilePath);  
  73.     hr = ipWksFtyPtr->OpenFromFile(bstrPath,0,&ipWksPtr);  
  74.     if (FAILED(hr))  
  75.     {  
  76.         return(0);  
  77.     }  
  78.     //得到要素类工作空间  
  79.     hr = ipWksPtr->QueryInterface(IID_IFeatureWorkspace,(void**)&m_pFwks);  
  80.     if (FAILED(hr))  
  81.     {  
  82.         return(0);  
  83.     }  
  84.     //释放指针  
  85.     if (bstrPath!=NULL)  
  86.     {  
  87.         SysFreeString(bstrPath);  
  88.         bstrPath = NULL;  
  89.     }  
  90.     return(1);  
  91. }  
  92.   
  93. // //功能:打开地理数据库  
  94. // //参数:clsName [in]-地理数据库名字  
  95. // //返回值:成功返回1,失败返回0或者负数  
  96. long ArcgisOpr::OpenFeatureClass(const char *szClsName)  
  97. {  
  98.     IWorkspacePtr           pWksPtr  = NULL;  
  99.     IFeatureWorkspacePtr    pFWksPtr = NULL;  
  100.     IFeatureClassPtr        pFclsPtr = NULL;  
  101.     IWorkspaceFactoryPtr    pWksFPtr = NULL;   
  102.     HRESULT                 hr       = S_FALSE;  
  103.     long                    rtn = 0;  
  104.     BSTR clsName = _com_util::ConvertStringToBSTR(szClsName);  
  105.     if(clsName==NULL)  
  106.         return (0);  
  107.       
  108.     //1.在打开之前先关闭前面打开的  
  109.     CloseFeatureClass();  
  110.     //2、获取工作空间  
  111.   
  112.     //3。打开地理数据库要素类  
  113.     hr = m_pFwks->OpenFeatureClass(clsName,&m_pFcls);  
  114.     if(SUCCEEDED(hr))  
  115.     {  
  116.         //4。取要素类类型  
  117.         hr = m_pFcls->get_ShapeType(&m_clsType);  
  118.         m_isOpen = 1;  
  119.         if(SUCCEEDED(hr))  
  120.             {  
  121.             rtn = 1;  
  122.             }  
  123.     }     
  124.     else  
  125.     {  
  126.         CloseFeatureClass();  
  127.         rtn = -1;  
  128.     }  
  129.     return(rtn);  
  130. }  
  131.   
  132. // //功能:关闭要素类  
  133. // //参数:无  
  134. // //返回:成功返回1,失败返回0或者负数  
  135. long ArcgisOpr::CloseFeatureClass()  
  136. {  
  137.     m_pFcls = NULL;  
  138.     m_isOpen = 0;  
  139.     m_clsType = esriGeometryNull;  
  140.     return (1);  
  141. }  
  142.   
  143. long ArcgisOpr::GetClsType(esriGeometryType type)  
  144. {  
  145.     type = m_clsType;  
  146.     return(1);  
  147. }  
  148.   
  149. long ArcgisOpr::IsOpened()  
  150. {  
  151.   
  152.     return m_isOpen;  
  153. }  
  154.   
  155. //获取要素个数  
  156. long ArcgisOpr::GetFeasNum(long *pnCnt)  
  157. {  
  158.     IQueryFilterPtr pQuery = NULL;  
  159.     HRESULT hr = S_FALSE;  
  160.     long rtn = 0;  
  161.     pQuery.CreateInstance(CLSID_QueryFilter);  
  162.     hr = m_pFcls->FeatureCount(pQuery,pnCnt);  
  163.   
  164.     if(SUCCEEDED(hr))  
  165.         rtn=1;  
  166.   
  167.     return (rtn);  
  168. }  
  169.   
  170. //获取要素类的属性结构  
  171. long ArcgisOpr::GetAttStru(IFields **pFlds)  
  172. {  
  173.     ITablePtr pTab = NULL;  
  174.     HRESULT hr = S_FALSE;  
  175.     pTab = m_pFcls;  
  176.     hr = pTab->get_Fields(pFlds);  
  177.     if (SUCCEEDED(hr)==1)  
  178.     {  
  179.         return(1);  
  180.     }  
  181.     return(0);  
  182. }  
  183.   
  184. //获取某一要素的属性值  
  185. long ArcgisOpr::GetAtt(long fID/*从0开始*/, ARC_IRow **pRow)  
  186. {  
  187.     long            rtn=0;  
  188.     IFeaturePtr     pFeature;  
  189.     HRESULT         hr = 0;  
  190.     IFieldsPtr      ptfields;  
  191.   
  192.     if(m_isOpen==0)  
  193.         return (0);  
  194.   
  195.     hr = m_pFcls->GetFeature(fID,&pFeature);  
  196.     if(SUCCEEDED(hr))  
  197.     {  
  198.         hr= pFeature->QueryInterface(IID_ARC_IRow,(void**)pRow);  
  199.         if(pRow!=NULL)  
  200.         {  
  201.             rtn =1;  
  202.         }  
  203.     }  
  204.   
  205.     return (rtn);  
  206. }  
  207.   
  208. //通过要素名称获取要素的ID  
  209. long ArcgisOpr::GetFeaIDByName(const char* pszFldName,const char* pszFeaName,long *pnID)  
  210. {  
  211.     int i = 0;  
  212.     long rtn = 0;  
  213.     long nCnt =0;  
  214.     ARC_IRowPtr pArow = NULL;  
  215.     IRowBufferPtr pRowBuf = NULL;  
  216.     HRESULT hr = S_FALSE;  
  217.     ITablePtr pTbl = m_pFcls;  
  218.     IFeaturePtr pFea = NULL;  
  219.     IFieldsPtr pFlds = NULL;  
  220.     char szFldName[64] = {0};  
  221.     long nIndex = 0;  
  222.     rtn = GetFeasNum(&nCnt);  
  223.     if (rtn <=0)  
  224.     {  
  225.         return(0);  
  226.     }  
  227.     GetAttStru(&pFlds);  
  228.     long nFldCnt;  
  229.     BSTR bstrFldName = NULL;  
  230.     bstrFldName = _com_util::ConvertStringToBSTR(pszFldName);  
  231.     pFlds->FindField(bstrFldName,&nIndex);  
  232.     VARIANT varValue;  
  233.     for (i=0;i<nCnt;i++)  
  234.     {  
  235.         hr = m_pFcls->GetFeature(i,&pFea);  
  236.         pArow = pFea;  
  237.         VariantInit(&varValue);  
  238.         pArow->get_Value(nIndex,&varValue);  
  239.         if(strcmp(pszFeaName,_com_util::ConvertBSTRToString(varValue.bstrVal))==0)  
  240.         {  
  241.   
  242.                 *pnID = i;  
  243.         }  
  244.         else  
  245.         {  
  246.             continue;  
  247.         }  
  248.   
  249.         if (bstrFldName!=NULL)  
  250.         {  
  251.             SysFreeString(bstrFldName);  
  252.             bstrFldName = NULL;  
  253.         }  
  254.     }  
  255.     return(0);  
  256. }  
  257.   
  258. //获取多边形外界矩形范围  
  259. long ArcgisOpr::polygon_GetRect(long id,D_RECT *rect)  
  260. {  
  261.     IFeaturePtr     pFeature;  
  262.     HRESULT         Isucc = 0;  
  263.     IEnvelopePtr pEnve = NULL;  
  264.     //1.判断入口参数  
  265.     if(id<1)  
  266.         return (0);  
  267.     if(m_isOpen==0)  
  268.         return (0);  
  269.   
  270.     //  id=id-1;         //esri的要素id从0开始,zoyon从1开始  
  271.   
  272.     //2.取要素  
  273.     Isucc = m_pFcls->GetFeature(id,&pFeature);  
  274.     Isucc = pFeature->get_Extent(&pEnve);  
  275.     if(FAILED(Isucc))  
  276.         return(0);  
  277.   
  278.     pEnve->get_XMin(&rect->xmin);  
  279.     pEnve->get_YMin(&rect->ymin);  
  280.     pEnve->get_XMax(&rect->xmax);  
  281.     pEnve->get_YMax(&rect->ymax);  
  282.     return (1);  
  283. }  
  284.   
  285. //获取多边形的边界点  
  286. long ArcgisOpr::GetDotsByPolygon(long nID,long *pnPolyCnt,long *pnTolPntCnt,/*D_DOT *pDots*/D_DOT Dots[])  
  287. {  
  288.     HRESULT hr = S_FALSE;  
  289.     IFeaturePtr pFea = NULL;  
  290.     IGeometryPtr pGeo = NULL;  
  291.     IPolygonPtr pPolygon = NULL;  
  292.     IGeometryCollectionPtr pGeoCol = NULL;  
  293.     ISegmentCollectionPtr pSegCol = NULL;  
  294.     IGeometryPtr pSmallPoly = NULL;  
  295.     ISegmentPtr pSeg = NULL;  
  296.     IPointPtr pPnt = NULL;  
  297.     D_DOT *dots = NULL;  
  298.     long nPolygonCnt = 0;  
  299.     long nSegCnt = 0;  
  300.     long nPntCnt = 0;  
  301.     long i = 0;  
  302.     int j = 0;  
  303.     long nPreNum = 0;  
  304.     long nTolPntsNum = 0;  
  305.     if (m_clsType == esriGeometryPolygon)  
  306.     {  
  307.         m_pFcls->GetFeature(nID,&pFea);  
  308.         pFea->get_Shape(&pGeo);  
  309.         pPolygon = pGeo;  
  310.         pGeoCol = pPolygon;  
  311.         pGeoCol->get_GeometryCount(&nPolygonCnt);  
  312.         dots = new D_DOT[20000];  
  313.         for (i = 0;i<nPolygonCnt;i++)  
  314.         {  
  315.             pGeoCol->get_Geometry(i,&pSmallPoly);  
  316.             pSegCol = pSmallPoly;  
  317.             pSegCol->get_SegmentCount(&nSegCnt);  
  318.             nPntCnt = nSegCnt+1;  
  319.             for (j = 0;j<nSegCnt;j++)  
  320.             {  
  321.                 pSegCol->get_Segment(j,&pSeg);  
  322.                 pSeg->get_FromPoint(&pPnt);  
  323.                 pPnt->get_X(&dots[j+nTolPntsNum].x);  
  324.                 pPnt->get_Y(&dots[j+nTolPntsNum].y);  
  325.                 dots[j+nTolPntsNum].nHoleID = i+1;  
  326.                 dots[j+nTolPntsNum].nIndex = j+1;  
  327.                 if (j==53)  
  328.                 {  
  329.                     j=53;  
  330.                 }  
  331.             }  
  332.             pSeg->get_ToPoint(&pPnt);  
  333.             pPnt->get_X(&dots[j+nTolPntsNum].x);  
  334.             pPnt->get_Y(&dots[j+nTolPntsNum].y);  
  335.             dots[j+nTolPntsNum].nHoleID = i+1;  
  336.             dots[j+nTolPntsNum].nIndex = j+1;  
  337.             nPreNum = nTolPntsNum;  
  338.             nTolPntsNum = nTolPntsNum+nPntCnt;  
  339.         }  
  340.         *pnPolyCnt = nPolygonCnt;  
  341.         *pnTolPntCnt = nTolPntsNum;  
  342.         for(i=0;i<nTolPntsNum;i++)  
  343.         {  
  344.             Dots[i] = dots[i];  
  345.         }  
  346.         delete []dots;  
  347.         return(1);  
  348.     }  
  349.     delete []dots;  
  350.     return(1);  
  351. }  
  352.   
  353. //添加点到要素类中。  
  354. long ArcgisOpr::AddDots(const char* pszName,long nPntsCnt,D_DOT dots[])  
  355. {  
  356.     HRESULT hr = S_FALSE;  
  357.     IFeaturePtr pFea = NULL;  
  358.     IPointPtr pPnt = NULL;    
  359.     BSTR bstrName = NULL;  
  360.     bstrName = _com_util::ConvertStringToBSTR(pszName);  
  361.     m_pFwks->OpenFeatureClass(bstrName,&m_pFcls1);  
  362.     int i= 0;  
  363.     for (i = 0;i<nPntsCnt;i++)  
  364.     {  
  365.         m_pFcls1->CreateFeature(&pFea);  
  366.         pPnt.CreateInstance(CLSID_Point);  
  367.         pPnt->put_X(dots[i].x);  
  368.         pPnt->put_Y(dots[i].y);  
  369.         pFea->putref_Shape(pPnt);  
  370.         pFea->Store();  
  371.     }  
  372.     if(bstrName!=NULL)  
  373.     {  
  374.         SysFreeString(bstrName);  
  375.         bstrName = NULL;  
  376.     }  
  377.     return(1);  
  378. }  
  379.   
  380. //获取点要素类中所有的点  
  381. long ArcgisOpr::GetAllDots(const char* pszClsName,D_DOT dots[],long *pPointsNum){  
  382.     HRESULT hr = S_FALSE;  
  383.     IFeaturePtr pFea = NULL;  
  384.     IPointPtr pPnt = NULL;    
  385.     IGeometryPtr pGeo = NULL;  
  386.     BSTR bstrName = NULL;  
  387.     D_DOT dot;  
  388.     bstrName = _com_util::ConvertStringToBSTR(pszClsName);  
  389.     m_pFwks->OpenFeatureClass(bstrName,&m_pFcls1);  
  390.     int i= 0;  
  391.     long nFeaNum = 0;  
  392.     m_pFcls1->FeatureCount(NULL,&nFeaNum);  
  393.     for (i = 0;i<nFeaNum;i++)  
  394.     {  
  395.         m_pFcls1->GetFeature(i,&pFea);  
  396.         pFea->get_Shape(&pGeo);  
  397.         pPnt = pGeo;  
  398.         pPnt->get_X(&(dot.x));  
  399.         pPnt->get_Y(&(dot.y));  
  400.         dots[i] = dot;  
  401.     }  
  402.     *pPointsNum = nFeaNum;  
  403.     if(bstrName!=NULL)  
  404.     {  
  405.         SysFreeString(bstrName);  
  406.         bstrName = NULL;  
  407.     }  
  408.     return(1);  
  409. }  
  410.   
  411. //获得所有的县  
  412. long ArcgisOpr::GetAllXian(const char *pszClsName,Xian xian[],long *pXianNum)  
  413. {  
  414.     IFeaturePtr ptFea = NULL;  
  415.     BSTR bstrName = _com_util::ConvertStringToBSTR(pszClsName);  
  416.     HRESULT hr = S_FALSE;  
  417.     IRowBufferPtr ptRowBuf = NULL;  
  418.     VARIANT var;  
  419.     VariantInit(&var);  
  420.     hr = m_pFwks->OpenFeatureClass(bstrName,&m_pFcls);  
  421.     if (hr == S_FALSE)  
  422.     {  
  423.         return 0;  
  424.     }  
  425.     long nFeaNum = 0;  
  426.     m_pFcls->FeatureCount(NULL,&nFeaNum);  
  427.     Xian tempXian;  
  428.     for (int i = 1030;i<nFeaNum;i++)  
  429.     {  
  430.         memset((void*)&tempXian,0,sizeof(Xian));  
  431.         m_pFcls->GetFeature(i,&ptFea);  
  432.         ptRowBuf = ptFea;  
  433.         ptRowBuf->get_Value(1,&var);  
  434.         strcpy(tempXian.szXianName,_com_util::ConvertBSTRToString(var.bstrVal));  
  435.         xian[i] = tempXian;  
  436.     }  
  437.     *pXianNum = nFeaNum;  
  438.     if (bstrName!=NULL)  
  439.     {  
  440.         SysFreeString(bstrName);  
  441.         bstrName = NULL;  
  442.     }  
  443.     return 1;  
  444. }  
  445.   
  446. //填充县的字段  
  447. long ArcgisOpr::FillXianFld(const char *pszClsName,Xian xian[])  
  448. {  
  449.   
  450.     IFeaturePtr ptFea = NULL;  
  451.     BSTR bstrName = _com_util::ConvertStringToBSTR(pszClsName);  
  452.     HRESULT hr = S_FALSE;  
  453.     IRowBufferPtr ptRowBuf = NULL;  
  454.     VARIANT var;  
  455.     ARC_IRowPtr ptRow = NULL;  
  456.     VariantInit(&var);  
  457.     hr = m_pFwks->OpenFeatureClass(bstrName,&m_pFcls);  
  458.     if (hr == S_FALSE)  
  459.     {  
  460.         return 0;  
  461.     }  
  462.     long nFeaNum = 0;  
  463.     m_pFcls->FeatureCount(NULL,&nFeaNum);  
  464.     Xian tempXian;  
  465.     for (int i = 1030;i<nFeaNum;i++)  
  466.     {  
  467.         tempXian = xian[i];  
  468.         m_pFcls->GetFeature(i,&ptFea);  
  469.         ptFea.QueryInterface(IID_ARC_IRow,&ptRow);  
  470.         ptRowBuf = ptFea;  
  471.         var.bstrVal = _com_util::ConvertStringToBSTR(tempXian.szCityName);  
  472.         ptRowBuf->put_Value(2,var);  
  473.         UpdateRow(ptRowBuf,ptRow);  
  474.         ptRow->Store();        
  475.     }  
  476.     if (bstrName!=NULL)  
  477.     {  
  478.         SysFreeString(bstrName);  
  479.         bstrName = NULL;  
  480.     }  
  481.     return 1;  
  482. }  
  483.   
  484. //将缓冲行更新到要素中  
  485. long ArcgisOpr::UpdateRow(IRowBufferPtr rowBuff,ARC_IRowPtr oldRow)  
  486. {//测试成功  
  487.     IFieldsPtr          flds;  
  488.     IFieldPtr           fld;  
  489.     long                rtn=0,fldNum=0,i=0;  
  490.     esriFieldType       esiType;  
  491.     VARIANT_BOOL        flag=0;  
  492.     VARIANT             eValue;  
  493.     HRESULT             Isucc = -1;  
  494.   
  495.     if(m_isOpen==0)  
  496.         return (0);  
  497.     if(rowBuff==NULL || oldRow==NULL)  
  498.         return(0);  
  499.   
  500.     Isucc = rowBuff->get_Fields(&flds);  
  501.     if(Isucc!=S_OK)  
  502.         return -1;  
  503.   
  504.     Isucc = flds->get_FieldCount(&fldNum);  
  505.     if(fldNum<1)  
  506.         return (0);  
  507.   
  508.     for(i=0;i<fldNum;i++)  
  509.     {  
  510.         flds->get_Field(i,&fld);  
  511.         if(fld==NULL)  
  512.             return (0);  
  513.   
  514.         fld->get_Type(&esiType);  
  515.         fld->get_Editable(&flag);  
  516.         if((esiType!=esriFieldTypeGeometry)&&(-1==flag))//不拷贝OID  
  517.         {  
  518.             Isucc=rowBuff->get_Value(i,&eValue);  
  519.             if(eValue.vt==VT_NULL)  
  520.             {  
  521.                 rtn = 1;  
  522.                 continue;  
  523.             }  
  524.             Isucc=oldRow->put_Value(i,eValue);  
  525.             //          if(FAILED(Isucc))  
  526.             //              return (0);  
  527.         }  
  528.     }  
  529.   
  530.     if(SUCCEEDED(Isucc))  
  531.         rtn = 1;  
  532.     return (rtn);  
  533. }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冷月宫主

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值