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