Revision 42283 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/AbstractMultiLine.java
AbstractMultiLine.java | ||
---|---|---|
31 | 31 |
|
32 | 32 |
import com.vividsolutions.jts.geom.LineString; |
33 | 33 |
|
34 |
import org.gvsig.fmap.geom.Geometry; |
|
35 |
import org.gvsig.fmap.geom.GeometryException; |
|
34 | 36 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
35 | 37 |
import org.gvsig.fmap.geom.jts.GeometryJTS; |
36 | 38 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
... | ... | |
57 | 59 |
* @param type |
58 | 60 |
*/ |
59 | 61 |
public AbstractMultiLine(int subtype) { |
60 |
super(subtype); |
|
62 |
super(Geometry.TYPES.MULTILINE, subtype);
|
|
61 | 63 |
} |
62 | 64 |
|
63 | 65 |
|
... | ... | |
65 | 67 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS() |
66 | 68 |
*/ |
67 | 69 |
public com.vividsolutions.jts.geom.Geometry getJTS() { |
68 |
List<LineString> lineStrings = new ArrayList<LineString>(primitives.size()); |
|
69 |
LineString lineString = null; |
|
70 |
for (Iterator iterator = primitives.iterator(); iterator.hasNext();) { |
|
71 |
Primitive primitive = (Primitive) iterator.next(); |
|
72 |
lineString = (LineString) ((GeometryJTS)primitive).getJTS(); |
|
70 |
LineString[] lineStrings = new LineString[primitives.size()]; |
|
71 |
for(int i=0; i<primitives.size(); i++){ |
|
72 |
lineStrings[i]=(LineString) ((GeometryJTS)primitives.get(i)).getJTS(); |
|
73 | 73 |
} |
74 |
return JTSUtils.createJTSMultiLineString(lineStrings.toArray(new LineString[lineStrings.size()]));
|
|
74 |
return JTSUtils.createJTSMultiLineString(lineStrings); |
|
75 | 75 |
} |
76 | 76 |
|
77 |
/* (non-Javadoc) |
|
78 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform) |
|
79 |
*/ |
|
80 |
public PathIterator getPathIterator(AffineTransform at) { |
|
81 |
MultiLineIterator pi = new MultiLineIterator(at); |
|
82 |
return pi; |
|
83 |
} |
|
77 |
// /* (non-Javadoc) |
|
78 |
// * @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform) |
|
79 |
// */ |
|
80 |
// public PathIterator getPathIterator(AffineTransform at) { |
|
81 |
// MultiLineIterator pi = new MultiLineIterator(at); |
|
82 |
// return pi; |
|
83 |
// } |
|
84 |
// |
|
85 |
// /* (non-Javadoc) |
|
86 |
// * @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform, double) |
|
87 |
// */ |
|
88 |
// public PathIterator getPathIterator(AffineTransform at, double flatness) { |
|
89 |
// return getPathIterator(at); |
|
90 |
// } |
|
91 |
// |
|
92 |
// /* (non-Javadoc) |
|
93 |
// * @see org.gvsig.fmap.geom.Geometry#getGeneralPath() |
|
94 |
// */ |
|
95 |
// public GeneralPathX getGeneralPath() { |
|
96 |
// return new DefaultGeneralPathX(getPathIterator(null), false, 0); |
|
97 |
// } |
|
98 |
// |
|
99 |
// protected class MultiLineIterator extends GeneralPathXIterator { |
|
100 |
// |
|
101 |
// /** Transform applied on the coordinates during iteration */ |
|
102 |
// private AffineTransform at; |
|
103 |
// |
|
104 |
// /** True when the point has been read once */ |
|
105 |
// private boolean done; |
|
106 |
// private int index = 0; |
|
107 |
// private List<PathIterator>iterators = new ArrayList<PathIterator>(primitives.size()); |
|
108 |
// |
|
109 |
// /** |
|
110 |
// * Creates a new PointIterator object. |
|
111 |
// * |
|
112 |
// * @param p |
|
113 |
// * The polygon |
|
114 |
// * @param at |
|
115 |
// * The affine transform applied to coordinates during |
|
116 |
// * iteration |
|
117 |
// */ |
|
118 |
// public MultiLineIterator(AffineTransform at) { |
|
119 |
// super(new GeneralPathX()); |
|
120 |
// if (at == null) { |
|
121 |
// at = new AffineTransform(); |
|
122 |
// } |
|
123 |
// |
|
124 |
// this.at = at; |
|
125 |
// for (Iterator iterator = primitives.iterator(); iterator.hasNext();) { |
|
126 |
// Primitive primitive = (Primitive) iterator.next(); |
|
127 |
// iterators.add(primitive.getPathIterator(at)); |
|
128 |
// } |
|
129 |
// done = false; |
|
130 |
// } |
|
131 |
// |
|
132 |
// /** |
|
133 |
// * Return the winding rule for determining the interior of the path. |
|
134 |
// * |
|
135 |
// * @return <code>WIND_EVEN_ODD</code> by default. |
|
136 |
// */ |
|
137 |
// public int getWindingRule() { |
|
138 |
// return PathIterator.WIND_EVEN_ODD; |
|
139 |
// } |
|
140 |
// |
|
141 |
// /** |
|
142 |
// * @see java.awt.geom.PathIterator#next() |
|
143 |
// */ |
|
144 |
// public void next() { |
|
145 |
// PathIterator pathIteratorPrimitive = iterators.get(index); |
|
146 |
// pathIteratorPrimitive.next(); |
|
147 |
// if(pathIteratorPrimitive.isDone()){ |
|
148 |
// index++; |
|
149 |
// done = (index==primitives.size()); |
|
150 |
// } |
|
151 |
// } |
|
152 |
// |
|
153 |
// /** |
|
154 |
// * @see java.awt.geom.PathIterator#isDone() |
|
155 |
// */ |
|
156 |
// public boolean isDone() { |
|
157 |
// return done; |
|
158 |
// } |
|
159 |
// |
|
160 |
// /** |
|
161 |
// * @see java.awt.geom.PathIterator#currentSegment(double[]) |
|
162 |
// */ |
|
163 |
// public int currentSegment(double[] coords) { |
|
164 |
// return iterators.get(index).currentSegment(coords); |
|
165 |
// } |
|
166 |
// |
|
167 |
// /* |
|
168 |
// * (non-Javadoc) |
|
169 |
// * |
|
170 |
// * @see java.awt.geom.PathIterator#currentSegment(float[]) |
|
171 |
// */ |
|
172 |
// public int currentSegment(float[] coords) { |
|
173 |
// return iterators.get(index).currentSegment(coords); |
|
174 |
// } |
|
175 |
// } |
|
176 |
// |
|
177 |
// |
|
178 |
// /* |
|
179 |
// * (non-Javadoc) |
|
180 |
// * |
|
181 |
// * @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform) |
|
182 |
// */ |
|
183 |
// public Shape getShape(AffineTransform affineTransform) { |
|
184 |
// return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
|
185 |
// } |
|
186 |
// |
|
187 |
// /* |
|
188 |
// * (non-Javadoc) |
|
189 |
// * |
|
190 |
// * @see org.gvsig.fmap.geom.Geometry#getShape() |
|
191 |
// */ |
|
192 |
// public Shape getShape() { |
|
193 |
// return new DefaultGeneralPathX(getPathIterator(null),false,0); |
|
194 |
// } |
|
84 | 195 |
|
85 | 196 |
/* (non-Javadoc) |
86 |
* @see org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform, double) |
|
87 |
*/ |
|
88 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
|
89 |
return getPathIterator(at); |
|
90 |
} |
|
91 |
|
|
92 |
/* (non-Javadoc) |
|
93 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath() |
|
94 |
*/ |
|
95 |
public GeneralPathX getGeneralPath() { |
|
96 |
return new DefaultGeneralPathX(getPathIterator(null), false, 0); |
|
97 |
} |
|
98 |
|
|
99 |
protected class MultiLineIterator extends GeneralPathXIterator { |
|
100 |
|
|
101 |
/** Transform applied on the coordinates during iteration */ |
|
102 |
private AffineTransform at; |
|
103 |
|
|
104 |
/** True when the point has been read once */ |
|
105 |
private boolean done; |
|
106 |
private int index = 0; |
|
107 |
private List<PathIterator>iterators = new ArrayList<PathIterator>(primitives.size()); |
|
108 |
|
|
109 |
/** |
|
110 |
* Creates a new PointIterator object. |
|
111 |
* |
|
112 |
* @param p |
|
113 |
* The polygon |
|
114 |
* @param at |
|
115 |
* The affine transform applied to coordinates during |
|
116 |
* iteration |
|
117 |
*/ |
|
118 |
public MultiLineIterator(AffineTransform at) { |
|
119 |
super(new GeneralPathX()); |
|
120 |
if (at == null) { |
|
121 |
at = new AffineTransform(); |
|
122 |
} |
|
123 |
|
|
124 |
this.at = at; |
|
125 |
for (Iterator iterator = primitives.iterator(); iterator.hasNext();) { |
|
126 |
Primitive primitive = (Primitive) iterator.next(); |
|
127 |
iterators.add(primitive.getPathIterator(at)); |
|
128 |
} |
|
129 |
done = false; |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Return the winding rule for determining the interior of the path. |
|
134 |
* |
|
135 |
* @return <code>WIND_EVEN_ODD</code> by default. |
|
136 |
*/ |
|
137 |
public int getWindingRule() { |
|
138 |
return PathIterator.WIND_EVEN_ODD; |
|
139 |
} |
|
140 |
|
|
141 |
/** |
|
142 |
* @see java.awt.geom.PathIterator#next() |
|
143 |
*/ |
|
144 |
public void next() { |
|
145 |
PathIterator pathIteratorPrimitive = iterators.get(index); |
|
146 |
pathIteratorPrimitive.next(); |
|
147 |
if(pathIteratorPrimitive.isDone()){ |
|
148 |
index++; |
|
149 |
done = (index==primitives.size()); |
|
150 |
} |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* @see java.awt.geom.PathIterator#isDone() |
|
155 |
*/ |
|
156 |
public boolean isDone() { |
|
157 |
return done; |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* @see java.awt.geom.PathIterator#currentSegment(double[]) |
|
162 |
*/ |
|
163 |
public int currentSegment(double[] coords) { |
|
164 |
return iterators.get(index).currentSegment(coords); |
|
165 |
} |
|
166 |
|
|
167 |
/* |
|
168 |
* (non-Javadoc) |
|
169 |
* |
|
170 |
* @see java.awt.geom.PathIterator#currentSegment(float[]) |
|
171 |
*/ |
|
172 |
public int currentSegment(float[] coords) { |
|
173 |
return iterators.get(index).currentSegment(coords); |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
|
|
178 |
/* |
|
179 |
* (non-Javadoc) |
|
180 |
* |
|
181 |
* @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform) |
|
182 |
*/ |
|
183 |
public Shape getShape(AffineTransform affineTransform) { |
|
184 |
return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
|
185 |
} |
|
186 |
|
|
187 |
/* |
|
188 |
* (non-Javadoc) |
|
189 |
* |
|
190 |
* @see org.gvsig.fmap.geom.Geometry#getShape() |
|
191 |
*/ |
|
192 |
public Shape getShape() { |
|
193 |
return new DefaultGeneralPathX(getPathIterator(null),false,0); |
|
194 |
} |
|
195 |
|
|
196 |
/* (non-Javadoc) |
|
197 | 197 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#flip() |
198 | 198 |
*/ |
199 | 199 |
public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
Also available in: Unified diff