Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.operation / src / main / java / org / gvsig / fmap / geom / operation / tojts / BaseMultiPrimitiveToJTS.java @ 40767

History | View | Annotate | Download (2.83 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
 
25
package org.gvsig.fmap.geom.operation.tojts;
26

    
27
import java.util.ArrayList;
28
import java.util.List;
29

    
30
import com.vividsolutions.jts.geom.MultiPolygon;
31
import com.vividsolutions.jts.geom.Polygon;
32

    
33
import org.slf4j.Logger;
34
import org.slf4j.LoggerFactory;
35

    
36
import org.gvsig.fmap.geom.Geometry;
37
import org.gvsig.fmap.geom.aggregate.MultiSurface;
38
import org.gvsig.fmap.geom.aggregate.impl.BaseMultiPrimitive;
39
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
40
import org.gvsig.fmap.geom.operation.GeometryOperationException;
41
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
42

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

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

    
76
                        } catch (GeometryOperationNotSupportedException e) {
77
                                throw new GeometryOperationException(e);
78
                        }
79
        }
80
        acum.setSRID(srid);
81
        return acum;
82
        }        
83
}