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 / surface / ellipse / BaseEllipse2DM.java @ 47432
History | View | Annotate | Download (5.66 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.surface.ellipse; |
24 |
|
25 |
import com.vividsolutions.jts.geom.Coordinate; |
26 |
import java.awt.geom.PathIterator; |
27 |
import org.gvsig.fmap.geom.Geometry; |
28 |
import org.gvsig.fmap.geom.GeometryException; |
29 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
30 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
31 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
32 |
import org.gvsig.fmap.geom.jts.aggregate.MultiLine2DM; |
33 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint2DM; |
34 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon2DM; |
35 |
import org.gvsig.fmap.geom.jts.mgeom.MCoordinate; |
36 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2DM; |
37 |
import org.gvsig.fmap.geom.jts.primitive.point.Point2DM; |
38 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2DM; |
39 |
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
40 |
import org.gvsig.fmap.geom.primitive.Line; |
41 |
import org.gvsig.fmap.geom.primitive.Point; |
42 |
import org.gvsig.fmap.geom.primitive.Polygon; |
43 |
|
44 |
|
45 |
/**
|
46 |
* @author fdiaz
|
47 |
*
|
48 |
*/
|
49 |
public abstract class BaseEllipse2DM extends AbstractEllipse { |
50 |
|
51 |
private double mValue = Double.NaN; |
52 |
|
53 |
/**
|
54 |
* @param subtype
|
55 |
*/
|
56 |
public BaseEllipse2DM(int type) { |
57 |
super(type, Geometry.SUBTYPES.GEOM2DM);
|
58 |
} |
59 |
|
60 |
/*
|
61 |
* (non-Javadoc)
|
62 |
*
|
63 |
* @see
|
64 |
* org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org
|
65 |
* .gvsig.fmap.geom.primitive.Point)
|
66 |
*/
|
67 |
@Override
|
68 |
protected Point fixPoint(Point point) { |
69 |
if (point instanceof Point2DM) { |
70 |
Point2DM point2DM = (Point2DM) point; |
71 |
if (Double.isNaN(mValue) && !(Double.isNaN(point2DM.getM()))) { |
72 |
mValue = point2DM.getM(); |
73 |
if (init!=null) { |
74 |
((Point2DM) init).setM(mValue); |
75 |
} |
76 |
if (end!=null) { |
77 |
((Point2DM) end).setM(mValue); |
78 |
} |
79 |
return point2DM;
|
80 |
} |
81 |
} |
82 |
return new Point2DM(point.getX(), point.getY(), Double.isNaN(mValue)?0:mValue); |
83 |
} |
84 |
|
85 |
/**
|
86 |
* @return
|
87 |
*/
|
88 |
protected ArrayListCoordinateSequence getJTSCoordinates() {
|
89 |
PathIterator pi = getPathIterator(null); |
90 |
ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
|
91 |
|
92 |
double coords[] = new double[6]; |
93 |
while (!pi.isDone()) {
|
94 |
switch (pi.currentSegment(coords)) {
|
95 |
case PathIterator.SEG_MOVETO: |
96 |
coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue)); |
97 |
break;
|
98 |
case PathIterator.SEG_LINETO: |
99 |
coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue)); |
100 |
break;
|
101 |
case PathIterator.SEG_QUADTO: |
102 |
coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue)); |
103 |
coordinates.add(new MCoordinate(coords[2], coords[3], Double.NaN, mValue)); |
104 |
break;
|
105 |
case PathIterator.SEG_CUBICTO: |
106 |
coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue)); |
107 |
coordinates.add(new MCoordinate(coords[2], coords[3], Double.NaN, mValue)); |
108 |
coordinates.add(new MCoordinate(coords[4], coords[5], Double.NaN, mValue)); |
109 |
break;
|
110 |
case PathIterator.SEG_CLOSE: |
111 |
if(!coordinates.isEmpty() && !coordinates.get(0).equals(coordinates.get(coordinates.size()-1))){ |
112 |
coordinates.add((Coordinate) coordinates.get(0).clone());
|
113 |
} |
114 |
break;
|
115 |
} |
116 |
pi.next(); |
117 |
} |
118 |
return coordinates;
|
119 |
} |
120 |
|
121 |
|
122 |
/* (non-Javadoc)
|
123 |
* @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
124 |
*/
|
125 |
public MultiPoint toPoints() throws GeometryException { |
126 |
MultiPoint multiPoint = new MultiPoint2DM();
|
127 |
Coordinate[] coordinates = getJTS().getCoordinates();
|
128 |
multiPoint.ensureCapacity(coordinates.length); |
129 |
for (int i = 0; i < coordinates.length; i++) { |
130 |
multiPoint.addPoint(new Point2DM(this.getProjection(), coordinates[i])); |
131 |
} |
132 |
return multiPoint;
|
133 |
} |
134 |
|
135 |
/* (non-Javadoc)
|
136 |
* @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
137 |
*/
|
138 |
public MultiLine toLines() throws GeometryException { |
139 |
MultiLine multiLine = new MultiLine2DM();
|
140 |
Line line = new Line2DM(getJTS().getCoordinates()); |
141 |
multiLine.addPrimitive(line); |
142 |
return multiLine;
|
143 |
} |
144 |
|
145 |
/* (non-Javadoc)
|
146 |
* @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
147 |
*/
|
148 |
public MultiPolygon toPolygons() throws GeometryException { |
149 |
MultiPolygon multiPolygon = new MultiPolygon2DM();
|
150 |
Polygon polygon = new Polygon2DM(getJTS().getCoordinates()); |
151 |
multiPolygon.addPrimitive(polygon); |
152 |
return multiPolygon;
|
153 |
} |
154 |
|
155 |
|
156 |
|
157 |
} |