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