svn-gvsig-desktop / 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 @ 44612
History | View | Annotate | Download (6.18 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2015 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.geom.jts.aggregate; |
24 |
|
25 |
import java.awt.Shape; |
26 |
import java.awt.geom.AffineTransform; |
27 |
import java.awt.geom.PathIterator; |
28 |
import java.util.Collections; |
29 |
import java.util.Iterator; |
30 |
|
31 |
import org.gvsig.fmap.geom.Geometry; |
32 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
33 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
34 |
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator; |
35 |
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
36 |
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
37 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
38 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
39 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
40 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
41 |
import org.gvsig.fmap.geom.primitive.Point; |
42 |
import org.gvsig.fmap.geom.primitive.Primitive; |
43 |
|
44 |
|
45 |
/**
|
46 |
* @author fdiaz
|
47 |
*
|
48 |
*/
|
49 |
public abstract class AbstractMultiPoint extends AbstractMultiPrimitive implements MultiPoint { |
50 |
|
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
private static final long serialVersionUID = 7056816718895043774L; |
55 |
|
56 |
/**
|
57 |
* @param subtype
|
58 |
*/
|
59 |
public AbstractMultiPoint(int subtype) { |
60 |
super(Geometry.TYPES.MULTIPOINT, subtype);
|
61 |
} |
62 |
|
63 |
@Override
|
64 |
public com.vividsolutions.jts.geom.Geometry getJTS() {
|
65 |
ArrayListCoordinateSequence coordinateSequence = new ArrayListCoordinateSequence();
|
66 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
67 |
PointJTS point = (PointJTS) iterator.next(); |
68 |
coordinateSequence.add(point.getJTSCoordinate()); |
69 |
} |
70 |
return JTSUtils.createJTSMultiPoint(coordinateSequence);
|
71 |
} |
72 |
|
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
|
86 |
public void addPoint(Point point) { |
87 |
point = fixPoint(point); |
88 |
primitives.add(point); |
89 |
} |
90 |
|
91 |
@Override
|
92 |
public Point getPointAt(int index) { |
93 |
return (Point)primitives.get(index); |
94 |
} |
95 |
|
96 |
@Override
|
97 |
public Shape getShape(AffineTransform affineTransform) { |
98 |
return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0); |
99 |
} |
100 |
|
101 |
@Override
|
102 |
public Shape getShape() { |
103 |
return new DefaultGeneralPathX(getPathIterator(null),false,0); |
104 |
} |
105 |
|
106 |
@Override
|
107 |
public PathIterator getPathIterator(AffineTransform at) { |
108 |
PointIterator pi = new PointIterator(at);
|
109 |
return pi;
|
110 |
} |
111 |
|
112 |
@Override
|
113 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
114 |
return getPathIterator(at);
|
115 |
} |
116 |
|
117 |
protected class PointIterator extends GeneralPathXIterator { |
118 |
|
119 |
/** Transform applied on the coordinates during iteration */
|
120 |
private final AffineTransform at; |
121 |
|
122 |
/** True when the point has been read once */
|
123 |
private boolean done; |
124 |
private int index = 0; |
125 |
|
126 |
public PointIterator(AffineTransform at) { |
127 |
super(new GeneralPathX()); |
128 |
if (at == null) { |
129 |
at = new AffineTransform(); |
130 |
} |
131 |
|
132 |
this.at = at;
|
133 |
done = false;
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* Return the winding rule for determining the interior of the path.
|
138 |
*
|
139 |
* @return <code>WIND_EVEN_ODD</code> by default.
|
140 |
*/
|
141 |
@Override
|
142 |
public int getWindingRule() { |
143 |
return PathIterator.WIND_EVEN_ODD; |
144 |
} |
145 |
|
146 |
/**
|
147 |
* @see java.awt.geom.PathIterator#next()
|
148 |
*/
|
149 |
@Override
|
150 |
public void next() { |
151 |
done = (primitives.size() == ++index); |
152 |
} |
153 |
|
154 |
/**
|
155 |
* @return
|
156 |
* @see java.awt.geom.PathIterator#isDone()
|
157 |
*/
|
158 |
@Override
|
159 |
public boolean isDone() { |
160 |
return done;
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* @return
|
165 |
* @see java.awt.geom.PathIterator#currentSegment(double[])
|
166 |
*/
|
167 |
@Override
|
168 |
public int currentSegment(double[] coords) { |
169 |
Point point = (Point) primitives.get(index); |
170 |
coords[0] = point.getX();
|
171 |
coords[1] = point.getY();
|
172 |
at.transform(coords, 0, coords, 0, 1); |
173 |
return PathIterator.SEG_MOVETO; |
174 |
} |
175 |
|
176 |
/*
|
177 |
* @see java.awt.geom.PathIterator#currentSegment(float[])
|
178 |
*/
|
179 |
@Override
|
180 |
public int currentSegment(float[] coords) { |
181 |
Point point = (Point) primitives.get(index); |
182 |
coords[0] = (float)point.getX(); |
183 |
coords[1] = (float)point.getY(); |
184 |
at.transform(coords, 0, coords, 0, 1); |
185 |
return PathIterator.SEG_MOVETO; |
186 |
} |
187 |
} |
188 |
|
189 |
@Override
|
190 |
public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
191 |
Collections.reverse(primitives);
|
192 |
} |
193 |
|
194 |
|
195 |
@Override
|
196 |
public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException { |
197 |
return JTSUtils.createGeometry(this.getProjection(), getJTS().buffer(distance)); |
198 |
} |
199 |
|
200 |
protected abstract Point fixPoint(Point point); |
201 |
} |