Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Dec 3, 2023
1 parent e1b3907 commit 6a4f80a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public ComponentJumpChecker(Collection<TaggedLineString> taggedLines) {
components = taggedLines;
}

/**
* Checks if a line section jumps a component if flattened.
*
* Assumes start <= end.
*
* @param line the line containing the section being flattened
* @param start start index of the section
* @param end end index of the section
* @param seg the flattening segment
* @return true if the flattened section jumps a component
*/
public boolean hasJump(TaggedLineString line, int start, int end, LineSegment seg) {
Envelope sectionEnv = computeEnvelope(line, start, end);
for (TaggedLineString comp : components) {
Expand All @@ -51,6 +62,18 @@ public boolean hasJump(TaggedLineString line, int start, int end, LineSegment se
return false;
}

/**
* Checks if two consecutive segments jumps a component if flattened.
* The segments are assumed to be consecutive.
* (so the seg1.p1 = seg2.p0).
* The flattening segment must be the segment between seg1.p0 and seg2.p1.
*
* @param line the line containing the section being flattened
* @param seg1 the first replaced segment
* @param seg2 the next replaced segment
* @param seg the flattening segment
* @return true if the flattened segment jumps a component
*/
public boolean hasJump(TaggedLineString line, LineSegment seg1, LineSegment seg2, LineSegment seg) {
Envelope sectionEnv = computeEnvelope(seg1, seg2);
for (TaggedLineString comp : components) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public void remove(LineSegment seg)
index.remove(new Envelope(seg.p0, seg.p1), seg);
}

public List query(LineSegment querySeg)
public List<Object> query(LineSegment querySeg)
{
Envelope env = new Envelope(querySeg.p0, querySeg.p1);

LineSegmentVisitor visitor = new LineSegmentVisitor(querySeg);
index.query(env, visitor);
List itemsFound = visitor.getItems();
List<Object> itemsFound = visitor.getItems();

// List listQueryItems = index.query(env);
// System.out.println("visitor size = " + itemsFound.size()
Expand All @@ -78,7 +78,7 @@ class LineSegmentVisitor
// MD - only seems to make about a 10% difference in overall time.

private LineSegment querySeg;
private ArrayList items = new ArrayList();
private ArrayList<Object> items = new ArrayList<Object>();

public LineSegmentVisitor(LineSegment querySeg) {
this.querySeg = querySeg;
Expand All @@ -91,5 +91,5 @@ public void visitItem(Object item)
items.add(item);
}

public ArrayList getItems() { return items; }
public ArrayList<Object> getItems() { return items; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ class TaggedLineString

private LineString parentLine;
private TaggedLineSegment[] segs;
private List resultSegs = new ArrayList();
private List<LineSegment> resultSegs = new ArrayList<LineSegment>();
private int minimumSize;
private boolean isPreserveEndpoint = true;
private boolean isKeepEndpoint = true;

public TaggedLineString(LineString parentLine) {
this(parentLine, 2, true);
}

public TaggedLineString(LineString parentLine, int minimumSize, boolean isPreserveEndpoint) {
public TaggedLineString(LineString parentLine, int minimumSize, boolean isKeepEndpoint) {
this.parentLine = parentLine;
this.minimumSize = minimumSize;
this.isPreserveEndpoint = isPreserveEndpoint;
this.isKeepEndpoint = isKeepEndpoint;
init();
}

public boolean isPreserveEndpoint() {
return isPreserveEndpoint;
public boolean isKeepEndpoint() {
return isKeepEndpoint;
}

public int getMinimumSize() { return minimumSize; }
Expand Down Expand Up @@ -124,7 +124,7 @@ public LinearRing asLinearRing() {
return parentLine.getFactory().createLinearRing(extractCoordinates(resultSegs));
}

private static Coordinate[] extractCoordinates(List segs)
private static Coordinate[] extractCoordinates(List<LineSegment> segs)
{
Coordinate[] pts = new Coordinate[segs.size() + 1];
LineSegment seg = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void simplify(TaggedLineString line)
linePts = line.getParentCoordinates();
simplifySection(0, linePts.length - 1, 0);

if (! line.isPreserveEndpoint() && CoordinateArrays.isRing(linePts)) {
if (! line.isKeepEndpoint() && CoordinateArrays.isRing(linePts)) {
simplifyRingEndpoint();
}
}
Expand Down Expand Up @@ -130,8 +130,8 @@ private void simplifySection(int i, int j, int depth)

/**
* Simplifies the result segments on either side of a ring endpoint
* (which has not been changed by prior simplification).
* This ensures that simplification removes flat endpoints.
* (which was not processed by the initial simplification).
* This ensures that simplification removes flat (collinear) endpoints.
*/
private void simplifyRingEndpoint()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static Geometry simplify(Geometry geom, double distanceTolerance)

private Geometry inputGeom;
private TaggedLinesSimplifier lineSimplifier = new TaggedLinesSimplifier();
private Map linestringMap;
private Map<LineString, TaggedLineString> linestringMap;

public TopologyPreservingSimplifier(Geometry inputGeom)
{
Expand All @@ -116,7 +116,7 @@ public Geometry getResultGeometry()
// empty input produces an empty result
if (inputGeom.isEmpty()) return inputGeom.copy();

linestringMap = new HashMap();
linestringMap = new HashMap<LineString, TaggedLineString>();
inputGeom.apply(new LineStringMapBuilderFilter(this));
lineSimplifier.simplify(linestringMap.values());
Geometry result = (new LineStringTransformer(linestringMap)).transform(inputGeom);
Expand All @@ -126,9 +126,9 @@ public Geometry getResultGeometry()
static class LineStringTransformer
extends GeometryTransformer
{
private Map linestringMap;
private Map<LineString, TaggedLineString> linestringMap;

public LineStringTransformer(Map linestringMap) {
public LineStringTransformer(Map<LineString, TaggedLineString> linestringMap) {
this.linestringMap = linestringMap;
}

Expand All @@ -137,7 +137,7 @@ protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geo
if (coords.size() == 0) return null;
// for linear components (including rings), simplify the linestring
if (parent instanceof LineString) {
TaggedLineString taggedLine = (TaggedLineString) linestringMap.get(parent);
TaggedLineString taggedLine = linestringMap.get(parent);
return createCoordinateSequence(taggedLine.getResultCoordinates());
}
// for anything else (e.g. points) just copy the coordinates
Expand Down Expand Up @@ -178,8 +178,8 @@ public void filter(Geometry geom)
if (line.isEmpty()) return;

int minSize = ((LineString) line).isClosed() ? 4 : 2;
boolean isPreserveEndpoint = (line instanceof LinearRing) ? false : true;
TaggedLineString taggedLine = new TaggedLineString((LineString) line, minSize, isPreserveEndpoint);
boolean isKeepEndpoint = (line instanceof LinearRing) ? false : true;
TaggedLineString taggedLine = new TaggedLineString((LineString) line, minSize, isKeepEndpoint);
tps.linestringMap.put(line, taggedLine);
}
}
Expand Down

0 comments on commit 6a4f80a

Please sign in to comment.