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 @ 42283

History | View | Annotate | Download (5.37 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.Line2D;
37
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D;
38
import org.gvsig.fmap.geom.operation.GeometryOperationException;
39
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
40
import org.gvsig.fmap.geom.primitive.GeneralPathX;
41
import org.gvsig.fmap.geom.primitive.Line;
42
import org.gvsig.fmap.geom.primitive.Polygon;
43
import org.gvsig.fmap.geom.primitive.Primitive;
44

    
45

    
46
/**
47
 * @author fdiaz
48
 *
49
 */
50
public class MultiLine3D extends AbstractMultiLine {
51

    
52
    /**
53
     *
54
     */
55
    private static final long serialVersionUID = 4864883331083875719L;
56

    
57
    /**
58
     * @param type
59
     * @param subtype
60
     */
61
    public MultiLine3D() {
62
        super(Geometry.SUBTYPES.GEOM2D);
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 MultiPoint3D();
70
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
71
            Line3D line = (Line3D) 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 MultiPolygon3D();
93
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
94
            Line3D line = (Line3D) 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
        MultiLine3D clone = new MultiLine3D();
109
        return clonePrimitives(clone);
110

    
111
    }
112

    
113

    
114
    /* (non-Javadoc)
115
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
116
     */
117
    public int getDimension() {
118
        return 3;
119
    }
120

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

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

    
137
    /* (non-Javadoc)
138
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
139
     */
140
    public boolean is3D() {
141
        return true;
142
    }
143

    
144

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

    
154
        if(primitive.getGeometryType().getSubType() == Geometry.SUBTYPES.GEOM3D){
155
            try {
156
                return primitive.toLines();
157
            } catch (GeometryException e) {
158
                String message = "Can't convert primitive to lines";
159
                logger.warn(message);
160
                throw new RuntimeException(message);
161
            }
162
        }
163

    
164
        String message = "Only 3D primitives can be fixed to MultiLine3D";
165
        notifyDeprecated(message);
166
        throw new UnsupportedOperationException(message);
167
    }
168
}