This is a migrated thread and some comments may be shown as answers.

Show points from SQL Server 2008

7 Answers 71 Views
Map
This is a migrated thread and some comments may be shown as answers.
Abel
Top achievements
Rank 1
Abel asked on 30 Nov 2017, 06:37 PM

Hi, I'm testing Telerik UI for WinForms.

I am trying to show points from a SQL Server database. But I can not make it work. This is the code

            'Conection DataBase
            go_con_sql.ConnectionString = "workstation id='.........';packet size=4096;user id=.......;pwd=.....;data source=..........;persist security info=False;initial catalog=EL_SAR_NET_V30_LUJAN"
            go_con_sql.Open()

            'Query **nod_obj is geometry data type
            Dim ls_sql As String = " Select nod_id,nod_descripcion,nod_obj from mags.EL_Nodos  "
            lo_SqlCommand = go_con_sql.CreateCommand()
            lo_SqlCommand.CommandText = ls_sql
            le_ConnectionState = lo_SqlCommand.Connection.State
            If lo_SqlCommand.Connection.State <> ConnectionState.Open Then lo_SqlCommand.Connection.Open()
            lo_SqlDataAdapter = New SqlClient.SqlDataAdapter(lo_SqlCommand)
            lo_SqlDataAdapter.Fill(lo_DataTable)

            'Load Bing 
            Dim cacheFolder As String = "..\..\cache"
            Dim bingProvider As BingRestMapProvider = New Telerik.WinControls.UI.BingRestMapProvider()
            bingProvider.UseSession = True
            bingProvider.BingKey = "JUnqKyILAJmo6DGiOQ1r~kPM5XDXLRRv1oTVw6XlLbQ~Ap55t-r-mO9JsRmL8z6YFqy6ivH1jv2CFsiEk4AP9JIJQnLfghVjCrIjCPVE-lDY"
            Dim cache As New LocalFileCacheProvider(cacheFolder)
            bingProvider.CacheProvider = cache
            Me.RadMap1.Providers.Add(bingProvider)


            'Load Layer Nodos
            Dim layer As New MapLayer("Nodos")
            Me.RadMap1.Layers.Add(layer)


            Dim source As New BindingSource()
            source.DataSource = lo_DataTable
            Dim datareader As New SqlGeospatialDataReader()
            datareader.Source = source
            datareader.GeospatialPropertyName = "nod_obj"

            'Here is error
            Dim elements As List(Of MapVisualElement) = datareader.Read(source, "nod_obj", True, Nothing) ', True, Nothing
            For Each item As MapVisualElement In elements
                item.BorderColor = Color.YellowGreen
            Next
            Me.RadMap1.Layers("Nodos").AddRange(elements)

The error is "GeospatialPropertyName"

 

What am I doing wrong?

Thank you

Regards

Abel

 

7 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 04 Dec 2017, 11:39 AM
Hi Abel,

How are you storing the data in your database? In this case, the "nod_obj" property should store a string like this - "Point (-84.3827345898996 33.858244576749)"

I am looking forward to your reply.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abel
Top achievements
Rank 1
answered on 04 Dec 2017, 05:04 PM

Hi Dimitar,

I changed the sql query to this

Dim ls_sql As String = " Select top 30 nod_id,nod_descripcion,nod_obj.STAsText() as nod_obj from mags.EL_Nodos  "

And It's the query return

POINT (-59.1170754766245 -34.5628101163443)

 

But, dont work. 

Same error in this line

 Dim elements As List(Of MapVisualElement) = datareader.Read(source, "nod_obj", True, Nothing)

Regards,

Abel

 

0
Dimitar
Telerik team
answered on 05 Dec 2017, 11:29 AM
Hi Abel,

I have further investigated this and it appears that the SqlGeospatialDataReader cannot properly parse the data when the DataSource is a DataTable. I have logged this issue on our Feedback Portal. You can track its progress, subscribe to status changes and add your comment to it here. I have also updated your Telerik Points.

To workaround this use a list of objects instead:
Private Function GetWktData(ByVal dt As DataTable) As List(Of WktDataRow)
    Dim wktDataCollection As New List(Of WktDataRow)()
    For Each item As DataRow In dt.Rows
        Dim row = New WktDataRow()
        row.Geometry = item("Geometry").ToString()
        wktDataCollection.Add(row)
 
    Next item
 
    Return wktDataCollection
 
End Function
Public Class WktDataRow
    Private _name As String
    Private _geometry As String
 
    Public Property Name() As String
        Get
            Return Me._name
        End Get
        Set(ByVal value As String)
            Me._name = value
        End Set
    End Property
 
    Public Property Geometry() As String
        Get
            Return Me._geometry
        End Get
        Set(ByVal value As String)
            Me._geometry = value
        End Set
    End Property
End Class

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abel
Top achievements
Rank 1
answered on 05 Dec 2017, 07:15 PM

Hi Dimitar,

It's work!

Other question.

How can i change the symbol to element?

I can change the color "item.BackColor = Color.Blue" but I don't know change the circle to a triangle 

 

Thank you

Regards

Abel

0
Dimitar
Telerik team
answered on 06 Dec 2017, 09:32 AM
Hi Abel,

The MapPoint element cannot change its shape. What you can do is create a custom MapVisualElement and override the Paint method which will allow you to draw anything. I have attached a small example that shows this. 

Please note that the point support images painting if that is suitable for you:
For Each item In elements
    Dim point = TryCast(item, MapPoint)
 
    If point IsNot Nothing Then
        point.Image = Image.FromFile("C:\img\delete.png")   
    End If
Next item

Do not hesitate to contact us if you have other questions.
 
Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abel
Top achievements
Rank 1
answered on 06 Dec 2017, 05:32 PM

Hi Dimitar,
It's work!

And last question,

Is there a layer control, to be able to turn them off and turn them on?

The added layers do not appear in the eye icon.

Thank you

Regards

Abel

 

 

 

0
Dimitar
Telerik team
answered on 11 Dec 2017, 08:57 AM
Hi Abel,

The layers are not visible in the MapViewButton. There is no built-in UI to show/hide them. For example, you can use an external button:
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Me.radMap1.Layers("Capitals").IsVisible = False
End Sub

Do not hesitate to contact us if you have other questions.
 
Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Map
Asked by
Abel
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Abel
Top achievements
Rank 1
Share this question
or