Statistics
| Revision:

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 / MultiLine3D.java @ 45425

History | View | Annotate | Download (6.09 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.util.Iterator;
28

    
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.GeometryException;
31
import org.gvsig.fmap.geom.aggregate.MultiLine;
32
import org.gvsig.fmap.geom.aggregate.MultiPoint;
33
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
34
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2D;
35
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D;
36
import org.gvsig.fmap.geom.operation.GeometryOperationException;
37
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
38
import org.gvsig.fmap.geom.primitive.Polygon;
39
import org.gvsig.fmap.geom.primitive.Primitive;
40

    
41

    
42
/**
43
 * @author fdiaz
44
 *
45
 */
46
public class MultiLine3D extends AbstractMultiLine {
47

    
48
    /**
49
     *
50
     */
51
    private static final long serialVersionUID = 4864883331083875719L;
52

    
53
    /**
54
     * @param type
55
     * @param subtype
56
     */
57
    public MultiLine3D() {
58
        super(Geometry.SUBTYPES.GEOM2D);
59
    }
60

    
61
    /* (non-Javadoc)
62
     * @see org.gvsig.fmap.geom.aggregate.MultiLine#toPoints()
63
     */
64
    public MultiPoint toPoints() throws GeometryException {
65
        MultiPoint multiPoint = new MultiPoint3D();
66
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
67
            Line3D line = (Line3D) iterator.next();
68
            MultiPoint points = line.toPoints();
69
            multiPoint.ensureCapacity(multiPoint.getPrimitivesNumber()+points.getPrimitivesNumber());
70
            for(int i=0; i<points.getPrimitivesNumber(); i++){
71
                multiPoint.addPoint(points.getPointAt(i));
72
            }
73
        }
74
        return multiPoint;
75
    }
76

    
77
    /* (non-Javadoc)
78
     * @see org.gvsig.fmap.geom.aggregate.MultiLine#toLines()
79
     */
80
    public MultiLine toLines() throws GeometryException {
81
        return this;
82
    }
83

    
84
    /* (non-Javadoc)
85
     * @see org.gvsig.fmap.geom.aggregate.MultiLine#toPolygons()
86
     */
87
    public MultiPolygon toPolygons() throws GeometryException {
88
        MultiPolygon multiPolygon = new MultiPolygon3D();
89
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
90
            Line3D line = (Line3D) iterator.next();
91
            MultiPolygon polygons = line.toPolygons();
92
            multiPolygon.ensureCapacity(multiPolygon.getPrimitivesNumber()+polygons.getPrimitivesNumber());
93
            for(int i=0; i<polygons.getPrimitivesNumber(); i++){
94
                multiPolygon.addSurface((Polygon)polygons.getPrimitiveAt(i));
95
            }
96
        }
97
        return multiPolygon;
98
    }
99

    
100
    /* (non-Javadoc)
101
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
102
     */
103
    public Geometry cloneGeometry() {
104
        MultiLine3D clone = new MultiLine3D();
105
        return clonePrimitives(clone);
106

    
107
    }
108

    
109

    
110
    /* (non-Javadoc)
111
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
112
     */
113
    public int getDimension() {
114
        return 3;
115
    }
116

    
117
    /* (non-Javadoc)
118
     * @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
119
     */
120
    public Shape getShape(AffineTransform affineTransform) {
121
        // TODO Auto-generated method stub
122
        return null;
123
    }
124

    
125
    /* (non-Javadoc)
126
     * @see org.gvsig.fmap.geom.Geometry#getShape()
127
     */
128
    public Shape getShape() {
129
        // TODO Auto-generated method stub
130
        return null;
131
    }
132

    
133
    /* (non-Javadoc)
134
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
135
     */
136
    public boolean is3D() {
137
        return true;
138
    }
139

    
140

    
141
    /* (non-Javadoc)
142
     * @see org.gvsig.fmap.geom.jts.aggregate.AbstractMultiLine#fixLine(org.gvsig.fmap.geom.primitive.Line)
143
     */
144
    @Override
145
    protected Geometry fixPrimitive(Primitive primitive) {
146
        if(primitive instanceof Line3D){
147
            return primitive;
148
        }
149

    
150
        if(primitive.getGeometryType().getSubType() == Geometry.SUBTYPES.GEOM3D){
151
            try {
152
                return primitive.toLines();
153
            } catch (GeometryException e) {
154
                String message = "Can't convert primitive to lines";
155
                LOGGER.warn(message);
156
                throw new RuntimeException(message);
157
            }
158
        }
159

    
160
        String message = "Only 3D primitives can be fixed to MultiLine3D";
161
        notifyDeprecated(message);
162
        throw new UnsupportedOperationException(message);
163
    }
164

    
165
    /* (non-Javadoc)
166
     * @see org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform)
167
     */
168
    public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
169
        MultiLine3D result = new MultiLine3D();
170
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
171
            Primitive primitive = (Primitive) iterator.next();
172
            Geometry offset = primitive.offset(distance);
173
            if(offset instanceof MultiLine){
174
                MultiLine multiOffset = (MultiLine)offset;
175
                for(int i=0; i<multiOffset.getPrimitivesNumber(); i++){
176
                    result.addPrimitive(multiOffset.getPrimitiveAt(i));
177
                }
178
            } else {
179
                result.addPrimitive((Primitive)primitive.offset(distance));
180
            }
181
        }
182
        return result;
183
    }
184
}