svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / primitive / impl / AbstractPrimitive.java @ 27049
History | View | Annotate | Download (7.4 KB)
1 |
package org.gvsig.fmap.geom.primitive.impl; |
---|---|
2 |
|
3 |
import java.awt.Shape; |
4 |
import java.awt.geom.AffineTransform; |
5 |
import java.awt.geom.Point2D; |
6 |
import java.io.Serializable; |
7 |
|
8 |
import org.cresques.cts.ICoordTrans; |
9 |
import org.cresques.cts.IProjection; |
10 |
import org.gvsig.fmap.geom.Geometry; |
11 |
import org.gvsig.fmap.geom.GeometryLocator; |
12 |
import org.gvsig.fmap.geom.handler.Handler; |
13 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
14 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
15 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
16 |
import org.gvsig.fmap.geom.primitive.FShape; |
17 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
18 |
import org.gvsig.fmap.geom.primitive.Primitive; |
19 |
import org.gvsig.fmap.geom.type.GeometryType; |
20 |
|
21 |
|
22 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
23 |
*
|
24 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
25 |
*
|
26 |
* This program is free software; you can redistribute it and/or
|
27 |
* modify it under the terms of the GNU General Public License
|
28 |
* as published by the Free Software Foundation; either version 2
|
29 |
* of the License, or (at your option) any later version.
|
30 |
*
|
31 |
* This program is distributed in the hope that it will be useful,
|
32 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
33 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
34 |
* GNU General Public License for more details.
|
35 |
*
|
36 |
* You should have received a copy of the GNU General Public License
|
37 |
* along with this program; if not, write to the Free Software
|
38 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
39 |
*
|
40 |
* For more information, contact:
|
41 |
*
|
42 |
* Generalitat Valenciana
|
43 |
* Conselleria d'Infraestructures i Transport
|
44 |
* Av. Blasco Ib??ez, 50
|
45 |
* 46010 VALENCIA
|
46 |
* SPAIN
|
47 |
*
|
48 |
* +34 963862235
|
49 |
* gvsig@gva.es
|
50 |
* www.gvsig.gva.es
|
51 |
*
|
52 |
* or
|
53 |
*
|
54 |
* IVER T.I. S.A
|
55 |
* Salamanca 50
|
56 |
* 46005 Valencia
|
57 |
* Spain
|
58 |
*
|
59 |
* +34 963163400
|
60 |
* dac@iver.es
|
61 |
*/
|
62 |
/* CVS MESSAGES:
|
63 |
*
|
64 |
* $Id: AbstractGeometry.java,v 1.2 2008/03/25 08:47:41 cvs Exp $
|
65 |
* $Log: AbstractGeometry.java,v $
|
66 |
* Revision 1.2 2008/03/25 08:47:41 cvs
|
67 |
* Visitors removed
|
68 |
*
|
69 |
* Revision 1.1 2008/03/12 08:46:20 cvs
|
70 |
* *** empty log message ***
|
71 |
*
|
72 |
*
|
73 |
*/
|
74 |
/**
|
75 |
* @author Jorge Piera Llodr? (jorge.piera@iver.es)
|
76 |
*/
|
77 |
public abstract class AbstractPrimitive implements Primitive, FShape, Serializable { |
78 |
private static final long serialVersionUID = -4334977368955260872L; |
79 |
protected String id = null; |
80 |
protected IProjection projection = null; |
81 |
|
82 |
/**
|
83 |
* Constructor without arguments. It is necessary to create
|
84 |
* geometries using the {@link GeometryType}{@link #create()}
|
85 |
* method
|
86 |
*/
|
87 |
public AbstractPrimitive() {
|
88 |
super();
|
89 |
} |
90 |
|
91 |
public AbstractPrimitive(String id, IProjection projection) { |
92 |
super();
|
93 |
this.id = id;
|
94 |
this.projection = projection;
|
95 |
} |
96 |
|
97 |
public AbstractPrimitive(IProjection projection) {
|
98 |
this(null, projection); |
99 |
} |
100 |
|
101 |
/**
|
102 |
* (non-Javadoc)
|
103 |
* @see com.iver.cit.gvsig.fmap.core.Geometry#getInternalShape()
|
104 |
* @deprecated this Geometry is a Shape.
|
105 |
*/
|
106 |
public Shape getInternalShape() { |
107 |
return this; |
108 |
} |
109 |
|
110 |
/* (non-Javadoc)
|
111 |
* @see org.gvsig.geometries.iso.AbstractGeometry#getId()
|
112 |
*/
|
113 |
public String getId() { |
114 |
return id;
|
115 |
} |
116 |
|
117 |
/* (non-Javadoc)
|
118 |
* @see org.gvsig.geometries.iso.AbstractGeometry#getSRS()
|
119 |
*/
|
120 |
public IProjection getSRS() {
|
121 |
return projection;
|
122 |
} |
123 |
|
124 |
/* (non-Javadoc)
|
125 |
* @see org.gvsig.geometries.iso.AbstractGeometry#transform(org.cresques.cts.IProjection)
|
126 |
*/
|
127 |
public AbstractPrimitive transform(IProjection newProjection) {
|
128 |
Geometry newGeom = cloneGeometry(); |
129 |
ICoordTrans coordTrans = projection.getCT(newProjection); |
130 |
newGeom.reProject(coordTrans); |
131 |
return (AbstractPrimitive)newGeom;
|
132 |
} |
133 |
|
134 |
|
135 |
/*
|
136 |
* TODO adaptar metodo procedente de UtilFunctions
|
137 |
*/
|
138 |
public static void rotateGeom(Geometry geometry, double radAngle, double basex, double basey) { |
139 |
AffineTransform at = new AffineTransform(); |
140 |
at.rotate(radAngle,basex,basey); |
141 |
geometry.transform(at); |
142 |
|
143 |
} |
144 |
|
145 |
/*
|
146 |
* TODO adaptar metodo procedente de UtilFunctions
|
147 |
*/
|
148 |
public static void moveGeom(Geometry geometry, double dx, double dy) { |
149 |
AffineTransform at = new AffineTransform(); |
150 |
at.translate(dx, dy); |
151 |
geometry.transform(at); |
152 |
} |
153 |
|
154 |
/*
|
155 |
* TODO adaptar metodo procedente de UtilFunctions
|
156 |
*/
|
157 |
public static void scaleGeom(Geometry geometry, Point2D basePoint, double sx, double sy) { |
158 |
AffineTransform at = new AffineTransform(); |
159 |
at.setToTranslation(basePoint.getX(),basePoint.getY()); |
160 |
at.scale(sx,sy); |
161 |
at.translate(-basePoint.getX(),-basePoint.getY()); |
162 |
geometry.transform(at); |
163 |
} |
164 |
|
165 |
/*
|
166 |
* (non-Javadoc)
|
167 |
* @see org.gvsig.fmap.geom.Geometry#fastIntersects(double, double, double, double)
|
168 |
*/
|
169 |
public boolean fastIntersects(double x, double y, double w, double h) { |
170 |
return intersects(x,y,w,h);
|
171 |
} |
172 |
|
173 |
/*
|
174 |
* (non-Javadoc)
|
175 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
176 |
*/
|
177 |
public Geometry cloneGeometry() {
|
178 |
return (Geometry)cloneFShape();
|
179 |
} |
180 |
|
181 |
/*
|
182 |
* (non-Javadoc)
|
183 |
* @see org.gvsig.fmap.geom.Geometry#getHandlers(int)
|
184 |
*/
|
185 |
public Handler[] getHandlers(int type) { |
186 |
if (type==STRETCHINGHANDLER){
|
187 |
return getStretchingHandlers();
|
188 |
}else if (type==SELECTHANDLER){ |
189 |
return getSelectHandlers();
|
190 |
} |
191 |
return null; |
192 |
} |
193 |
|
194 |
/*
|
195 |
* (non-Javadoc)
|
196 |
* @see org.gvsig.fmap.geom.Geometry#isSimple()
|
197 |
*/
|
198 |
public boolean isSimple() { |
199 |
return true; |
200 |
} |
201 |
|
202 |
/*
|
203 |
* (non-Javadoc)
|
204 |
* @see org.gvsig.fmap.geom.Geometry#invokeOperation(int, org.gvsig.fmap.geom.operation.GeometryOperationContext)
|
205 |
*/
|
206 |
public Object invokeOperation(int index, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException { |
207 |
return GeometryLocator.getGeometryManager().invokeOperation(index, this, ctx); |
208 |
} |
209 |
|
210 |
/*
|
211 |
* (non-Javadoc)
|
212 |
* @see java.lang.Comparable#compareTo(T)
|
213 |
*/
|
214 |
public int compareTo(Object arg0) { |
215 |
// TODO Auto-generated method stub
|
216 |
return -1; |
217 |
} |
218 |
|
219 |
/*
|
220 |
* (non-Javadoc)
|
221 |
* @see java.lang.Object#toString()
|
222 |
*/
|
223 |
public String toString() { |
224 |
String name=getGeometryType().getName();
|
225 |
return name.substring(name.lastIndexOf(".")+1); |
226 |
} |
227 |
|
228 |
/*
|
229 |
* (non-Javadoc)
|
230 |
* @see java.lang.Object#equals(java.lang.Object)
|
231 |
*/
|
232 |
public boolean equals(Object obj) { |
233 |
if (obj == null) { |
234 |
return false; |
235 |
} |
236 |
if (this.getClass() != obj.getClass()) { |
237 |
return false; |
238 |
} |
239 |
|
240 |
AbstractPrimitive other = (AbstractPrimitive) obj; |
241 |
if (this.getGeometryType().getType() != other.getGeometryType() |
242 |
.getType()) { |
243 |
return false; |
244 |
|
245 |
} |
246 |
|
247 |
if (this.projection != other.projection) { |
248 |
if (this.projection == null) { |
249 |
return false; |
250 |
} |
251 |
if (this.projection.getAbrev() != other.projection.getAbrev()) { //FIXME this must be false |
252 |
return false; |
253 |
} |
254 |
} |
255 |
if (!this.getBounds().equals(other.getBounds())) { |
256 |
return false; |
257 |
} |
258 |
|
259 |
|
260 |
GeneralPathX myPath = this.getGeneralPath();
|
261 |
GeneralPathX otherPath = other.getGeneralPath(); |
262 |
if (myPath == null) { |
263 |
if (otherPath != null) { |
264 |
return false; |
265 |
} else {
|
266 |
// TODO checkThis
|
267 |
return true; |
268 |
} |
269 |
|
270 |
} |
271 |
if (myPath.getNumCoords() != otherPath.getNumCoords()) {
|
272 |
return false; |
273 |
} |
274 |
if (myPath.getNumTypes() != otherPath.getNumTypes()) {
|
275 |
return false; |
276 |
} |
277 |
// double diff;
|
278 |
double[] myPoints = myPath.getPointCoords(); |
279 |
double[] otherPoints = otherPath.getPointCoords(); |
280 |
for (int i = 0; i < myPoints.length; i++) { |
281 |
if (myPoints[i] != otherPoints[i]) {
|
282 |
return false; |
283 |
} |
284 |
// diff = Math.abs(myPoints[i] - otherPoints[i]);
|
285 |
// if (diff != 0 && diff < 0.0000001 ){
|
286 |
// return false;
|
287 |
// };
|
288 |
} |
289 |
return true; |
290 |
} |
291 |
} |