Revision 800 org.gvsig.lrs/trunk/org.gvsig.lrs/org.gvsig.lrs.app/org.gvsig.lrs.app.mainplugin/src/main/java/org/gvsig/lrs/app/showmeasures/ShowMeasuresExtension.java
ShowMeasuresExtension.java | ||
---|---|---|
69 | 69 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsLocator; |
70 | 70 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsManager; |
71 | 71 |
import org.gvsig.lrs.lib.api.LrsShowMeasuresAlgorithmParams; |
72 |
import static org.gvsig.lrs.lib.api.LrsShowMeasuresAlgorithmParams.LRS_SHOWMEASURES_KILOMETER; |
|
73 |
import static org.gvsig.lrs.lib.api.LrsShowMeasuresAlgorithmParams.LRS_SHOWMEASURES_METER; |
|
72 | 74 |
import org.gvsig.lrs.lib.api.exceptions.LrsGettingParametersException; |
73 | 75 |
import org.gvsig.lrs.lib.api.exceptions.LrsNeededParameterException; |
74 | 76 |
import org.gvsig.lrs.swing.api.JLrsAlgorithmParams; |
... | ... | |
169 | 171 |
WindowManager.MODE.WINDOW); |
170 | 172 |
|
171 | 173 |
final double distance = params.getDistance(); |
174 |
final int units = params.getUnits(); |
|
172 | 175 |
|
173 | 176 |
Thread task = new Thread(new Runnable() { |
174 | 177 |
|
175 | 178 |
public void run() { |
176 | 179 |
try { |
177 |
showMeasures(graphics, activeLayer, distance, taskStatus); |
|
180 |
showMeasures(graphics, activeLayer, distance, units, taskStatus);
|
|
178 | 181 |
mapContext.invalidate(); |
179 | 182 |
if(!taskStatus.isRunning() && progressDialog.asJComponent().isVisible()){ |
180 | 183 |
progressDialog.asJComponent().setVisible(false); |
... | ... | |
241 | 244 |
* Shows measurements along the selected features in a layer with a fixed spacing |
242 | 245 |
* |
243 | 246 |
*/ |
244 |
private void showMeasures(GraphicLayer graphics, FLyrVect layer, double distance, SimpleTaskStatus taskStatus) |
|
247 |
private void showMeasures(GraphicLayer graphics, FLyrVect layer, double distance, int units, SimpleTaskStatus taskStatus)
|
|
245 | 248 |
throws DataException, CreateGeometryException, LocatorException { |
246 | 249 |
FeatureStore featureStore = layer.getFeatureStore(); |
247 | 250 |
FeatureSelection selection = featureStore.getFeatureSelection(); |
... | ... | |
256 | 259 |
Feature feature = (Feature) it.next(); |
257 | 260 |
Geometry geometry = feature.getDefaultGeometry(); |
258 | 261 |
if (geometry instanceof Line) { |
259 |
curValue = showLineMeasures(graphics, curValue, (Line) geometry, distance, ct); |
|
262 |
curValue = showLineMeasures(graphics, curValue, (Line) geometry, distance, units, ct);
|
|
260 | 263 |
taskStatus.setCurValue(curValue); |
261 | 264 |
} else if (geometry instanceof MultiLine) { |
262 | 265 |
MultiLine multiLine = (MultiLine) geometry; |
263 | 266 |
int primitives = multiLine.getPrimitivesNumber(); |
264 | 267 |
for (int i = 0; i < primitives; i++) { |
265 |
curValue = showLineMeasures(graphics, curValue, (Line) multiLine.getPrimitiveAt(i), distance, ct); |
|
268 |
curValue = showLineMeasures(graphics, curValue, (Line) multiLine.getPrimitiveAt(i), distance, units, ct);
|
|
266 | 269 |
taskStatus.setCurValue(curValue); |
267 | 270 |
} |
268 | 271 |
} |
... | ... | |
283 | 286 |
* @throws LocatorException |
284 | 287 |
* @throws CreateGeometryException |
285 | 288 |
*/ |
286 |
private long showLineMeasures(GraphicLayer graphics, long curValue, Line line, Double distance, ICoordTrans ct) throws CreateGeometryException, LocatorException { |
|
289 |
private long showLineMeasures(GraphicLayer graphics, long curValue, Line line, Double distance, int units, ICoordTrans ct) throws CreateGeometryException, LocatorException {
|
|
287 | 290 |
long value = curValue; |
288 | 291 |
for (int i = 0; i < line.getNumVertices() - 1; i++) { |
289 | 292 |
value++; |
... | ... | |
292 | 295 |
|
293 | 296 |
double div = m0 / distance; |
294 | 297 |
if (isMultiple(m0, distance)) { |
295 |
showMeasure(graphics, vertex, m0, ct); |
|
298 |
showMeasure(graphics, vertex, m0, units, ct);
|
|
296 | 299 |
} |
297 | 300 |
Point nextVertex = line.getVertex(i + 1); |
298 | 301 |
double m1 = nextVertex.getCoordinateAt(vertex.getDimension() - 1); |
... | ... | |
300 | 303 |
for (Iterator iterator = multiples.iterator(); iterator.hasNext();) { |
301 | 304 |
Double m = (Double) iterator.next(); |
302 | 305 |
Point point = getPointWithMBetweenTwoVertex(m, vertex, nextVertex); |
303 |
showMeasure(graphics, point, m, ct); |
|
306 |
showMeasure(graphics, point, m, units, ct);
|
|
304 | 307 |
} |
305 | 308 |
} |
306 | 309 |
value++; |
... | ... | |
313 | 316 |
* @param m |
314 | 317 |
* @param ct |
315 | 318 |
*/ |
316 |
private void showMeasure(GraphicLayer graphics, Point p, double m, ICoordTrans ct) { |
|
319 |
private void showMeasure(GraphicLayer graphics, Point p, double m, int units, ICoordTrans ct) {
|
|
317 | 320 |
|
318 | 321 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
319 | 322 |
SymbolManager symbolManager = MapContextLocator.getSymbolManager(); |
320 | 323 |
|
321 | 324 |
ISymbol markerSymbol = symbolManager.createSymbol(Geometry.TYPES.POINT, Color.RED); |
322 | 325 |
ISimpleTextSymbol textSymbol = getTextSymbol(); |
326 |
DecimalFormat formato = new DecimalFormat("0.000"); |
|
327 |
double theMeasure = m; |
|
328 |
if(units == LRS_SHOWMEASURES_METER){ |
|
329 |
theMeasure = m/1000; |
|
330 |
} |
|
331 |
|
|
332 |
String text = formato.format(theMeasure); |
|
333 |
if(units == LRS_SHOWMEASURES_METER || units == LRS_SHOWMEASURES_KILOMETER){ |
|
334 |
text = text.replace(",", " + "); |
|
335 |
} |
|
323 | 336 |
|
324 |
DecimalFormat formato = new DecimalFormat("0.000"); |
|
325 |
textSymbol.setText(formato.format(m).replace(",", " + ")); |
|
337 |
textSymbol.setText(text); |
|
326 | 338 |
int idMarkerSymbol = graphics.addSymbol(markerSymbol); |
327 | 339 |
int idTextSymbol = graphics.addSymbol(textSymbol); |
328 | 340 |
Point clonedPoint = (Point) p.cloneGeometry(); |
Also available in: Unified diff