OGRErr AODataSource::DeleteLayer( int iLayer ) { if( iLayer < 0 || iLayer >= static_cast<int>(m_layers.size()) ) return OGRERR_FAILURE; // Fetch ArObject Table before deleting OGR layer object ITablePtr ipTable; m_layers[iLayer]->GetTable(&ipTable); std::string name = m_layers[iLayer]->GetLayerDefn()->GetName(); // delete OGR layer delete m_layers[iLayer]; m_layers.erase(m_layers.begin() + iLayer); IDatasetPtr ipDataset = ipTable; HRESULT hr; if (FAILED(hr = ipDataset->Delete())) { CPLError( CE_Warning, CPLE_AppDefined, "%s was not deleted however it has been closed", name.c_str()); AOErr(hr, "Failed deleting dataset"); return OGRERR_FAILURE; } else return OGRERR_NONE; }
////////////////////////////////////////////////////////////////////////// //简要描述 : 写要素类到CAD文件 //输入参数 : //返 回 值 : // // //修改日志 : ////////////////////////////////////////////////////////////////////////// STDMETHODIMP CDwgWriter::FeatureClass2Dwgfile(IFeatureClass* pFtCls) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // TODO: 在此添加实现代码 if (pFtCls == NULL) return S_FALSE; //m_pgrsDlg.Show(); CString sLog; CString sFtClsName; CComBSTR bsFtClsName; IDatasetPtr pDataset = pFtCls; if (pDataset != NULL) { pDataset->get_Name(&bsFtClsName); } else { pFtCls->get_AliasName(&bsFtClsName); } sFtClsName = bsFtClsName; int pos = sFtClsName.ReverseFind('.'); if (pos > 0) { sFtClsName = sFtClsName.Right(sFtClsName.GetLength() - pos - 1); } try { if (m_XDataCfgs.GetCount() == 0) //没有扩展属性 { m_dwgWriter.FeatureClass2Dwgfile(pFtCls, NULL); } else { XDataAttrLists* pXDataAttrLists = NULL; m_XDataCfgs.Lookup(sFtClsName, pXDataAttrLists); m_dwgWriter.FeatureClass2Dwgfile(pFtCls, pXDataAttrLists); } } catch (...) { sLog = sFtClsName + "图层写入到CAD文件时出错。"; m_dwgWriter.WriteLog(sLog); m_pgrsDlg.Hide(); return S_FALSE; } //m_pgrsDlg.Hide(); return S_OK; }
bool AOLayer::Initialize(ITable* pTable) { HRESULT hr; m_ipTable = pTable; CComBSTR temp; IDatasetPtr ipDataset = m_ipTable; if (FAILED(hr = ipDataset->get_Name(&temp))) return false; m_pFeatureDefn = new OGRFeatureDefn(CW2A(temp)); //Should I "new" an OGR smart pointer - sample says so, but it doesn't seem right //as long as we use the same compiler & settings in both the ogr build and this //driver, we should be OK m_pFeatureDefn->Reference(); IFeatureClassPtr ipFC = m_ipTable; VARIANT_BOOL hasOID = VARIANT_FALSE; ipFC->get_HasOID(&hasOID); if (hasOID == VARIANT_TRUE) { ipFC->get_OIDFieldName(&temp); m_strOIDFieldName = CW2A(temp); } if (FAILED(hr = ipFC->get_ShapeFieldName(&temp))) return AOErr(hr, "No shape field found!"); m_strShapeFieldName = CW2A(temp); IFieldsPtr ipFields; if (FAILED(hr = ipFC->get_Fields(&ipFields))) return AOErr(hr, "Fields not found!"); long shapeIndex = -1; if (FAILED(hr = ipFields->FindField(temp, &shapeIndex))) return AOErr(hr, "Shape field not found!"); IFieldPtr ipShapeField; if (FAILED(hr = ipFields->get_Field(shapeIndex, &ipShapeField))) return false; // Use GeometryDef to set OGR shapetype and Spatial Reference information // IGeometryDefPtr ipGeoDef; if (FAILED(hr = ipShapeField->get_GeometryDef(&ipGeoDef))) return false; OGRwkbGeometryType ogrGeoType; if (!AOToOGRGeometry(ipGeoDef, &ogrGeoType)) return false; m_pFeatureDefn->SetGeomType(ogrGeoType); if (wkbFlatten(ogrGeoType) == wkbMultiLineString || wkbFlatten(ogrGeoType) == wkbMultiPoint) m_forceMulti = true; // Mapping of Spatial Reference will be passive about errors // (it is possible we won't be able to map some ESRI-specific projections) esriGeometry::ISpatialReferencePtr ipSR = NULL; if (FAILED(hr = ipGeoDef->get_SpatialReference(&ipSR))) { AOErr(hr, "Failed Fetching ESRI spatial reference"); } else { if (!AOToOGRSpatialReference(ipSR, &m_pSRS)) { //report error, but be passive about it CPLError( CE_Warning, CPLE_AppDefined, "Failed Mapping ESRI Spatial Reference"); } } // Map fields // return AOToOGRFields(ipFields, m_pFeatureDefn, m_OGRFieldToESRIField); }