vcasp
路人甲
路人甲
  • 注册日期2006-07-03
  • 发帖数34
  • QQ
  • 铜币230枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2012回复:0

问关于AO实现CAD文件转化为5个shp文件的问题

楼主#
更多 发布于:2006-08-23 13:06
<P>要用AO实现把CAD文件转化成为四个shp文件,就像arcmap里面的一样,有point、polyline、polygon、multipatch、annotation 首先我把读CAD文件,得到5个featureclass</P>
<P>首先有这么一个问题,我看了一下arcmap里面的转化结果,point层和annotation层都是点层,featuretype都是FTsimple,那如何分别得到point要素类和annotation要素类啊,</P>
<P>我发现annotation要素类属性数据有text和fontid字段(点要素类里有text但无fontid)</P>
<P>所以我就用有无fontid来判断是否为annotation,最后转化的数据是正确的,但是fontid不是每个annotation要素类都有的,是不是有别的更标准的方法判断出annotation要素类啊 </P>
<P>Dim pPolyGonCls As IFeatureClass  '面要素类<BR>        Dim pLineCls As IFeatureClass  '线要素类<BR>        Dim pPointCls As IFeatureClass  '点要素类<BR>        Dim pMulPatchCls As IFeatureClass  '多点要素类<BR>        Dim pAnnoCls As IFeatureClass   '标注要素类<BR>        Dim i As Short<BR>        '分名别类得到CAD文件的各个要素类<BR>        For i = 0 To pClsContainer.ClassCount - 1<BR>                    pClsContainer.Class(i).ShapeType = esriGeometryType.esriGeometryPoint AndAlso Not pClsContainer.Class(i).FindField("FontId") >= 0 Then<BR>                pPointCls = pClsContainer.Class(i)<BR>                     ElseIf pClsContainer.Class(i).ShapeType = esriGeometryType.esriGeometryPoint AndAlso pClsContainer.Class(i).FindField("FontId") >= 0 Then<BR>                pAnnoCls = pClsContainer.Class(i)<BR>            End If<BR>        Next</P>

<P>下面我创建一个shp文件对应的要素类,再把上面得到的对应的要素类的每一个要素的数据付给新建的要素,部分代码如下</P>
<P> pNewFeatCls = pFeatWs.CreateFeatureClass(sShpDir, pFields, Nothing, Nothing, esriFeatureType.esriFTSimple, "shape", "")<BR>        Dim pFeat As IFeature<BR>        pFeat = pCursor.NextFeature()<BR>        Dim pNewFeat As IFeature<BR>        While Not pFeat Is Nothing<BR>            pNewFeat = pNewFeatCls.CreateFeature()<BR>            pNewFeat.Shape = pFeat.Shape<BR>            For i = 2 To pFeat.Fields.FieldCount - 1<BR>                pNewFeat.Value(i) = pFeat.Value(i)<BR>            Next<BR>            pNewFeat.Store()<BR>            pFeat = pCursor.NextFeature()<BR>        End While</P>
<P>最后的确转化成功为5个shp文件,和arcmap里的转化结果比较,图形数据和属性数据都是正确的,</P>
<P>但是arcmap结果里的annotation直接显示的是标注,而我的annotation显示的是一个个点</P>
<P>不知道是哪里出了问题</P>
<P>还有关于新建的要素类的字段的问题,我需要把原来CAD文件对应的要素类的属性字段都付给新建的要素类,该如何操作啊</P>
<P>我大致是这样做的</P>
<P>先定义一个shape字段,然后用下面的代码把CAD文件对应要素类的字段付给新建的要素类(除第一二个字段,第一个字段是图员的唯一标识,第二个字段是shape)</P>
<P>但是感觉这样也太麻烦了,而且还不见得能和原来的完全一致,是否有更方便的方法啊</P>
<P>  For i = 2 To pAnnoCls.Fields.FieldCount - 1<BR>            pField = New Field<BR>            pFieldEdit = pField<BR>            With pFieldEdit<BR>                .Name_2 = pAnnoCls.Fields.Field(i).Name<BR>                .Type_2 = pAnnoCls.Fields.Field(i).Type<BR>                .AliasName_2 = pAnnoCls.Fields.Field(i).AliasName<BR>                .DefaultValue_2 = pAnnoCls.Fields.Field(i).DefaultValue<BR>                .Editable_2 = pAnnoCls.Fields.Field(i).Editable<BR>                .IsNullable_2 = pAnnoCls.Fields.Field(i).Editable<BR>                .Length_2 = pAnnoCls.Fields.Field(i).Length<BR>                .Precision_2 = pAnnoCls.Fields.Field(i).Precision<BR>            End With<BR>            pFieldsEdit.AddField(pField)<BR>        Next</P>
<P>这些困扰我很久,期待高手的指点,在此谢谢了</P>



喜欢0 评分0
游客

返回顶部