MCPcopy Create free account
hub / github.com/Kitware/VTK / WriteData

Method WriteData

IO/GeoJSON/vtkGeoJSONWriter.cxx:233–505  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

231
232//------------------------------------------------------------------------------
233void vtkGeoJSONWriter::WriteData()
234{
235 ostream* fp;
236 vtkPolyData* input = vtkPolyData::SafeDownCast(this->GetInput());
237
238 vtkDebugMacro(<< "Writing vtk polygonal data to geojson file...");
239 fp = this->OpenFile();
240 if (!fp)
241 {
242 return;
243 }
244
245 this->WriterHelper->append("{\n");
246 this->WriterHelper->append("\"type\": \"Feature\",\n");
247 vtkDataArray* da = input->GetPointData()->GetScalars();
248 if (!da)
249 {
250 da = input->GetPointData()->GetArray(0);
251 }
252 if (da)
253 {
254 switch (this->ScalarFormat)
255 {
256 case 0:
257 this->WriterHelper->append("\"properties\": {\"ScalarFormat\": \"none\"},\n");
258 break;
259 case 1:
260 this->WriterHelper->append("\"properties\": {\"ScalarFormat\": \"rgb\"},\n");
261 break;
262 case 2:
263 double rng[2];
264 da->GetRange(rng);
265 this->WriterHelper->append(
266 "\"properties\": {\"ScalarFormat\": \"values\", \"ScalarRange\": [");
267 this->WriterHelper->append(rng[0]);
268 this->WriterHelper->append(",");
269 this->WriterHelper->append(rng[1]);
270 this->WriterHelper->append("] },\n");
271 break;
272 }
273 }
274 else
275 {
276 this->WriterHelper->append("\"properties\": {\"ScalarFormat\": \"none\"},\n");
277 }
278 this->WriterHelper->append("\"geometry\":\n");
279 this->WriterHelper->append("{\n");
280 this->WriterHelper->append("\"type\": \"GeometryCollection\",\n");
281 this->WriterHelper->append("\"geometries\":\n");
282 this->WriterHelper->append("[\n");
283
284 const vtkIdType* cellPts = nullptr;
285 vtkIdType cellSize = 0;
286 vtkIdType numlines, numpolys;
287 numlines = input->GetLines()->GetNumberOfCells();
288 numpolys = input->GetPolys()->GetNumberOfCells();
289
290 // VERTS

Callers

nothing calls this directly

Calls 15

OpenFileMethod · 0.95
WriteScalarMethod · 0.95
ConditionalCommaMethod · 0.95
CloseFileMethod · 0.95
IsNanFunction · 0.85
GetPolysMethod · 0.80
GetVertsMethod · 0.80
GetInputMethod · 0.45
appendMethod · 0.45
GetScalarsMethod · 0.45
GetPointDataMethod · 0.45
GetArrayMethod · 0.45

Tested by

no test coverage detected