Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
alatas committed Mar 25, 2014
1 parent 226eea9 commit d280d8b
Show file tree
Hide file tree
Showing 38 changed files with 1,398 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
28 changes: 28 additions & 0 deletions GeoJSON4EntityFramework.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30110.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "GeoJSON4EntityFramework", "GeoJSON4EntityFramework\GeoJSON4EntityFramework.vbproj", "{7B0F6694-A109-4F3F-84A0-9FA49193AF31}"
EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "TestProject", "TestProject\TestProject.vbproj", "{3AA1813C-601C-4FFF-8F7A-7070649CAF65}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B0F6694-A109-4F3F-84A0-9FA49193AF31}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{7B0F6694-A109-4F3F-84A0-9FA49193AF31}.Debug|Any CPU.Build.0 = Release|Any CPU
{7B0F6694-A109-4F3F-84A0-9FA49193AF31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B0F6694-A109-4F3F-84A0-9FA49193AF31}.Release|Any CPU.Build.0 = Release|Any CPU
{3AA1813C-601C-4FFF-8F7A-7070649CAF65}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{3AA1813C-601C-4FFF-8F7A-7070649CAF65}.Debug|Any CPU.Build.0 = Release|Any CPU
{3AA1813C-601C-4FFF-8F7A-7070649CAF65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3AA1813C-601C-4FFF-8F7A-7070649CAF65}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions GeoJSON4EntityFramework/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
8 changes: 8 additions & 0 deletions GeoJSON4EntityFramework/Base/GeoJsonElement.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Public MustInherit Class GeoJsonElement(Of T)
<JsonProperty(PropertyName:="type", Order:=1)>
Public ReadOnly Property TypeName As String
Get
Return GetType(T).Name
End Get
End Property
End Class
14 changes: 14 additions & 0 deletions GeoJSON4EntityFramework/Base/GeoJsonGeometry.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Public MustInherit Class GeoJsonGeometry(Of T)
Inherits GeoJsonElement(Of T)

Public MustOverride Sub CreateFromDbGeometry(inp As Entity.Spatial.DbGeometry)

<JsonProperty(PropertyName:="coordinates")>
Public MustOverride ReadOnly Property Coordinates() As Object

Public Shared Function FromDbGeometry(inp As Entity.Spatial.DbGeometry) As GeoJsonGeometry(Of T)
Dim obj As GeoJsonGeometry(Of T) = CTypeDynamic(Activator.CreateInstance(Of T)(), GetType(T))
obj.CreateFromDbGeometry(inp)
Return obj
End Function
End Class
3 changes: 3 additions & 0 deletions GeoJSON4EntityFramework/Base/IGeometry.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Public Interface IGeoJsonGeometry

End Interface
21 changes: 21 additions & 0 deletions GeoJSON4EntityFramework/Elements/Coordinate.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Public Class Coordinate
Sub New()
MyBase.New()
End Sub

Sub New(_x As Double, _y As Double)
X = _x
Y = _y
End Sub

Public ReadOnly Property Coordinate As Double()
Get
Return New Double() {X, Y}
End Get
End Property

Public Property X As Double

Public Property Y As Double

End Class
7 changes: 7 additions & 0 deletions GeoJSON4EntityFramework/Elements/CoordinateList.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Public Class CoordinateList
Inherits List(Of Coordinate)

Sub AddNew(X As Double, Y As Double)
MyBase.Add(New Coordinate(X, Y))
End Sub
End Class
40 changes: 40 additions & 0 deletions GeoJSON4EntityFramework/Elements/Feature.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Public Class Feature
Inherits GeoJsonElement(Of Feature)
<JsonProperty(PropertyName:="id", Order:=2)>
Public Property ID As String

<JsonProperty(PropertyName:="properties", Order:=3)>
Public Property Properties As New Dictionary(Of String, String)

<JsonProperty(PropertyName:="geometry", Order:=4)>
<JsonConverter(GetType(GenericListConverter(Of IGeoJsonGeometry)))>
Public Property Geometry As New List(Of IGeoJsonGeometry)

Sub New()
MyBase.New()
End Sub

Sub New(ParamArray Geometries() As IGeoJsonGeometry)
MyBase.New()
Geometry = Geometries.ToList
End Sub

Public Shared Function FromDbGeometry(inp As Entity.Spatial.DbGeometry) As Feature
Dim f As New Feature

Select Case inp.SpatialTypeName
Case "MultiPolygon"
f.Geometry.Add(MultiPolygon.FromDbGeometry(inp))
Case "Polygon"
f.Geometry.Add(Polygon.FromDbGeometry(inp))
Case "Point"
f.Geometry.Add(Point.FromDbGeometry(inp))
Case "MultPoint"
f.Geometry.Add(MultiPoint.FromDbGeometry(inp))
Case Else
Throw New NotImplementedException
End Select

Return f
End Function
End Class
7 changes: 7 additions & 0 deletions GeoJSON4EntityFramework/Elements/FeatureCollection.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Public Class FeatureCollection
Inherits GeoJsonElement(Of FeatureCollection)

<JsonConverter(GetType(GenericListConverter(Of Feature)))>
<JsonProperty(PropertyName:="features")>
Public Property Features As New List(Of Feature)
End Class
36 changes: 36 additions & 0 deletions GeoJSON4EntityFramework/Elements/MultiPoint.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Public Class MultiPoint
Inherits GeoJsonGeometry(Of MultiPoint)
Implements IGeoJsonGeometry

Public Property Points As New List(Of Point)

Public Overrides ReadOnly Property Coordinates As Object
Get
If Points.Count = 0 Then
Return New Double() {}
ElseIf Points.Count = 1 Then
Dim out(0) As Double
out(0) = Points(0).Coordinates
Return out
Else
Dim out(Points.Count - 1)() As Double

Parallel.For(0, Points.Count, Sub(i)
out(i) = Points(i).Coordinates
End Sub)
Return out
End If
End Get
End Property

Public Overrides Sub CreateFromDbGeometry(inp As Entity.Spatial.DbGeometry)
If inp.SpatialTypeName <> MyBase.TypeName Then Throw New ArgumentException
Points.Clear()

For i As Integer = 1 To inp.ElementCount
Dim element = inp.ElementAt(i)
If element.SpatialTypeName <> "Point" Then Throw New ArgumentException
Points.Add(Point.FromDbGeometry(element))
Next
End Sub
End Class
37 changes: 37 additions & 0 deletions GeoJSON4EntityFramework/Elements/MultiPolygon.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Public Class MultiPolygon
Inherits GeoJsonGeometry(Of MultiPolygon)
Implements IGeoJsonGeometry

<JsonIgnore()>
Public Property Polygons As New List(Of Polygon)

Public Overrides ReadOnly Property Coordinates As Object
Get
If Polygons.Count = 0 Then
Return New Double() {}
ElseIf Polygons.Count = 1 Then
Dim out(0)()() As Double
out(0) = Polygons(0).Coordinates
Return out
Else
Dim out(Polygons.Count - 1)()()() As Double

Parallel.For(0, Polygons.Count, Sub(i)
out(i) = Polygons(i).Coordinates
End Sub)
Return out
End If
End Get
End Property

Public Overrides Sub CreateFromDbGeometry(inp As Entity.Spatial.DbGeometry)
If inp.SpatialTypeName <> "MultiPolygon" Then Throw New ArgumentException
Polygons.Clear()

For i As Integer = 1 To inp.ElementCount
Dim element = inp.ElementAt(i)
If element.SpatialTypeName <> "Polygon" Then Throw New ArgumentException
Polygons.Add(Polygon.FromDbGeometry(element))
Next
End Sub
End Class
17 changes: 17 additions & 0 deletions GeoJSON4EntityFramework/Elements/Point.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Public Class Point
Inherits GeoJsonGeometry(Of Point)
Implements IGeoJsonGeometry

Public Property Point As New Coordinate(0, 0)

Public Overrides ReadOnly Property Coordinates As Object
Get
Return Point.Coordinate
End Get
End Property

Public Overrides Sub CreateFromDbGeometry(inp As Entity.Spatial.DbGeometry)
If inp.SpatialTypeName <> MyBase.TypeName Then Throw New ArgumentException
Point = New Coordinate(inp.XCoordinate, inp.YCoordinate)
End Sub
End Class
39 changes: 39 additions & 0 deletions GeoJSON4EntityFramework/Elements/Polygon.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Public Class Polygon
Inherits GeoJsonGeometry(Of Polygon)
Implements IGeoJsonGeometry

<Newtonsoft.Json.JsonIgnore()>
Public Property Points As New CoordinateList

Public Overrides ReadOnly Property Coordinates()
Get
Try
If Points.Count = 0 Then
Return New Double() {}
ElseIf Points.Count = 1 Then
Dim out() As Double = New Double() {Points(0).X, Points(0).Y}
Return out
Else
Dim out(0)()() As Double
out(0) = New Double(Points.Count - 1)() {}
Parallel.For(0, Points.Count, Sub(i)
out(0)(i) = Points(i).Coordinate
End Sub)
Return out
End If
Catch ex As Exception
Return New Double() {}
End Try
End Get
End Property

Public Overrides Sub CreateFromDbGeometry(inp As Entity.Spatial.DbGeometry)
If inp.SpatialTypeName <> MyBase.TypeName Then Throw New ArgumentException
Points.Clear()

For i As Integer = 1 To inp.PointCount
Dim point = inp.PointAt(i)
Points.AddNew(point.XCoordinate, point.YCoordinate)
Next
End Sub
End Class
Loading

0 comments on commit d280d8b

Please sign in to comment.