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

Method ExtractPolygon

IO/GeoJSON/vtkGeoJSONFeature.cxx:221–288  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

219
220//------------------------------------------------------------------------------
221vtkPolyData* vtkGeoJSONFeature::ExtractPolygon(
222 const Json::Value& coordinate, vtkPolyData* outputData)
223{
224 // Check if Coordinate Array corresponds to Polygon
225 if (!IsPolygon(coordinate))
226 {
227 vtkErrorMacro(<< "Wrong data format for a Polygon!");
228 return nullptr;
229 }
230
231 bool POLYGON_WITH_HOLES = coordinate.size() > 1;
232
233 vtkPoints* points = outputData->GetPoints();
234 vtkAbstractArray* array = outputData->GetCellData()->GetAbstractArray("feature-id");
235 vtkStringArray* ids = vtkArrayDownCast<vtkStringArray>(array);
236
237 // Output is either vtkPolygon or vtkPolyLine,
238 // depending on OutputPolygons option.
239 vtkCellArray* polys = nullptr;
240 vtkCell* exteriorPoly = nullptr;
241 if (this->OutlinePolygons)
242 {
243 polys = outputData->GetLines();
244 exteriorPoly = vtkPolyLine::New();
245 }
246 else
247 {
248 polys = outputData->GetPolys();
249 exteriorPoly = vtkPolygon::New();
250 }
251
252 // For exterior Polygon
253 const Json::Value& exteriorPolygon = coordinate[0];
254
255 int EXTERIOR_POLYGON_VERTEX_COUNT = exteriorPolygon.size() - 1;
256 exteriorPoly->GetPointIds()->SetNumberOfIds(EXTERIOR_POLYGON_VERTEX_COUNT);
257
258 double point[3];
259 // Remember first point, if needed for polyline
260 this->CreatePoint(exteriorPolygon[0], point);
261 vtkIdType idPoint0 = points->InsertNextPoint(point);
262 exteriorPoly->GetPointIds()->SetId(0, idPoint0);
263
264 // Add points for rest of polygon
265 for (int i = 1; i < EXTERIOR_POLYGON_VERTEX_COUNT; i++)
266 {
267 this->CreatePoint(exteriorPolygon[i], point);
268 vtkIdType id = points->InsertNextPoint(point);
269 exteriorPoly->GetPointIds()->SetId(i, id);
270 }
271
272 // For outline mode, add first point to the end
273 if (this->OutlinePolygons)
274 {
275 exteriorPoly->GetPointIds()->InsertNextId(idPoint0);
276 }
277
278 polys->InsertNextCell(exteriorPoly);

Callers 2

ExtractMultiPolygonMethod · 0.95

Calls 15

CreatePointMethod · 0.95
GetAbstractArrayMethod · 0.80
GetPolysMethod · 0.80
SetNumberOfIdsMethod · 0.80
InsertNextIdMethod · 0.80
DeleteMethod · 0.65
NewFunction · 0.50
sizeMethod · 0.45
GetPointsMethod · 0.45
GetCellDataMethod · 0.45
GetLinesMethod · 0.45
GetPointIdsMethod · 0.45

Tested by

no test coverage detected