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 / primitive / point / Point2DM.java @ 42374
History | View | Annotate | Download (6.75 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.primitive.point; |
24 |
|
25 |
import java.awt.geom.AffineTransform; |
26 |
import java.awt.geom.PathIterator; |
27 |
|
28 |
import com.vividsolutions.jts.geom.Coordinate; |
29 |
import com.vividsolutions.jts.geom.CoordinateSequence; |
30 |
|
31 |
import org.gvsig.fmap.geom.Geometry; |
32 |
import org.gvsig.fmap.geom.GeometryException; |
33 |
import org.gvsig.fmap.geom.GeometryLocator; |
34 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
35 |
import org.gvsig.fmap.geom.jts.MCoordinate; |
36 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint2DM; |
37 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
38 |
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator; |
39 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
40 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
41 |
import org.gvsig.fmap.geom.type.GeometryType; |
42 |
|
43 |
/**
|
44 |
* @author fdiaz
|
45 |
*
|
46 |
*/
|
47 |
public class Point2DM extends AbstractPoint { |
48 |
|
49 |
/**
|
50 |
*
|
51 |
*/
|
52 |
private static final long serialVersionUID = 7829655161985732518L; |
53 |
|
54 |
/**
|
55 |
*
|
56 |
*/
|
57 |
public Point2DM(Coordinate coordinates) {
|
58 |
super(Geometry.SUBTYPES.GEOM2DM, MCoordinate.convertCoordinate(coordinates));
|
59 |
} |
60 |
|
61 |
/**
|
62 |
*
|
63 |
*/
|
64 |
public Point2DM() {
|
65 |
this(JTSUtils.createMCoordinate(0, 0, 0)); |
66 |
} |
67 |
|
68 |
/**
|
69 |
*
|
70 |
*/
|
71 |
public Point2DM(double x, double y, double m) { |
72 |
this(JTSUtils.createMCoordinate(x, y, m));
|
73 |
} |
74 |
|
75 |
public double getM() { |
76 |
return ((org.hibernate.spatial.jts.mgeom.MCoordinate)this.coordinate).m; |
77 |
} |
78 |
|
79 |
/*
|
80 |
* (non-Javadoc)
|
81 |
*
|
82 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
83 |
*/
|
84 |
public int getDimension() { |
85 |
return 3; |
86 |
} |
87 |
|
88 |
/*
|
89 |
* (non-Javadoc)
|
90 |
*
|
91 |
* @see org.gvsig.fmap.geom.Geometry#getGeometryType()
|
92 |
*/
|
93 |
public GeometryType getGeometryType() {
|
94 |
try {
|
95 |
return GeometryLocator.getGeometryManager()
|
96 |
.getGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2DM); |
97 |
} catch (Exception e) { |
98 |
return null; |
99 |
} |
100 |
} |
101 |
|
102 |
/*
|
103 |
* (non-Javadoc)
|
104 |
*
|
105 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
106 |
*/
|
107 |
public Geometry cloneGeometry() {
|
108 |
return new Point2DM(MCoordinate.convertCoordinate((Coordinate) coordinate.clone())); |
109 |
} |
110 |
|
111 |
/*
|
112 |
* (non-Javadoc)
|
113 |
*
|
114 |
* @see org.gvsig.fmap.geom.primitive.Point#getCoordinateAt(int)
|
115 |
*/
|
116 |
public double getCoordinateAt(int dimension) { |
117 |
if (dimension == 2) { |
118 |
return this.getM(); |
119 |
} |
120 |
return super.getCoordinateAt(dimension); |
121 |
} |
122 |
|
123 |
/*
|
124 |
* (non-Javadoc)
|
125 |
*
|
126 |
* @see org.gvsig.fmap.geom.primitive.Point#setCoordinateAt(int, double)
|
127 |
*/
|
128 |
public void setCoordinateAt(int dimension, double value) { |
129 |
if (dimension == 2) { |
130 |
this.coordinate.setOrdinate(CoordinateSequence.M, value);
|
131 |
return;
|
132 |
} |
133 |
this.coordinate.setOrdinate(dimension, value);
|
134 |
} |
135 |
|
136 |
/*
|
137 |
* (non-Javadoc)
|
138 |
*
|
139 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
|
140 |
*/
|
141 |
public boolean is3D() { |
142 |
return false; |
143 |
} |
144 |
|
145 |
/* (non-Javadoc)
|
146 |
* @see org.gvsig.fmap.geom.jts.primitive.point.PointJTS#setJTSCoordinate(com.vividsolutions.jts.geom.Coordinate)
|
147 |
*/
|
148 |
public void setJTSCoordinate(Coordinate coordinate) { |
149 |
this.coordinate = coordinate;
|
150 |
} |
151 |
|
152 |
/*
|
153 |
* (non-Javadoc)
|
154 |
*
|
155 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
156 |
*/
|
157 |
public GeneralPathX getGeneralPath() {
|
158 |
return new DefaultGeneralPathX(new PointIterator(null),false,0); |
159 |
} |
160 |
|
161 |
/*
|
162 |
* (non-Javadoc)
|
163 |
*
|
164 |
* @see
|
165 |
* org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
|
166 |
* )
|
167 |
*/
|
168 |
public PathIterator getPathIterator(AffineTransform at) { |
169 |
PointIterator pi = new PointIterator(at);
|
170 |
return pi;
|
171 |
} |
172 |
|
173 |
public class PointIterator extends GeneralPathXIterator { |
174 |
/** Transform applied on the coordinates during iteration */
|
175 |
private AffineTransform at; |
176 |
|
177 |
/** True when the point has been read once */
|
178 |
private boolean done; |
179 |
|
180 |
/**
|
181 |
* Creates a new PointIterator object.
|
182 |
*
|
183 |
* @param p The polygon
|
184 |
* @param at The affine transform applied to coordinates during iteration
|
185 |
*/
|
186 |
public PointIterator(AffineTransform at) { |
187 |
super(new GeneralPathX()); |
188 |
if (at == null) { |
189 |
at = new AffineTransform(); |
190 |
} |
191 |
|
192 |
this.at = at;
|
193 |
done = false;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* Return the winding rule for determining the interior of the path.
|
198 |
*
|
199 |
* @return <code>WIND_EVEN_ODD</code> by default.
|
200 |
*/
|
201 |
public int getWindingRule() { |
202 |
return PathIterator.WIND_EVEN_ODD; |
203 |
} |
204 |
|
205 |
/**
|
206 |
* @see java.awt.geom.PathIterator#next()
|
207 |
*/
|
208 |
public void next() { |
209 |
done = true;
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* @see java.awt.geom.PathIterator#isDone()
|
214 |
*/
|
215 |
public boolean isDone() { |
216 |
return done;
|
217 |
} |
218 |
|
219 |
/**
|
220 |
* @see java.awt.geom.PathIterator#currentSegment(double[])
|
221 |
*/
|
222 |
public int currentSegment(double[] coords) { |
223 |
coords[0] = getX();
|
224 |
coords[1] = getY();
|
225 |
at.transform(coords, 0, coords, 0, 1); |
226 |
|
227 |
return PathIterator.SEG_MOVETO; |
228 |
} |
229 |
|
230 |
/* (non-Javadoc)
|
231 |
* @see java.awt.geom.PathIterator#currentSegment(float[])
|
232 |
*/
|
233 |
public int currentSegment(float[] coords) { |
234 |
coords[0] = (float) getX(); |
235 |
coords[1] = (float) getY(); |
236 |
at.transform(coords, 0, coords, 0, 1); |
237 |
|
238 |
return PathIterator.SEG_MOVETO; |
239 |
} |
240 |
} |
241 |
|
242 |
/* (non-Javadoc)
|
243 |
* @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
244 |
*/
|
245 |
public MultiPoint toPoints() throws GeometryException { |
246 |
MultiPoint multiPoint = new MultiPoint2DM();
|
247 |
multiPoint.addPoint(this);
|
248 |
return multiPoint;
|
249 |
} |
250 |
|
251 |
} |