------------------------------------------------------------------------------
| 257 | |
| 258 | //------------------------------------------------------------------------------ |
| 259 | void vtkGeoJSONReader::GeoJSONReaderInternal::ParseFeatureProperties( |
| 260 | const Json::Value& propertiesNode, std::vector<GeoJSONProperty>& featureProperties, |
| 261 | const char* serializedPropertiesArrayName) |
| 262 | { |
| 263 | featureProperties.clear(); |
| 264 | |
| 265 | GeoJSONProperty spec; |
| 266 | GeoJSONProperty property; |
| 267 | std::vector<GeoJSONProperty>::iterator iter = this->PropertySpecs.begin(); |
| 268 | for (; iter != this->PropertySpecs.end(); ++iter) |
| 269 | { |
| 270 | spec = *iter; |
| 271 | property.Name = spec.Name; |
| 272 | |
| 273 | Json::Value const& propertyNode = propertiesNode[spec.Name]; |
| 274 | if (propertyNode.isNull()) |
| 275 | { |
| 276 | property.Value = spec.Value; |
| 277 | featureProperties.push_back(property); |
| 278 | continue; |
| 279 | } |
| 280 | |
| 281 | // (else) |
| 282 | switch (spec.Value.GetType()) |
| 283 | { |
| 284 | case VTK_BIT: |
| 285 | property.Value = vtkVariant(propertyNode.asBool()); |
| 286 | break; |
| 287 | |
| 288 | case VTK_DOUBLE: |
| 289 | property.Value = vtkVariant(propertyNode.asDouble()); |
| 290 | break; |
| 291 | |
| 292 | case VTK_INT: |
| 293 | property.Value = vtkVariant(propertyNode.asInt()); |
| 294 | break; |
| 295 | |
| 296 | case VTK_STRING: |
| 297 | property.Value = vtkVariant(propertyNode.asString()); |
| 298 | break; |
| 299 | } |
| 300 | |
| 301 | featureProperties.push_back(property); |
| 302 | } |
| 303 | |
| 304 | // Add GeoJSON string if enabled |
| 305 | if (serializedPropertiesArrayName) |
| 306 | { |
| 307 | property.Name = serializedPropertiesArrayName; |
| 308 | |
| 309 | Json::StreamWriterBuilder builder; |
| 310 | builder["commentStyle"] = "None"; |
| 311 | builder["indentation"] = ""; |
| 312 | std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter()); |
| 313 | |
| 314 | std::stringstream stream; |
| 315 | writer->write(propertiesNode, &stream); |
| 316 | std::string propString = stream.str(); |
no test coverage detected