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/AbstractMultiPolygon.java
AbstractMultiPolygon.java | ||
---|---|---|
58 | 58 |
*/ |
59 | 59 |
private static final long serialVersionUID = 6663703214829442424L; |
60 | 60 |
|
61 |
/** |
|
62 |
* @param type |
|
63 |
*/ |
|
64 | 61 |
public AbstractMultiPolygon(int subtype) { |
65 | 62 |
super(Geometry.TYPES.MULTIPOLYGON, subtype); |
66 | 63 |
} |
67 | 64 |
|
68 |
/* (non-Javadoc) |
|
69 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS() |
|
70 |
*/ |
|
71 | 65 |
public com.vividsolutions.jts.geom.Geometry getJTS() { |
72 | 66 |
com.vividsolutions.jts.geom.Polygon[] polygons = new com.vividsolutions.jts.geom.Polygon[primitives.size()]; |
73 | 67 |
for (int i=0; i<primitives.size(); i++){ |
... | ... | |
76 | 70 |
return JTSUtils.createJTSMultiPolygon(polygons); |
77 | 71 |
} |
78 | 72 |
|
79 |
/* (non-Javadoc) |
|
80 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform) |
|
81 |
*/ |
|
73 |
@Override |
|
74 |
public Geometry force2D() throws GeometryOperationNotSupportedException, GeometryOperationException { |
|
75 |
MultiPolygon2D other = new MultiPolygon2D(); |
|
76 |
other.setProjection(this.getProjection()); |
|
77 |
other.ensureCapacity(primitives.size()); |
|
78 |
for (Primitive primitive : primitives) { |
|
79 |
other.addPrimitive((Primitive)primitive.force2D()); |
|
80 |
} |
|
81 |
return other; |
|
82 |
} |
|
83 |
|
|
84 |
@Override |
|
82 | 85 |
public PathIterator getPathIterator(AffineTransform at) { |
83 | 86 |
MultiPolygonIterator pi = new MultiPolygonIterator(at); |
84 | 87 |
return pi; |
85 | 88 |
} |
86 | 89 |
|
87 |
/* (non-Javadoc) |
|
88 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform, double) |
|
89 |
*/ |
|
90 |
@Override |
|
90 | 91 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
91 | 92 |
return getPathIterator(at); |
92 | 93 |
} |
93 | 94 |
|
94 |
/* (non-Javadoc) |
|
95 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath() |
|
96 |
*/ |
|
95 |
@Override |
|
97 | 96 |
public GeneralPathX getGeneralPath() { |
98 | 97 |
return new DefaultGeneralPathX(getPathIterator(null), false, 0); |
99 | 98 |
} |
100 | 99 |
|
101 | 100 |
|
102 |
/* (non-Javadoc) |
|
103 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#flip() |
|
104 |
*/ |
|
101 |
@Override |
|
105 | 102 |
public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
106 | 103 |
for (Iterator iterator = primitives.iterator(); iterator.hasNext();) { |
107 | 104 |
((GeometryJTS)iterator.next()).flip(); |
... | ... | |
109 | 106 |
Collections.reverse(primitives); |
110 | 107 |
} |
111 | 108 |
|
112 |
/* (non-Javadoc) |
|
113 |
* @see org.gvsig.fmap.geom.aggregate.MultiSurface#addSurface(org.gvsig.fmap.geom.primitive.Surface) |
|
114 |
*/ |
|
109 |
@Override |
|
115 | 110 |
public void addSurface(Surface surface) { |
116 | 111 |
GeometryType geometryType = surface.getGeometryType(); |
117 | 112 |
if(geometryType.getType() == Geometry.TYPES.POLYGON && geometryType.getSubType() == getGeometryType().getSubType()){ |
... | ... | |
128 | 123 |
|
129 | 124 |
} |
130 | 125 |
|
131 |
/* (non-Javadoc) |
|
132 |
* @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform) |
|
133 |
*/ |
|
126 |
@Override |
|
134 | 127 |
public Shape getShape(AffineTransform affineTransform) { |
135 | 128 |
int capacity = 0; |
136 | 129 |
for( int i = 0; i < this.getPrimitivesNumber(); i++ ) { |
... | ... | |
143 | 136 |
return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0, capacity); |
144 | 137 |
} |
145 | 138 |
|
146 |
/* (non-Javadoc) |
|
147 |
* @see org.gvsig.fmap.geom.Geometry#getShape() |
|
148 |
*/ |
|
139 |
@Override |
|
149 | 140 |
public Shape getShape() { |
150 | 141 |
return getShape(null); |
151 | 142 |
} |
... | ... | |
153 | 144 |
protected class MultiPolygonIterator extends GeneralPathXIterator { |
154 | 145 |
|
155 | 146 |
/** Transform applied on the coordinates during iteration */ |
156 |
private AffineTransform at; |
|
147 |
private final AffineTransform at;
|
|
157 | 148 |
|
158 | 149 |
/** True when the point has been read once */ |
159 | 150 |
private boolean done; |
160 | 151 |
private int index = 0; |
161 |
private List<PathIterator>iterators = new ArrayList<PathIterator>(primitives.size());
|
|
152 |
private final List<PathIterator>iterators;
|
|
162 | 153 |
|
163 |
/** |
|
164 |
* Creates a new PointIterator object. |
|
165 |
* |
|
166 |
* @param p |
|
167 |
* The polygon |
|
168 |
* @param at |
|
169 |
* The affine transform applied to coordinates during |
|
170 |
* iteration |
|
171 |
*/ |
|
172 | 154 |
public MultiPolygonIterator(AffineTransform at) { |
173 | 155 |
super(new GeneralPathX()); |
156 |
this.iterators = new ArrayList<>(primitives.size()); |
|
174 | 157 |
if (at == null) { |
175 | 158 |
at = new AffineTransform(); |
176 | 159 |
} |
177 | 160 |
|
178 | 161 |
this.at = at; |
179 |
for (Iterator iterator = primitives.iterator(); iterator.hasNext();) { |
|
180 |
Primitive primitive = (Primitive) iterator.next(); |
|
162 |
for (Primitive primitive : primitives) { |
|
181 | 163 |
iterators.add(primitive.getPathIterator(at)); |
182 | 164 |
} |
183 | 165 |
done = false; |
184 | 166 |
} |
185 | 167 |
|
186 |
/**
|
|
168 |
/* |
|
187 | 169 |
* Return the winding rule for determining the interior of the path. |
188 | 170 |
* |
189 | 171 |
* @return <code>WIND_EVEN_ODD</code> by default. |
190 | 172 |
*/ |
173 |
@Override |
|
191 | 174 |
public int getWindingRule() { |
192 | 175 |
return PathIterator.WIND_EVEN_ODD; |
193 | 176 |
} |
194 | 177 |
|
195 |
/**
|
|
178 |
/* |
|
196 | 179 |
* @see java.awt.geom.PathIterator#next() |
197 | 180 |
*/ |
181 |
@Override |
|
198 | 182 |
public void next() { |
199 | 183 |
PathIterator pathIteratorPrimitive = iterators.get(index); |
200 | 184 |
pathIteratorPrimitive.next(); |
... | ... | |
204 | 188 |
} |
205 | 189 |
} |
206 | 190 |
|
207 |
/**
|
|
191 |
/* |
|
208 | 192 |
* @see java.awt.geom.PathIterator#isDone() |
209 | 193 |
*/ |
194 |
@Override |
|
210 | 195 |
public boolean isDone() { |
211 | 196 |
return done; |
212 | 197 |
} |
213 | 198 |
|
214 |
/**
|
|
199 |
/* |
|
215 | 200 |
* @see java.awt.geom.PathIterator#currentSegment(double[]) |
216 | 201 |
*/ |
202 |
@Override |
|
217 | 203 |
public int currentSegment(double[] coords) { |
218 | 204 |
return iterators.get(index).currentSegment(coords); |
219 | 205 |
} |
220 | 206 |
|
221 | 207 |
/* |
222 |
* (non-Javadoc) |
|
223 |
* |
|
224 | 208 |
* @see java.awt.geom.PathIterator#currentSegment(float[]) |
225 | 209 |
*/ |
210 |
@Override |
|
226 | 211 |
public int currentSegment(float[] coords) { |
227 | 212 |
return iterators.get(index).currentSegment(coords); |
228 | 213 |
} |
Also available in: Unified diff