@@ -54,51 +54,12 @@ function valueOfOrNull(value) {
54
54
return isNaN ( value ) ? NGSI_LD_NULL : value ;
55
55
}
56
56
57
- /**
58
- * @param {String/Array } value Comma separated list or array of values
59
- * @return {Array } Array of Lat/Lngs for use as GeoJSON
60
- */
61
- function splitLngLat ( value ) {
62
- const lngLats = typeof value === 'string' || value instanceof String ? value . split ( ',' ) : value ;
63
- lngLats . forEach ( ( element , index , lngLats ) => {
64
- if ( Array . isArray ( element ) ) {
65
- lngLats [ index ] = splitLngLat ( element ) ;
66
- } else if ( ( typeof element === 'string' || element instanceof String ) && element . includes ( ',' ) ) {
67
- lngLats [ index ] = splitLngLat ( element ) ;
68
- } else {
69
- lngLats [ index ] = Number . parseFloat ( element ) ;
70
- }
71
- } ) ;
72
- return lngLats ;
73
- }
74
-
75
- /**
76
- * @param {String } value Value to be analyzed
77
- * @return {Array } split pairs of GeoJSON coordinates
78
- */
79
- function getLngLats ( value ) {
80
- const lngLats = _ . flatten ( splitLngLat ( value ) ) ;
81
- if ( lngLats . length === 2 ) {
82
- return lngLats ;
83
- }
84
-
85
- if ( lngLats . length % 2 !== 0 ) {
86
- logger . error ( context , 'Bad attribute value type.' + 'Expecting geo-coordinates. Received:%s' , value ) ;
87
- throw Error ( ) ;
88
- }
89
- const arr = [ ] ;
90
- for ( let i = 0 , len = lngLats . length ; i < len ; i = i + 2 ) {
91
- arr . push ( [ lngLats [ i ] , lngLats [ i + 1 ] ] ) ;
92
- }
93
- return arr ;
94
- }
95
-
96
57
/**
97
58
* Amends an NGSIv2 attribute to NGSI-LD format
98
59
* All native JSON types are respected and cast as Property values
99
60
* Relationships must be give the type relationship
100
61
*
101
- * @param {String } attr Attribute to be analyzed
62
+ * @param {Object } attr Attribute to be analyzed
102
63
* @return {Object } an object containing the attribute in NGSI-LD
103
64
* format
104
65
*/
@@ -153,33 +114,34 @@ function convertNGSIv2ToLD(attr) {
153
114
case 'geoproperty' :
154
115
case 'point' :
155
116
case 'geo:point' :
117
+ case 'geo:json' :
156
118
obj . type = 'GeoProperty' ;
157
- obj . value = { type : 'Point' , coordinates : getLngLats ( attr . value ) } ;
119
+ obj . value = NGSIUtils . getLngLats ( 'Point' , attr . value ) ;
158
120
break ;
159
121
case 'linestring' :
160
122
case 'geo:linestring' :
161
123
obj . type = 'GeoProperty' ;
162
- obj . value = { type : 'LineString' , coordinates : getLngLats ( attr . value ) } ;
124
+ obj . value = NGSIUtils . getLngLats ( 'LineString' , attr . value ) ;
163
125
break ;
164
126
case 'polygon' :
165
127
case 'geo:polygon' :
166
128
obj . type = 'GeoProperty' ;
167
- obj . value = { type : 'Polygon' , coordinates : getLngLats ( attr . value ) } ;
129
+ obj . value = NGSIUtils . getLngLats ( 'Polygon' , attr . value ) ;
168
130
break ;
169
131
case 'multipoint' :
170
132
case 'geo:multipoint' :
171
133
obj . type = 'GeoProperty' ;
172
- obj . value = { type : 'MultiPoint' , coordinates : getLngLats ( attr . value ) } ;
134
+ obj . value = NGSIUtils . getLngLats ( 'MultiPoint' , attr . value ) ;
173
135
break ;
174
136
case 'multilinestring' :
175
137
case 'geo:multilinestring' :
176
138
obj . type = 'GeoProperty' ;
177
- obj . value = { type : 'MultiLineString' , coordinates : attr . value } ;
139
+ obj . value = NGSIUtils . getLngLats ( 'MultiLineString' , attr . value ) ;
178
140
break ;
179
141
case 'multipolygon' :
180
142
case 'geo:multipolygon' :
181
143
obj . type = 'GeoProperty' ;
182
- obj . value = { type : 'MultiPolygon' , coordinates : attr . value } ;
144
+ obj . value = NGSIUtils . getLngLats ( 'MultiPolygon' , attr . value ) ;
183
145
break ;
184
146
185
147
// Relationships
0 commit comments