Commit 1e5594fa authored by John Tourtellott's avatar John Tourtellott
Browse files

Change GeoJSON reader to parse LineString features into vtkPolyLine instances

parent 8de76a3a
Pipeline #1334 failed with stage
......@@ -11,6 +11,7 @@ def load_geojson(input_string, feature_properties={}):
to attach as cell data in the returned vtkPolyData.
'''
reader = vtk.vtkGeoJSONReader()
#reader.DebugOn()
reader.StringInputModeOn()
reader.SetStringInput(input_string)
for name,default_value in feature_properties.items():
......@@ -70,7 +71,7 @@ if __name__ == '__main__' :
# Check cell counts
expected_verts = 1
expected_lines = 3
expected_lines = 1
expected_polys = 1
num_verts = polydata.GetNumberOfVerts()
......@@ -84,12 +85,28 @@ if __name__ == '__main__' :
print('Wrong number of lines: returned %s, should be %s' % \
(num_lines, expected_lines))
num_errors += 1
else:
# Check number of points in the (first) polyline
id_list = vtk.vtkIdList()
polydata.GetLines().GetCell(0, id_list)
if id_list.GetNumberOfIds() != 4:
print('Wrong number of points in line 0: returned %s, should be %s' % \
(id_list.GetNumberOfIds(), 4))
num_errors += 1
num_polys = polydata.GetNumberOfPolys()
if num_polys != expected_polys:
print('Wrong number of polys: returned %s, should be %s' % \
(num_polys, expected_polys))
num_errors += 1
else:
# Check number of points in the (first) polygon
id_list = vtk.vtkIdList()
polydata.GetPolys().GetCell(0, id_list)
if id_list.GetNumberOfIds() != 4:
print('Wrong number of points in poly 0: returned %s, should be %s' % \
(id_list.GetNumberOfIds(), 4))
num_errors += 1
# Check cell data
cell_data = polydata.GetCellData()
......
......@@ -183,41 +183,28 @@ vtkPolyData *vtkGeoJSONFeature::
ExtractLineString(const Json::Value& coordinates, vtkPolyData *outputData)
{
//Check if Coordinates corresponds to Line String
if ( ! IsLineString( coordinates ) )
if (!IsLineString(coordinates))
{
vtkErrorMacro (<< "Wrong data format for a Line String!");
return NULL;
}
vtkCellArray *lines = outputData->GetLines();
vtkPoints *points = outputData->GetPoints();
vtkNew<vtkPolyLine> polyLine;
double xyz[3];
vtkIdList *pointIdList = polyLine->GetPointIds();
vtkIdType pointId;
for (Json::Value::ArrayIndex i = 0; i < coordinates.size(); i++)
{
this->CreatePoint(coordinates[i], xyz);
pointId = points->InsertNextPoint(xyz);
pointIdList->InsertNextId(pointId);
}
outputData->GetLines()->InsertNextCell(polyLine.GetPointer());
vtkAbstractArray *array =
outputData->GetCellData()->GetAbstractArray("feature-id");
vtkStringArray *ids = vtkStringArray::SafeDownCast(array);
int LINE_COUNT = coordinates.size();
double start[3], end[3];
CreatePoint(coordinates[0], start);
vtkIdType lineId[2];
lineId[0] = points->InsertNextPoint(start);
for (int i = 1; i < LINE_COUNT; i++)
{
CreatePoint(coordinates[i], end);
lineId[1] = points->InsertNextPoint(end);
vtkNew<vtkLine> line;
line->GetPointIds()->SetId(0, lineId[0]);
line->GetPointIds()->SetId(1, lineId[1]);
lines->InsertNextCell(line.GetPointer());
ids->InsertNextValue(this->FeatureId);
lineId[0] = lineId[1];
}
ids->InsertNextValue(this->FeatureId);
return outputData;
}
......@@ -234,11 +221,9 @@ ExtractMultiLineString(const Json::Value& coordinateArray,
return NULL;
}
int LINE_STRING_COUNT = coordinateArray.size();
for (int i = 0; i < LINE_STRING_COUNT; i++)
for (Json::Value::ArrayIndex i = 0; i < coordinateArray.size(); i++)
{
this->ExtractLineString( coordinateArray[i], outputData);
this->ExtractLineString(coordinateArray[i], outputData);
}
return outputData;
......@@ -326,12 +311,10 @@ ExtractMultiPolygon(const Json::Value& coordinateArray, vtkPolyData *outputData)
return NULL;
}
int POLYGON_COUNT = coordinateArray.size();
for (int i = 0; i < POLYGON_COUNT; i++)
for (Json::Value::ArrayIndex i = 0; i < coordinateArray.size(); i++)
{
//Extract polygon into different polyData and append into a common polyData using the appendPolyData Filter
this->ExtractPolygon( coordinateArray[i], outputData);
this->ExtractPolygon(coordinateArray[i], outputData);
}
return outputData;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment