use of com.revolsys.geometry.model.Lineal in project com.revolsys.open by revolsys.
the class MultiLineStringSegment method next.
@Override
public Segment next() {
final Lineal lineal = this.lineal;
this.segmentIndex++;
while (this.partIndex < lineal.getGeometryCount()) {
final LineString part = getPart();
if (this.segmentIndex < part.getSegmentCount()) {
return this;
} else {
this.partIndex++;
this.segmentIndex = 0;
}
}
throw new NoSuchElementException();
}
use of com.revolsys.geometry.model.Lineal in project com.revolsys.open by revolsys.
the class MultiLineStringSegment method hasNext.
@Override
public boolean hasNext() {
if (getGeometry().isEmpty()) {
return false;
} else {
final Lineal line = this.lineal;
int partIndex = this.partIndex;
int segmentIndex = this.segmentIndex + 1;
final int geometryCount = line.getGeometryCount();
while (partIndex < geometryCount) {
final LineString part = line.getGeometry(partIndex);
final int segmentCount = part.getSegmentCount();
if (segmentIndex < segmentCount) {
return true;
} else {
partIndex++;
segmentIndex = 0;
}
}
return false;
}
}
use of com.revolsys.geometry.model.Lineal in project com.revolsys.open by revolsys.
the class MultiLineStringVertex method hasNext.
@Override
public boolean hasNext() {
if (getGeometry().isEmpty()) {
return false;
} else {
final Lineal lineal = getLineal();
int partIndex = this.partIndex;
int vertexIndex = this.vertexIndex + 1;
while (partIndex < lineal.getGeometryCount()) {
final LineString lineString = lineal.getLineString(partIndex);
if (vertexIndex < lineString.getVertexCount()) {
return true;
} else {
partIndex++;
vertexIndex = 0;
}
}
return false;
}
}
use of com.revolsys.geometry.model.Lineal in project com.revolsys.open by revolsys.
the class LineSequencer method isSequenced.
/**
* Tests whether a {@link Geometry} is sequenced correctly.
* {@link LineString}s are trivially sequenced.
* {@link Lineal}s are checked for correct sequencing.
* Otherwise, <code>isSequenced</code> is defined
* to be <code>true</code> for geometries that are not lineal.
*
* @param geom the geometry to test
* @return <code>true</code> if the geometry is sequenced or is not lineal
*/
public static boolean isSequenced(final Geometry geom) {
if (!(geom instanceof Lineal) || geom instanceof LineString) {
return true;
}
final Lineal lineal = (Lineal) geom;
// the nodes in all subgraphs which have been completely scanned
final Set prevSubgraphNodes = new TreeSet();
Point lastNode = null;
final List currNodes = new ArrayList();
for (int i = 0; i < lineal.getGeometryCount(); i++) {
final LineString line = (LineString) lineal.getGeometry(i);
final Point startNode = line.getPoint(0);
final Point endNode = line.getPoint(line.getVertexCount() - 1);
/**
* If this linestring is connected to a previous subgraph, geom is not sequenced
*/
if (prevSubgraphNodes.contains(startNode)) {
return false;
}
if (prevSubgraphNodes.contains(endNode)) {
return false;
}
if (lastNode != null) {
if (!startNode.equals(lastNode)) {
// start new connected sequence
prevSubgraphNodes.addAll(currNodes);
currNodes.clear();
}
}
currNodes.add(startNode);
currNodes.add(endNode);
lastNode = endNode;
}
return true;
}
use of com.revolsys.geometry.model.Lineal in project com.revolsys.open by revolsys.
the class LineSequencer method computeSequence.
private void computeSequence() {
if (this.isRun) {
return;
}
this.isRun = true;
final List sequences = findSequences();
if (sequences == null) {
return;
}
this.sequencedGeometry = buildSequencedGeometry(sequences);
this.isSequenceable = true;
final int finalLineCount = this.sequencedGeometry.getGeometryCount();
Assert.isTrue(this.lineCount == finalLineCount, "Lines were missing from result");
Assert.isTrue(this.sequencedGeometry instanceof Lineal, "Result is not lineal");
}
Aggregations