⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geopolygonfeature.cpp

📁 arcgis geodatabase Access 数据库创建
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// GeoPolyGonFeature.cpp: implementation of the CGeoPolyGonFeature class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TestGeoDatabase.h"
#include "GeoPolyGonFeature.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGeoPolyGonFeature::CGeoPolyGonFeature()
{
	
	ipGonColl.CreateInstance(CLSID_Polygon);
}

CGeoPolyGonFeature::~CGeoPolyGonFeature()
{
	
}
//* NAME : createMultipartPolygonRingSegmentCollection
//* DESCRIPTION: Create a multipart polygon using rings via ISegmentCollection.
//* This function is demonstrating it by creating 1001
//* concentric square rings and add those to a polygon.
//* NOTE : This is the approach to use if non-linear segments (Circular Arc, Elliptical Arc and Bezier Curve) have to be created.
//*************************************************************************
HRESULT CGeoPolyGonFeature::CreatePolygonWithPointCollection(IFeatureClassPtr pFeatureClass)
{
	/////////////////////////////////////////////
	CComPtr<IWorkspaceEdit> pWorkspaceEdit;
	IDatasetPtr data;
	CComPtr<IWorkspace>  ipwork;
	data=    pFeatureClass;
	data->get_Workspace(&ipwork);
	HRESULT	hr=ipwork->QueryInterface(&pWorkspaceEdit) ;
	
	
	hr = pWorkspaceEdit->StartEditing(TRUE);
	if (FAILED(hr))
	{
		AfxMessageBox("开始编辑失败!" );
		pWorkspaceEdit->AbortEditOperation();
		return FALSE;
	}
	hr = pWorkspaceEdit->StartEditOperation();
	if (FAILED(hr))
	{
		AfxMessageBox("开始编辑操作失败!"  );
		pWorkspaceEdit->AbortEditOperation();
		return FALSE;
	}
	
	///////////////////////////////////////////////////////
	
	this->SetSpatialReference();
	
	
	// 存储多边行
	CComPtr<IFeature> ipFeat;
  	 hr=pFeatureClass->CreateFeature(&ipFeat);
	 IGeometryPtr ipGeom =ipGonColl;
	 /////////////??????????????????????????类型问题????
     hr=ipFeat->putref_Shape(ipGeom);
     hr=ipFeat->Store();
     hr=pWorkspaceEdit->StopEditOperation();
	 hr=pWorkspaceEdit->StopEditing(TRUE);
	 return S_OK;
}

void CGeoPolyGonFeature::SetSpatialReference()
{
	
	//*********************************************************
	// THE SPATIAL REFERENCE SHOULD BE SET HERE ON THE POLYGON
	// Here the spatial reference is created in memory but could also come from various sources:
	// IMap, IGeodataset, IGeometry etc...
	ISpatialReferencePtr ipspref(CLSID_UnknownCoordinateSystem);
	ipspref->SetFalseOriginAndUnits(0, 0, 10000); // Set the false origin and units.
	IGeometryPtr ipGeoSpRef(ipGonColl);
	ipGeoSpRef->putref_SpatialReference(ipspref);
	
}

void CGeoPolyGonFeature::AddPoint(IPointPtr pt)
{
	ipGonColl->AddPoint(pt);
}

HRESULT CGeoPolyGonFeature::CreatePolygonWithSegmentCollection(IFeatureClassPtr pFeatureClass)
{
	
	CComPtr<IWorkspaceEdit> pWorkspaceEdit;
	IDatasetPtr data;
	CComPtr<IWorkspace>  ipwork;
	data=    pFeatureClass;
	data->get_Workspace(&ipwork);
	HRESULT	hr=ipwork->QueryInterface(&pWorkspaceEdit) ;
	hr = pWorkspaceEdit->StartEditing(TRUE);
	if (FAILED(hr))
	{
		AfxMessageBox("开始编辑失败!" );
		pWorkspaceEdit->AbortEditOperation();
		return FALSE;
	}
	hr = pWorkspaceEdit->StartEditOperation();
	if (FAILED(hr))
	{
		AfxMessageBox("开始编辑操作失败!"  );
		pWorkspaceEdit->AbortEditOperation();
		return FALSE;
	}
	////////////////////////////////////////////////////////////////////////////
	ISegmentCollectionPtr ipGonColl1(CLSID_Polygon);
	//*********************************************************
	// Here the spatial reference is created in memory but could also come from various sources:
	ISpatialReferencePtr ipspref(CLSID_UnknownCoordinateSystem);
	ipspref->SetFalseOriginAndUnits(0, 0, 10000);
	IGeometryPtr ipGeoSpRef(ipGonColl1);
	ipGeoSpRef->putref_SpatialReference(ipspref);
	//*********************************************************创建面
	int i;
	ILinePtr ipLine[4];
	IPointPtr ipPoint[4];
	ISegmentPtr ipSegment[4];
	for (i = 0; i < 4; ++i)
	{
		ipLine[i].CreateInstance(CLSID_Line);
		ipPoint[i].CreateInstance(CLSID_Point);
		ipSegment[i] = ipLine[i];
	}
	// Put the coordinates of the points
	ipPoint[0]->PutCoords(0, 0);
	ipPoint[1]->PutCoords(100, 0);
	ipPoint[2]->PutCoords(100, 100);
	ipPoint[3]->PutCoords(0, 100);
	// Put the coordinates of the line
	ipLine[0]->PutCoords(ipPoint[0], ipPoint[1]);
	ipLine[1]->PutCoords(ipPoint[1], ipPoint[2]);
	ipLine[2]->PutCoords(ipPoint[2], ipPoint[3]);
	ipLine[3]->PutCoords(ipPoint[3], ipPoint[0]);
	// Add the segments in the polygon via the ISegmentCollection
	for (i = 0; i < 4; ++i)
	{
		ipGonColl1->AddSegment(ipSegment[i]);
	}
	
	/////////////////////////////////////////////
	// 存储多边行
  	 IPolygonPtr pl;
	 pl=ipGonColl1;
     ITopologicalOperatorPtr pTopoOp; 
	 pTopoOp = pl;
     hr=pTopoOp->Simplify();
     pl->Close();
     CComPtr<IFeature> ipFeat;
	 hr=pFeatureClass->CreateFeature(&ipFeat);
	 IGeometryPtr ipGeom=pl;
	 /////////////??????????????????????????类型问题????
     hr=ipFeat->putref_Shape(ipGeom);
     hr=ipFeat->Store();
     hr=pWorkspaceEdit->StopEditOperation();
	 hr=pWorkspaceEdit->StopEditing(TRUE);
	 return S_OK;
	 
}


HRESULT CGeoPolyGonFeature::createMultipartPolygonRingSegmentCollection(IFeatureClassPtr pFeatureClass)
{
	CComPtr<IWorkspaceEdit> pWorkspaceEdit;
	IDatasetPtr data;
	CComPtr<IWorkspace>  ipwork;
	data=    pFeatureClass;
	data->get_Workspace(&ipwork);
	HRESULT	hr=ipwork->QueryInterface(&pWorkspaceEdit) ;
	hr = pWorkspaceEdit->StartEditing(TRUE);
	if (FAILED(hr))
	{
		AfxMessageBox("开始编辑失败!" );
		pWorkspaceEdit->AbortEditOperation();
		return FALSE;
	}
	hr = pWorkspaceEdit->StartEditOperation();
	if (FAILED(hr))
	{
		AfxMessageBox("开始编辑操作失败!"  );
		pWorkspaceEdit->AbortEditOperation();
		return FALSE;
	}
	
	
	
	
	IGeometryCollectionPtr ipGonColl1(CLSID_Polygon);
	
	//*********************************************************
	//THE SPATIAL REFERENCE SHOULD BE SET HERE ON THE POLYGON
	//Here the spatial reference is created in memory but could also come from various sources:
	//IMap, IGeodataset, IGeometry etc...
	ISpatialReferencePtr ipspref(CLSID_UnknownCoordinateSystem);
	ipspref->SetFalseOriginAndUnits(0, 0, 10000);  // Set the false origin and units.
	// The XYUnits value is equivalent to the precision specified when creating a feature class
	IGeometryPtr ipGeoSpRef(ipGonColl1);
	ipGeoSpRef->putref_SpatialReference(ipspref);
	// *********************************************************
	// Initialize offset values
	double d0X0 = 0, d0Y0 = 0,
		d0X1 = 0, d0Y1 = 0,
		d0X2 = 0, d0Y2 = 0,
		d0X3 = 0, d0Y3 = 0;
	double d1X0 = 1000, d1Y0 = 1000,
		d1X1 = 1000, d1Y1 = 1000,
		d1X2 = 1000, d1Y2 = 1000,
		d1X3 = 1000, d1Y3 = 1000;
	int i, j;
	// Initialize the points
	IPointPtr ipPointsRing0[4];
	IPointPtr ipPointsRing1[4];
	for (i = 0; i < 4; ++i)
	{
		ipPointsRing0[i].CreateInstance(CLSID_Point);
		ipPointsRing1[i].CreateInstance(CLSID_Point);
	}
	// Loop to change the coordinates of the points
	ISegmentCollectionPtr ipRingColl[2];
	ILinePtr ipLine0[4];
	ILinePtr ipLine1[4];
	ISegmentPtr ipSeg0[4];
	ISegmentPtr ipSeg1[4];
	IGeometryPtr ipGeometry[2];
	for (i = 0; i < 1001; ++i)
	{
		ipRingColl[0].CreateInstance(CLSID_Ring);
		ipRingColl[1].CreateInstance(CLSID_Ring);
		// Lines are passed by reference to the polygon using ISegmentCollection
		// so a new line has to be instantiated to avoid the polygon to become degenerated
		for (j = 0; j < 4; ++j)
		{
			ipLine0[j].CreateInstance(CLSID_Line);
			ipLine1[j].CreateInstance(CLSID_Line);
			// QI (Query interface) to make sure that we have the correct type of geometry
			// when passing these arrays to the addsegments.
			// If passing directly the lines array it will fatal VB. This is a known limit of VB.
			ipSeg0[j] = ipLine0[j];
			ipSeg1[j] = ipLine1[j];
		}
		ipGeometry[0] = ipRingColl[0];
		ipGeometry[1] = ipRingColl[1];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -