Skip to content

Commit 8586e8c

Browse files
committed
Merge pull request #7 from jumpinjackie/master
routed to additions_2 branch
2 parents 1c7db37 + fd23113 commit 8586e8c

File tree

14 files changed

+148
-46
lines changed

14 files changed

+148
-46
lines changed

GeoJSON4EntityFramework.sln

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 2013
4-
VisualStudioVersion = 12.0.30110.0
4+
VisualStudioVersion = 12.0.31101.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "GeoJSON4EntityFramework", "GeoJSON4EntityFramework\GeoJSON4EntityFramework.vbproj", "{7B0F6694-A109-4F3F-84A0-9FA49193AF31}"
77
EndProject
@@ -17,12 +17,12 @@ Global
1717
Release|Any CPU = Release|Any CPU
1818
EndGlobalSection
1919
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20-
{7B0F6694-A109-4F3F-84A0-9FA49193AF31}.Debug|Any CPU.ActiveCfg = Release|Any CPU
21-
{7B0F6694-A109-4F3F-84A0-9FA49193AF31}.Debug|Any CPU.Build.0 = Release|Any CPU
20+
{7B0F6694-A109-4F3F-84A0-9FA49193AF31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{7B0F6694-A109-4F3F-84A0-9FA49193AF31}.Debug|Any CPU.Build.0 = Debug|Any CPU
2222
{7B0F6694-A109-4F3F-84A0-9FA49193AF31}.Release|Any CPU.ActiveCfg = Release|Any CPU
2323
{7B0F6694-A109-4F3F-84A0-9FA49193AF31}.Release|Any CPU.Build.0 = Release|Any CPU
24-
{3AA1813C-601C-4FFF-8F7A-7070649CAF65}.Debug|Any CPU.ActiveCfg = Release|Any CPU
25-
{3AA1813C-601C-4FFF-8F7A-7070649CAF65}.Debug|Any CPU.Build.0 = Release|Any CPU
24+
{3AA1813C-601C-4FFF-8F7A-7070649CAF65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{3AA1813C-601C-4FFF-8F7A-7070649CAF65}.Debug|Any CPU.Build.0 = Debug|Any CPU
2626
{3AA1813C-601C-4FFF-8F7A-7070649CAF65}.Release|Any CPU.ActiveCfg = Release|Any CPU
2727
{3AA1813C-601C-4FFF-8F7A-7070649CAF65}.Release|Any CPU.Build.0 = Release|Any CPU
2828
{3622D159-0C66-4208-89FD-8DCD782B96F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

GeoJSON4EntityFramework/Elements/Coordinate.vb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Public Class Coordinate
1+
<JsonConverter(GetType(CoordinateConverter))>
2+
Public Class Coordinate
23
Sub New()
34
MyBase.New()
45
End Sub
@@ -14,8 +15,10 @@
1415
End Get
1516
End Property
1617

18+
<JsonIgnore()>
1719
Public Property X As Double
1820

21+
<JsonIgnore()>
1922
Public Property Y As Double
2023

2124
End Class
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Public Class FeatureCollection
22
Inherits GeoJsonElement(Of FeatureCollection)
33

4-
<JsonConverter(GetType(GenericListConverter(Of Feature)))>
54
<JsonProperty(PropertyName:="features")>
65
Public Property Features As New List(Of Feature)
76
End Class

GeoJSON4EntityFramework/Elements/FeatureEF6.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
f.Geometry.Add(Point.FromDbGeometry(inp))
1313
Case "MultPoint"
1414
f.Geometry.Add(MultiPoint.FromDbGeometry(inp))
15-
Case Else
16-
Throw New NotImplementedException
15+
Case "GeometryCollection"
16+
f.Geometry.Add(GeometryCollection.FromDbGeometry(inp))
1717
End Select
1818

1919
Return f
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Partial Public Class GeometryCollection
2+
Inherits GeoJsonElement(Of GeometryCollection)
3+
Implements IGeoJsonGeometry
4+
5+
<JsonProperty(PropertyName:="geometries")>
6+
Public Property Geometries As New List(Of IGeoJsonGeometry)
7+
8+
Shared Function FromDbGeometry(inp As Entity.Spatial.DbGeometry) As IGeoJsonGeometry
9+
Dim obj As New GeometryCollection()
10+
obj.CreateFromDbGeometry(inp)
11+
Return obj
12+
End Function
13+
14+
End Class
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Partial Public Class GeometryCollection
2+
Public Sub CreateFromDbGeometry(inp As Entity.Spatial.DbGeometry)
3+
If inp.SpatialTypeName <> "GeometryCollection" Then Throw New ArgumentException
4+
Geometries.Clear()
5+
6+
For i As Integer = 1 To inp.ElementCount
7+
Dim element = inp.ElementAt(i)
8+
Select Case element.SpatialTypeName
9+
Case "MultiPolygon"
10+
Geometries.Add(MultiPolygon.FromDbGeometry(element))
11+
Case "Polygon"
12+
Geometries.Add(Polygon.FromDbGeometry(element))
13+
Case "Point"
14+
Geometries.Add(Point.FromDbGeometry(element))
15+
Case "MultiPoint"
16+
Geometries.Add(MultiPoint.FromDbGeometry(element))
17+
End Select
18+
Next
19+
End Sub
20+
End Class

GeoJSON4EntityFramework/Elements/MultiPolygon.vb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,11 @@
77

88
Public Overrides ReadOnly Property Coordinates As Object
99
Get
10-
If Polygons.Count = 0 Then
11-
Return New Double() {}
12-
Else
13-
Dim out(Polygons.Count - 1)()()() As Double
14-
15-
Parallel.For(0, Polygons.Count, Sub(i)
16-
out(i) = Polygons(i).Coordinates
17-
End Sub)
18-
Return out
19-
End If
10+
Dim result As New List(Of Object)()
11+
For Each poly In Polygons
12+
result.Add(poly.Coordinates)
13+
Next
14+
Return result
2015
End Get
2116
End Property
2217
End Class

GeoJSON4EntityFramework/Elements/Polygon.vb

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,11 @@
33
Implements IGeoJsonGeometry
44

55
<Newtonsoft.Json.JsonIgnore()>
6-
Public Property Points As New CoordinateList
6+
Public Property Rings As New List(Of CoordinateList)
77

88
Public Overrides ReadOnly Property Coordinates()
99
Get
10-
Try
11-
If Points.Count = 0 Then
12-
Return New Double() {}
13-
ElseIf Points.Count = 1 Then
14-
Throw New Exception("There must be an array of two or more points")
15-
Else
16-
Dim out(0)()() As Double
17-
out(0) = New Double(Points.Count - 1)() {}
18-
Parallel.For(0, Points.Count, Sub(i)
19-
out(0)(i) = Points(i).Coordinate
20-
End Sub)
21-
Return out
22-
End If
23-
Catch ex As Exception
24-
Return New Double() {}
25-
End Try
10+
Return Rings
2611
End Get
2712
End Property
2813
End Class
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
Partial Class Polygon
2+
3+
Private Function RingToCoordinateList(ring As Entity.Spatial.DbGeometry) As CoordinateList
4+
Dim extRingCoords As New CoordinateList()
5+
For i = 1 To ring.PointCount
6+
Dim pt = ring.PointAt(i)
7+
extRingCoords.Add(New Coordinate(pt.XCoordinate, pt.YCoordinate))
8+
Next
9+
Return extRingCoords
10+
End Function
11+
212
Public Overrides Sub CreateFromDbGeometry(inp As Entity.Spatial.DbGeometry)
313
If inp.SpatialTypeName <> MyBase.TypeName Then Throw New ArgumentException
4-
Points.Clear()
14+
Rings.Clear()
515

6-
For i As Integer = 1 To inp.PointCount
7-
Dim point = inp.PointAt(i)
8-
Points.AddNew(point.XCoordinate, point.YCoordinate)
9-
Next
16+
' Process exterior ring
17+
Dim extRing = inp.ExteriorRing
18+
Rings.Add(RingToCoordinateList(extRing))
19+
20+
' Process interior rings (ie. holes)
21+
If inp.InteriorRingCount > 0 Then
22+
For i = 1 To inp.InteriorRingCount
23+
Dim intRing = inp.InteriorRingAt(i)
24+
Rings.Add(RingToCoordinateList(intRing))
25+
Next
26+
End If
1027
End Sub
1128
End Class

GeoJSON4EntityFramework/GeoJSON4EntityFramework.vbproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@
7979
<ItemGroup>
8080
<Compile Include="Base\GeoJsonGeometryEF6.vb" />
8181
<Compile Include="Elements\FeatureEF6.vb" />
82+
<Compile Include="Elements\GeometryCollection.vb" />
8283
<Compile Include="Elements\MultiPointEF6.vb" />
8384
<Compile Include="Elements\MultiPolygonEF6.vb" />
8485
<Compile Include="Elements\PointEF6.vb" />
8586
<Compile Include="Elements\PolygonEF6.vb" />
87+
<Compile Include="JsonNET\CoordinateConverter.vb" />
8688
<Compile Include="JsonNET\GeoJsonSerializer.vb" />
8789
<Compile Include="Elements\Coordinate.vb" />
8890
<Compile Include="Elements\CoordinateList.vb" />
@@ -123,6 +125,7 @@
123125
</ItemGroup>
124126
<ItemGroup>
125127
<None Include="App.config" />
128+
<Compile Include="Elements\GeometryCollectionEF6.vb" />
126129
<None Include="My Project\Application.myapp">
127130
<Generator>MyApplicationCodeGenerator</Generator>
128131
<LastGenOutput>Application.Designer.vb</LastGenOutput>

0 commit comments

Comments
 (0)