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 / aggregate / MultiLine2DM.java @ 42278
History | View | Annotate | Download (4.97 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.aggregate; |
24 |
|
25 |
import java.awt.Shape; |
26 |
import java.awt.geom.AffineTransform; |
27 |
import java.awt.geom.PathIterator; |
28 |
import java.util.Iterator; |
29 |
|
30 |
import org.gvsig.fmap.geom.Geometry; |
31 |
import org.gvsig.fmap.geom.GeometryException; |
32 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
33 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
34 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
35 |
import org.gvsig.fmap.geom.handler.Handler; |
36 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2DM; |
37 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
38 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
39 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
40 |
import org.gvsig.fmap.geom.primitive.Line; |
41 |
import org.gvsig.fmap.geom.primitive.Polygon; |
42 |
import org.gvsig.fmap.geom.primitive.Primitive; |
43 |
|
44 |
|
45 |
/**
|
46 |
* @author fdiaz
|
47 |
*
|
48 |
*/
|
49 |
public class MultiLine2DM extends AbstractMultiLine { |
50 |
|
51 |
|
52 |
/**
|
53 |
*
|
54 |
*/
|
55 |
private static final long serialVersionUID = 7970383739561430594L; |
56 |
|
57 |
/**
|
58 |
* @param type
|
59 |
* @param subtype
|
60 |
*/
|
61 |
public MultiLine2DM() {
|
62 |
super(Geometry.SUBTYPES.GEOM2DM);
|
63 |
} |
64 |
|
65 |
/* (non-Javadoc)
|
66 |
* @see org.gvsig.fmap.geom.aggregate.MultiLine#toPoints()
|
67 |
*/
|
68 |
public MultiPoint toPoints() throws GeometryException { |
69 |
MultiPoint multiPoint = new MultiPoint2DM();
|
70 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
71 |
Line2DM line = (Line2DM) iterator.next(); |
72 |
MultiPoint points = line.toPoints(); |
73 |
multiPoint.ensureCapacity(multiPoint.getPrimitivesNumber()+points.getPrimitivesNumber()); |
74 |
for(int i=0; i<points.getPrimitivesNumber(); i++){ |
75 |
multiPoint.addPoint(points.getPointAt(i)); |
76 |
} |
77 |
} |
78 |
return multiPoint;
|
79 |
} |
80 |
|
81 |
/* (non-Javadoc)
|
82 |
* @see org.gvsig.fmap.geom.aggregate.MultiLine#toLines()
|
83 |
*/
|
84 |
public MultiLine toLines() throws GeometryException { |
85 |
return this; |
86 |
} |
87 |
|
88 |
/* (non-Javadoc)
|
89 |
* @see org.gvsig.fmap.geom.aggregate.MultiLine#toPolygons()
|
90 |
*/
|
91 |
public MultiPolygon toPolygons() throws GeometryException { |
92 |
MultiPolygon multiPolygon = new MultiPolygon2DM();
|
93 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
94 |
Line2DM line = (Line2DM) iterator.next(); |
95 |
MultiPolygon polygons = line.toPolygons(); |
96 |
multiPolygon.ensureCapacity(multiPolygon.getPrimitivesNumber()+polygons.getPrimitivesNumber()); |
97 |
for(int i=0; i<polygons.getPrimitivesNumber(); i++){ |
98 |
multiPolygon.addSurface((Polygon)polygons.getPrimitiveAt(i));
|
99 |
} |
100 |
} |
101 |
return multiPolygon;
|
102 |
} |
103 |
|
104 |
/* (non-Javadoc)
|
105 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
106 |
*/
|
107 |
public Geometry cloneGeometry() {
|
108 |
MultiLine2DM clone = new MultiLine2DM();
|
109 |
return clonePrimitives(clone);
|
110 |
} |
111 |
|
112 |
/* (non-Javadoc)
|
113 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
114 |
*/
|
115 |
public int getDimension() { |
116 |
return 3; |
117 |
} |
118 |
|
119 |
/* (non-Javadoc)
|
120 |
* @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
|
121 |
*/
|
122 |
public Shape getShape(AffineTransform affineTransform) { |
123 |
// TODO Auto-generated method stub
|
124 |
return null; |
125 |
} |
126 |
|
127 |
/* (non-Javadoc)
|
128 |
* @see org.gvsig.fmap.geom.Geometry#getShape()
|
129 |
*/
|
130 |
public Shape getShape() { |
131 |
// TODO Auto-generated method stub
|
132 |
return null; |
133 |
} |
134 |
|
135 |
/* (non-Javadoc)
|
136 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
|
137 |
*/
|
138 |
public boolean is3D() { |
139 |
return false; |
140 |
} |
141 |
|
142 |
/* (non-Javadoc)
|
143 |
* @see org.gvsig.fmap.geom.jts.aggregate.AbstractMultiLine#fixLine(org.gvsig.fmap.geom.primitive.Line)
|
144 |
*/
|
145 |
@Override
|
146 |
protected Primitive fixPrimitive(Primitive curve) {
|
147 |
if(!(curve instanceof Line2DM)){ |
148 |
String message = "Only Line2DM primitives can be added to a MultiLine2DM"; |
149 |
notifyDeprecated(message); |
150 |
throw new UnsupportedOperationException(message); |
151 |
} |
152 |
return curve;
|
153 |
} |
154 |
} |