Revision: 5476 http://sourceforge.net/p/jump-pilot/code/5476 Author: michaudm Date: 2017-07-29 10:14:20 +0000 (Sat, 29 Jul 2017) Log Message: ----------- BlendLineStringsPlugIn : improve quality, performance and make it undoable
Modified Paths: -------------- core/trunk/ChangeLog core/trunk/src/language/jump.properties core/trunk/src/language/jump_cz.properties core/trunk/src/language/jump_de.properties core/trunk/src/language/jump_es.properties core/trunk/src/language/jump_fi.properties core/trunk/src/language/jump_fr.properties core/trunk/src/language/jump_hu.properties core/trunk/src/language/jump_it.properties core/trunk/src/language/jump_ja_JP.properties core/trunk/src/language/jump_ml.properties core/trunk/src/language/jump_pt.properties core/trunk/src/language/jump_pt_BR.properties core/trunk/src/language/jump_ta_IN.properties core/trunk/src/language/jump_te.properties core/trunk/src/language/jump_zh_CN.properties core/trunk/src/language/jump_zh_HK.properties core/trunk/src/org/openjump/core/ui/plugin/tools/BlendLineStringsPlugIn.java Modified: core/trunk/ChangeLog =================================================================== --- core/trunk/ChangeLog 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/ChangeLog 2017-07-29 10:14:20 UTC (rev 5476) @@ -3,6 +3,9 @@ # 2. make sure that lines break at 80 chars for constricted display situations #<-------------------------------- 80 chars ----------------------------------># +2017-07-29 mmichaud <m.michael.mich...@orange.fr> + * BlendLineStringsPlugIn : improve quality, performance and make it undoable + 2017-07-27 mmichaud <m.michael.mich...@orange.fr> * AutoAssignAttributePlugIn : inverse options order (simple to more complex) * Deprecate ReplaceValuePlugIn (redundant with the previous one, not undoable) Modified: core/trunk/src/language/jump.properties =================================================================== --- core/trunk/src/language/jump.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1356,7 +1356,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.script-snippets = Script snippets org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression = Test Expression org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors = Too many errors -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings = Blend Lines +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn = Blend Lines org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New = New org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance = The blend tolerance. org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance = Tolerance Modified: core/trunk/src/language/jump_cz.properties =================================================================== --- core/trunk/src/language/jump_cz.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_cz.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1223,7 +1223,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.script-snippets = Kousky skript\u016F org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression = Testov\u00E1n\u00ED v\u00FDrazu org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors = P\u0159\u00EDli\u0161 mnoho chyb -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings = Spojit linie +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn = Spojit linie org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New = Nov\u00FD org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance = Tolerance pro spojen\u00ED. org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance = Tolerance Modified: core/trunk/src/language/jump_de.properties =================================================================== --- core/trunk/src/language/jump_de.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_de.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1253,7 +1253,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.script-snippets = Skript Programm Schnipsel org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression = Test-Ausdruck (Skript) org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors = Zu viele Fehler gefunden -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings = Verbinden von Linien +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn = Verbinden von Linien org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New = Neu org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance = Die Fangtoleranz. org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance = Toleranz Modified: core/trunk/src/language/jump_es.properties =================================================================== --- core/trunk/src/language/jump_es.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_es.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1213,7 +1213,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression=Test Espresion org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors=Encontrados muchos errores org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.A-new-layer-will-be-created-for-the-results=Esto crea un nuevo nivel con los resultados -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings=Fusionar las l\u00edneas +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn=Fusionar las l\u00edneas org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Create-a-new-layer-for-the-results=Crear una nueva capa con los resultados org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New=Nueva org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.remove-source-lines=Eliminar las l\u00edneas originales Modified: core/trunk/src/language/jump_fi.properties =================================================================== --- core/trunk/src/language/jump_fi.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_fi.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1258,7 +1258,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression=Testiskripti org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors=Liian monta virhett\u00e4 org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.A-new-layer-will-be-created-for-the-results=Tuloksia varten luodaan uusi karttataso -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings=Sulauta viivat +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn=Sulauta viivat org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Create-a-new-layer-for-the-results=Luo uusi taso tuloksille. org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New=Uusi org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.remove-source-lines=Poista l\u00e4hdeviivat Modified: core/trunk/src/language/jump_fr.properties =================================================================== --- core/trunk/src/language/jump_fr.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_fr.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1223,7 +1223,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.script-snippets = Exemples org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression = Tester l'expression org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors = Trop d'erreurs rencontr\u00e9es -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings = Fusionner les lignes +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn = Fusionner les lignes org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New = Nouveau org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance = Tol\u00e9rance de fusion. org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance = Tol\u00e9rance Modified: core/trunk/src/language/jump_hu.properties =================================================================== --- core/trunk/src/language/jump_hu.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_hu.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1219,7 +1219,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.script-snippets = Szkript r\u00e9szlet org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression = Teszt kifejez\u00e9s org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors = T\u00fal sok hiba -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings = Vonalak egyes\u00edt\u00e9se +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn = Vonalak egyes\u00edt\u00e9se org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New = \u00daj org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance = Egys\u00edt\u00e9si tolerancia org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance = T\u0171r\u00e9s Modified: core/trunk/src/language/jump_it.properties =================================================================== --- core/trunk/src/language/jump_it.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_it.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1221,7 +1221,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression=Test Espressione org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors=Riscontrati troppi errori org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.A-new-layer-will-be-created-for-the-results=Verr\u00e0 crearo un nuovo livello per i risultati -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings=Unisci linee +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn=Unisci linee org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Create-a-new-layer-for-the-results=Crea un nuovo livello con i risultati org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New=Nuovo org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.remove-source-lines=Eliminare le linee originali Modified: core/trunk/src/language/jump_ja_JP.properties =================================================================== --- core/trunk/src/language/jump_ja_JP.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_ja_JP.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1218,7 +1218,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.script-snippets = \#T\: Script snippets org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression = \#T\: org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors = \#T\: -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings = \u30e9\u30a4\u30f3\u3092\u878d\u5408\u3059\u308b +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn = \u30e9\u30a4\u30f3\u3092\u878d\u5408\u3059\u308b org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New = \u65b0\u898f org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance = \u878d\u5408\u306e\u8a31\u5bb9\u5ea6. org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance = \u8a31\u5bb9\u5ea6 Modified: core/trunk/src/language/jump_ml.properties =================================================================== --- core/trunk/src/language/jump_ml.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_ml.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1648,7 +1648,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.script-snippets = \#T\: Script snippets org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression = \#T\: org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors = \#T\: -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings = \#T\: +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn = \#T\: org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New = \#T\: org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance = \#T\: org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance = \#T\: Modified: core/trunk/src/language/jump_pt.properties =================================================================== --- core/trunk/src/language/jump_pt.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_pt.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1219,7 +1219,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.script-snippets = \#T\: Script snippets org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression = \#T\: org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors = \#T\: -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings = Misturar linhas +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn = Misturar linhas org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New = Novo org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance = Toler\u00e2ncia da mistura. org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance = Toler\u00e2ncia Modified: core/trunk/src/language/jump_pt_BR.properties =================================================================== --- core/trunk/src/language/jump_pt_BR.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_pt_BR.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1219,7 +1219,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.script-snippets = \#T\: Script snippets org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression = \#T\: org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors = \#T\: -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings = Misturar linhas +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn = Misturar linhas org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New = Novo org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance = Toler\u00e2ncia da mistura. org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance = Toler\u00e2ncia Modified: core/trunk/src/language/jump_ta_IN.properties =================================================================== --- core/trunk/src/language/jump_ta_IN.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_ta_IN.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1217,7 +1217,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.script-snippets = \#T\: Script snippets org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression = \#T\: org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors = \#T\: -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings = \u0b95\u0bb2\u0baa\u0bcd\u0baa\u0bc1 \u0b95\u0bc7\u0bbe\u0b9f\u0bc1\u0b95\u0bb3\u0bcd +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn = \u0b95\u0bb2\u0baa\u0bcd\u0baa\u0bc1 \u0b95\u0bc7\u0bbe\u0b9f\u0bc1\u0b95\u0bb3\u0bcd org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New = \u0baa\u0bc1\u0ba4\u0bbf\u0baf org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance = \u0b95\u0bb2\u0bb5\u0bc8 \u0b9a\u0b95\u0bbf\u0baa\u0bcd\u0baa\u0bc1\u0ba4\u0bcd\u0ba4\u0ba9\u0bcd\u0bae\u0bc8 org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance = \#T\:Tolerance Modified: core/trunk/src/language/jump_te.properties =================================================================== --- core/trunk/src/language/jump_te.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_te.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1446,7 +1446,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.script-snippets = \#T\: Script snippets org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression = \#T\: org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors = \#T\: -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings = Fusionner les lignes +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn = Fusionner les lignes org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New = Nouveau org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance = Tol\u00e9rance de fusion. org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance = Tol\u00e9rance Modified: core/trunk/src/language/jump_zh_CN.properties =================================================================== --- core/trunk/src/language/jump_zh_CN.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_zh_CN.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1303,7 +1303,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.script-snippets = \#T\: Script snippets org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression = \#T\: org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors = \#T\: -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings = \u6df7\u5408\u7ebf\u8def +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn = \u6df7\u5408\u7ebf\u8def org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New = \u65b0 org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance = \u5171\u6df7\u7269\u5bbd\u5bb9\u3002 org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance = \u516c\u5dee Modified: core/trunk/src/language/jump_zh_HK.properties =================================================================== --- core/trunk/src/language/jump_zh_HK.properties 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/language/jump_zh_HK.properties 2017-07-29 10:14:20 UTC (rev 5476) @@ -1302,7 +1302,7 @@ org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.script-snippets = \#T\: Script snippets org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.test-expression = \#T\: org.openjump.core.ui.plugin.tools.BeanshellAttributeCalculatorPlugIn.too-many-errors = \#T\: -org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings = \u6df7\u5408\u7dda\u8def +org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn = \u6df7\u5408\u7dda\u8def org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New = \u65b0 org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance = \u5171\u6df7\u7269\u5bec\u5bb9\u3002 org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance = \u516c\u5dee Modified: core/trunk/src/org/openjump/core/ui/plugin/tools/BlendLineStringsPlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/tools/BlendLineStringsPlugIn.java 2017-07-27 20:29:07 UTC (rev 5475) +++ core/trunk/src/org/openjump/core/ui/plugin/tools/BlendLineStringsPlugIn.java 2017-07-29 10:14:20 UTC (rev 5476) @@ -34,18 +34,14 @@ package org.openjump.core.ui.plugin.tools; import java.util.Collection; -import java.util.Iterator; -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.CoordinateList; -import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.LineString; + +import com.vividsolutions.jts.geom.*; +import com.vividsolutions.jts.index.quadtree.Quadtree; import com.vividsolutions.jump.I18N; import com.vividsolutions.jump.feature.Feature; import com.vividsolutions.jump.feature.FeatureDataset; import com.vividsolutions.jump.workbench.WorkbenchContext; -import com.vividsolutions.jump.workbench.model.Layer; -import com.vividsolutions.jump.workbench.model.LayerManager; -import com.vividsolutions.jump.workbench.model.StandardCategoryNames; +import com.vividsolutions.jump.workbench.model.*; import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn; import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory; import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck; @@ -54,18 +50,21 @@ import com.vividsolutions.jump.workbench.ui.MenuNames; import com.vividsolutions.jump.workbench.ui.MultiInputDialog; import java.util.ArrayList; +import java.util.List; import javax.swing.JCheckBox; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +/** + * Blend lines which (nearly) touch each others. + */ public class BlendLineStringsPlugIn extends AbstractPlugIn { - - private WorkbenchContext workbenchContext; - + + private final String THE_BLEND_TOLERANCE_TOOLTIP = I18N.get("org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-blend-tolerance"); private final String NEW_LAYER = I18N.get("org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.New"); private final String TOLERANCE = I18N.get("org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Tolerance"); - private final String PLUGIN_NAME = I18N.get("org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.Blend-LineStrings"); + private final String PLUGIN_NAME = I18N.get("org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn"); private final String REMOVE_SOURCE_LINES = I18N.get("org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.remove-source-lines"); private final String REMOVE_SOURCE_LINES_TOOLTIP = I18N.get("org.openjump.core.ui.plugin.tools.BlendLineStringsPlugIn.The-source-lines-will-be-removed"); @@ -78,14 +77,12 @@ private boolean removeSourceLines = false; private boolean transferFirstAttributesToAllResultingLineStrings = false; private boolean createNewLayer = false; - - private JCheckBox removeCheckBox = null; - private JCheckBox newLayerCheckBox = null; - public void initialize(PlugInContext context) throws Exception - { - workbenchContext = context.getWorkbenchContext(); - context.getFeatureInstaller().addMainMenuItem(this, new String[] { MenuNames.TOOLS, MenuNames.TOOLS_EDIT_GEOMETRY }, PLUGIN_NAME, false, null, this.createEnableCheck(workbenchContext)); + + public void initialize(PlugInContext context) throws Exception { + context.getFeatureInstaller().addMainMenuPlugin(this, + new String[]{MenuNames.TOOLS, MenuNames.TOOLS_EDIT_GEOMETRY }, + PLUGIN_NAME, false, null, this.createEnableCheck(context.getWorkbenchContext())); } public boolean execute(final PlugInContext context) throws Exception @@ -94,140 +91,196 @@ reportNothingToUndoYet(context); MultiInputDialog dialog = new MultiInputDialog(context.getWorkbenchFrame(), getName(), true); - setDialogValues(dialog, context); + setDialogValues(dialog); GUIUtil.centreOnWindow(dialog); dialog.setVisible(true); if (! dialog.wasOKPressed()) { return false; } + getDialogValues(dialog); - Collection selectedFeatures = context.getLayerViewPanel().getSelectionManager().getFeaturesWithSelectedItems(); - Feature currFeature = ((Feature) selectedFeatures.iterator().next()); - Collection selectedCategories = context.getLayerNamePanel().getSelectedCategories(); - LayerManager layerManager = context.getLayerManager(); - FeatureDataset newFeatures = new FeatureDataset(currFeature.getSchema()); - ArrayList<Feature> inputFeatures = new ArrayList(selectedFeatures.size()); - Layer selectedLayer = (Layer) context.getLayerViewPanel().getSelectionManager().getLayersWithSelectedItems().iterator().next(); - - // get all LineString Features into the inputFeatures variable - Iterator<Feature> selectedFeaturesIterator = selectedFeatures.iterator(); - while (selectedFeaturesIterator.hasNext()) - { - Feature feature = selectedFeaturesIterator.next(); - if (feature.getGeometry() instanceof LineString) + Layer selectedLayer = context.getLayerViewPanel().getSelectionManager().getLayersWithSelectedItems().iterator().next(); + Collection<Feature> selectedFeatures = context.getLayerViewPanel().getSelectionManager().getFeaturesWithSelectedItems(); + Feature currFeature = selectedFeatures.iterator().next(); + + // inputLines list will be processed until there is no more feature in the list + List<Feature> inputLines = new ArrayList<>(); + // removeFeatures keep track of original features to be removed from the layer + ArrayList<Feature> removeFeatures = new ArrayList<>(selectedFeatures.size()); + // quadtree is used to accelerate search. It is updated after each blending operation + Quadtree quadtree = new Quadtree(); + for (Feature f : selectedFeatures) { + if (f.getGeometry() instanceof LineString) { - inputFeatures.add(feature); + inputLines.add(f); + removeFeatures.add(f); + quadtree.insert(f.getGeometry().getEnvelopeInternal(), f); } } - // loop through all LineStrings - while (inputFeatures.size() > 0) - { - //start a new blended linestring - boolean blended = false; - Feature inputFeature = inputFeatures.get(0); - Feature blendedFeature; - if (transferFirstAttributesToAllResultingLineStrings) { - blendedFeature = currFeature.clone(false); - } else { - blendedFeature = inputFeature.clone(false); - } - CoordinateList blendedCoords = new CoordinateList(inputFeature.getGeometry().getCoordinates()); - Feature startFeature = inputFeatures.remove(0); - //sequence through remaining input linestrings - //and find those which can be added to either - //the beginning or end of the current blended coordinate list - int currIndex = 0; //index of current linestring in input vector - while (currIndex < inputFeatures.size()) - { - inputFeature = inputFeatures.get(currIndex); - CoordinateList lsCoords = new CoordinateList(inputFeature.getGeometry().getCoordinates()); - if (blended(blendedCoords, lsCoords)) - { - inputFeatures.remove(currIndex); - currIndex = 0; //start at top since some that were rejected before might add to new string - blended = true; - // remove the original LineString if required - if (removeSourceLines && !createNewLayer) selectedLayer.getFeatureCollectionWrapper().remove(inputFeature); + while (inputLines.size()>0) { + Feature currentFeature = inputLines.get(0); + CoordinateList blendedCoords = new CoordinateList(currentFeature.getGeometry().getCoordinates()); + // Temporary list used to update inputLines after each blending operation + // (after currentLine blending, we remove all features blended to the currentFeature from inputLines list) + List<Feature> remove = new ArrayList<>(); + + // currentFeature is processed until no more candidate is found + boolean blended = true; + while(blended) { + Envelope search_env = currentFeature.getGeometry().getEnvelopeInternal(); + search_env.expandBy(blendTolerance); + // Find candidate lines for blending + List<Feature> candidates = quadtree.query(search_env); + candidates.remove(currentFeature); + // Try to blend the neares line first + Feature bestCandidate = nearest( + blendedCoords.getCoordinate(0), + blendedCoords.getCoordinate(blendedCoords.size()-1), + candidates); + if (bestCandidate != null) { + Feature blendedFeature; + if (transferFirstAttributesToAllResultingLineStrings) { + blendedFeature = currFeature.clone(false); + } else { + blendedFeature = currentFeature.clone(false); + } + CoordinateList lsCoords = new CoordinateList(bestCandidate.getGeometry().getCoordinates()); + if (blended(blendedCoords, lsCoords)) { + quadtree.remove(currentFeature.getGeometry().getEnvelopeInternal(), currentFeature); + quadtree.remove(bestCandidate.getGeometry().getEnvelopeInternal(), bestCandidate); + remove.add(currentFeature); + remove.add(bestCandidate); + blendedFeature.setGeometry(new GeometryFactory().createLineString(blendedCoords.toCoordinateArray())); + quadtree.insert(blendedFeature.getGeometry().getEnvelopeInternal(), blendedFeature); + currentFeature = blendedFeature; + } + } else { + blended = false; } - else - { - currIndex++; - } } - - // only if two or more LineStrings are blended, we delete the starting LineString and add the new blended LineString to the selected or new Layer - if (blended) { - if (removeSourceLines && !createNewLayer) selectedLayer.getFeatureCollectionWrapper().remove(startFeature); - blendedFeature.setGeometry(new GeometryFactory().createLineString(blendedCoords.toCoordinateArray())); - if (createNewLayer) { - newFeatures.add(blendedFeature); - } else { - selectedLayer.getFeatureCollectionWrapper().add(blendedFeature); - } - } + inputLines.remove(0); + inputLines.removeAll(remove); } - + + if(createNewLayer) { - layerManager.addLayer(selectedCategories.isEmpty() - ? StandardCategoryNames.WORKING - : selectedCategories.iterator().next().toString(), - layerManager.uniqueLayerName(NEW_LAYER), - newFeatures); - layerManager.getLayer(0).setFeatureCollectionModified(true); - layerManager.getLayer(0).setEditable(true); - } - - + LayerManager layerManager = context.getLayerManager(); + Collection selectedCategories = context.getLayerNamePanel().getSelectedCategories(); + FeatureDataset newFeatures = new FeatureDataset(currFeature.getSchema()); + newFeatures.addAll(quadtree.queryAll()); + layerManager.addLayer(selectedCategories.isEmpty() + ? StandardCategoryNames.WORKING + : selectedCategories.iterator().next().toString(), + layerManager.uniqueLayerName(NEW_LAYER), + newFeatures); + } else { + updateLayer(selectedLayer, removeFeatures, quadtree.queryAll()); + } return true; } + + private void updateLayer(final Layer layer, final List<Feature> remove, final List<Feature> newFeatures) { + layer.getLayerManager().getUndoableEditReceiver().startReceiving(); + try { + UndoableCommand command = + new UndoableCommand(I18N.get(AutoAssignAttributePlugIn.class.getName())) { + public void execute() { + if (removeSourceLines) { + layer.getFeatureCollectionWrapper().removeAll(remove); + layer.getLayerManager().fireFeaturesChanged(remove, FeatureEventType.DELETED,layer); + } + layer.getFeatureCollectionWrapper().addAll(newFeatures); + layer.getLayerManager().fireFeaturesChanged(newFeatures, FeatureEventType.ADDED,layer); + } + public void unexecute() { + layer.getFeatureCollectionWrapper().removeAll(newFeatures); + layer.getLayerManager().fireFeaturesChanged(newFeatures, FeatureEventType.DELETED,layer); + if (removeSourceLines) { + layer.getFeatureCollectionWrapper().addAll(remove); + layer.getLayerManager().fireFeaturesChanged(remove, FeatureEventType.ADDED,layer); + } + } + }; + command.execute(); + layer.getLayerManager().getUndoableEditReceiver().receive(command.toUndoableEdit()); + } finally { + layer.getLayerManager().getUndoableEditReceiver().stopReceiving(); + } + } + + private Feature nearest(Coordinate start0, Coordinate end0, List<Feature> candidates) { + Feature best = null; + double max = blendTolerance; + for (Feature c : candidates) { + Coordinate[] cc = c.getGeometry().getCoordinates(); + if (cc.length==0) continue; + Coordinate start1 = cc[0]; + Coordinate end1 = cc[cc.length-1]; + double d00 = start0.distance(start1); + double d01 = start0.distance(end1); + double d10 = end0.distance(start1); + double d11 = end0.distance(end1); + if (d00==0||d01==0||d10==0||d11==0) return c; + if (d00 <= max) {max = d00; best = c;} + if (d01 <= max) {max = d01; best = c;} + if (d10 <= max) {max = d10; best = c;} + if (d11 <= max) {max = d11; best = c;} + } + return best; + } - private boolean blended(CoordinateList blendedCoords, CoordinateList lsCoords) - { + private boolean blended(CoordinateList blendedCoords, CoordinateList lsCoords) { Coordinate start = blendedCoords.getCoordinate(0); Coordinate end = blendedCoords.getCoordinate(blendedCoords.size()-1); Coordinate first = lsCoords.getCoordinate(0); Coordinate last = lsCoords.getCoordinate(lsCoords.size()-1); - if (start.distance(first) < blendTolerance) - { - for (int i = 1; i < lsCoords.size(); i++) - { + double d00 = start.distance(first); + double d01 = start.distance(last); + double d10 = end.distance(first); + double d11 = end.distance(last); + double max = blendTolerance; + int result = -1; + if (d00 <= max) { + max = d00; + result = 0; + } + if (d01 <= max) { + max = d01; + result = 1; + } + if (d10 <= max) { + max = d10; + result = 2; + } + if (d11 <= max) { + //max = d11; + result = 3; + } + if (result == 0) { + for (int i = 1; i < lsCoords.size(); i++) { blendedCoords.add(0, lsCoords.getCoordinate(i)); } - } - else if (start.distance(last) < blendTolerance) - { - for (int i = lsCoords.size()-2; i >= 0; i--) - { + } else if (result == 1) { + for (int i = lsCoords.size()-2; i >= 0; i--) { blendedCoords.add(0, lsCoords.getCoordinate(i)); } - } - else if (end.distance(first) < blendTolerance) - { - for (int i = 1; i < lsCoords.size(); i++) - { + } else if (result == 2) { + for (int i = 1; i < lsCoords.size(); i++) { blendedCoords.add(lsCoords.getCoordinate(i)); } - } - else if (end.distance(last) < blendTolerance) - { - for (int i = lsCoords.size()-2; i >= 0; i--) - { + } else if (result == 3) { + for (int i = lsCoords.size()-2; i >= 0; i--) { blendedCoords.add(lsCoords.getCoordinate(i)); - } + } } - else - { - return false; - } - return true; + return result > -1; } - private void setDialogValues(MultiInputDialog dialog, PlugInContext context) - { + private void setDialogValues(MultiInputDialog dialog) { dialog.addDoubleField(TOLERANCE, blendTolerance, 6, THE_BLEND_TOLERANCE_TOOLTIP); - removeCheckBox = dialog.addCheckBox(REMOVE_SOURCE_LINES, removeSourceLines, REMOVE_SOURCE_LINES_TOOLTIP); + final JCheckBox removeCheckBox = dialog.addCheckBox(REMOVE_SOURCE_LINES, removeSourceLines, REMOVE_SOURCE_LINES_TOOLTIP); removeCheckBox.setEnabled(!createNewLayer); dialog.addCheckBox(TRANSFER_FIRST_ATTRIBUTES_TO_ALL_RESULTING_LINE_STRINGS, transferFirstAttributesToAllResultingLineStrings, TRANSFER_FIRST_ATTRIBUTES_TO_ALL_RESULTING_LINE_STRINGS_TOOLTIP); - newLayerCheckBox = dialog.addCheckBox(CREATE_NEW_LAYER, createNewLayer, CREATE_NEW_LAYER_TOOLTIP); + final JCheckBox newLayerCheckBox = dialog.addCheckBox(CREATE_NEW_LAYER, createNewLayer, CREATE_NEW_LAYER_TOOLTIP); newLayerCheckBox.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { @@ -234,7 +287,7 @@ removeCheckBox.setEnabled(!((JCheckBox) e.getSource()).isSelected()); } }); - } + } private void getDialogValues(MultiInputDialog dialog) { blendTolerance = dialog.getDouble(TOLERANCE); ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel