Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2058 / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / operation / tojts / BaseMultiPrimitiveToJTS.java @ 39246

History | View | Annotate | Download (2.83 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.operation.tojts;
29

    
30
import java.util.ArrayList;
31
import java.util.List;
32

    
33
import com.vividsolutions.jts.geom.MultiPolygon;
34
import com.vividsolutions.jts.geom.Polygon;
35

    
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38

    
39
import org.gvsig.fmap.geom.Geometry;
40
import org.gvsig.fmap.geom.aggregate.MultiSurface;
41
import org.gvsig.fmap.geom.aggregate.impl.BaseMultiPrimitive;
42
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
43
import org.gvsig.fmap.geom.operation.GeometryOperationException;
44
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
45

    
46
/**
47
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
48
 */
49
public class BaseMultiPrimitiveToJTS  extends ToJTS{
50
    
51
    private static Logger logger = LoggerFactory.getLogger(BaseMultiPrimitiveToJTS.class);
52
        /*
53
         * (non-Javadoc)
54
         * @see org.gvsig.fmap.geom.operation.tojts.ToJTS#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.geom.operation.GeometryOperationContext)
55
         */
56
        public Object invoke(Geometry geom, GeometryOperationContext ctx) throws GeometryOperationException {
57
                int srid = -1;
58
                if (ctx != null){
59
                        srid = ((JTSGeometryOperationContext)ctx).getSrid();
60
                }
61
                
62
                BaseMultiPrimitive mp = (BaseMultiPrimitive) geom;
63
                int prim_n = mp.getPrimitivesNumber();
64
                
65
        com.vividsolutions.jts.geom.Geometry item = null;
66
        com.vividsolutions.jts.geom.Geometry acum = null;
67

    
68
        for (int i = 0; i < prim_n; i++){
69
                try {
70
                    item = (com.vividsolutions.jts.geom.Geometry)
71
                        mp.getPrimitiveAt(i).invokeOperation(CODE, ctx);
72
                    item.setSRID(srid);
73
                    if (acum == null) {
74
                        acum = item;
75
                    } else {
76
                        acum = acum.union(item);
77
                    }
78

    
79
                        } catch (GeometryOperationNotSupportedException e) {
80
                                throw new GeometryOperationException(e);
81
                        }
82
        }
83
        acum.setSRID(srid);
84
        return acum;
85
        }        
86
}