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