编译通过,但还未调试:
//为线要素增加高程值(Z值)
void CAsongGISView::LineAddZvalue(IMapPtr ipMap, IQueryFilterPtr ipFilter)
{
LONG count(0);
HRESULT hr;
ipMap->get_LayerCount(&count);
for(int i = 0; i<count; i++)
{
ILayerPtr ipCurrentLayer;
IGeoFeatureLayerPtr ipGeoFeat;
ipMap->get_Layer(i,&ipCurrentLayer);
hr = ipCurrentLayer->QueryInterface(IID_IGeoFeatureLayer,(LPVOID*)&ipGeoFeat);
if(FAILED(hr))
{
AfxMessageBox("所打开的对象不是图形要素!");
return;
}
else
{
IFeatureLayerPtr ipFeatureLayer(ipCurrentLayer);
IFeatureClassPtr ipFeatureClass;
ipFeatureLayer->get_FeatureClass(&ipFeatureClass);
IDatasetPtr ipDataset(ipFeatureClass);
if (ipDataset != NULL)
{
IWorkspacePtr ipWork;
ipDataset->get_Workspace(&ipWork);
IWorkspaceEditPtr ipWorkspaceEdit(ipWork);
VARIANT_BOOL vbIsBeginEdited;
ipWorkspaceEdit->IsBeingEdited(&vbIsBeginEdited);
if (!vbIsBeginEdited)
{
ipWorkspaceEdit->StartEditing(VARIANT_TRUE);
ipWorkspaceEdit->StartEditOperation();
ipWorkspaceEdit->EnableUndoRedo();//true;
IFeatureLayerPtr ipEditFeatureLayer(ipCurrentLayer);
long lSHAPE;
long lng_strSurH;
long lng_endSurH(0);
IFeatureClassPtr ipFeatCls;
IFieldsPtr ipFields;
IFieldPtr ipField;
ipEditFeatureLayer->get_FeatureClass(&ipFeatCls);
ipFeatCls->get_Fields(&ipFields);
ipFields->FindField(CComBSTR("SHAPE"),&lSHAPE);
ipFields->FindField(CComBSTR("Elevation"),&lng_strSurH);
//ipFields->FindField(CComBSTR("END_H"),&lng_endSurH);
if (!(lng_strSurH == -1 || lng_endSurH == -1))
{
esriGeometryType shpType;
ipFeatCls->get_ShapeType(&shpType);
if (shpType == esriGeometryLine || shpType == esriGeometryPolyline)
{
long RecNumber;
IFeatureCursorPtr ipCursor;
IFeaturePtr ipFeature;
ipFeatCls->FeatureCount(ipFilter,&RecNumber);
ipEditFeatureLayer->Search(ipFilter, VARIANT_TRUE,&ipCursor);
ipCursor->NextFeature(&ipFeature);
while (ipFeature != NULL)
{
IGeometryPtr ipGeom;
ipFeature->get_Shape(&ipGeom);
IZAwarePtr ipNewZaware(ipGeom);
ipNewZaware->put_ZAware(VARIANT_TRUE);
IPointCollectionPtr ipPointCollection(ipGeom);
//给第一个点及最后一个点加Z值
IPointPtr ipGeo_TempPoint;
long ptCount;
double dblZ;
VARIANT vdblValue;
ipPointCollection->get_PointCount(&ptCount);
ipPointCollection->get_Point(0,&ipGeo_TempPoint);
ipFeature->get_Value(lng_strSurH,&vdblValue);
dblZ = vdblValue.dblVal;
ipGeo_TempPoint->put_Z(dblZ);
ipPointCollection->UpdatePoint(0, ipGeo_TempPoint);
ipPointCollection->get_Point(ptCount-1,&ipGeo_TempPoint);
ipFeature->Store();
ipCursor->NextFeature(&ipFeature);
}
}
}
ipWorkspaceEdit->StopEditOperation();
ipWorkspaceEdit->StopEditing(VARIANT_TRUE);
}
}
}
}
}
计划明天调试一下,可能还有很多需要改动的地方。