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

History | View | Annotate | Download (6.11 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.Line2DM;
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 MultiLine2DM extends AbstractMultiLine {
47

    
48

    
49
    /**
50
     *
51
     */
52
    private static final long serialVersionUID = 7970383739561430594L;
53

    
54
    /**
55
     * @param type
56
     * @param subtype
57
     */
58
    public MultiLine2DM() {
59
        super(Geometry.SUBTYPES.GEOM2DM);
60
    }
61

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

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

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

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

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

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

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

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

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

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

    
158
        String message = "Only 2D primitives can be fixed to MultiLine2DM";
159
        notifyDeprecated(message);
160
        throw new UnsupportedOperationException(message);
161
    }
162

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