Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGPE-gvSIG / src / org / gvsig / fmap / drivers / gpe / model / GPEMultiGeometry.java @ 27067

History | View | Annotate | Download (3.62 KB)

1
package org.gvsig.fmap.drivers.gpe.model;
2

    
3
import java.awt.geom.PathIterator;
4
import java.awt.geom.Rectangle2D;
5
import java.util.ArrayList;
6

    
7
import com.iver.cit.gvsig.fmap.core.FShape;
8
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
9
import com.iver.cit.gvsig.fmap.core.IGeometry;
10
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
11

    
12
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
13
 *
14
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
29
 *
30
 * For more information, contact:
31
 *
32
 *  Generalitat Valenciana
33
 *   Conselleria d'Infraestructures i Transport
34
 *   Av. Blasco Ib??ez, 50
35
 *   46010 VALENCIA
36
 *   SPAIN
37
 *
38
 *      +34 963862235
39
 *   gvsig@gva.es
40
 *      www.gvsig.gva.es
41
 *
42
 *    or
43
 *
44
 *   IVER T.I. S.A
45
 *   Salamanca 50
46
 *   46005 Valencia
47
 *   Spain
48
 *
49
 *   +34 963163400
50
 *   dac@iver.es
51
 */
52
/* CVS MESSAGES:
53
 *
54
 * $Id$
55
 * $Log$
56
 *
57
 */
58
/**
59
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
60
 */
61
public class GPEMultiGeometry extends GPEGeometry{
62
        protected IGeometry geometry = null;
63
        protected ArrayList geometries = null;
64
        protected Rectangle2D bounds = null;
65
        
66
        public  GPEMultiGeometry(String id, String srs) {
67
                super(id, null, srs);
68
                geometries = new ArrayList();                
69
        }
70
        
71
        /*
72
         * (non-Javadoc)
73
         * @see com.iver.cit.gvsig.fmap.drivers.gpe.model.GPEGeometry#getGeometry()
74
         */
75
        public IGeometry getIGeometry() {
76
                if (geometry == null){
77
                        geometry = ShapeFactory.createPolygon2D(createGeneralXPath());
78
                }
79
                return geometry;
80
        }
81
        
82
        /**
83
         * Create the general X path
84
         * @return
85
         */
86
        protected GeneralPathX createGeneralXPath(){
87
                GeneralPathX gp = new GeneralPathX();
88
                for (int i=0 ; i<geometries.size() ; i++){
89
                        IGeometry geom =((GPEGeometry)geometries.get(i)).getIGeometry();
90
                        FShape shape = (FShape)geom.getInternalShape();
91
                        PathIterator it = shape.getPathIterator(null);
92
                        int theType;
93
                        double[] theData = new double[6];                        
94
                        while (!it.isDone()){
95
                                theType = it.currentSegment(theData);
96
                                switch (theType) {
97
                                case PathIterator.SEG_MOVETO:
98
                                        gp.moveTo(theData[0], theData[1]);                        
99
                                        break;
100
                                case PathIterator.SEG_LINETO:
101
                                        gp.lineTo(theData[0], theData[1]);                
102
                                        break;
103
                                case PathIterator.SEG_CLOSE:        
104
                                        break;
105
                                }
106
                                it.next();
107
                        }
108
                }
109
                return gp;
110
        }
111
        
112
        /**
113
         * Gets one geometry
114
         * @param i
115
         * Geometry position
116
         * @return
117
         * A Geometry
118
         */
119
        public GPEGeometry getGeometryAt(int i){
120
                return (GPEGeometry)geometries.get(i);
121
        }
122
        
123
        /**
124
         * @return the number of geometries
125
         */
126
        public int getGeometriesSize(){
127
                return geometries.size();
128
        }
129
        
130
        /**
131
         * Adds a new geometry
132
         * @param geometry
133
         * The geometry to add
134
         */
135
        public void addGeometry(GPEGeometry geometry){
136
                if (bounds == null){
137
                        bounds = geometry.getShapeBounds();
138
                }else{
139
                        bounds.add(geometry.getShapeBounds());
140
                }
141
                geometries.add(geometry);
142
        }
143
        
144
        /*
145
         * (non-Javadoc)
146
         * @see com.iver.cit.gvsig.fmap.drivers.gpe.model.GPEGeometry#getShapeBounds()
147
         */
148
        public Rectangle2D getShapeBounds() {
149
                return bounds;
150
        }
151
}