Revision: 6621
http://sourceforge.net/p/jump-pilot/code/6621
Author: michaudm
Date: 2020-11-11 11:01:59 +0000 (Wed, 11 Nov 2020)
Log Message:
-----------
Fix #510 + acceleration
Modified Paths:
--------------
core/trunk/src/org/openjump/core/rasterimage/algorithms/VectorizeAlgorithm.java
Modified:
core/trunk/src/org/openjump/core/rasterimage/algorithms/VectorizeAlgorithm.java
===================================================================
---
core/trunk/src/org/openjump/core/rasterimage/algorithms/VectorizeAlgorithm.java
2020-11-11 10:30:58 UTC (rev 6620)
+++
core/trunk/src/org/openjump/core/rasterimage/algorithms/VectorizeAlgorithm.java
2020-11-11 11:01:59 UTC (rev 6621)
@@ -3,8 +3,7 @@
import java.awt.Point;
import java.awt.geom.Point2D;
import java.awt.image.DataBuffer;
-import java.util.ArrayList;
-import java.util.Collections;
+import java.util.*;
import org.openjump.core.rasterimage.sextante.OpenJUMPSextanteRasterLayer;
import
org.openjump.core.rasterimage.sextante.rasterWrappers.GridWrapperNotInterpolated;
@@ -43,24 +42,21 @@
public static WorkbenchFrame frame =
JUMPWorkbench.getInstance().getFrame();
- private static int arrPos(int valIn, double[] arrayIn) {
+ //private static int arrPos(double valIn, double[] arrayIn) {
+ // for (int i = 0; i < arrayIn.length; i++) {
+ // if (arrayIn[i] == valIn) {
+ // return i;
+ // }
+ // }
+ // return -1;
+ //}
- int valOut = -9999;
- for (int i = 0; i < arrayIn.length; i++) {
- if (arrayIn[i] == valIn) {
- valOut = i;
- break;
- }
- }
- return valOut;
- }
-
/**
* Create a FeatureCollection of polygons defining a
GridWrapperNotInterpolated and number of band
* AdbToolbox algorithm
- * @param gwrapper. GridWrapperNotInterpolated
- * @param explodeMultipolygons. Explode MultiPolygons in Polygons
- * @param band. Number of band (0,1,2,etc)
+ * @param gwrapper GridWrapperNotInterpolated
+ * @param explodeMultipolygons Explode MultiPolygons in Polygons
+ * @param band Number of band (0,1,2,etc)
* @return
*/
public static FeatureCollection toPolygonsAdbToolBox(
@@ -74,11 +70,12 @@
// Find unique values
final double[] uniqueVals = findUniqueVals(gwrapper, noData, band);
final int uniqueValsCount = uniqueVals.length;
+ final Map<Double,Integer> index = index(uniqueVals);
// Scan lines
@SuppressWarnings("unchecked")
final ArrayList<Polygon>[] arrAll = new ArrayList[uniqueValsCount];
for (int i = 0; i < arrAll.length; i++) {
- arrAll[i] = new ArrayList<Polygon>();
+ arrAll[i] = new ArrayList<>();
}
final Coordinate[] coords = new Coordinate[5];
final PackedCoordinateSequenceFactory pcsf = new
PackedCoordinateSequenceFactory();
@@ -110,7 +107,8 @@
final CoordinateSequence cs = pcsf.create(coords);
lr = new LinearRing(cs, geomFactory);
polygon = new Polygon(lr, null, geomFactory);
- arrAll[arrPos((int) oldVal, uniqueVals)].add(polygon);
+ //arrAll[arrPos((int) oldVal,
uniqueVals)].add(polygon);
+ arrAll[index.get(oldVal)].add(polygon);
}
oldVal = val;
cStart = c;
@@ -134,7 +132,7 @@
for (int g = 0; g < geom.getNumGeometries(); g++) {
feature = new BasicFeature(featSchema);
feature.setGeometry(geom.getGeometryN(g));
- feature.setAttribute(1, new Integer(ID));
+ feature.setAttribute(1, ID);
feature.setAttribute(2, uniqueVals[i]);
featColl.add(feature);
ID++;
@@ -141,7 +139,7 @@
}
} else {
feature = new BasicFeature(featSchema);
- feature.setAttribute(1, new Integer(ID));
+ feature.setAttribute(1, ID);
feature.setGeometry(geom);
feature.setAttribute(2, uniqueVals[i]);
featColl.add(feature);
@@ -183,6 +181,14 @@
return uniqueVals;
}
+ private static Map<Double,Integer> index(double[] values) {
+ Map<Double,Integer> map = new HashMap<>(values.length);
+ for (int i = 0 ; i < values.length ; i++) {
+ map.put(values[i],i);
+ }
+ return map;
+ }
+
private static int[][] m_Lock;
private static char[][] m_Area;
private static int m_iNX;
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel