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 / MultiPolygon2DM.java @ 42441

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

    
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.fmap.geom.GeometryException;
29
import org.gvsig.fmap.geom.aggregate.MultiLine;
30
import org.gvsig.fmap.geom.aggregate.MultiPoint;
31
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
32
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
33
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2D;
34
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2D;
35
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2DM;
36
import org.gvsig.fmap.geom.jts.util.JTSUtils;
37
import org.gvsig.fmap.geom.operation.GeometryOperationException;
38
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
39
import org.gvsig.fmap.geom.primitive.Primitive;
40

    
41

    
42
/**
43
 * @author fdiaz
44
 *
45
 */
46
public class MultiPolygon2DM extends AbstractMultiPolygon {
47

    
48

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

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

    
61
    /* (non-Javadoc)
62
     * @see org.gvsig.fmap.geom.aggregate.MultiPolygon#toPoints()
63
     */
64
    public MultiPoint toPoints() throws GeometryException {
65
        MultiPoint multiPoint = new MultiPoint2DM();
66
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
67
            Polygon2DM polygon = (Polygon2DM) iterator.next();
68
            MultiPoint points = polygon.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.MultiPolygon#toLines()
79
     */
80
    public MultiLine toLines() throws GeometryException {
81
        MultiLine multiLine = new MultiLine2D();
82
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
83
            Polygon2D polygon = (Polygon2D) iterator.next();
84
            MultiLine lines = polygon.toLines();
85
            multiLine.ensureCapacity(multiLine.getPrimitivesNumber()+lines.getPrimitivesNumber());
86
            for(int i=0; i<lines.getPrimitivesNumber(); i++){
87
                multiLine.addPrimitive((Line2D)lines.getPrimitiveAt(i));
88
            }
89
        }
90
        return multiLine;
91
    }
92

    
93
    /* (non-Javadoc)
94
     * @see org.gvsig.fmap.geom.aggregate.MultiPolygon#toPolygons()
95
     */
96
    public MultiPolygon toPolygons() throws GeometryException {
97
        return this;
98
    }
99

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

    
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.jts.aggregate.AbstractMultiPrimitive#fixPrimitive(org.gvsig.fmap.geom.primitive.Primitive)
118
     */
119
    @Override
120
    protected Geometry fixPrimitive(Primitive primitive) {
121
        if(primitive instanceof Polygon2DM){
122
            return primitive;
123
        }
124

    
125
        if(primitive.getGeometryType().getSubType() == Geometry.SUBTYPES.GEOM2DM){
126
            MultiPolygon polygons;
127
            try {
128
                polygons = primitive.toPolygons();
129
            } catch (GeometryException e) {
130
                String message = "Can't convert primitive to polygons";
131
                logger.warn(message);
132
                throw new RuntimeException(message);
133
            }
134
            return polygons;
135
        }
136

    
137
        String message = "Only 2DM primitives can be fixed to MultiPolygon2DM";
138
        notifyDeprecated(message);
139
        throw new UnsupportedOperationException(message);
140
    }
141

    
142

    
143
    /* (non-Javadoc)
144
     * @see org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform)
145
     */
146
    public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
147
        return JTSUtils.createGeometry(getJTS().buffer(distance));
148
    }
149
}