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 / curve / line / BaseLine2DM.java @ 42357
History | View | Annotate | Download (5.94 KB)
1 | 42260 | fdiaz | /* 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.curve.line; |
||
24 | |||
25 | 42283 | fdiaz | import java.util.ArrayList; |
26 | 42269 | fdiaz | import java.util.Iterator; |
27 | |||
28 | 42260 | fdiaz | import com.vividsolutions.jts.geom.Coordinate; |
29 | 42267 | fdiaz | import com.vividsolutions.jts.geom.CoordinateSequence; |
30 | 42260 | fdiaz | |
31 | import org.gvsig.fmap.geom.Geometry; |
||
32 | 42269 | fdiaz | import org.gvsig.fmap.geom.GeometryException; |
33 | import org.gvsig.fmap.geom.aggregate.MultiLine; |
||
34 | import org.gvsig.fmap.geom.aggregate.MultiPoint; |
||
35 | import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
||
36 | import org.gvsig.fmap.geom.jts.aggregate.MultiLine2DM; |
||
37 | import org.gvsig.fmap.geom.jts.aggregate.MultiPoint2DM; |
||
38 | import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon2DM; |
||
39 | 42260 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.point.Point2DM; |
40 | 42269 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2DM; |
41 | 42267 | fdiaz | import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
42 | import org.gvsig.fmap.geom.jts.util.ReadOnlyCoordinates; |
||
43 | 42260 | fdiaz | import org.gvsig.fmap.geom.primitive.Point; |
44 | |||
45 | |||
46 | |||
47 | /**
|
||
48 | * @author fdiaz
|
||
49 | *
|
||
50 | */
|
||
51 | 42270 | fdiaz | public abstract class BaseLine2DM extends AbstractLine { |
52 | 42260 | fdiaz | |
53 | /**
|
||
54 | *
|
||
55 | */
|
||
56 | private static final long serialVersionUID = -2009183729409385543L; |
||
57 | |||
58 | /**
|
||
59 | 42283 | fdiaz | * @param polygon
|
60 | */
|
||
61 | public BaseLine2DM(int type) { |
||
62 | super(type, Geometry.SUBTYPES.GEOM2DM);
|
||
63 | this.coordinates = new ArrayListCoordinateSequence(new ArrayList<Coordinate>()); |
||
64 | } |
||
65 | |||
66 | /**
|
||
67 | 42304 | fdiaz | * @param polygon
|
68 | * @param coordinates
|
||
69 | */
|
||
70 | public BaseLine2DM(int type, Coordinate[] coordinates) { |
||
71 | super(type, Geometry.SUBTYPES.GEOM2DM);
|
||
72 | initializeCoordinates(coordinates); |
||
73 | } |
||
74 | |||
75 | |||
76 | /**
|
||
77 | * @param coordinates
|
||
78 | */
|
||
79 | private void initializeCoordinates(Coordinate[] coordinates) { |
||
80 | 42260 | fdiaz | this.coordinates = new ArrayListCoordinateSequence(new ReadOnlyCoordinates(coordinates)); |
81 | 42267 | fdiaz | if(coordinates.length<1){ |
82 | anyVertex = new Point2DM(0,0,0); |
||
83 | } else {
|
||
84 | anyVertex = new Point2DM(coordinates[0].x, coordinates[0].y, coordinates[0].getOrdinate(CoordinateSequence.M)); |
||
85 | } |
||
86 | 42260 | fdiaz | } |
87 | |||
88 | 42304 | fdiaz | |
89 | |||
90 | 42260 | fdiaz | /* (non-Javadoc)
|
91 | * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double)
|
||
92 | */
|
||
93 | public void addVertex(double x, double y) { |
||
94 | 42309 | fdiaz | this.addVertex(new Point2DM(x, y, 0)); |
95 | 42267 | fdiaz | } |
96 | 42260 | fdiaz | |
97 | /* (non-Javadoc)
|
||
98 | * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double, double)
|
||
99 | */
|
||
100 | public void addVertex(double x, double y, double z) { |
||
101 | 42267 | fdiaz | String message = "Can't add x,y,z coordinate to Polygon2DM."; |
102 | notifyDeprecated(message); |
||
103 | throw new UnsupportedOperationException(message); |
||
104 | } |
||
105 | 42260 | fdiaz | |
106 | |||
107 | /* (non-Javadoc)
|
||
108 | * @see org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org.gvsig.fmap.geom.primitive.Point)
|
||
109 | */
|
||
110 | @Override
|
||
111 | protected Point fixPoint(Point point) { |
||
112 | if (point instanceof Point2DM) { |
||
113 | return point;
|
||
114 | } else {
|
||
115 | return new Point2DM(point.getX(), point.getY(), 0); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | 42269 | fdiaz | /* (non-Javadoc)
|
120 | * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
||
121 | */
|
||
122 | public MultiPoint toPoints() throws GeometryException { |
||
123 | MultiPoint multiPoint = new MultiPoint2DM();
|
||
124 | 42271 | fdiaz | multiPoint.ensureCapacity(coordinates.size()); |
125 | for (Iterator<Coordinate> iterator = coordinates.iterator(); iterator.hasNext();) { |
||
126 | 42269 | fdiaz | Coordinate coordinate = (Coordinate) iterator.next(); |
127 | multiPoint.addPoint(new Point2DM(coordinate));
|
||
128 | } |
||
129 | return multiPoint;
|
||
130 | } |
||
131 | |||
132 | /* (non-Javadoc)
|
||
133 | * @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
||
134 | */
|
||
135 | public MultiLine toLines() throws GeometryException { |
||
136 | MultiLine multiLine = new MultiLine2DM();
|
||
137 | multiLine.addPrimitive(this);
|
||
138 | return multiLine;
|
||
139 | } |
||
140 | |||
141 | /* (non-Javadoc)
|
||
142 | * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
||
143 | */
|
||
144 | public MultiPolygon toPolygons() throws GeometryException { |
||
145 | MultiPolygon multiPolygon = new MultiPolygon2DM();
|
||
146 | Polygon2DM polygon = new Polygon2DM(coordinates.toCoordinateArray());
|
||
147 | multiPolygon.addPrimitive(polygon); |
||
148 | return multiPolygon;
|
||
149 | } |
||
150 | |||
151 | 42283 | fdiaz | |
152 | /* (non-Javadoc)
|
||
153 | * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getVertex(int)
|
||
154 | */
|
||
155 | public Point getVertex(int index) { |
||
156 | Point2DM vertex = new Point2DM(this.coordinates.get(index)); |
||
157 | anyVertex = vertex; |
||
158 | return vertex;
|
||
159 | } |
||
160 | |||
161 | 42322 | fdiaz | /* (non-Javadoc)
|
162 | * @see org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#getCoordinateAt(int, int)
|
||
163 | */
|
||
164 | @Override
|
||
165 | public double getCoordinateAt(int index, int dimension) { |
||
166 | if (dimension == 2) { |
||
167 | return super.getCoordinateAt(index, CoordinateSequence.M); |
||
168 | } |
||
169 | return super.getCoordinateAt(index, dimension); |
||
170 | } |
||
171 | |||
172 | /* (non-Javadoc)
|
||
173 | * @see org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#setCoordinateAt(int, int, double)
|
||
174 | */
|
||
175 | @Override
|
||
176 | public void setCoordinateAt(int index, int dimension, double value) { |
||
177 | if (dimension == 2) { |
||
178 | super.setCoordinateAt(index, CoordinateSequence.M, value);
|
||
179 | 42325 | fdiaz | return;
|
180 | 42322 | fdiaz | } |
181 | super.setCoordinateAt(index, dimension, value);
|
||
182 | } |
||
183 | 42260 | fdiaz | } |