use of gov.usgs.cida.utilities.features.AttributeGetter in project coastal-hazards by USGS-CIDA.
the class CRSUtils method gatherPointsIntoLineList.
private static List<LineString> gatherPointsIntoLineList(SimpleFeature start, FeatureIterator<SimpleFeature> rest) {
List<LineString> lines = new LinkedList<>();
SimpleFeatureType featureType = start.getFeatureType();
AttributeGetter getter = new AttributeGetter(featureType);
SimpleFeature previous = null;
SimpleFeature current = start;
List<Coordinate> currentLine = new LinkedList<>();
while (current != null) {
Geometry geometry = (Geometry) current.getDefaultGeometry();
Geometries geomType = Geometries.get(geometry);
switch(geomType) {
case LINESTRING:
case MULTILINESTRING:
// flush currentLine to list before starting new one
if (currentLine.size() > 0) {
lines.add(buildLineString(currentLine));
currentLine = new LinkedList<>();
}
List<LineString> separatedLines = breakLinesIntoLineList(current);
lines.addAll(separatedLines);
break;
case POINT:
Point p = (Point) geometry;
if (isNewLineSegment(previous, current, getter)) {
// only create a line if 2 or more points exist
if (currentLine.size() > 1) {
lines.add(buildLineString(currentLine));
} else {
// DO nothing right now, signifies a single point segnment
LOGGER.warn("Single point feature found and is being ignored, segment_id" + getter.getValue(Constants.SEGMENT_ID_ATTR, current));
}
currentLine = new LinkedList<>();
}
currentLine.add(p.getCoordinate());
break;
case MULTIPOINT:
MultiPoint mp = (MultiPoint) geometry;
if (isNewLineSegment(previous, current, getter)) {
lines.add(buildLineString(currentLine));
currentLine = new LinkedList<>();
}
for (int i = 0; i < mp.getNumPoints(); i++) {
Point pointMember = (Point) mp.getGeometryN(i);
currentLine.add(pointMember.getCoordinate());
}
break;
case POLYGON:
case MULTIPOLYGON:
throw new UnsupportedFeatureTypeException(geomType.getSimpleName() + " features not supported");
default:
throw new UnsupportedFeatureTypeException("Only line type supported");
}
if (rest.hasNext()) {
previous = current;
current = rest.next();
} else {
if (currentLine.size() > 0) {
lines.add(buildLineString(currentLine));
currentLine = new LinkedList<>();
}
current = null;
}
}
return lines;
}
Aggregations