KenHeer1 was asking for a simple example to generate GeoJSON output similar to the one used in this example.

The actual JSON is located here, and this is what it looks like:
{
	"type": "FeatureCollection",
	"features": [
		{
			"geometry": {
				"type": "Point",
				"coordinates": [6.18218, 45.5949]
			},
			"type": "Feature",
			"properties": {
				"elevation": 1770,
				"name": "Col d'Arclusaz"
			},
			"id": 472
		}, ... more features...
	}
}

So first you need to define classes to represent your specific FeatureCollection and Feature:
Public Class MyFeatureCollection
    Inherits langsamu.GeoJSON.FeatureCollection(Of MyFeature)
End Class
Public Class MyFeature
    Inherits langsamu.GeoJSON.PointFeature(Of MyProperties)

    Private _ID As String
    <Newtonsoft.Json.JsonProperty("id")> _
    Public Property ID() As String
        Get
            Return _ID
        End Get
        Set(ByVal value As String)
            _ID = value
        End Set
    End Property
End Class

And then a class to represent your actual data:
Public Class MyProperties
    Private _Elevation As String
    <Newtonsoft.Json.JsonProperty("elevation")> _
    Public Property Elevation() As String
        Get
            Return _Elevation
        End Get
        Set(ByVal value As String)
            _Elevation = value
        End Set
    End Property

    Private _Name As String
    <Newtonsoft.Json.JsonProperty("name")> _
    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        End Set
    End Property
End Class

Then you're ready to use it:
Public Class Example
    Public Function GetJSON() As String
        Dim MyCollection = New MyFeatureCollection With {
            .Features = New MyFeature() {
                New MyFeature() With {
                    .ID = 472,
                    .Geometry = New langsamu.GeoJSON.Point(6.18218, 45.5949),
                    .Properties = New MyProperties() With {
                        .Elevation = 1770,
                        .Name = "CollectionBase d'Arclusaz"
                    }
                },
                New MyFeature() With {
                    .ID = 458,
                    .Geometry = New langsamu.GeoJSON.Point(6.27827, 45.6769),
                    .Properties = New MyProperties() With {
                        .Elevation = 1831,
                        .Name = "Pointe de C\u00f4te Favre"
                    }
                }
            }
        }

        Dim Builder As New System.Text.StringBuilder
        Dim Writer As New System.IO.StringWriter(Builder)

        Call New Newtonsoft.Json.JsonSerializer().Serialize(Writer, MyCollection)

        Return Builder.ToString
    End Sub
End Class

Last edited Oct 13, 2010 at 10:13 PM by langsamu, version 3

Comments

KenHeer1 Oct 14, 2010 at 7:01 PM 
Works Great. Thanks!