------------------------------------------------------------------------------
| 219 | |
| 220 | //------------------------------------------------------------------------------ |
| 221 | vtkPolyData* 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); |
no test coverage detected