Ejemplo n.º 1
0
//////////////////////////////////////////////////////////////////////////
//简要描述 : 写要素类到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;
}
Ejemplo n.º 2
0
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);
}