📄 geopolygonfeature.cpp
字号:
d0X0 -= 5; d0Y0 -= 5;
d0X1 += 5; d0Y1 -= 5;
d0X2 += 5; d0Y2 += 5;
d0X3 -= 5; d0Y3 += 5;
// Put the coordinates of the points to use in the first ring
ipPointsRing0[0]->PutCoords(d0X0, d0Y0);
ipPointsRing0[1]->PutCoords(d0X1, d0Y1);
ipPointsRing0[2]->PutCoords(d0X2, d0Y2);
ipPointsRing0[3]->PutCoords(d0X3, d0Y3);
d1X0 -= 5; d1Y0 -= 5;
d1X1 += 5; d1Y1 -= 5;
d1X2 += 5; d1Y2 += 5;
d1X3 -= 5; d1Y3 += 5;
// Put the coordinates of the points to use in the second ring
ipPointsRing1[0]->PutCoords(d1X0, d1Y0);
ipPointsRing1[1]->PutCoords(d1X1, d1Y1);
ipPointsRing1[2]->PutCoords(d1X2, d1Y2);
ipPointsRing1[3]->PutCoords(d1X3, d1Y3);
// Put the coordinates of the lines
ipLine0[0]->PutCoords(ipPointsRing0[0], ipPointsRing0[1]);
ipLine0[1]->PutCoords(ipPointsRing0[1], ipPointsRing0[2]);
ipLine0[2]->PutCoords(ipPointsRing0[2], ipPointsRing0[3]);
ipLine0[3]->PutCoords(ipPointsRing0[3], ipPointsRing0[0]);
ipLine1[0]->PutCoords(ipPointsRing1[0], ipPointsRing1[1]);
ipLine1[1]->PutCoords(ipPointsRing1[1], ipPointsRing1[2]);
ipLine1[2]->PutCoords(ipPointsRing1[2], ipPointsRing1[3]);
ipLine1[3]->PutCoords(ipPointsRing1[3], ipPointsRing1[0]);
// Add the segments to the rings
for (j = 0; j < 4; ++j)
{
ipRingColl[0]->AddSegment(ipSeg0[j]);
ipRingColl[1]->AddSegment(ipSeg1[j]);
}
//
ipGeometry[0]=ipRingColl[0];
ipGeometry[1]=ipRingColl[1];
for (j = 0; j < 2; ++j)
{
hr=ipGonColl1->AddGeometry(ipGeometry[j]);
}
}
/////////////////////////////////////////////
// 存储面
/* IPolygonPtr pl;
pl=ipGonColl1;
ITopologicalOperatorPtr pTopoOp;
pTopoOp = pl;
hr=pTopoOp->Simplify();
pl->Close();
CComPtr<IFeature> ipFeat;
hr=pFeatureClass->CreateFeature(&ipFeat);
IGeometryPtr ipGeom=pl;
/////////////??????????????????????????what matter????
hr=ipFeat->putref_Shape(ipGeom);
hr=ipFeat->Store();
hr=pWorkspaceEdit->StopEditOperation();
hr=pWorkspaceEdit->StopEditing(TRUE);*/
IPolygonPtr pl;
pl=ipGonColl1;
ITopologicalOperatorPtr pTopoOp;
pTopoOp = pl;
hr=pTopoOp->Simplify();
pl->Close();
IFeatureBufferPtr pFeatureBuffer;
IFeatureCursorPtr pFeatureCursor ;
IGeometryPtr ipgeom=pl;
hr= pFeatureClass->Insert(TRUE,&pFeatureCursor);
hr = pFeatureClass->CreateFeatureBuffer(&pFeatureBuffer);
hr= pFeatureBuffer->putref_Shape(ipgeom);
pFeatureCursor->InsertFeature(pFeatureBuffer,0) ;
hr=pWorkspaceEdit->StopEditOperation();
hr=pWorkspaceEdit->StopEditing(TRUE);
return S_OK;
}
HRESULT CGeoPolyGonFeature::createMultipartPolygonRingPointCollection(IFeatureClassPtr pFeatureClass)
{
// Create the resulting polygon
IGeometryCollectionPtr ipGonCol(CLSID_Polygon);
//*********************************************************
ISpatialReferencePtr ipspref(CLSID_UnknownCoordinateSystem);
ipspref->SetFalseOriginAndUnits(0, 0, 100000); // Set the false origin and units.
IGeometryPtr ipGeoSpRef(ipGonCol);
ipGeoSpRef->putref_SpatialReference(ipspref);
// *********************************************************
double d0X0 = 0, d0Y0 = 0,
d0X1 = 0, d0Y1 = 0,
d0X2 = 0, d0Y2 = 0,
d0X3 = 0, d0Y3 = 0;
double d1X0 = 10000, d1Y0 = 10000,
d1X1 = 10000, d1Y1 = 10000,
d1X2 = 10000, d1Y2 = 10000,
d1X3 = 10000, d1Y3 = 10000;
int i, j;
IPointCollectionPtr ipRingsColl[2];
IGeometryPtr ipGeometry[2];
IPointPtr ipPointsRing0[5];
IPointPtr ipPointsRing1[5];
IPathPtr ss[12];
// Loop to change the coordinates of the points
// for (i = 0; i < 10 ; ++i)
// {
ipRingsColl[0].CreateInstance(CLSID_Ring);
ipRingsColl[1].CreateInstance(CLSID_Ring);
//QI(Query Interface) to make sure that we have the correct type of geometry when passing this array to the addsegments
// Create the new points
for (j = 0; j < 5; ++j)
{
ipPointsRing0[j].CreateInstance(CLSID_Point);
ipPointsRing1[j].CreateInstance(CLSID_Point);
}
d0X0 -= 5; d0Y0 -= 5;
d0X1 += 5; d0Y1 -= 5;
d0X2 += 5; d0Y2 += 5;
d0X3 -= 5; d0Y3 += 5;
// Put the coordinates of the points to use in the first ring
ipPointsRing0[0]->PutCoords(d0X0, d0Y0);
ipPointsRing0[1]->PutCoords(d0X1, d0Y1);
ipPointsRing0[2]->PutCoords(d0X2, d0Y2);
ipPointsRing0[3]->PutCoords(d0X3, d0Y3);
ipPointsRing0[4]->PutCoords(d0X0, d0Y0);
// Add the points to the ring
for (j = 0; j < 5; ++j)
{
ipRingsColl[0]->AddPoint(ipPointsRing0[j]);
}
d1X0 -= 5; d1Y0 -= 5;
d1X1 += 5; d1Y1 -= 5;
d1X2 += 5; d1Y2 += 5;
d1X3 -= 5; d1Y3 += 5;
// Put the coordinates of the points to use in the second ring
ipPointsRing1[0]->PutCoords(d1X0, d1Y0);
ipPointsRing1[1]->PutCoords(d1X1, d1Y1);
ipPointsRing1[2]->PutCoords(d1X2, d1Y2);
ipPointsRing1[3]->PutCoords(d1X3, d1Y3);
ipPointsRing1[4]->PutCoords(d1X0, d1Y0);
// Add the points to the ring
for (j = 0; j < 5; ++j)
{
ipRingsColl[1]->AddPoint(ipPointsRing0[j]);
}
ipGeometry[0] = ipRingsColl[0];
ipGeometry[1] = ipRingsColl[1];
// Add the rings to the polygon
for (j = 0; j < 2; ++j)
{
//ipGeometry[j] = ipRingsColl[j];
hr=ipGonCol->AddGeometry(ipGeometry[j]);
}
this->StartOption(pFeatureClass);
//'为每个Ring 创建一个新Polygon,将Polygon 进行simplify 后,pGeometryCollection 中
IGeometryCollectionPtr pGeometryCollection(CLSID_Polygon);
IGeometryCollectionPtr pGeometry(CLSID_Polygon);
ITopologicalOperatorPtr pTopologicalOperator;
long count;
IGeometryPtr Geo(CLSID_Polygon),Geo1(CLSID_Polygon) ;
hr=ipGonCol->get_GeometryCount(&count);
esriGeometryType type;
long hh;
for(i=0;i<count;i++)
{
ipGonCol->get_Geometry(i,&Geo);
hr=Geo->get_GeometryType(&type);
if(type==esriGeometryRing)
{
hr=pGeometryCollection.CreateInstance(CLSID_Polygon);
hr=pTopologicalOperator = pGeometryCollection;
hr=pGeometryCollection->AddGeometry(Geo);
hr=pTopologicalOperator->Simplify();
}
}
///////////////////////////////////
CComPtr<IFeature> ipFeat;
IPolygonPtr pl;
long count1;
pGeometryCollection->get_GeometryCount(&count1);
for(i=0;i<count1;i++)
{
hr=pFeatureClass->CreateFeature(&ipFeat);
pGeometryCollection->get_Geometry(i,&Geo1);// .Geometry
pl=Geo1;
hr=ipFeat->putref_Shape(pl);
hr=ipFeat->Store();
}
/* IPolygonPtr pl;
IGeometryPtr geo(CLSID_Polygon);
ITopologicalOperatorPtr pTopoOp;
CComPtr<IFeature> ipFeat;
long count;
ipGonCol->get_GeometryCount(&count);
hr=pFeatureClass->CreateFeature(&ipFeat);
for(i=0;i<count;i++)
{
ipGonCol->get_Geometry(i,&geo);
pl=geo;
pTopoOp=pl;
pTopoOp->Simplify();
pl->Close();
hr=ipFeat->putref_Shape(pl);
hr=ipFeat->Store();
}*/
this->StopOption();
return S_OK;
}
HRESULT CGeoPolyGonFeature::StartOption(IFeatureClassPtr pFeatureClass)
{
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;
}
return 0;
}
HRESULT CGeoPolyGonFeature::StopOption( )
{
hr=pWorkspaceEdit->StopEditOperation();
hr=pWorkspaceEdit->StopEditing(TRUE);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -