111 |
111 |
import java.awt.geom.Point2D;
|
112 |
112 |
import java.awt.image.BufferedImage;
|
113 |
113 |
import java.util.ArrayList;
|
114 |
|
import java.util.HashMap;
|
115 |
114 |
import java.util.Iterator;
|
116 |
115 |
import java.util.List;
|
117 |
|
import java.util.Map;
|
118 |
116 |
import java.util.TreeMap;
|
119 |
117 |
import java.util.TreeSet;
|
120 |
118 |
|
|
119 |
import org.slf4j.Logger;
|
|
120 |
import org.slf4j.LoggerFactory;
|
|
121 |
|
121 |
122 |
import org.gvsig.compat.print.PrintAttributes;
|
122 |
123 |
import org.gvsig.fmap.dal.exception.DataException;
|
123 |
124 |
import org.gvsig.fmap.dal.exception.ReadException;
|
... | ... | |
131 |
132 |
import org.gvsig.fmap.geom.GeometryLocator;
|
132 |
133 |
import org.gvsig.fmap.geom.GeometryManager;
|
133 |
134 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
|
134 |
|
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
|
135 |
|
import org.gvsig.fmap.geom.exception.CreateGeometryException;
|
136 |
135 |
import org.gvsig.fmap.geom.operation.GeometryOperationException;
|
137 |
136 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
|
138 |
137 |
import org.gvsig.fmap.geom.primitive.Envelope;
|
... | ... | |
163 |
162 |
import org.gvsig.tools.ToolsLocator;
|
164 |
163 |
import org.gvsig.tools.dispose.DisposableIterator;
|
165 |
164 |
import org.gvsig.tools.dynobject.DynStruct;
|
166 |
|
import org.gvsig.tools.locator.LocatorException;
|
167 |
165 |
import org.gvsig.tools.persistence.PersistenceManager;
|
168 |
166 |
import org.gvsig.tools.persistence.PersistentState;
|
169 |
167 |
import org.gvsig.tools.persistence.exception.PersistenceException;
|
170 |
168 |
import org.gvsig.tools.task.Cancellable;
|
171 |
169 |
|
172 |
|
import org.slf4j.Logger;
|
173 |
|
import org.slf4j.LoggerFactory;
|
174 |
|
|
175 |
170 |
/**
|
176 |
171 |
*
|
177 |
172 |
* GeneralLabelingStrategy.java
|
... | ... | |
213 |
208 |
* print product (PDF, PS, ...)
|
214 |
209 |
*/
|
215 |
210 |
|
|
211 |
private List<Geometry> drawnGeometryLabels;
|
|
212 |
|
216 |
213 |
public GeneralLabelingStrategy() {
|
217 |
214 |
method = SymbologyLocator.getSymbologyManager()
|
218 |
215 |
.createDefaultLabelingMethod();
|
... | ... | |
243 |
240 |
}
|
244 |
241 |
}
|
245 |
242 |
|
246 |
|
public void draw(BufferedImage mapImage, Graphics2D mapGraphics,
|
247 |
|
double scale, ViewPort viewPort, Cancellable cancel, double dpi)
|
248 |
|
throws ReadException {
|
|
243 |
public void draw(BufferedImage mapImage, Graphics2D mapGraphics, double scale, ViewPort viewPort,
|
|
244 |
Cancellable cancel, double dpi) throws ReadException {
|
249 |
245 |
|
250 |
|
int x = (int) viewPort.getOffset().getX();
|
251 |
|
int y = (int) viewPort.getOffset().getY();
|
|
246 |
drawnGeometryLabels = new ArrayList<Geometry>(1000);
|
252 |
247 |
|
253 |
|
// offsets for page generation (PDF, PS, direct printing)
|
254 |
|
int print_offset_x = x;
|
255 |
|
int print_offset_y = y;
|
256 |
|
if (printMode) {
|
257 |
|
// for printing, we never offset the labels themselves
|
258 |
|
x = 0;
|
259 |
|
y = 0;
|
260 |
|
printMode = false;
|
261 |
|
}
|
|
248 |
int x = (int) viewPort.getOffset().getX();
|
|
249 |
int y = (int) viewPort.getOffset().getY();
|
262 |
250 |
|
263 |
|
TreeMap<String[], GeometryItem> labelsToPlace = null;
|
|
251 |
// offsets for page generation (PDF, PS, direct printing)
|
|
252 |
int print_offset_x = x;
|
|
253 |
int print_offset_y = y;
|
|
254 |
if (printMode) {
|
|
255 |
// for printing, we never offset the labels themselves
|
|
256 |
x = 0;
|
|
257 |
y = 0;
|
|
258 |
printMode = false;
|
|
259 |
}
|
264 |
260 |
|
265 |
|
String[] usedFields = getUsedFields();
|
|
261 |
TreeMap<String[], GeometryItem> labelsToPlace = null;
|
266 |
262 |
|
267 |
|
int notPlacedCount = 0;
|
268 |
|
int placedCount = 0;
|
|
263 |
String[] usedFields = getUsedFields();
|
269 |
264 |
|
270 |
|
/*
|
271 |
|
* Get the label placement solvers according the user's settings
|
272 |
|
*/
|
273 |
|
ILabelPlacement placement = PlacementManager.getPlacement(
|
274 |
|
getPlacementConstraints(), layer.getShapeType());
|
|
265 |
int notPlacedCount = 0;
|
|
266 |
int placedCount = 0;
|
275 |
267 |
|
276 |
|
BufferedImage targetBI;
|
277 |
|
Graphics2D targetGr;
|
|
268 |
/*
|
|
269 |
* Get the label placement solvers according the user's settings
|
|
270 |
*/
|
|
271 |
ILabelPlacement placement = PlacementManager.getPlacement(getPlacementConstraints(), layer.getShapeType());
|
278 |
272 |
|
279 |
|
/*
|
280 |
|
* get an ordered set of the LabelClasses up on the label priority
|
281 |
|
*/
|
282 |
|
ILabelClass[] lcs = method.getLabelClasses();
|
283 |
|
TreeSet<ILabelClass> ts = new TreeSet<ILabelClass>(
|
284 |
|
new LabelClassComparatorByPriority());
|
|
273 |
BufferedImage targetBI;
|
|
274 |
Graphics2D targetGr;
|
285 |
275 |
|
286 |
|
for (int i = 0; i < lcs.length; i++)
|
287 |
|
ts.add(lcs[i]);
|
|
276 |
/*
|
|
277 |
* get an ordered set of the LabelClasses up on the label priority
|
|
278 |
*/
|
|
279 |
ILabelClass[] lcs = method.getLabelClasses();
|
|
280 |
TreeSet<ILabelClass> ts = new TreeSet<ILabelClass>(new LabelClassComparatorByPriority());
|
288 |
281 |
|
289 |
|
if (ts.size() == 0)
|
290 |
|
return;
|
|
282 |
for (int i = 0; i < lcs.length; i++)
|
|
283 |
ts.add(lcs[i]);
|
291 |
284 |
|
292 |
|
/*
|
293 |
|
* now we have an ordered set, it is only need to give a pass for each
|
294 |
|
* label class to render by priorities.
|
295 |
|
*
|
296 |
|
* If no priorities were defined, the following loop only executes once
|
297 |
|
*/
|
298 |
|
for (ILabelClass lc : ts) {
|
|
285 |
if (ts.size() == 0)
|
|
286 |
return;
|
299 |
287 |
|
300 |
|
if (!lc.isVisible(scale)) {
|
301 |
|
/*
|
302 |
|
* Avoid non-visible labels
|
303 |
|
*/
|
304 |
|
continue;
|
305 |
|
}
|
|
288 |
/*
|
|
289 |
* now we have an ordered set, it is only need to give a pass for each
|
|
290 |
* label class to render by priorities.
|
|
291 |
*
|
|
292 |
* If no priorities were defined, the following loop only executes once
|
|
293 |
*/
|
|
294 |
for (ILabelClass lc : ts) {
|
306 |
295 |
|
307 |
|
FeatureSet fset = null;
|
308 |
|
DisposableIterator diter = null;
|
309 |
|
try {
|
|
296 |
if (!lc.isVisible(scale)) {
|
|
297 |
/*
|
|
298 |
* Avoid non-visible labels
|
|
299 |
*/
|
|
300 |
continue;
|
|
301 |
}
|
310 |
302 |
|
311 |
|
try {
|
312 |
|
fset = method.getFeatureIteratorByLabelClass(layer, lc,
|
313 |
|
viewPort, usedFields);
|
314 |
|
} catch (DataException e) {
|
315 |
|
throw new ReadException(layer.getFeatureStore()
|
316 |
|
.getProviderName(), e);
|
317 |
|
}
|
|
303 |
FeatureSet fset = null;
|
|
304 |
DisposableIterator diter = null;
|
|
305 |
try {
|
318 |
306 |
|
319 |
|
// duplicates treatment stuff
|
320 |
|
/* handle the duplicates mode */
|
321 |
|
int duplicateMode = getDuplicateLabelsMode();
|
322 |
|
if (duplicateMode == IPlacementConstraints.REMOVE_DUPLICATE_LABELS) {
|
323 |
|
// we need to register the labels already placed
|
|
307 |
try {
|
|
308 |
fset = method.getFeatureIteratorByLabelClass(layer, lc, viewPort, usedFields);
|
|
309 |
} catch (DataException e) {
|
|
310 |
throw new ReadException(layer.getFeatureStore().getProviderName(), e);
|
|
311 |
}
|
324 |
312 |
|
325 |
|
labelsToPlace = new TreeMap<String[], GeometryItem>(
|
326 |
|
new RemoveDuplicatesComparator());
|
327 |
|
}
|
|
313 |
// duplicates treatment stuff
|
|
314 |
/* handle the duplicates mode */
|
|
315 |
int duplicateMode = getDuplicateLabelsMode();
|
|
316 |
if (duplicateMode == IPlacementConstraints.REMOVE_DUPLICATE_LABELS) {
|
|
317 |
// we need to register the labels already placed
|
328 |
318 |
|
329 |
|
boolean bLabelsReallocatable = !isAllowingOverlap();
|
|
319 |
labelsToPlace = new TreeMap<String[], GeometryItem>(new RemoveDuplicatesComparator());
|
|
320 |
}
|
330 |
321 |
|
331 |
|
BufferedImage overlapDetectImage = null;
|
332 |
|
Graphics2D overlapDetectGraphics = null;
|
333 |
|
if (bLabelsReallocatable) {
|
334 |
|
int width = viewPort.getImageWidth() + print_offset_x;
|
|
322 |
boolean bLabelsReallocatable = !isAllowingOverlap();
|
335 |
323 |
|
336 |
|
if (width < 0) {
|
337 |
|
width = 1;
|
338 |
|
}
|
339 |
|
int height = viewPort.getImageHeight() + print_offset_y;
|
340 |
|
if (height < 0) {
|
341 |
|
height = 1;
|
342 |
|
}
|
343 |
|
if (mapImage != null)
|
344 |
|
overlapDetectImage = new BufferedImage(
|
345 |
|
mapImage.getWidth() + print_offset_x,
|
346 |
|
mapImage.getHeight() + print_offset_y,
|
347 |
|
BufferedImage.TYPE_INT_ARGB);
|
348 |
|
else
|
349 |
|
overlapDetectImage = new BufferedImage(
|
350 |
|
viewPort.getImageWidth() + print_offset_x,
|
351 |
|
viewPort.getImageHeight() + print_offset_y,
|
352 |
|
BufferedImage.TYPE_INT_ARGB);
|
|
324 |
BufferedImage overlapDetectImage = null;
|
|
325 |
Graphics2D overlapDetectGraphics = null;
|
|
326 |
if (bLabelsReallocatable) {
|
|
327 |
int width = viewPort.getImageWidth() + print_offset_x;
|
353 |
328 |
|
354 |
|
overlapDetectGraphics = overlapDetectImage.createGraphics();
|
355 |
|
overlapDetectGraphics.setRenderingHints(mapGraphics
|
356 |
|
.getRenderingHints());
|
357 |
|
}
|
358 |
|
if (bLabelsReallocatable) {
|
359 |
|
targetBI = overlapDetectImage;
|
360 |
|
targetGr = overlapDetectGraphics;
|
361 |
|
targetGr.translate(-x, -y);
|
362 |
|
} else {
|
363 |
|
targetBI = mapImage;
|
364 |
|
targetGr = mapGraphics;
|
365 |
|
}
|
|
329 |
if (width < 0) {
|
|
330 |
width = 1;
|
|
331 |
}
|
|
332 |
int height = viewPort.getImageHeight() + print_offset_y;
|
|
333 |
if (height < 0) {
|
|
334 |
height = 1;
|
|
335 |
}
|
|
336 |
if (mapImage != null)
|
|
337 |
overlapDetectImage =
|
|
338 |
new BufferedImage(mapImage.getWidth() + print_offset_x, mapImage.getHeight()
|
|
339 |
+ print_offset_y, BufferedImage.TYPE_INT_ARGB);
|
|
340 |
else
|
|
341 |
overlapDetectImage =
|
|
342 |
new BufferedImage(viewPort.getImageWidth() + print_offset_x, viewPort.getImageHeight()
|
|
343 |
+ print_offset_y, BufferedImage.TYPE_INT_ARGB);
|
366 |
344 |
|
367 |
|
try {
|
368 |
|
diter = fset.fastIterator();
|
369 |
|
} catch (DataException e) {
|
370 |
|
throw new ReadException(layer.getFeatureStore()
|
371 |
|
.getProviderName(), e);
|
372 |
|
}
|
373 |
|
Feature featu = null;
|
374 |
|
Geometry geome = null;
|
|
345 |
overlapDetectGraphics = overlapDetectImage.createGraphics();
|
|
346 |
overlapDetectGraphics.setRenderingHints(mapGraphics.getRenderingHints());
|
|
347 |
}
|
|
348 |
if (bLabelsReallocatable) {
|
|
349 |
targetBI = overlapDetectImage;
|
|
350 |
targetGr = overlapDetectGraphics;
|
|
351 |
targetGr.translate(-x, -y);
|
|
352 |
} else {
|
|
353 |
targetBI = mapImage;
|
|
354 |
targetGr = mapGraphics;
|
|
355 |
}
|
375 |
356 |
|
376 |
|
while (!cancel.isCanceled() && diter.hasNext()) {
|
|
357 |
try {
|
|
358 |
diter = fset.fastIterator();
|
|
359 |
} catch (DataException e) {
|
|
360 |
throw new ReadException(layer.getFeatureStore().getProviderName(), e);
|
|
361 |
}
|
|
362 |
Feature featu = null;
|
|
363 |
Geometry geome = null;
|
377 |
364 |
|
378 |
|
featu = (Feature) diter.next();
|
379 |
|
geome = featu.getDefaultGeometry();
|
380 |
|
if (geome == null || geome.getType() == Geometry.TYPES.NULL) {
|
381 |
|
continue;
|
382 |
|
}
|
|
365 |
while (!cancel.isCanceled() && diter.hasNext()) {
|
383 |
366 |
|
384 |
|
if (!setupLabel(featu, lc, cancel, usedFields, viewPort,
|
385 |
|
dpi, duplicateMode)) {
|
386 |
|
continue;
|
387 |
|
}
|
|
367 |
featu = (Feature) diter.next();
|
|
368 |
geome = featu.getDefaultGeometry();
|
|
369 |
if (geome == null || geome.getType() == Geometry.TYPES.NULL) {
|
|
370 |
continue;
|
|
371 |
}
|
388 |
372 |
|
389 |
|
String[] texts = lc.getTexts();
|
|
373 |
if (!setupLabel(featu, lc, cancel, usedFields, viewPort, dpi, duplicateMode)) {
|
|
374 |
continue;
|
|
375 |
}
|
390 |
376 |
|
391 |
|
if (duplicateMode == IPlacementConstraints.REMOVE_DUPLICATE_LABELS) {
|
392 |
|
// check if this text (so label) is already present in
|
393 |
|
// the map
|
|
377 |
String[] texts = lc.getTexts();
|
394 |
378 |
|
395 |
|
GeometryItem item = labelsToPlace.get(texts);
|
396 |
|
if (item == null) {
|
397 |
|
item = new GeometryItem(geome, 0);
|
398 |
|
labelsToPlace.put(texts, item);
|
399 |
|
}
|
400 |
|
if (item.geom != null) {
|
|
379 |
if (duplicateMode == IPlacementConstraints.REMOVE_DUPLICATE_LABELS) {
|
|
380 |
// check if this text (so label) is already present in
|
|
381 |
// the map
|
401 |
382 |
|
402 |
|
notPlacedCount++;
|
403 |
|
if (geome.getType() != Geometry.TYPES.POINT) {
|
|
383 |
GeometryItem item = labelsToPlace.get(texts);
|
|
384 |
if (item == null) {
|
|
385 |
item = new GeometryItem(geome, 0);
|
|
386 |
labelsToPlace.put(texts, item);
|
|
387 |
}
|
|
388 |
if (item.geom != null) {
|
404 |
389 |
|
405 |
|
Envelope auxBox = geome.getEnvelope();
|
406 |
|
double perimeterAux = 2 * (auxBox.getLength(0) + auxBox
|
407 |
|
.getLength(1));
|
408 |
|
if (perimeterAux > item.savedPerimeter) {
|
409 |
|
item.geom = geome; // FConverter.jts_to_igeometry(jtsGeom);
|
410 |
|
item.savedPerimeter = perimeterAux;
|
411 |
|
}
|
412 |
|
} else {
|
413 |
|
int weigh = item.weigh;
|
|
390 |
notPlacedCount++;
|
|
391 |
if (geome.getType() != Geometry.TYPES.POINT) {
|
414 |
392 |
|
415 |
|
try {
|
416 |
|
Point pointFromLabel = item.geom.centroid();
|
417 |
|
Point pointGeome = geome.centroid();
|
418 |
|
item.geom = GeometryLocator
|
419 |
|
.getGeometryManager()
|
420 |
|
.createPoint(
|
421 |
|
(pointFromLabel.getX()
|
422 |
|
* weigh + pointGeome.getX())
|
423 |
|
/ (weigh + 1),
|
424 |
|
(pointFromLabel.getY()
|
425 |
|
* weigh + pointGeome
|
426 |
|
.getY())
|
427 |
|
/ (weigh + 1),
|
428 |
|
Geometry.SUBTYPES.GEOM2D);
|
429 |
|
} catch (Exception ex) {
|
430 |
|
throw new ReadException(layer
|
431 |
|
.getFeatureStore()
|
432 |
|
.getProviderName(), ex);
|
433 |
|
}
|
|
393 |
Envelope auxBox = geome.getEnvelope();
|
|
394 |
double perimeterAux = 2 * (auxBox.getLength(0) + auxBox.getLength(1));
|
|
395 |
if (perimeterAux > item.savedPerimeter) {
|
|
396 |
item.geom = geome; // FConverter.jts_to_igeometry(jtsGeom);
|
|
397 |
item.savedPerimeter = perimeterAux;
|
|
398 |
}
|
|
399 |
} else {
|
|
400 |
int weigh = item.weigh;
|
434 |
401 |
|
435 |
|
}
|
436 |
|
} else {
|
437 |
|
item.geom = geome;
|
438 |
|
}
|
439 |
|
item.weigh++;
|
440 |
|
} else {
|
441 |
|
// Check if size is a pixel
|
442 |
|
if (isOnePoint(viewPort, geome)) {
|
443 |
|
continue;
|
444 |
|
}
|
|
402 |
try {
|
|
403 |
Point pointFromLabel = item.geom.centroid();
|
|
404 |
Point pointGeome = geome.centroid();
|
|
405 |
item.geom =
|
|
406 |
GeometryLocator.getGeometryManager().createPoint(
|
|
407 |
(pointFromLabel.getX() * weigh + pointGeome.getX()) / (weigh + 1),
|
|
408 |
(pointFromLabel.getY() * weigh + pointGeome.getY()) / (weigh + 1),
|
|
409 |
Geometry.SUBTYPES.GEOM2D);
|
|
410 |
} catch (Exception ex) {
|
|
411 |
throw new ReadException(layer.getFeatureStore().getProviderName(), ex);
|
|
412 |
}
|
445 |
413 |
|
446 |
|
List<Geometry> geome_parts = new ArrayList<Geometry>();
|
447 |
|
if (duplicateMode == IPlacementConstraints.ONE_LABEL_PER_FEATURE_PART) {
|
448 |
|
geome_parts = getGeometryParts(geome);
|
449 |
|
} else {
|
450 |
|
geome_parts.add(geome);
|
451 |
|
}
|
|
414 |
}
|
|
415 |
} else {
|
|
416 |
item.geom = geome;
|
|
417 |
}
|
|
418 |
item.weigh++;
|
|
419 |
} else {
|
|
420 |
// Check if size is a pixel
|
|
421 |
if (isOnePoint(viewPort, geome)) {
|
|
422 |
continue;
|
|
423 |
}
|
452 |
424 |
|
453 |
|
try {
|
454 |
|
int n = geome_parts.size();
|
455 |
|
for (int k = 0; k < n; k++) {
|
456 |
|
drawLabelInGeom(targetBI, targetGr, lc,
|
457 |
|
placement, viewPort,
|
458 |
|
geome_parts.get(k), cancel, dpi,
|
459 |
|
bLabelsReallocatable);
|
460 |
|
}
|
461 |
|
} catch (GeometryException e) {
|
462 |
|
throw new ReadException(layer.getFeatureStore()
|
463 |
|
.getProviderName(), e);
|
464 |
|
}
|
|
425 |
List<Geometry> geome_parts = new ArrayList<Geometry>();
|
|
426 |
if (duplicateMode == IPlacementConstraints.ONE_LABEL_PER_FEATURE_PART) {
|
|
427 |
geome_parts = getGeometryParts(geome);
|
|
428 |
} else {
|
|
429 |
geome_parts.add(geome);
|
|
430 |
}
|
465 |
431 |
|
466 |
|
placedCount++;
|
467 |
|
}
|
468 |
|
}
|
|
432 |
try {
|
|
433 |
int n = geome_parts.size();
|
|
434 |
for (int k = 0; k < n; k++) {
|
|
435 |
drawLabelInGeom(targetBI, targetGr, lc, placement, viewPort, geome_parts.get(k),
|
|
436 |
cancel, dpi, bLabelsReallocatable);
|
|
437 |
}
|
|
438 |
} catch (GeometryException e) {
|
|
439 |
throw new ReadException(layer.getFeatureStore().getProviderName(), e);
|
|
440 |
}
|
469 |
441 |
|
470 |
|
// ======= End iteration in feature set ====================
|
|
442 |
placedCount++;
|
|
443 |
}
|
|
444 |
}
|
471 |
445 |
|
472 |
|
if (duplicateMode == IPlacementConstraints.REMOVE_DUPLICATE_LABELS) {
|
473 |
|
Iterator<String[]> textsIt = labelsToPlace.keySet()
|
474 |
|
.iterator();
|
475 |
|
while (!cancel.isCanceled() && textsIt.hasNext()) {
|
476 |
|
notPlacedCount++;
|
477 |
|
String[] texts = textsIt.next();
|
|
446 |
// ======= End iteration in feature set ====================
|
478 |
447 |
|
479 |
|
GeometryItem item = labelsToPlace.get(texts);
|
480 |
|
if (item != null) {
|
481 |
|
lc.setTexts(texts);
|
482 |
|
// Check if size is a pixel
|
483 |
|
if (isOnePoint(viewPort, item.geom)) {
|
484 |
|
continue;
|
485 |
|
}
|
|
448 |
if (duplicateMode == IPlacementConstraints.REMOVE_DUPLICATE_LABELS) {
|
|
449 |
Iterator<String[]> textsIt = labelsToPlace.keySet().iterator();
|
|
450 |
while (!cancel.isCanceled() && textsIt.hasNext()) {
|
|
451 |
notPlacedCount++;
|
|
452 |
String[] texts = textsIt.next();
|
486 |
453 |
|
487 |
|
try {
|
488 |
|
drawLabelInGeom(targetBI, targetGr, lc,
|
489 |
|
placement, viewPort, item.geom, cancel,
|
490 |
|
dpi, bLabelsReallocatable);
|
491 |
|
} catch (GeometryException e) {
|
492 |
|
throw new ReadException(layer.getFeatureStore()
|
493 |
|
.getProviderName(), e);
|
494 |
|
}
|
495 |
|
}
|
496 |
|
}
|
497 |
|
}
|
|
454 |
GeometryItem item = labelsToPlace.get(texts);
|
|
455 |
if (item != null) {
|
|
456 |
lc.setTexts(texts);
|
|
457 |
// Check if size is a pixel
|
|
458 |
if (isOnePoint(viewPort, item.geom)) {
|
|
459 |
continue;
|
|
460 |
}
|
498 |
461 |
|
499 |
|
if (bLabelsReallocatable) {
|
500 |
|
targetGr.translate(x, y);
|
501 |
|
if (mapImage != null) {
|
502 |
|
mapGraphics.drawImage(overlapDetectImage, null, null);
|
503 |
|
} else {
|
504 |
|
mapGraphics.drawImage(overlapDetectImage, null, null);
|
505 |
|
}
|
506 |
|
}
|
|
462 |
try {
|
|
463 |
drawLabelInGeom(targetBI, targetGr, lc, placement, viewPort, item.geom, cancel, dpi,
|
|
464 |
bLabelsReallocatable);
|
|
465 |
} catch (GeometryException e) {
|
|
466 |
throw new ReadException(layer.getFeatureStore().getProviderName(), e);
|
|
467 |
}
|
|
468 |
}
|
|
469 |
}
|
|
470 |
}
|
507 |
471 |
|
508 |
|
} finally {
|
509 |
|
if (diter != null) {
|
510 |
|
diter.dispose();
|
511 |
|
}
|
512 |
|
if (fset != null){
|
513 |
|
fset.dispose();
|
514 |
|
}
|
515 |
|
}
|
516 |
|
} // big iteration
|
|
472 |
if (bLabelsReallocatable) {
|
|
473 |
targetGr.translate(x, y);
|
|
474 |
if (mapImage != null) {
|
|
475 |
mapGraphics.drawImage(overlapDetectImage, null, null);
|
|
476 |
} else {
|
|
477 |
mapGraphics.drawImage(overlapDetectImage, null, null);
|
|
478 |
}
|
|
479 |
}
|
517 |
480 |
|
518 |
|
}
|
|
481 |
} finally {
|
|
482 |
if (diter != null) {
|
|
483 |
diter.dispose();
|
|
484 |
}
|
|
485 |
if (fset != null) {
|
|
486 |
fset.dispose();
|
|
487 |
}
|
|
488 |
}
|
|
489 |
} // big iteration
|
519 |
490 |
|
|
491 |
}
|
|
492 |
|
520 |
493 |
private List<Geometry> getGeometryParts(Geometry ge) {
|
521 |
494 |
|
522 |
495 |
List<Geometry> resp = new ArrayList<Geometry>();
|
... | ... | |
569 |
542 |
Cancellable cancel, boolean bLabelsReallocatable)
|
570 |
543 |
throws GeometryException {
|
571 |
544 |
|
|
545 |
GeometryManager gm = GeometryLocator.getGeometryManager();
|
572 |
546 |
int i;
|
573 |
547 |
for (i = 0; !cancel.isCanceled() && i < llm.size(); i++) {
|
574 |
548 |
LabelLocationMetrics labelMetrics = llm.get(i);
|
... | ... | |
577 |
551 |
if (pc instanceof MultiShapePlacementConstraints) {
|
578 |
552 |
MultiShapePlacementConstraints mpc = (MultiShapePlacementConstraints) pc;
|
579 |
553 |
|
580 |
|
GeometryManager gm = GeometryLocator.getGeometryManager();
|
581 |
|
GeometryType line_gt = null;
|
582 |
|
GeometryType polyg_gt = null;
|
583 |
554 |
GeometryType geom_gt = null;
|
584 |
555 |
|
585 |
|
line_gt = gm.getGeometryType(TYPES.CURVE, SUBTYPES.GEOM2D);
|
586 |
|
polyg_gt = gm.getGeometryType(TYPES.SURFACE, SUBTYPES.GEOM2D);
|
587 |
556 |
geom_gt = gm.getGeometryType(geom.getType(), SUBTYPES.GEOM2D);
|
588 |
557 |
|
589 |
558 |
if (geom_gt.getType() == TYPES.POINT
|
... | ... | |
744 |
713 |
return true;
|
745 |
714 |
}
|
746 |
715 |
|
747 |
|
private boolean isOverlapping(BufferedImage bi, Geometry lblgeom) {
|
|
716 |
private boolean isOverlapping(BufferedImage bi, Geometry lblgeom) {
|
748 |
717 |
|
749 |
|
if (lblgeom == null || lblgeom.getType() == TYPES.NULL) {
|
750 |
|
return false;
|
751 |
|
}
|
752 |
|
|
753 |
|
Envelope rPixels = lblgeom.getEnvelope();
|
754 |
|
int minx = (int) rPixels.getMinimum(0);
|
755 |
|
int miny = (int) rPixels.getMinimum(1);
|
756 |
|
int maxx = (int) rPixels.getMaximum(0);
|
757 |
|
int maxy = (int) rPixels.getMaximum(1);
|
758 |
|
|
759 |
|
for (int i = minx; i <= maxx; i++) {
|
760 |
|
for (int j = miny; j <= maxy; j++) {
|
761 |
|
|
762 |
|
GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
763 |
|
try {
|
764 |
|
if (!lblgeom.contains(geomManager.createPoint(i, j, Geometry.SUBTYPES.GEOM2D))
|
765 |
|
// contains seems to don't detect points
|
766 |
|
// placed in the rectangle boundaries
|
767 |
|
&& !lblgeom.intersects(geomManager.createEnvelope(i, j, i, j, Geometry.SUBTYPES.GEOM2D).getGeometry())) {
|
768 |
|
continue;
|
769 |
|
}
|
770 |
|
} catch (CreateGeometryException | GeometryOperationNotSupportedException | GeometryOperationException
|
771 |
|
| CreateEnvelopeException e) {
|
772 |
|
logger.warn("Can't check overlapping with point ("+i+","+j+").");
|
773 |
|
|
774 |
|
}
|
775 |
|
|
776 |
|
if (i < 0 || j < 0) {
|
777 |
|
continue;
|
778 |
|
}
|
779 |
|
|
780 |
|
if (bi.getWidth() < i + 1 || bi.getHeight() < j + 1) {
|
781 |
|
continue;
|
782 |
|
}
|
783 |
|
|
784 |
|
if (bi.getRGB(i, j) != 0) {
|
|
718 |
for (Iterator iterator = drawnGeometryLabels.iterator(); iterator.hasNext();) {
|
|
719 |
Geometry drawnGeometry = (Geometry) iterator.next();
|
|
720 |
try {
|
|
721 |
if (drawnGeometry.intersects(lblgeom)) {
|
785 |
722 |
return true;
|
786 |
723 |
}
|
|
724 |
} catch (GeometryOperationNotSupportedException | GeometryOperationException e) {
|
|
725 |
logger.warn("Can't check overlapping geometry");
|
787 |
726 |
}
|
788 |
727 |
}
|
789 |
|
return false;
|
790 |
|
}
|
|
728 |
drawnGeometryLabels.add(lblgeom);
|
|
729 |
return false;
|
791 |
730 |
|
|
731 |
}
|
|
732 |
|
792 |
733 |
private boolean isOnePoint(ViewPort viewPort, Geometry geom) {
|
793 |
734 |
|
794 |
735 |
boolean onePoint = false;
|