get field value

1232
6
11-09-2013 07:36 AM
NestorasPapadopoulos
New Contributor
Hallo everyone,
I am trying to make a tool in arcobjects using VStudio 2010 and VB (.net, framework 3.5). I want to select a particular shapefile, then select the first record of it (FID=0) and then assign the value of a particular field to variable. After that with a for loop I will take the values of that field for all the rows.
I have made functions for all the actions (select layer by name, select row, select field by name) but it doesn't work. I get silly warnings and correction, but I am new to arcobjects and I can't handle it.
Any help is welcomed
0 Kudos
6 Replies
JohnStephens
Occasional Contributor
Hallo everyone,
I am trying to make a tool in arcobjects using VStudio 2010 and VB (.net, framework 3.5). I want to select a particular shapefile, then select the first record of it (FID=0) and then assign the value of a particular field to variable. After that with a for loop I will take the values of that field for all the rows.
I have made functions for all the actions (select layer by name, select row, select field by name) but it doesn't work. I get silly warnings and correction, but I am new to arcobjects and I can't handle it.
Any help is welcomed


You're going to need to post some code or show us the warning for us to help.
0 Kudos
NestorasPapadopoulos
New Contributor
Hallo,
thanks for replying to my thread. The code I' ve written since now is below. trig_srtm30 is a point shapefile and poly_C1toend is a polygon shapefile. I want to select each point, get the coordinates of each point and then pove the whole polygon shapefile according to the coordinates I get. Thank you very much.

Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Carto
Public Class Tool1
  Inherits ESRI.ArcGIS.Desktop.AddIns.Tool

   

#Region "Select Map Features by Attribute Query"

'''<summary>Select features in the IActiveView by an attribute query using a SQL syntax in a where clause.</summary>
'''
'''<param name="activeView">An IActiveView interface</param>
'''<param name="featureLayer">An IFeatureLayer interface to select upon</param>
'''<param name="whereClause">A System.String that is the SQL where clause syntax to select features. Example: "CityName = 'Redlands'"</param>
''' 
'''<remarks>Providing and empty string "" will return all records.</remarks>
Public Sub SelectMapFeaturesByAttributeQuery(ByVal activeView As IActiveView, ByVal featureLayer As IFeatureLayer, ByVal whereClause As System.String)

  If activeView Is Nothing OrElse featureLayer Is Nothing OrElse whereClause Is Nothing Then
   Return
  End If

  Dim featureSelection As IFeatureSelection = TryCast(featureLayer, IFeatureSelection) ' Dynamic Cast

  ' Set up the query
  Dim queryFilter As IQueryFilter = New QueryFilterClass
  queryFilter.WhereClause = whereClause

  ' Invalidate only the selection cache. Flag the original selection
  activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

  ' Perform the selection
  featureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, False)

  ' Flag the new selection
  activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

End Sub
#End Region

    ' select coords and assign to variables by select Map Features by Atribute Query
    Dim row As Double
    Dim pX As Double
    Dim pY As Double

SelectMapFeaturesByAttributeQuery(activeView, trig_srtm30, "FID=row")

    pX=trig_srtm30.X(Value)
    pY=trig_srtm30.Y(Value)

#Region "Clear Selected Map Features"

'''<summary>Clear the selected features in the IActiveView for a specified IFeatureLayer.</summary>
'''
'''<param name="activeView">An IActiveView interface</param>
'''<param name="featureLayer">An IFeatureLayer</param>
'''
'''<remarks></remarks>
Public Sub ClearSelectedMapFeatures(ByVal activeView As IActiveView, ByVal featureLayer As IFeatureLayer)

  If activeView Is Nothing OrElse featureLayer Is Nothing Then

    Return

  End If

  Dim featureSelection As IFeatureSelection = TryCast(featureLayer, IFeatureSelection) ' Dynamic Cast

  ' Invalidate only the selection cache. Flag the original selection
  activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

  ' Clear the selection
  featureSelection.Clear()

  ' Flag the new selection
  activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

End Sub
#End Region
    ' Clear selection
    ClearSelectedMapFeatures(activeView, trig_srtm30)

    ' select polygon shapefile which will be moved by select Map Features by Atribute Query
    SelectMapFeaturesByAttributeQuery(activeView, poly_C1toend, "")

    ' move shapefile according to new coords


  Public Sub New()



  End Sub

  Protected Overrides Sub OnUpdate()
    Enabled = My.ArcMap.Application IsNot Nothing
    End Sub

End Class
0 Kudos
JohnStephens
Occasional Contributor
Can you edit your post and put the code in the 'CODE' tags?

Also, what is the error and what line is it being thrown at?
0 Kudos
NestorasPapadopoulos
New Contributor
Can you edit your post and put the code in the 'CODE' tags?

Also, what is the error and what line is it being thrown at?


Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Carto
Public Class Tool1
  Inherits ESRI.ArcGIS.Desktop.AddIns.Tool

    

#Region "Select Map Features by Attribute Query"

'''<summary>Select features in the IActiveView by an attribute query using a SQL syntax in a where clause.</summary>
''' 
'''<param name="activeView">An IActiveView interface</param>
'''<param name="featureLayer">An IFeatureLayer interface to select upon</param>
'''<param name="whereClause">A System.String that is the SQL where clause syntax to select features. Example: "CityName = 'Redlands'"</param>
'''  
'''<remarks>Providing and empty string "" will return all records.</remarks>
Public Sub SelectMapFeaturesByAttributeQuery(ByVal activeView As IActiveView, ByVal featureLayer As IFeatureLayer, ByVal whereClause As System.String)

  If activeView Is Nothing OrElse featureLayer Is Nothing OrElse whereClause Is Nothing Then
   Return
  End If

  Dim featureSelection As IFeatureSelection = TryCast(featureLayer, IFeatureSelection) ' Dynamic Cast

  ' Set up the query
  Dim queryFilter As IQueryFilter = New QueryFilterClass
  queryFilter.WhereClause = whereClause

  ' Invalidate only the selection cache. Flag the original selection
  activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

  ' Perform the selection
  featureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, False)

  ' Flag the new selection
  activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

End Sub
#End Region

    ' select coords and assign to variables by select Map Features by Atribute Query
    Dim row As Double
    Dim pX As Double
    Dim pY As Double

SelectMapFeaturesByAttributeQuery(activeView, trig_srtm30, "FID=row")

    pX=trig_srtm30.X(Value)
    pY=trig_srtm30.Y(Value)

#Region "Clear Selected Map Features"

'''<summary>Clear the selected features in the IActiveView for a specified IFeatureLayer.</summary>
''' 
'''<param name="activeView">An IActiveView interface</param>
'''<param name="featureLayer">An IFeatureLayer</param>
''' 
'''<remarks></remarks>
Public Sub ClearSelectedMapFeatures(ByVal activeView As IActiveView, ByVal featureLayer As IFeatureLayer)

  If activeView Is Nothing OrElse featureLayer Is Nothing Then

    Return

  End If

  Dim featureSelection As IFeatureSelection = TryCast(featureLayer, IFeatureSelection) ' Dynamic Cast

  ' Invalidate only the selection cache. Flag the original selection
  activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

  ' Clear the selection
  featureSelection.Clear()

  ' Flag the new selection
  activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

End Sub
#End Region
    ' Clear selection 
    ClearSelectedMapFeatures(activeView, trig_srtm30)

    ' select polygon shapefile which will be moved by select Map Features by Atribute Query
    SelectMapFeaturesByAttributeQuery(activeView, poly_C1toend, "")

    ' move shapefile according to new coords


  Public Sub New()



  End Sub

  Protected Overrides Sub OnUpdate()
    Enabled = My.ArcMap.Application IsNot Nothing
    End Sub

End Class


I got the warning "Warning 1 The file content is an invalid ESRI ArcGIS Add-in configuration xml."
and the errors that "Declarations expected" at lines 48, 50, 51, 83

thanks for replying
0 Kudos
NeilClemmons
Regular Contributor III
Looks to me like you have code inside your class definition that is not inside a property or function definition.
0 Kudos
RayanthaRathnayake
New Contributor
Looks to me like you have code inside your class definition that is not inside a property or function definition.


I thought he is correct. move your written functions ("SelectMapFeaturesByAttributeQuery", "ClearSelectedMapFeatures") to inside the "Public Class Tool1".
0 Kudos