Revision 44612 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/aggregate/AbstractMultiPoint.java
AbstractMultiPoint.java | ||
---|---|---|
54 | 54 |
private static final long serialVersionUID = 7056816718895043774L; |
55 | 55 |
|
56 | 56 |
/** |
57 |
* @param type |
|
58 | 57 |
* @param subtype |
59 | 58 |
*/ |
60 | 59 |
public AbstractMultiPoint(int subtype) { |
61 | 60 |
super(Geometry.TYPES.MULTIPOINT, subtype); |
62 | 61 |
} |
63 | 62 |
|
64 |
/* (non-Javadoc) |
|
65 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS() |
|
66 |
*/ |
|
63 |
@Override |
|
67 | 64 |
public com.vividsolutions.jts.geom.Geometry getJTS() { |
68 | 65 |
ArrayListCoordinateSequence coordinateSequence = new ArrayListCoordinateSequence(); |
69 | 66 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
... | ... | |
73 | 70 |
return JTSUtils.createJTSMultiPoint(coordinateSequence); |
74 | 71 |
} |
75 | 72 |
|
76 |
/* (non-Javadoc) |
|
77 |
* @see org.gvsig.fmap.geom.aggregate.MultiPoint#addPoint(org.gvsig.fmap.geom.primitive.Point) |
|
78 |
*/ |
|
73 |
|
|
74 |
@Override |
|
75 |
public Geometry force2D() throws GeometryOperationNotSupportedException, GeometryOperationException { |
|
76 |
MultiPoint2D other = new MultiPoint2D(); |
|
77 |
other.setProjection(this.getProjection()); |
|
78 |
other.ensureCapacity(primitives.size()); |
|
79 |
for (Primitive primitive : primitives) { |
|
80 |
other.addPrimitive((Primitive)primitive.force2D()); |
|
81 |
} |
|
82 |
return other; |
|
83 |
} |
|
84 |
|
|
85 |
@Override |
|
79 | 86 |
public void addPoint(Point point) { |
80 | 87 |
point = fixPoint(point); |
81 | 88 |
primitives.add(point); |
82 | 89 |
} |
83 | 90 |
|
84 |
/* (non-Javadoc) |
|
85 |
* @see org.gvsig.fmap.geom.aggregate.MultiPoint#getPointAt(int) |
|
86 |
*/ |
|
91 |
@Override |
|
87 | 92 |
public Point getPointAt(int index) { |
88 | 93 |
return (Point)primitives.get(index); |
89 | 94 |
} |
90 | 95 |
|
91 |
/* |
|
92 |
* (non-Javadoc) |
|
93 |
* |
|
94 |
* @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform) |
|
95 |
*/ |
|
96 |
@Override |
|
96 | 97 |
public Shape getShape(AffineTransform affineTransform) { |
97 | 98 |
return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
98 | 99 |
} |
99 | 100 |
|
100 |
/* |
|
101 |
* (non-Javadoc) |
|
102 |
* |
|
103 |
* @see org.gvsig.fmap.geom.Geometry#getShape() |
|
104 |
*/ |
|
101 |
@Override |
|
105 | 102 |
public Shape getShape() { |
106 | 103 |
return new DefaultGeneralPathX(getPathIterator(null),false,0); |
107 | 104 |
} |
108 | 105 |
|
109 |
/* |
|
110 |
* (non-Javadoc) |
|
111 |
* |
|
112 |
* @see |
|
113 |
* org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform |
|
114 |
* ) |
|
115 |
*/ |
|
106 |
@Override |
|
116 | 107 |
public PathIterator getPathIterator(AffineTransform at) { |
117 | 108 |
PointIterator pi = new PointIterator(at); |
118 | 109 |
return pi; |
119 | 110 |
} |
120 | 111 |
|
121 |
/* |
|
122 |
* (non-Javadoc) |
|
123 |
* |
|
124 |
* @see |
|
125 |
* org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform |
|
126 |
* , double) |
|
127 |
*/ |
|
112 |
@Override |
|
128 | 113 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
129 | 114 |
return getPathIterator(at); |
130 | 115 |
} |
... | ... | |
132 | 117 |
protected class PointIterator extends GeneralPathXIterator { |
133 | 118 |
|
134 | 119 |
/** Transform applied on the coordinates during iteration */ |
135 |
private AffineTransform at; |
|
120 |
private final AffineTransform at;
|
|
136 | 121 |
|
137 | 122 |
/** True when the point has been read once */ |
138 | 123 |
private boolean done; |
139 | 124 |
private int index = 0; |
140 | 125 |
|
141 |
/** |
|
142 |
* Creates a new PointIterator object. |
|
143 |
* |
|
144 |
* @param p |
|
145 |
* The polygon |
|
146 |
* @param at |
|
147 |
* The affine transform applied to coordinates during |
|
148 |
* iteration |
|
149 |
*/ |
|
150 | 126 |
public PointIterator(AffineTransform at) { |
151 | 127 |
super(new GeneralPathX()); |
152 | 128 |
if (at == null) { |
... | ... | |
162 | 138 |
* |
163 | 139 |
* @return <code>WIND_EVEN_ODD</code> by default. |
164 | 140 |
*/ |
141 |
@Override |
|
165 | 142 |
public int getWindingRule() { |
166 | 143 |
return PathIterator.WIND_EVEN_ODD; |
167 | 144 |
} |
... | ... | |
169 | 146 |
/** |
170 | 147 |
* @see java.awt.geom.PathIterator#next() |
171 | 148 |
*/ |
149 |
@Override |
|
172 | 150 |
public void next() { |
173 | 151 |
done = (primitives.size() == ++index); |
174 | 152 |
} |
175 | 153 |
|
176 | 154 |
/** |
155 |
* @return |
|
177 | 156 |
* @see java.awt.geom.PathIterator#isDone() |
178 | 157 |
*/ |
158 |
@Override |
|
179 | 159 |
public boolean isDone() { |
180 | 160 |
return done; |
181 | 161 |
} |
182 | 162 |
|
183 | 163 |
/** |
164 |
* @return |
|
184 | 165 |
* @see java.awt.geom.PathIterator#currentSegment(double[]) |
185 | 166 |
*/ |
167 |
@Override |
|
186 | 168 |
public int currentSegment(double[] coords) { |
187 | 169 |
Point point = (Point) primitives.get(index); |
188 | 170 |
coords[0] = point.getX(); |
... | ... | |
192 | 174 |
} |
193 | 175 |
|
194 | 176 |
/* |
195 |
* (non-Javadoc) |
|
196 |
* |
|
197 | 177 |
* @see java.awt.geom.PathIterator#currentSegment(float[]) |
198 | 178 |
*/ |
179 |
@Override |
|
199 | 180 |
public int currentSegment(float[] coords) { |
200 | 181 |
Point point = (Point) primitives.get(index); |
201 | 182 |
coords[0] = (float)point.getX(); |
... | ... | |
205 | 186 |
} |
206 | 187 |
} |
207 | 188 |
|
208 |
/* (non-Javadoc) |
|
209 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#flip() |
|
210 |
*/ |
|
189 |
@Override |
|
211 | 190 |
public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
212 | 191 |
Collections.reverse(primitives); |
213 | 192 |
} |
214 | 193 |
|
215 | 194 |
|
216 |
/* (non-Javadoc) |
|
217 |
* @see org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform) |
|
218 |
*/ |
|
195 |
@Override |
|
219 | 196 |
public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException { |
220 | 197 |
return JTSUtils.createGeometry(this.getProjection(), getJTS().buffer(distance)); |
221 | 198 |
} |
222 | 199 |
|
223 |
/** |
|
224 |
* @param point |
|
225 |
* @return |
|
226 |
*/ |
|
227 | 200 |
protected abstract Point fixPoint(Point point); |
228 | 201 |
} |
Also available in: Unified diff