📄 geopointfeature.cpp
字号:
// GeoPointFeature.cpp: implementation of the CGeoPointFeature class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "TestGeoDatabase.h"
#include "GeoPointFeature.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CGeoPointFeature::CGeoPointFeature()
{
m_x=0;
m_y=0;
}
CGeoPointFeature::~CGeoPointFeature()
{
}
BOOL CGeoPointFeature::CreatePoint(IFeatureClassPtr pFeatureClass,double x,double y)
{
//pFeatureClass->get
CComPtr<IWorkspaceEdit> pWorkspaceEdit;
IDatasetPtr data;
CComPtr<IWorkspace> ipwork;
data= pFeatureClass;
data->get_Workspace(&ipwork);
HRESULT hr=ipwork->QueryInterface(&pWorkspaceEdit) ;
IFeatureWorkspacePtr fw;
hr=pWorkspaceEdit->QueryInterface(&fw);
/* IFeatureClassPtr pFeatc;
hr=fw->OpenFeatureClass(CComBSTR(L"Points"),&pFeatc);
*/
///////////////////////////////////////////////////////////
hr = pWorkspaceEdit->StartEditing(TRUE);
if (FAILED(hr))
{
AfxMessageBox("开始编辑失败!" );
pWorkspaceEdit->AbortEditOperation();
return FALSE;
}
hr = pWorkspaceEdit->StartEditOperation();
if (FAILED(hr))
{
AfxMessageBox("开始编辑操作失败!" );
pWorkspaceEdit->AbortEditOperation();
return FALSE;
}
////////////////////////////////
IFieldsPtr ipFieldsNew;
long indX=10, indY=100, indV=88;
// hr = pFeatureClass->get_Fields(&ipFieldsNew);
//if (FAILED(hr = ipFieldsNew->FindField(CComBSTR(L"Longitude"), &indX))) {AfxMessageBox("aaa");return hr;}
/////////////////////////////////
IFeatureCursorPtr ipFeatureCursor;
IFeatureBufferPtr ipFeatureBuffer;
pFeatureClass->Insert(VARIANT_TRUE, &ipFeatureCursor);
pFeatureClass->CreateFeatureBuffer(&ipFeatureBuffer);
/////////////////////////
/* IPointPtr ipPoint(CLSID_Point);
ipPoint->put_X(x);
ipPoint->put_Y(y);
IGeometryPtr ipGeom = ipPoint;
if (FAILED(hr = ipFeatureBuffer->putref_Shape(ipGeom)))
{
AfxMessageBox("dd");
return hr;
}
// NOTE: We do not have to explicitly add the data for Lat. and Long. b/c the shape field
// holds this type of data. It is sometimes useful to have the Lat. and Long. data
// explicitly in the table, however, and we do this here.
ipFeatureBuffer->put_Value(indX, CComVariant(x));
ipFeatureBuffer->put_Value(indY, CComVariant(y));
// Insert the feature, its ID is returned
CComVariant ret;
hr = ipFeatureCursor->InsertFeature(ipFeatureBuffer, &ret);
if (FAILED(hr))
{
AfxMessageBox("hh");
return hr;
}
int newFeatureCount;
// Flush the insert cursor every 100 features
if (++newFeatureCount % 100 == 0)
{
ipFeatureCursor->Flush();
}
*/
CComPtr<IFeature> ipFeat ;
hr= pFeatureClass->CreateFeature(&ipFeat);
if (FAILED(hr))
{
AfxMessageBox("建立要素失败");
return hr;
}
// Create a new point and add it to the shape field
IPointCollectionPtr IPoints;
IPointPtr ipPoint(CLSID_Point);
ipPoint->put_X(x);
ipPoint->put_Y(y);
IGeometryPtr ipGeom = ipPoint;
hr=ipFeat->putref_Shape(ipGeom);
if (FAILED(hr))
{
AfxMessageBox("eee");
return hr;}
hr=ipFeat->Store();
hr=pWorkspaceEdit->StopEditOperation();
hr=pWorkspaceEdit->StopEditing(TRUE);
if(FAILED(hr))
AfxMessageBox("aaa");
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -