Revision: 4938 http://sourceforge.net/p/jump-pilot/code/4938 Author: michaudm Date: 2016-06-18 21:13:40 +0000 (Sat, 18 Jun 2016) Log Message: ----------- Add "interpolate z" option in CoverageCleanerPlugIn
Modified Paths: -------------- plug-ins/TopologyPlugin/trunk/build.xml plug-ins/TopologyPlugin/trunk/doc/TopologyExtension4OJ.odt plug-ins/TopologyPlugin/trunk/doc/TopologyExtension4OJ_fr.odt plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/Coverage.java plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/CoverageCleaner.java plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/CoverageFeature.java plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/MatchedVertex.java plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/Segment.java plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/Shell.java plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/VertexMap.java plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/plugin/clean/CoverageCleanerPlugIn.java plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/qa/FeatureCoordinateMap.java plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/TopologyExtension.java plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/topology.properties plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/topology_fr.properties plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/topology_it.properties Added Paths: ----------- plug-ins/TopologyPlugin/trunk/test/fr/michaelm/jump/plugin/topology/CoverageCleanerTest.java Modified: plug-ins/TopologyPlugin/trunk/build.xml =================================================================== --- plug-ins/TopologyPlugin/trunk/build.xml 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/build.xml 2016-06-18 21:13:40 UTC (rev 4938) @@ -17,7 +17,7 @@ <property name="dist" value="dist" /> <property name="javadoc" value="javadoc" /> - <property name="version" value="0.8.2" /> + <property name="version" value="0.9.0" /> <!--property name="current-oj" value="C:\Users\Michaël\DEVELOPPEMENTS\OpenJUMP-2012\dist\openjump-1.6.0alpha\lib\ext" /--> <!-- =================================================================== --> Modified: plug-ins/TopologyPlugin/trunk/doc/TopologyExtension4OJ.odt =================================================================== (Binary files differ) Modified: plug-ins/TopologyPlugin/trunk/doc/TopologyExtension4OJ_fr.odt =================================================================== (Binary files differ) Modified: plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/Coverage.java =================================================================== --- plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/Coverage.java 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/Coverage.java 2016-06-18 21:13:40 UTC (rev 4938) @@ -40,7 +40,6 @@ /** * A coverage is a set of adjacent polygons build from a FeatureCollection. */ - public class Coverage { private Map<Feature,CoverageFeature> featureMap = @@ -67,16 +66,15 @@ * * @param adjustableCoords a Set of the coordinates which can be adjusted */ - public void setAdjustableCoordinates(Set adjustableCoords) { + public void setAdjustableCoordinates(Set<Coordinate> adjustableCoords) { this.adjustableCoords = adjustableCoords; } public FeatureCollection getAdjustmentIndicators() { GeometryFactory fact = new GeometryFactory(); - List indicatorLineList = new ArrayList(); - Collection vertices = vertexMap.getVertices(); - for (Iterator i = vertices.iterator(); i.hasNext(); ) { - Vertex v = (Vertex) i.next(); + List<Geometry> indicatorLineList = new ArrayList<Geometry>(); + Collection<Vertex> vertices = vertexMap.getVertices(); + for (Vertex v : vertices) { if (v.isAdjusted()) { Coordinate[] lineSeg = new Coordinate[] { v.getOriginalCoordinate(), v.getAdjustedCoordinate() }; Geometry line = fact.createLineString(lineSeg); @@ -99,26 +97,25 @@ * Returns Polygon from featureList * @TODO : process multipolygons */ - public List getCoverageFeatureList(List<Feature> featureList) { - List<CoverageFeature> cgfList = new ArrayList(); - for (Iterator<Feature> i = featureList.iterator(); i.hasNext(); ) { - Feature f = (Feature) i.next(); + public List<CoverageFeature> getCoverageFeatureList(List<Feature> featureList) { + List<CoverageFeature> cgfList = new ArrayList<CoverageFeature>(); + for (Feature feature : featureList) { // currently only polygons are handled - if (f.getGeometry() instanceof Polygon) - cgfList.add(getCoverageFeature(f)); + if (feature.getGeometry() instanceof Polygon) { + cgfList.add(getCoverageFeature(feature)); + } } return cgfList; } - public void computeAdjustedFeatureUpdates(double distanceTolerance) { + public void computeAdjustedFeatureUpdates(double distanceTolerance, boolean interpolate_z, double scale) { adjustedFC = new FeatureDataset(features.getFeatureSchema()); Collection<CoverageFeature> cgfColl = featureMap.values(); - for (Iterator<CoverageFeature> i = cgfColl.iterator(); i.hasNext(); ) { - CoverageFeature cgf = i.next(); + for (CoverageFeature cgf : cgfColl) { Debug.println(" feature " + cgf.getFeature().getID()); - if (cgf.isAdjusted(distanceTolerance)) { + if (cgf.isAdjusted(distanceTolerance, interpolate_z, scale)) { Debug.println(" feature " + cgf.getFeature().getID() + " is adjusted"); - Geometry g = cgf.getAdjustedGeometry(distanceTolerance); + Geometry g = cgf.getAdjustedGeometry(distanceTolerance, interpolate_z, scale); // The following tip is able to transform an auto-intersecting // polygon into a MultiPolygon (only if it is noded) if (!g.isValid()) g = g.buffer(0); Modified: plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/CoverageCleaner.java =================================================================== --- plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/CoverageCleaner.java 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/CoverageCleaner.java 2016-06-18 21:13:40 UTC (rev 4938) @@ -49,10 +49,9 @@ */ public class CoverageCleaner { - public static boolean hasMultiPolygonFeature(List featureList) { - for (Iterator i = featureList.iterator(); i.hasNext(); ) { - Feature f = (Feature) i.next(); - if (f.getGeometry() instanceof MultiPolygon) { + public static boolean hasMultiPolygonFeature(List<Feature> featureList) { + for (Feature feature : featureList) { + if (feature.getGeometry() instanceof MultiPolygon) { return true; } } @@ -73,9 +72,19 @@ * The maximum angle between matching segments. */ public double angleTolerance = 22.5; + /** + * If true, coordinates inserted in a segment from another feature will + * have a z interpolated on the segment ends rather than the z of the + * other feature + */ + public boolean interpolateZ = false; + /** + * Scale factor to reduce precision of the z if interpolate_z is true + */ + public double zScale = 1.0; } - private static GeometryFactory geomFactory = new GeometryFactory(); + //private static GeometryFactory geomFactory = new GeometryFactory(); //input data private Parameters param; @@ -86,7 +95,7 @@ private FeatureCollection matchedFC; private List<FeatureSegment> matchedSegments = null; private SegmentIndex matchedSegmentIndex = null; - private Set matchedSegmentCoordSet = null; + private Set<Coordinate> matchedSegmentCoordSet = null; /** * The features which may be adjusted (due to having matched segments @@ -269,7 +278,7 @@ segmentMatcher, matchedSegmentIndex); } Debug.println(" 6.2 computeAdjustedFeatureUpdates"); - cvg.computeAdjustedFeatureUpdates(param.distanceTolerance); + cvg.computeAdjustedFeatureUpdates(param.distanceTolerance, param.interpolateZ, param.zScale); } } Modified: plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/CoverageFeature.java =================================================================== --- plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/CoverageFeature.java 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/CoverageFeature.java 2016-06-18 21:13:40 UTC (rev 4938) @@ -73,11 +73,11 @@ return holes; } - public boolean isAdjusted(double distanceTolerance) { + public boolean isAdjusted(double distanceTolerance, boolean interpolate_z, double scale) { if (!isProcessed) return false; - isAdjusted |= shell.isAdjusted(distanceTolerance); + isAdjusted |= shell.isAdjusted(distanceTolerance, interpolate_z, scale); for (Shell hole : holes) { - isAdjusted |= hole.isAdjusted(distanceTolerance); + isAdjusted |= hole.isAdjusted(distanceTolerance, interpolate_z, scale); } return isAdjusted; } @@ -91,11 +91,11 @@ * the original geometry are cloned and added to the new geometry. * * @return an adjusted version of the geometry for this Feature - * @return null if the adjusted geometry is invalid + * (or null if the adjusted geometry is invalid) */ - public Geometry getAdjustedGeometry(double distanceTolerance) { + public Geometry getAdjustedGeometry(double distanceTolerance, boolean interpolate_z, double scale) { Debug.println(" adjust shell"); - Coordinate[] coord = shell.getAdjusted(distanceTolerance); + Coordinate[] coord = shell.getAdjusted(distanceTolerance, interpolate_z, scale); // check for a valid ring if (coord.length <= 3) return null; @@ -107,12 +107,11 @@ Coordinate[][] coords = new Coordinate[holes.length][]; for (int i = 0 ; i < holes.length ; i++) { Debug.println(" adjust hole " + (i+1)); - coords[i] = holes[i].getAdjusted(distanceTolerance); + coords[i] = holes[i].getAdjusted(distanceTolerance, interpolate_z, scale); if (coords[i].length <= 3) continue; rings.add(fact.createLinearRing(coords[i])); } - Geometry adjGeom = fact.createPolygon(fact.createLinearRing(coord), rings.toArray(new LinearRing[0])); - return adjGeom; + return fact.createPolygon(fact.createLinearRing(coord), rings.toArray(new LinearRing[0])); } /** @@ -121,20 +120,19 @@ * @param nearFeatures a list of CoverageGapFeatures that are close to this feature * @param segMatcher the SegmentMatcher to use, initialized with the distance tolerance */ - public void computeAdjustment(List nearFeatures, + public void computeAdjustment(List<CoverageFeature> nearFeatures, SegmentMatcher segMatcher, SegmentIndex matchedSegmentIndex) { computeAdjustmentSingle(nearFeatures, segMatcher, matchedSegmentIndex); } - public boolean computeAdjustmentSingle(List nearFeatures, + public boolean computeAdjustmentSingle(List<CoverageFeature> nearFeatures, SegmentMatcher segMatcher, SegmentIndex matchedSegmentIndex) { isProcessed = true; boolean isModified = false; // Compare this feature with all near feature candidates - for (Iterator i = nearFeatures.iterator(); i.hasNext(); ) { - CoverageFeature cgf = (CoverageFeature) i.next(); + for (CoverageFeature cgf : nearFeatures) { if (cgf == this) continue; //if (cgf.getFeature().getID() < feature.getID()) continue; Debug.println(" Try to match " + feature.getID() + "/0 with feature " + cgf.getFeature().getID() + "..."); Modified: plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/MatchedVertex.java =================================================================== --- plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/MatchedVertex.java 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/MatchedVertex.java 2016-06-18 21:13:40 UTC (rev 4938) @@ -32,7 +32,6 @@ package com.vividsolutions.jcs.conflate.coverage; -import java.util.*; import com.vividsolutions.jts.geom.*; /** Modified: plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/Segment.java =================================================================== --- plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/Segment.java 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/Segment.java 2016-06-18 21:13:40 UTC (rev 4938) @@ -34,7 +34,6 @@ import java.util.*; import com.vividsolutions.jts.geom.*; -import com.vividsolutions.jts.util.Debug; /** * Represents a single line segment from the edge of a shell of a Polygon @@ -45,15 +44,18 @@ private Shell shell; private Vertex vertex[] = new Vertex[2]; + private double z_ini, z_fin; private LineSegment seg; private List<MatchedVertex> matchedVertexList = new ArrayList<MatchedVertex>(); private List<Coordinate> insertedCoordList = null; // a marker to know if this Segment is referenced in the SegmentIndex private boolean isInIndex = false; - public Segment(Vertex v0, Vertex v1, Shell shell) { + public Segment(Vertex v0, Vertex v1, Shell shell, double z_ini, double z_fin) { vertex[0] = v0; vertex[1] = v1; + this.z_ini = z_ini; + this.z_fin = z_fin; this.shell = shell; seg = new LineSegment(vertex[0].getCoordinate(), vertex[1].getCoordinate()); double segLen = v0.getCoordinate().distance(v1.getCoordinate()); @@ -63,10 +65,12 @@ public Vertex getVertex(int i) { return vertex[i]; } + public double getZIni() {return z_ini;} + public LineSegment getLineSegment() { return seg; } - public List getInsertedCoordinates() { - if (insertedCoordList == null) computeInserted(); + public List getInsertedCoordinates(boolean interpolate_z, double scale) { + if (insertedCoordList == null) computeInserted(interpolate_z, scale); return insertedCoordList; } @@ -158,8 +162,12 @@ return false; } - private void computeInserted() { - // compute position of matched vertices, taking into acccount any adjustments to the underlying vertex + private void computeInserted(boolean interpolate_z, double scale) { + //System.out.println("v0 avant :" + this + " : " + vertex[0].getOriginalCoordinate()); + //System.out.println("v0 après :" + this + " : " + vertex[0].getAdjustedCoordinate()); + //System.out.println("v1 avant :" + this + " : " + vertex[1].getOriginalCoordinate()); + //System.out.println("v1 après :" + this + " : " + vertex[1].getAdjustedCoordinate()); + // compute position of matched vertices, taking into account any adjustments to the underlying vertex for (Iterator j = matchedVertexList.iterator(); j.hasNext(); ) { MatchedVertex mv = (MatchedVertex) j.next(); mv.computePosition(this.getLineSegment()); @@ -174,17 +182,33 @@ for (Iterator i = matchedVertexList.iterator(); i.hasNext(); ) { MatchedVertex mv = (MatchedVertex) i.next(); Coordinate coord = mv.getVertex().getCoordinate(); - // prevent duplicate coordinates if (prevCoord != null && coord.equals2D(prevCoord)) continue; prevCoord = coord; if (mv.getPosition() > 0.0 && mv.getPosition() < 1.0) { + if (interpolate_z) { + coord = (Coordinate)coord.clone(); + coord.z = Math.round(interpolate(coord)*scale)/scale; + } insertedCoordList.add(coord); } } } + private double interpolate(Coordinate c) { + Coordinate c0 = vertex[0].getOriginalCoordinate(); + Coordinate c1 = vertex[1].getOriginalCoordinate(); + double d0 = c.distance(c0); + double d1 = c.distance(c1); + double l = c0.distance(c1); + if (d0 >= l) return z_fin; + else if (d1 >= l) return z_ini; + else if (Double.isNaN(z_ini)) return z_fin; + else if (Double.isNaN(z_fin)) return z_ini; + else return c0.z + (z_fin-z_ini)*d0/l; + } + public String toString() { return toLineString(vertex[0].getOriginalCoordinate(), vertex[1].getOriginalCoordinate()); } Modified: plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/Shell.java =================================================================== --- plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/Shell.java 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/Shell.java 2016-06-18 21:13:40 UTC (rev 4938) @@ -81,6 +81,14 @@ return shellIndex; } + public VertexMap getVertexMap() { + return vertexMap; + } + + public LinearRing getRing() { + return ring; + } + public void initialize(LinearRing ring, Set<Coordinate> adjustableCoords) { this.ring = ring; uniqueCoord = CoordinateArrays.removeRepeatedPoints(ring.getCoordinates()); @@ -111,8 +119,8 @@ * Creates a Vertex for vertex i <b>if</b> * this is a vertex that might be modified. * - * @param i - * @param adjustableCoords + * @param i index + * @param adjustableCoords Set of adjustable coordinates */ private void createVertex(int i, Set<Coordinate> adjustableCoords) { Coordinate pt = uniqueCoord[i]; @@ -130,21 +138,13 @@ private Segment createSegment(int i) { Vertex v0 = vertexMap.get(uniqueCoord[i]); Vertex v1 = vertexMap.get(uniqueCoord[i+1]); - Segment segment = new Segment(v0, v1, this); - return segment; + return new Segment(v0, v1, this, uniqueCoord[i].z, uniqueCoord[i+1].z); } // [2013-01-26] segmentIndex contains segments with original coordinates // private boolean isInIndex(SegmentIndex segmentIndex, int i) { - //if (segments[i] == null) { - return segmentIndex.contains(new FeatureSegment(null, uniqueCoord[i], uniqueCoord[i + 1], -1, -1)); - //} - //return segmentIndex.contains(new FeatureSegment(null, segments[i].getVertex(0).getCoordinate(), segments[i].getVertex(1).getCoordinate())); - // - //return segmentIndex.contains(new FeatureSegment(null, - // segments[i].getVertex(0).getOriginalCoordinate(), - // segments[i].getVertex(1).getOriginalCoordinate())); + return segmentIndex.contains(new FeatureSegment(null, uniqueCoord[i], uniqueCoord[i + 1], -1, -1)); } public boolean match(Shell shell, SegmentMatcher segmentMatcher, @@ -160,6 +160,7 @@ // this method might cause the coordinates to change, so make sure they are recomputed adjustedCoord = null; boolean isAdjusted = false; + /** * Only matched segments are considered for adjustment * (Non-matched ones either are already paired, @@ -172,25 +173,12 @@ for (int i = 0; i < segments.length; i++) { if (segments[i] == null) continue; if (!segments[i].isInIndex()) continue; - //if (!isInIndex(matchedSegmentIndex, i)) { - // Debug.println(" match segment " + getFeatureID() + "/" + shellIndex + "/" + i + " not in index"); - // continue; - //} Envelope env = new Envelope(segments[i].getLineSegment().p0.x, segments[i].getLineSegment().p1.x, segments[i].getLineSegment().p0.y, segments[i].getLineSegment().p1.y); env.expandBy(2*segmentMatcher.getDistanceTolerance()); - //Set<FeatureSegment> candidateSegments = matchedSegmentIndex.query(env); - //Set<FeatureSegment> candidateSegments = matchedSegmentIndex.getMatches(new FeatureSegment(null, uniqueCoord[i], uniqueCoord[i + 1], -1, -1)); for (int j = 0; j < shell.segments.length; j++) { - //Debug.print(" match segment " + - // getFeatureID() + "/" + shellIndex + "/" + i + " with " + - // shell.getFeatureID() + "/" + shell.getShellIndex() + "/" + j + " : "); if (shell.segments[j] == null) continue; if (!shell.segments[j].isInIndex()) continue; - //if (!shell.isInIndex(matchedSegmentIndex, j)) { - // Debug.println("not in index"); - // continue; - //} - + Segment seg0 = getSegment(i); Segment seg1 = shell.getSegment(j); /** @@ -222,18 +210,18 @@ return isAdjusted; } - public boolean isAdjusted(double distanceTolerance) { - computeAdjusted(distanceTolerance); + public boolean isAdjusted(double distanceTolerance, boolean interpolate_z, double scale) { + computeAdjusted(distanceTolerance, interpolate_z, scale); boolean isAdjusted = ! CoordinateArrays.equals(uniqueCoord, adjustedCoord); return isAdjusted; } - public Coordinate[] getAdjusted(double distanceTolerance) { - computeAdjusted(distanceTolerance); + public Coordinate[] getAdjusted(double distanceTolerance, boolean interpolate_z, double scale) { + computeAdjusted(distanceTolerance, interpolate_z, scale); return adjustedCoord; } - private void computeAdjusted(double distanceTolerance) { + private void computeAdjusted(double distanceTolerance, boolean interpolate_z, double scale) { // already computed if (adjustedCoord != null) return; CoordinateList coordList = new CoordinateList(); @@ -241,6 +229,10 @@ // For each segment of this Shell for (int i = 0; i < segments.length; i++) { Coordinate pt = getAdjustedCoordinate(i); + if (interpolate_z && segments[i] != null) { + pt = (Coordinate)pt.clone(); + pt.z = segments[i].getZIni(); + } // add first coordinate coordList.add(pt, false); if (!pt.equals(uniqueCoord[i])) { @@ -248,8 +240,8 @@ } if (segments[i] != null) { // add inserted coordinates - coordList.addAll(segments[i].getInsertedCoordinates(), false); - Debug.println(" " + i + " : insert " + segments[i].getInsertedCoordinates()); + coordList.addAll(segments[i].getInsertedCoordinates(interpolate_z, scale), false); + Debug.println(" " + i + " : insert " + segments[i].getInsertedCoordinates(interpolate_z, scale)); } } coordList.closeRing(); @@ -257,7 +249,7 @@ // modulo arithmetic coordList.remove(coordList.size()-1); CoordinateList noRepeatCoordList = removeRepeatedSegments(coordList); - noRepeatCoordList = removeMicroLoops(coordList, distanceTolerance); + noRepeatCoordList = removeMicroLoops(noRepeatCoordList, distanceTolerance); noRepeatCoordList.closeRing(); adjustedCoord = noRepeatCoordList.toCoordinateArray(); } @@ -267,7 +259,7 @@ if (segments[i] != null) { Coordinate c = segments[i].getVertex(0).getCoordinate(); //[mmichaud 2013-01-26] improvement : if the new position of the - // vertex has itself been adjuste, return the new new position + // vertex has itself been adjusted, return the new new position // TODO : may it enter an infinite loop ? if (!vertexMap.contains(c)) return c; Vertex v = vertexMap.get(c); @@ -285,7 +277,7 @@ * Remove any repeated segments * (e.g. a pattern of Coordinates of the form "a-b-a" is converted to "a" ) * - * @param coordList + * @param coordList list of coordinates to clean */ private CoordinateList removeRepeatedSegments(CoordinateList coordList) { int size = coordList.size(); @@ -308,10 +300,9 @@ * (e.g. a pattern of Coordinates of the form "a-b-c-a" with a-b, b-c and c-a * smaller than tolerance is converted to "a" ) * - * @param coordList + * @param coordList list of coordinates to clean */ private CoordinateList removeMicroLoops(CoordinateList coordList, double distanceTolerance) { - //CoordinateList noRepeatCoordList = new CoordinateList(); int size = coordList.size(); for (int i = 0; i < size && size > 4; i++) { Coordinate a = coordList.getCoordinate(i%(size)); @@ -334,11 +325,11 @@ } public boolean isConflict() { - for (int i = 0; i < segments.length; i++) { - if (segments[i] == null) continue; - if (segments[i].isConflict()) return true; - if (segments[i].getVertex(0).isConflict()) return true; - if (segments[i].getVertex(1).isConflict()) return true; + for (Segment segment : segments) { + if (segment == null) continue; + if (segment.isConflict()) return true; + if (segment.getVertex(0).isConflict()) return true; + if (segment.getVertex(1).isConflict()) return true; } return false; } Modified: plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/VertexMap.java =================================================================== --- plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/VertexMap.java 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/conflate/coverage/VertexMap.java 2016-06-18 21:13:40 UTC (rev 4938) @@ -53,7 +53,7 @@ /** * get the Vertex which source coordinate is p. - * Note that if the vertext does not exists, it is created and returned by + * Note that if the vertex does not exists, it is created and returned by * this method. * See usage in Shell. */ Modified: plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/plugin/clean/CoverageCleanerPlugIn.java =================================================================== --- plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/plugin/clean/CoverageCleanerPlugIn.java 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/plugin/clean/CoverageCleanerPlugIn.java 2016-06-18 21:13:40 UTC (rev 4938) @@ -33,43 +33,46 @@ package com.vividsolutions.jcs.plugin.clean; import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.util.Iterator; -import javax.swing.JComboBox; +import javax.swing.*; import com.vividsolutions.jcs.conflate.coverage.CoverageCleaner; import com.vividsolutions.jump.util.feature.FeatureStatistics; -import com.vividsolutions.jump.workbench.JUMPWorkbench; import com.vividsolutions.jump.workbench.model.*; import com.vividsolutions.jump.workbench.plugin.*; import com.vividsolutions.jump.workbench.ui.GUIUtil; import com.vividsolutions.jump.workbench.ui.MultiInputDialog; -import com.vividsolutions.jump.workbench.ui.plugin.*; import com.vividsolutions.jump.feature.Feature; import com.vividsolutions.jump.feature.FeatureCollection; import com.vividsolutions.jump.feature.FeatureDataset; import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.util.*; import com.vividsolutions.jump.task.*; import com.vividsolutions.jump.workbench.ui.*; -//import com.vividsolutions.jcs.plugin.I18NPlug; import fr.michaelm.jump.plugin.topology.I18NPlug; public class CoverageCleanerPlugIn extends ThreadedBasePlugIn { - private final static String TOPOLOGY = I18NPlug.getI18N("Topology"); - private final static String LAYER = I18NPlug.getI18N("Layer"); - private final static String EXPLODE = I18NPlug.getI18N("qa.CoverageCleanerPlugIn.explode-first"); - private final static String NORMALIZE = I18NPlug.getI18N("qa.CoverageCleanerPlugIn.normalize-first"); - private final static String DIST_TOL = I18NPlug.getI18N("dist-tolerance"); - private final static String ANGLE_TOL = I18NPlug.getI18N("angle-tolerance"); - private final static String USE_FENCE = I18NPlug.getI18N("use-fence"); + private final static String TOPOLOGY = I18NPlug.getI18N("Topology"); + private final static String LAYER = I18NPlug.getI18N("Layer"); + private final static String EXPLODE = I18NPlug.getI18N("qa.CoverageCleanerPlugIn.explode-first"); + private final static String NORMALIZE = I18NPlug.getI18N("qa.CoverageCleanerPlugIn.normalize-first"); + private final static String DIST_TOL = I18NPlug.getI18N("dist-tolerance"); + private final static String ANGLE_TOL = I18NPlug.getI18N("angle-tolerance"); + private final static String USE_FENCE = I18NPlug.getI18N("use-fence"); + private final static String INTERPOLATE_Z = I18NPlug.getI18N("qa.CoverageCleanerPlugIn.interpolate-z"); + private final static String INTERPOLATE_Z_TT = I18NPlug.getI18N("qa.CoverageCleanerPlugIn.interpolate-z-tooltip"); + private final static String Z_PRECISION = I18NPlug.getI18N("qa.CoverageCleanerPlugIn.z-precision"); + private final static String Z_PRECISION_TT = I18NPlug.getI18N("qa.CoverageCleanerPlugIn.z-precision-tooltip"); private Layer layer; private CoverageCleaner.Parameters param = new CoverageCleaner.Parameters(); private boolean useFence; private boolean explode = true; private boolean normalize = true; + private int zPrecision = 1; public CoverageCleanerPlugIn() { } @@ -82,12 +85,12 @@ } public void initialize(PlugInContext context) throws Exception { - context.getFeatureInstaller().addMainMenuItem( - this, new String[]{MenuNames.PLUGINS, TOPOLOGY}, - I18NPlug.getI18N("qa.CoverageCleanerPlugIn.adjust-polygon-boundaries") + "...", - false, null, new MultiEnableCheck() - .add(context.getCheckFactory().createTaskWindowMustBeActiveCheck()) - .add(context.getCheckFactory().createAtLeastNLayersMustExistCheck(1))); + context.getFeatureInstaller().addMainMenuPlugin( + this, new String[]{MenuNames.PLUGINS, TOPOLOGY}, + I18NPlug.getI18N("qa.CoverageCleanerPlugIn.adjust-polygon-boundaries") + "...", + false, null, new MultiEnableCheck() + .add(context.getCheckFactory().createTaskWindowMustBeActiveCheck()) + .add(context.getCheckFactory().createAtLeastNLayersMustExistCheck(1))); } public boolean execute(PlugInContext context) throws Exception { @@ -196,8 +199,24 @@ I18NPlug.getI18N("qa.CoverageCleanerPlugIn.dist-tolerance-definition")); dialog.addDoubleField(ANGLE_TOL, param.angleTolerance, 4, I18NPlug.getI18N("qa.CoverageCleanerPlugIn.angle-tolerance-definition")); + + dialog.addSeparator(); + + final JCheckBox interpolateZCB = dialog.addCheckBox(INTERPOLATE_Z, param.interpolateZ, INTERPOLATE_Z_TT); + final JTextField zPrecisionTF = dialog.addIntegerField(Z_PRECISION, zPrecision, 4, Z_PRECISION_TT); + + dialog.addSeparator(); + dialog.addCheckBox(USE_FENCE, useFence, - I18NPlug.getI18N("qa.CoverageCleanerPlugIn.process-segments-in-fence-only")); + I18NPlug.getI18N("qa.CoverageCleanerPlugIn.process-segments-in-fence-only")); + + zPrecisionTF.setEnabled(interpolateZCB.isSelected()); + interpolateZCB.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + zPrecisionTF.setEnabled(interpolateZCB.isSelected()); + } + }); } private void getDialogValues(MultiInputDialog dialog) { @@ -205,6 +224,9 @@ param.distanceTolerance = dialog.getDouble(DIST_TOL); param.angleTolerance = dialog.getDouble(ANGLE_TOL); useFence = dialog.getBoolean(USE_FENCE); + param.interpolateZ = dialog.getBoolean(INTERPOLATE_Z); + zPrecision = dialog.getInteger(Z_PRECISION); + param.zScale = Math.pow(10, zPrecision); } private FeatureCollection explodeOrNormalize(FeatureCollection fc) { Modified: plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/qa/FeatureCoordinateMap.java =================================================================== --- plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/qa/FeatureCoordinateMap.java 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/src/com/vividsolutions/jcs/qa/FeatureCoordinateMap.java 2016-06-18 21:13:40 UTC (rev 4938) @@ -34,9 +34,7 @@ import java.util.*; import com.vividsolutions.jump.feature.*; -import com.vividsolutions.jump.geom.*; import com.vividsolutions.jts.geom.*; -import com.vividsolutions.jts.geom.LineSegment; import com.vividsolutions.jump.util.CoordinateArrays; import com.vividsolutions.jump.task.*; @@ -54,13 +52,12 @@ public static Set getFeaturesWithVertices(TaskMonitor monitor, FeatureCollection fc, - Collection coords) { + Collection<Coordinate> coords) { FeatureCoordinateMap map = new FeatureCoordinateMap(monitor); map.add(fc); - Set featuresWithVertices = new HashSet(); - for (Iterator i = coords.iterator(); i.hasNext(); ) { - Coordinate pt = (Coordinate) i.next(); - featuresWithVertices.addAll(map.getFeatures(pt)); + Set<Feature> featuresWithVertices = new HashSet<Feature>(); + for (Coordinate coord : coords) { + featuresWithVertices.addAll(map.getFeatures(coord)); } return featuresWithVertices; } @@ -108,18 +105,16 @@ } public void add(Coordinate pt, Feature f) { - List<Feature> featureList = (List) coordMap.get(pt); + List<Feature> featureList = coordMap.get(pt); if (featureList == null) { featureList = new ArrayList<Feature>(); coordMap.put(pt, featureList); } featureList.add(f); } - - public Collection values() { return coordMap.values(); } - - public List getFeatures(Coordinate p) { - return (List) coordMap.get(p); + + public List<Feature> getFeatures(Coordinate p) { + return coordMap.get(p); } } Modified: plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/TopologyExtension.java =================================================================== --- plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/TopologyExtension.java 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/TopologyExtension.java 2016-06-18 21:13:40 UTC (rev 4938) @@ -34,6 +34,7 @@ import com.vividsolutions.jump.workbench.plugin.PlugInContext; // History +// 0.9.0 (2016-06-18) : add an option to interpolate z in CoverageCleanerPlugIn // 0.8.2 (2016-06-12) : fix two bugs in CoverageCleanerPlugIn (angle between // - angle between segments was not computed correctly // - holes were not managed in some cases @@ -70,7 +71,7 @@ } public String getVersion() { - return "0.8.2 (2016-06-12)"; + return "0.9.0 (2016-06-18)"; } public void configure(PlugInContext context) throws Exception { Modified: plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/topology.properties =================================================================== --- plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/topology.properties 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/topology.properties 2016-06-18 21:13:40 UTC (rev 4938) @@ -120,6 +120,10 @@ qa.CoverageCleanerPlugIn.dist-tolerance-definition = The Distance Tolerance determines how large gaps and overlaps can be qa.CoverageCleanerPlugIn.angle-tolerance-definition = The Angle Tolerance (in degrees) controls how parallel matched segments must be qa.CoverageCleanerPlugIn.process-segments-in-fence-only = Process segments in fence only +qa.CoverageCleanerPlugIn.interpolate-z = Interpolate Z +qa.CoverageCleanerPlugIn.interpolate-z-tooltip = Interpolate Z of new points rather than pickink it from adjacent geometry +qa.CoverageCleanerPlugIn.z-precision = Precision of interpolated Z +qa.CoverageCleanerPlugIn.z-precision-tooltip = Number of decimal places for interpolated z qa.CoverageCleaner.matching-segments = Matching segments qa.CoverageCleaner.adjusting-features = Adjusting features Modified: plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/topology_fr.properties =================================================================== --- plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/topology_fr.properties 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/topology_fr.properties 2016-06-18 21:13:40 UTC (rev 4938) @@ -111,11 +111,13 @@ qa.CoverageCleanerPlugIn.explode-first-definition = D\u00E9composer les g\u00E9om\u00E9tries qa.CoverageCleanerPlugIn.normalize-first = Normaliser les g\u00E9ometries qa.CoverageCleanerPlugIn.normalize-first-definition = Normaliser les g\u00E9ometries -qa.CoverageCleanerPlugIn.number-of-features-adjusted = \# d'objets ajust\xE9s:\ -qa.CoverageCleanerPlugIn.number-of-vertices-adjusted = \# de points ajust\xE9s:\ -qa.CoverageCleanerPlugIn.min-adjustment-size = taille du plus petit ajustement:\ -qa.CoverageCleanerPlugIn.max-adjustment-size = taille du plus grand ajustement:\ -qa.CoverageCleanerPlugIn.description = Retire tous les d\xE9fauts d'ajustement (interstices et micro-recouvrements) de taille inf\xE9rieure \u00E0 la tol\xE9rance indiqu\xE9e. +qa.CoverageCleanerPlugIn.number-of-features-adjusted = \# d'objets ajust\xE9s\: +qa.CoverageCleanerPlugIn.number-of-vertices-adjusted = \# de points ajust\xE9s\: +qa.CoverageCleanerPlugIn.min-adjustment-size = taille du plus petit ajustement\: +qa.CoverageCleanerPlugIn.max-adjustment-size = taille du plus grand ajustement\: +qa.CoverageCleanerPlugIn.description = Retire tous les d\xE9fauts d'ajustement (interstices et micro-recouvrements) de taille inf\xE9rieure \u00E0 la tol\xE9rance indiqu\xE9e.\ +\n\ +Par d\xE9faut, le z conserv\xE9 sur la fronti\xE8re commune est celui de l'objet d'o\xF9 vient le point. Si l'option "interpoler le z" est coch\xE9e, le z des points ajout\xE9s sur chaque objet est interpol\xE9 sur cet objet. qa.CoverageCleanerPlugIn.dist-tolerance-definition = La distance de tol\xE9rance indique la taille minimum acceptable pour un interstice ou un recouvrement qa.CoverageCleanerPlugIn.angle-tolerance-definition = La tol\xE9rance (en degr\xE9s) contr\xF4le le parall\xE9lisme des fronti\xE8res consid\xE9r\xE9es communes qa.CoverageCleanerPlugIn.process-segments-in-fence-only = Traiter uniquement les segments situ\xE9s dans le cadre @@ -206,3 +208,6 @@ ProjectPointsOnLinesPlugIn.no-feature-in-target-layer = La couche cible ne contient aucune objet ! ProjectPointsOnLinesPlugIn.snap-tolerance=Tol\xE9rance d'accrochage ProjectPointsOnLinesPlugIn.snap-tolerance-tooltip=Tol\xE9rance d'accroche \xE0 un point existant (mesur\xE9 le long du segment) +qa.CoverageCleanerPlugIn.interpolate-z=Interpoler le z des points ins\xE9r\xE9s +qa.CoverageCleanerPlugIn.interpolate-z-tooltip=Interpole le z des points ins\xE9r\xE9s plut\xF4t que de conserver le z de l'objet d'origine +qa.CoverageCleanerPlugIn.z-precision=Pr\xE9cision du z interpol\xE9 Modified: plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/topology_it.properties =================================================================== --- plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/topology_it.properties 2016-06-17 06:09:52 UTC (rev 4937) +++ plug-ins/TopologyPlugin/trunk/src/fr/michaelm/jump/plugin/topology/topology_it.properties 2016-06-18 21:13:40 UTC (rev 4938) @@ -169,3 +169,4 @@ Topology=Topologia use-fence=Limita la analisi alla cornice work-on-copy=Lavora su una copia +qa.CoverageCleanerPlugIn.z-precision=Pr\xE9cision du z interpol\xE9 Added: plug-ins/TopologyPlugin/trunk/test/fr/michaelm/jump/plugin/topology/CoverageCleanerTest.java =================================================================== --- plug-ins/TopologyPlugin/trunk/test/fr/michaelm/jump/plugin/topology/CoverageCleanerTest.java (rev 0) +++ plug-ins/TopologyPlugin/trunk/test/fr/michaelm/jump/plugin/topology/CoverageCleanerTest.java 2016-06-18 21:13:40 UTC (rev 4938) @@ -0,0 +1,90 @@ +package fr.michaelm.jump.plugin.topology; + +import com.vividsolutions.jcs.conflate.coverage.CoverageCleaner; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Envelope; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.index.strtree.STRtree; +import com.vividsolutions.jts.io.ParseException; +import com.vividsolutions.jts.io.WKTReader; +import com.vividsolutions.jump.feature.*; +import com.vividsolutions.jump.task.DummyTaskMonitor; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.Iterator; +import java.util.List; + +/** + * Created by UMichael on 10/06/2016. + */ +public class CoverageCleanerTest { + + static WKTReader reader = new WKTReader(); + //FeatureCollection fc; + + //@Before + //public void before() throws Exception { + // FeatureSchema schema = new FeatureSchema(); + // schema.addAttribute("GEOMETRY", AttributeType.GEOMETRY); +// + // Geometry poly1 = reader.read("POLYGON (( 677942.5 6863565.5 75.1, 677944.7 6863557 75.1, 677932.4 6863553.7 75.1, 677930.1 6863562.1 75.1, 677942.5 6863565.5 75.1 ))"); + // Geometry poly2 = reader.read("POLYGON (( 677938 6863555.2 75.1, 677942.7 6863556.5 75.1, 677943.7 6863552.3 75.1, 677939.1 6863551 75.3, 677938 6863555.2 75.1 ))"); + // Feature feature1 = new BasicFeature(schema); + // feature1.setGeometry(poly1); + // Feature feature2 = new BasicFeature(schema); + // feature2.setGeometry(poly2); +// + // fc = new FeatureDataset(schema); + // fc.add(feature1); + // fc.add(feature2); + //} + + FeatureCollection createDataset(Geometry...geometries) { + FeatureSchema schema = new FeatureSchema(); + schema.addAttribute("GEOMETRY", AttributeType.GEOMETRY); + FeatureCollection ds = new FeatureDataset(schema); + for (Geometry g : geometries) { + Feature feature1 = new BasicFeature(schema); + feature1.setGeometry(g); + ds.add(feature1); + } + return ds; + } + + /** Projette le point sur la première ligne */ + @Test + public void coverageCleanerTest1() throws ParseException { + Geometry poly1 = reader.read("POLYGON (( 677942.5 6863565.5 75.1, 677944.7 6863557 75.1, 677932.4 6863553.7 75.1, 677930.1 6863562.1 75.1, 677942.5 6863565.5 75.1 ))"); + Geometry poly2 = reader.read("POLYGON (( 677938 6863555.2 75.1, 677942.7 6863556.5 75.1, 677943.7 6863552.3 75.1, 677939.1 6863551 75.3, 677938 6863555.2 75.1 ))"); + FeatureCollection fc = createDataset(poly1, poly2); + CoverageCleaner cleaner = new CoverageCleaner(fc, new DummyTaskMonitor()); + cleaner.process(new CoverageCleaner.Parameters(0.3, 22)); + FeatureCollection result = cleaner.getAdjustedFeatures(); + // 1 objet ajusté + Assert.assertEquals(1, result.size()); + } + + @Test + public void coverageCleanerTest2() throws ParseException { + Geometry poly1 = reader.read("POLYGON (( 796702.4 6303661.9 63.9, 796702.4 6303668.8 63.9, 796713.1 6303670.6 63.9, 796713.1 6303661.5 63.9, 796712.7 6303661.5 63.9, 796702.4 6303661.9 63.9 ))"); + Geometry poly2 = reader.read("POLYGON (( 796712.7 6303651.3 63.7, 796712.7 6303661.5 63.7, 796717.7 6303661.3 63.7, 796717.6 6303651 63.7, 796712.7 6303651.3 63.7 ))"); + FeatureCollection fc = createDataset(poly1, poly2); + CoverageCleaner cleaner = new CoverageCleaner(fc, new DummyTaskMonitor()); + cleaner.process(new CoverageCleaner.Parameters(0.3, 22)); + FeatureCollection result = cleaner.getAdjustedFeatures(); + Assert.assertEquals(1, result.size()); + } + + @Test + public void coverageCleanerTest3() throws ParseException { + Geometry poly1 = reader.read("POLYGON (( 808524 6302863, 808524 6302873, 808542 6302873, 808542 6302863, 808524 6302863 ), ( 808526 6302865, 808531.0022255091 6302864.729235475, 808540 6302865, 808540 6302871, 808526 6302871, 808526 6302865 ))"); + Geometry poly2 = reader.read("POLYGON (( 808526 6302865, 808526 6302871, 808540 6302871, 808540 6302865, 808526 6302865 ))"); + FeatureCollection fc = createDataset(poly1, poly2); + CoverageCleaner cleaner = new CoverageCleaner(fc, new DummyTaskMonitor()); + cleaner.process(new CoverageCleaner.Parameters(0.3, 22)); + FeatureCollection result = cleaner.getAdjustedFeatures(); + Assert.assertEquals(1, result.size()); + } +} ------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports. http://sdm.link/zohomanageengine _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel