Hi,
I need to use some SQL functions like LTrim, RTrim, Round etc.
I am using below code:
Dim dynamicOverlay As LayerOverlay = DirectCast(map.CustomOverlays("Layer"), LayerOverlay)
Dim mssqlFeatureLayer As MsSql2008FeatureLayer = DirectCast(dynamicOverlay.Layers("Layer"), MsSql2008FeatureLayer)
mssqlFeatureLayer.Open()
Dim d As New DataTable()
d = mssqlFeatureLayer.QueryTools.ExecuteQuery("SELECT ROUND(X,0) AS XCrd FROM Table")
For Each row As DataRow In d.Rows
mssqlFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle(row("XCrd").ToString(), "Arial", 9, DrawingFontStyles.Italic Or DrawingFontStyles.Bold, GeoColor.GetRandomGeoColor(RandomColorType.All))
Next
mssqlFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
mssqlFeatureLayer.Close()
But it not display anything on map.
So Is something wrong in this code?
Use SQL Query to display data on map
Hi Vivek,
It looks you just set the text style for the layer.
So if the text style for label has any problem you cannot get the result.
Could you please make sure the items as below for find the problem:
1. Add a break point and make sure the "d" contains the value you want.
2. Set the style for your shape (AreaStyle, LineStyle or PointStyle) and see whether they are rendered correct.
3. Double check whether you assign correct connect string, table name and column id.
Regards,
Don
Hi Don.
Thanks for Reply.
I have checked above points you have mentioned and all it fine, but still not data display on map.
If I have use simple X column which is from that table like below then it display data on map,
For Each row As DataRow In d.Rows
mssqlFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle(“X”, “Arial”, 9, DrawingFontStyles.Italic Or DrawingFontStyles.Bold, GeoColor.GetRandomGeoColor(RandomColorType.All))
Next
and If I have use row(“XCrd”) this then it can’t display data on map
Is this due to for loop? or can I use customStyle for this?
Can you give me demo related to this?
Hi Vivek,
If what I understand is correct, you want to format the text label and if the label is numeric type, then round it, if string, then we trim it. If yes, I think the textFormat and NumericFormat property should be fit for this case Following code snippet will show you how to round the ‘X’ column to 0 decimal:
Dim mssqlFeatureLayer As New MsSql2008FeatureLayer(connectionString, "layer", "ID")
mssqlFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("x", "Arial", 9, DrawingFontStyles.Italic Or DrawingFontStyles.Bold, GeoColor.GetRandomGeoColor(RandomColorType.All))
mssqlFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.TextFormat = "{0:F0}"
mssqlFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
As for the custom style, most of the cases are when we want to display multi-column labels for one feature.
If there is any thing misunderstanding, please feel free to correct me.
Thanks.
Troy
Thanks Troy,
I need to do this using SQL query. I also need to use other SQL functions like Trim, Rtrim etc…
So at present I am not able to display data on map using code I have post, so Is anything wrong in my code?
Hi Vivek,
I think you can try to register the Formatting event to custom your label string, the below codes show it:
Dim customStringStyle As TextStyle = TextStyles.Interstate3(“CNTRY_NAME”)
customStringStyle.Formatting += customStringStyle_Formatting
Dim customNumStyle As TextStyle = TextStyles.Interstate3(“POP_CNTRY”)
customNumStyle.XOffsetInPixel = 30
customNumStyle.YOffsetInPixel = 30
customNumStyle.Formatting += customNumStyle_Formatting
Dim connectString As String = "User ID=thinkgeo;Password=123456789;Data Source=192.168.0.80;Initial Catalog=InternalDB;"
Dim sql2008Layer As New MsSql2008FeatureLayer(connectString, “cntry02”, “ID”)
sql2008Layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.Country2)
sql2008Layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(customStringStyle)
sql2008Layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(customNumStyle)
sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
…
Private Sub customNumStyle_Formatting(sender As Object, e As FormattingPositionStyleEventArgs)
e.Text = Math.Round((Decimal.Parse(e.Text)), 2) + String.Empty
End Sub
Private Sub customStringStyle_Formatting(sender As Object, e As FormattingPositionStyleEventArgs)
e.Text = e.Text.Trim()
End Sub
In your codes, we can’t use the loop for the style setting and the TextStyle’s constructor parameter columnname also can’t be custom.
Please let us know if it is fit for you.
Thanks,
Troy