27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.9.0/module_geographicElement.rb', line 27
def self.unpack(aGeoElements)
aIntGeoEle = Array.new
aGeoElements.each do |hGeoJsonElement|
intMetadataClass = InternalMetadata.new
hGeoElement = intMetadataClass.newGeoElement
if hGeoJsonElement.has_key?('type')
elementType = hGeoJsonElement['type']
else
return nil
end
if hGeoJsonElement.has_key?('id')
s = hGeoJsonElement['id']
if s != ''
hGeoElement[:elementId] = s
end
end
if hGeoJsonElement.has_key?('crs')
hGeoCrs = hGeoJsonElement['crs']
Adiwg_GeoCoordSystem.unpack(hGeoCrs, hGeoElement)
end
if hGeoJsonElement.has_key?('properties')
hGeoProps = hGeoJsonElement['properties']
Adiwg_GeoProperties.unpack(hGeoProps, hGeoElement)
end
if hGeoJsonElement.has_key?('bbox')
if hGeoJsonElement['bbox'].length == 4
aBBox = hGeoJsonElement['bbox']
boxElement = Marshal.load(Marshal.dump(hGeoElement))
boxElement[:elementGeometry] = Adiwg_BoundingBox.unpack(aBBox)
aIntGeoEle << boxElement
end
end
case elementType
when 'Feature'
if hGeoJsonElement.has_key?('geometry')
hGeometry = hGeoJsonElement['geometry']
unless hGeometry.nil?
unless hGeometry.empty?
if hGeometry.has_key?('type')
geometryType = hGeometry['type']
aCoordinates = hGeometry['coordinates']
unless aCoordinates.empty?
case geometryType
when 'Point', 'MultiPoint'
hGeoElement[:elementGeometry] = Adiwg_Point.unpack(aCoordinates, geometryType)
when 'LineString', 'MultiLineString'
hGeoElement[:elementGeometry] = Adiwg_LineString.unpack(aCoordinates, geometryType)
when 'Polygon', 'MultiPolygon'
hGeoElement[:elementGeometry] = Adiwg_Polygon.unpack(aCoordinates, geometryType)
else
end
aIntGeoEle << hGeoElement
end
end
end
end
end
when 'FeatureCollection'
if hGeoJsonElement.has_key?('features')
aFeatures = hGeoJsonElement['features']
unless aFeatures.empty?
intGeometry = intMetadataClass.newGeometry
intGeometry[:geoType] = 'MultiGeometry'
intGeometry[:geometry] = Adiwg_GeographicElement.unpack(aFeatures)
hGeoElement[:elementGeometry] = intGeometry
aIntGeoEle << hGeoElement
end
end
when 'Point', 'MultiPoint'
aCoordinates = hGeoJsonElement['coordinates']
hGeoElement[:elementGeometry] = Adiwg_Point.unpack(aCoordinates, elementType)
aIntGeoEle << hGeoElement
when 'LineString', 'MultiLineString'
aCoordinates = hGeoJsonElement['coordinates']
hGeoElement[:elementGeometry] = Adiwg_LineString.unpack(aCoordinates, elementType)
aIntGeoEle << hGeoElement
when 'Polygon', 'MultiPolygon'
aCoordinates = hGeoJsonElement['coordinates']
hGeoElement[:elementGeometry] = Adiwg_Polygon.unpack(aCoordinates, elementType)
aIntGeoEle << hGeoElement
when 'GeometryCollection'
if hGeoJsonElement.has_key?('geometries')
aGeometries = hGeoJsonElement['geometries']
unless aGeometries.empty?
intGeometry = intMetadataClass.newGeometry
intGeometry[:geoType] = 'MultiGeometry'
intGeometry[:geometry] = Adiwg_GeographicElement.unpack(aGeometries)
hGeoElement[:elementGeometry] = intGeometry
aIntGeoEle << hGeoElement
end
end
end
end
return aIntGeoEle
end
|