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