You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects Visual Basic for Application (VBA) forum

Create SQL Syntax from field value for labe...   Robert Johansson Nov 14, 2003
Re: Create SQL Syntax from field value for...   Olivier Damanet Nov 14, 2003
Re: Create SQL Syntax from field value for...   Robert Johansson Nov 14, 2003
Re: Create SQL Syntax from field value for...   Robert Johansson Nov 16, 2003
Re: Create SQL Syntax from field value for...   Olivier Damanet Nov 17, 2003
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Create SQL Syntax from field value for labeling? 
Author Robert Johansson 
Date Nov 14, 2003 
Message Hey!
I have a kind of odd problem, I want to create a SQL syntax from field values so I can label a map different. the values could look like this. 1;2;3;10; where the value 1 2 3 10 is telling that if 10 is choosed in application then this record should be labeled. and the ; is just a separator.

So now is my question is this possible? taking out the value and making the sql query cointaing all rows that got a 10 inside it is possible, that I know.

But is it possible to take that SQL with VBA to label the map different like you can do manually like this:

Right click the layer --> Choose properties --> Labels --> Define classes of features --> SQL query --> choose the values you want. (example: [MapID] = '1;2;10;' OR [MapID] = '10;')

 
  I live in my own little world but thats okey, they know me here 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Create SQL Syntax from field value for labeling? 
Author Olivier Damanet 
Date Nov 14, 2003 
Message I've never used labels by code, but looking at the developer help, here is what I understood:
-A layer can have one or more LabelEngineLayerProperties object associated with it. These can be listed through IGeoFeatureLayer.AnnotationProperties. I guess it uses one label engine if you select 'Label all the features the same way', while it probably uses several label engines that define each class of features.
-For each LabelEngineLayerProperties object, the following interfaces and properties seem to be pointing to the information you basicaly access within the properties page:

ILabelEngineLayerProperties:
.BasicOverposterLayerProperties : the label placement settings
.Expression : the label expression (The Label Field, or VB Script expression, etc.)
.Symbol : the text symbol used for labeling
IAnnotateLayerProperties:
.Class : the class name
.WhereClause : the SQL whereclause that applies to this class
.AnnotationMinimumScale
.AnnotationMaximumScale

I hope this can help. 
  Olivier. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Create SQL Syntax from field value for labeling? 
Author Robert Johansson 
Date Nov 14, 2003 
Message That tells me it should be possible so yes its helping, I need to look into it alittle more next week to know for sure how much it helped ;-) 
  I live in my own little world but thats okey, they know me here 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Create SQL Syntax from field value for labeling? 
Author Robert Johansson 
Date Nov 16, 2003 
Message I need some help getting started, Ive tryed to make some code just labeling but Im not all that good with this vb. any pointers? I post the code I got so far 
 
Dim fc As IFeatureClass
 Dim pFeatLayer As IFeatureLayer
 Dim pDoc As IMxDocument
 Dim pMap As IMap
 
 Set pDoc = ThisDocument
 Set pMap = pDoc.Maps.Item(0)
 Set pFeatLayer = pMap.Layer(0)
 Set fc = pFeatLayer.FeatureClass

  Dim fL As IFeatureLayer
  Set fL = New FeatureLayer
  Set fL.FeatureClass = fc

  'get AnnotateLayerPropertiesCollection from GeoFeatureLayer
  Dim pGeoFL As IGeoFeatureLayer
  Set pGeoFL = fL  'QI (Query Interface)
  Dim pAnnoLayerPropsColl As IAnnotateLayerPropertiesCollection
  Set pAnnoLayerPropsColl = pGeoFL.AnnotationProperties

  'get the (first) AnnotateLayerProperties property set in the collection
  Dim pAnnoLayerProps As IAnnotateLayerProperties
  pAnnoLayerPropsColl.QueryItem 0, pAnnoLayerProps, Nothing, Nothing
 
  I live in my own little world but thats okey, they know me here 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Create SQL Syntax from field value for labeling? 
Author Olivier Damanet 
Date Nov 17, 2003 
Message In your code, you create a New FeatureLayer (fL) and set it the data source from the first layer. Therefore, you are actually not managing the first layer, but another layer -in memory- which is not added to the map.
See the code below. It directly uses the reference to the first layer and query interface it to IGeoFeatureLayer. It takes the default LabelEngine, and set its expression field to [GROUP_TXT]. Then it creates a new LabelEngine, using now the field [NAME] to add another label to all features where "GROUP_TXT" is not 'Edificios'.

Note: I use a shapefile to test this code. If you use another data source type (e.g. a geodatabase), you should change the character enclosing the field name in the SQL WhereClause. 
 
Sub labelFirstLayer()
  Dim fc As IFeatureClass
  Dim pFeatLayer As IFeatureLayer
  Dim pDoc As IMxDocument
  Dim pMap As IMap
  
  Set pDoc = ThisDocument
  Set pMap = pDoc.Maps.Item(0)
  Set pFeatLayer = pMap.Layer(0)
  
'+++get AnnotateLayerPropertiesCollection from GeoFeatureLayer
  Dim pGeoFL As IGeoFeatureLayer
  Set pGeoFL = pFeatLayer 'QI (Query Interface)
  
  Dim pAnnoLayerPropsColl As IAnnotateLayerPropertiesCollection
  Set pAnnoLayerPropsColl = pGeoFL.AnnotationProperties

'+++get the (first and *assuming* only one) AnnotateLayerProperties property set in the collection
  Dim pAnnoLayerProps As IAnnotateLayerProperties
  pAnnoLayerPropsColl.QueryItem 0, pAnnoLayerProps, Nothing, Nothing
  'turn on label for the first label class
  pAnnoLayerProps.DisplayAnnotation = True
  pAnnoLayerProps.LabelWhichFeatures = esriVisibleFeatures
  'set the field [GROUP_TXT] for the labelling expression
  Dim pLabelEngine As ILabelEngineLayerProperties
  Set pLabelEngine = pAnnoLayerProps 'qi
  pLabelEngine.Expression = "[GROUP_TXT]"
  
'+++create a new label class
  Set pAnnoLayerProps = New LabelEngineLayerProperties
  pAnnoLayerProps.DisplayAnnotation = True
  pAnnoLayerProps.LabelWhichFeatures = esriVisibleFeatures
  pAnnoLayerProps.Class = "NoGroup"
  'set the field [NAME] for the labelling expression
  Set pLabelEngine = pAnnoLayerProps 'qi
  pLabelEngine.Expression = "[NAME]"
  'label only where [GROUP_TXT] = ""
  pAnnoLayerProps.WhereClause = "NOT ""GROUP_TXT"" = 'Edificios'"
  
'+++add it the new class the AnnotateLayerPropertiesCollection
  pAnnoLayerPropsColl.Add pAnnoLayerProps
  
'+++turn on label on the layer
  pGeoFL.DisplayAnnotation = True
  
'+++refresh map
  pDoc.ActiveView.Refresh
  
End Sub
 
  Olivier.