svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.buffer.impl / src / main / java / org / gvsig / raster / lib / buffer / impl / DefaultVectorROI.java @ 44831
History | View | Annotate | Download (3.41 KB)
1 |
package org.gvsig.raster.lib.buffer.impl; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Collections; |
5 |
import java.util.List; |
6 |
|
7 |
import org.gvsig.fmap.geom.Geometry; |
8 |
import org.gvsig.fmap.geom.GeometryLocator; |
9 |
import org.gvsig.fmap.geom.GeometryManager; |
10 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
11 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
12 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
13 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
14 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
15 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
16 |
import org.gvsig.fmap.geom.primitive.Envelope; |
17 |
import org.gvsig.fmap.geom.primitive.Point; |
18 |
import org.gvsig.raster.lib.buffer.api.VectorROI; |
19 |
import org.gvsig.raster.lib.buffer.api.exceptions.GettingEnvelopeException; |
20 |
import org.gvsig.tools.locator.LocatorException; |
21 |
|
22 |
/**
|
23 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
24 |
*
|
25 |
*/
|
26 |
public class DefaultVectorROI extends AbstractROI implements VectorROI { |
27 |
|
28 |
List<Geometry> rois;
|
29 |
|
30 |
/**
|
31 |
* Default constructor
|
32 |
*/
|
33 |
public DefaultVectorROI() {
|
34 |
this.rois = new ArrayList<Geometry>(); |
35 |
} |
36 |
|
37 |
@Override
|
38 |
public boolean isInside(int cellX, int cellY) throws CreateGeometryException, |
39 |
GeometryOperationNotSupportedException, GeometryOperationException { |
40 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
41 |
Point point = geomManager.createPoint(cellX, cellY, Geometry.SUBTYPES.GEOM2D);
|
42 |
// TODO: convertir este punto a coordenadas desde p?xeles
|
43 |
return isInside(point);
|
44 |
|
45 |
} |
46 |
|
47 |
@Override
|
48 |
public boolean isInside(Geometry geometry) throws GeometryOperationNotSupportedException, |
49 |
GeometryOperationException { |
50 |
if (rois != null && !rois.isEmpty()) { |
51 |
for (Geometry geom : rois) {
|
52 |
if (geom.contains(geometry)) {
|
53 |
return true; |
54 |
} |
55 |
} |
56 |
} |
57 |
return false; |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public Envelope getEnvelope() throws GettingEnvelopeException { |
62 |
Envelope envelope = null;
|
63 |
for (Geometry geom : rois) {
|
64 |
try {
|
65 |
if (envelope == null) { |
66 |
envelope = (Envelope) geom.getEnvelope().clone(); |
67 |
} else {
|
68 |
envelope.add((Envelope) geom.getEnvelope().clone()); |
69 |
} |
70 |
} catch (CloneNotSupportedException e) { |
71 |
throw new GettingEnvelopeException(geom, e); |
72 |
} |
73 |
} |
74 |
|
75 |
if (envelope == null) { |
76 |
// Create default 2D envelope
|
77 |
try {
|
78 |
return GeometryLocator.getGeometryManager().createEnvelope(SUBTYPES.GEOM2D);
|
79 |
} catch (LocatorException | CreateEnvelopeException e) {
|
80 |
throw new GettingEnvelopeException(e); |
81 |
} |
82 |
} |
83 |
|
84 |
return envelope;
|
85 |
} |
86 |
|
87 |
@Override
|
88 |
public void addGeometry(Geometry geometry) { |
89 |
if(!geometry.getGeometryType().isSubTypeOf(SUBTYPES.GEOM2D)){
|
90 |
throw new IllegalArgumentException("Vector ROI only supports 2D geometries"); |
91 |
} |
92 |
this.rois.add(geometry);
|
93 |
} |
94 |
|
95 |
@Override
|
96 |
public void removeGeometry(int index) { |
97 |
this.rois.remove(index);
|
98 |
} |
99 |
|
100 |
@Override
|
101 |
public List<Geometry> getGeometries() { |
102 |
return Collections.unmodifiableList(this.rois); |
103 |
} |
104 |
|
105 |
@Override
|
106 |
public int getGeometryCount() { |
107 |
return this.rois.size(); |
108 |
} |
109 |
|
110 |
} |