阅读:1883回复:6
如何从IRasterLayer 得到 它的属性字段
Dim pRasterLyr As IRasterLayer<br>
Dim pTableFields As ITableFields<br> Dim pfield As IField<br> Dim ii As Integer<br> <br> On Error GoTo Error_handler<br> <br> If TypeOf pLyr Is IRasterLayer Then<br> Set pRasterLyr = pLyr <br> Set pTableFields = pRasterLyr ' ***********************************************<br> For ii = 0 To pTableFields.FieldCount - 1<br> Set pfield = pTableFields.Field(ii)<br> If pfield.Type = esriFieldTypeDouble Or pfield.Type = esriFieldTypeInteger Or pfield.Type = esriFieldTypeSingle Then<br> cmbField.AddItem pfield.Name<br> End If<br> Next ii<br> Else<br> <br> 为什么这种方法VB会提示“类型不匹配”, 或者有其他方法嘛? 谢谢<br> <br> <br> |
|
1楼#
发布于:2005-11-09 16:10
<P>接口类ITableFields是不能这么用的: Set pTableFields = pRasterLyr ,你可以查一下帮助,它只能用于:</P>
<DIV> <TABLE cellSpacing=4 cols=2 cellPadding=4> <TR vAlign=top> <TH width="35%">CoClasses and Classes</TH> <TH width="65%">Description</TH></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="ms-its:esriCarto.chm::/CadAnnotationLayer.htm" target="_blank" >CadAnnotationLayer (esriCarto)</A></B></TD> <TD class=t width="65%">An ESRI Cad annotation layer.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="ms-its:esriCarto.chm::/CadFeatureLayer.htm" target="_blank" >CadFeatureLayer (esriCarto)</A></B></TD> <TD class=t width="65%">ESRI CAD Feature Layer class.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="ms-its:esriCarto.chm::/CoverageAnnotationLayer.htm" target="_blank" >CoverageAnnotationLayer (esriCarto)</A></B></TD> <TD class=t width="65%">An ESRI coverage annotation layer.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="ms-its:esriCarto.chm::/DimensionLayer.htm" target="_blank" >DimensionLayer (esriCarto)</A></B></TD> <TD class=t width="65%">A collection of properties for a dimension layer.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="ms-its:esriCarto.chm::/FDOGraphicsLayer.htm" target="_blank" >FDOGraphicsLayer (esriCarto)</A></B></TD> <TD class=t width="65%">A collection of properties for an annotation layer (feature data object graphics layer).</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="ms-its:esriCarto.chm::/FeatureLayer.htm" target="_blank" >FeatureLayer (esriCarto)</A></B></TD> <TD class=t width="65%">A collection of features and their visual representation.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="ms-its:esriCarto.chm::/GdbRasterCatalogLayer.htm" target="_blank" >GdbRasterCatalogLayer (esriCarto)</A></B></TD> <TD class=t width="65%">Geodabase RasterCatalog source and display options.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="ms-its:esriCarto.chm::/RasterLayer.htm" target="_blank" >RasterLayer (esriCarto)</A></B></TD> <TD class=t width="65%">Raster layer source and display options.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="ms-its:esriCarto.chm::/StandaloneTable.htm" target="_blank" >StandaloneTable (esriCarto)</A></B></TD> <TD class=t width="65%">A standalone table.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="ms-its:esriTrackingAnalyst.chm::/TemporalFeatureLayer.htm" target="_blank" >TemporalFeatureLayer (esriTrackingAnalyst)</A></B></TD> <TD class=t width="65%">Defines the coclass IDL parameters and attributes of the TemporalFeatureLayer COM object.</TD></TR> <TR vAlign=top> <TD class=t width="35%"><B><a href="ms-its:esriCarto.chm::/TinLayer.htm" target="_blank" >TinLayer (esriCarto)</A></B></TD> <TD class=t width="65%">The TIN Layer class.</TD></TR></TD></TR></TABLE></DIV> <P> <OBJECT><PARAM><PARAM><PARAM></OBJECT><BR></P> |
|
2楼#
发布于:2005-11-09 16:15
<P>再给你贴段代码,是帮助里面的:</P><CODE><PRE>Sub AccessValueOfRasterTable(pRaster As IRaster, sFieldName As String, RowIndex As Integer)
' pRaster: input raster ' sFieldName: field name in the raster table ' RowIndex: row index in the table ' Get Rasterband Dim pRasterCol As IRasterBandCollection Set pRasterCol = pRaster Dim pBand As IRasterBand Set pBand = pRasterCol.Item(0)</PRE><PRE> ' Get the raster table Dim pTable As <FONT style="BACKGROUND-COLOR: #0a246a" color=#ffffff>ITable</FONT> Dim ExistTable As Boolean pBand.HasTable ExistTable If ExistTable = False Then Exit Sub Set pTable = pBand.AttributeTable ' Get field index Dim FieldIndex As Integer FieldIndex = pTable.FindField(sFieldName) ' Get the value Dim ValueResult As Variant Dim pRow As IRow Set pRow = pTable.GetRow(RowIndex) ValueResult = pRow.Value(FieldIndex) ' Here is the result MsgBox ValueResult Exit Sub ERH: MsgBox Err.Description End Sub</PRE></CODE> |
|
3楼#
发布于:2005-11-10 12:48
<b><a href="ms-its:esriCarto.chm::/RasterLayer.htm" target="_blank" >我看帮助:ITABLEFIELDS</a><br>
<br> <a href="ms-its:esriCarto.chm::/RasterLayer.htm" target="_blank" >里面有这个: RasterLayer (esriCarto)</a></b>Raster layer source and display options.<br> <br> 怎么才能把这个接口和这个class联系上?刚开始学,不好意思。<br> <br> 第二个也照着做了,还是搞不定,说什么 “自动化错误”, 再帮忙看看吧。十分感谢<br> <br> <br> |
|
4楼#
发布于:2005-11-10 16:09
<P>我测试了一下,这还真是一个问题。好像Itable,ITableFields等几个接口都没有被这个类引用似的!这个问题还没有解决,可以看看这个链接!</P>
<P><a href="http://forums.esri.com/Thread.asp?c=93;f=993;t=142563#413920" target="_blank" >http://forums.esri.com/Thread.asp?c=93;f=993;t=142563#413920</A></P> <P>好像这个问题是出现在ArcGIS9中,在8中就可以应用。</P> |
|
5楼#
发布于:2005-11-14 12:01
<P>例子是没有问题的,现在附上我的测试代码:</P>
<P>首先在窗体上放置一个Mapcontrol,名称为:Mapcontrol1;放置一个按钮,Name:Command1。然后在MapControl里面加载一个栅格数据。窗体代码如下:</P> <P>Option Explicit</P> <P>Private Sub Command1_Click()<BR> <BR> Dim pRaster As IRaster<BR> Dim pRL As IRasterLayer<BR> Dim pDs As IRasterDataset<BR> <BR> Set pRL = MapControl1.Layer(0)<BR> Set pRaster = pRL.Raster<BR> Call AccessValueOfRasterTable(pRaster, "Value", 1)<BR>End Sub</P> <P>Sub AccessValueOfRasterTable(pRaster As IRaster, _<BR> sFieldName As String, _<BR> RowIndex As Integer)<BR> ' pRaster: input raster ' sFieldName: field name in the raster table<BR> ' RowIndex: row index in the table<BR> ' Get Rasterband<BR> Dim pRasterCol As IRasterBandCollection<BR> <BR> Set pRasterCol = pRaster<BR> Dim pBand As iRasterBand<BR> Set pBand = pRasterCol.Item(0)<BR> ' Get the raster table<BR> Dim pTable As ITable<BR> Dim ExistTable As Boolean<BR> pBand.HasTable ExistTable</P> <P> If ExistTable = False Then Exit Sub<BR> Set pTable = pBand.AttributeTable<BR> ' Get field index<BR> Dim FieldIndex As Integer<BR> '*********************输出字段以便察看*******************<BR> For FieldIndex = 0 To pTable.Fields.FieldCount - 1<BR> Debug.Print pTable.Fields.Field(FieldIndex).name<BR> Next FieldIndex<BR> '******************************************************<BR> FieldIndex = pTable.FindField(sFieldName)<BR> ' Get the value<BR> Dim ValueResult As Variant<BR> Dim pRow As IRow<BR> Set pRow = pTable.GetRow(RowIndex)<BR> ValueResult = pRow.Value(FieldIndex)<BR> ' Here is the result<BR> MsgBox ValueResult<BR> Exit Sub<BR>ERH:<BR> MsgBox Err.Description<BR>End Sub</P> |
|
6楼#
发布于:2005-11-16 13:01
谢谢你们两位。
<script type="text/javascript" language="javascript"><br>document.write (usercolor('14','wavvylia'));<br></script><font color="#61b713" face="Verdana"><b>wavvylia大侠的方法是可以的,刚开始是我的数据的问题。但是狠奇怪在arcmap里就可以看,但是程序中就不行。</b></font> |
|