Statistics
| Revision:

gvsig-gazetteer / org.gvsig.gazetteer / trunk / org.gvsig.gazetteer / org.gvsig.gazetteer.lib / src / main / java / org / gvsig / gazetteer / utils / GazetteerGeometriesFactory.java @ 103

History | View | Annotate | Download (4.34 KB)

1
package org.gvsig.gazetteer.utils;
2

    
3
import java.awt.geom.Point2D;
4
import java.util.ArrayList;
5
import java.util.Map;
6

    
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9
import org.gvsig.fmap.geom.primitive.Point;
10
import org.gvsig.gazetteer.querys.Feature;
11
import org.gvsig.xmlschema.lib.api.som.IXSTypeDefinition;
12

    
13

    
14
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
15
 *
16
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
17
 *
18
 * This program is free software; you can redistribute it and/or
19
 * modify it under the terms of the GNU General Public License
20
 * as published by the Free Software Foundation; either version 2
21
 * of the License, or (at your option) any later version.
22
 *
23
 * This program is distributed in the hope that it will be useful,
24
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 * GNU General Public License for more details.
27
 *
28
 * You should have received a copy of the GNU General Public License
29
 * along with this program; if not, write to the Free Software
30
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
31
 *
32
 * For more information, contact:
33
 *
34
 *  Generalitat Valenciana
35
 *   Conselleria d'Infraestructures i Transport
36
 *   Av. Blasco Ib??ez, 50
37
 *   46010 VALENCIA
38
 *   SPAIN
39
 *
40
 *      +34 963862235
41
 *   gvsig@gva.es
42
 *      www.gvsig.gva.es
43
 *
44
 *    or
45
 *
46
 *   IVER T.I. S.A
47
 *   Salamanca 50
48
 *   46005 Valencia
49
 *   Spain
50
 *
51
 *   +34 963163400
52
 *   dac@iver.es
53
 */
54
/* CVS MESSAGES:
55
 *
56
 * $Id: GazetteerGeometriesFactory.java 572 2007-07-27 12:40:11 +0000 (Fri, 27 Jul 2007) jpiera $
57
 * $Log$
58
 * Revision 1.1.2.2  2007/07/13 12:00:35  jorpiell
59
 * Add the posibility to add a new panel
60
 *
61
 * Revision 1.1.2.1  2007/07/10 11:18:04  jorpiell
62
 * Added the registers
63
 *
64
 *
65
 */
66
/**
67
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
68
 */
69
public class GazetteerGeometriesFactory {
70
        private static final Logger logger = LoggerFactory.getLogger(GazetteerGeometriesFactory.class);
71
        private String attName = null;
72

    
73
        public GazetteerGeometriesFactory(String attName) {
74
                super();
75
                this.attName = attName;
76
        }
77

    
78
        /*
79
        public Object createGeometry(String gmlGeometry) {
80
                GMLReader reader = new GMLReader();
81
                try {
82
                        Geometry geom = reader.read(gmlGeometry,new GeometryFactory());
83
                        Point point = geom.getInterior Point();
84
                        return new Point2D.Double(point.getX(),point.getY());
85
                }  catch (Exception e){
86
                        logger.error("Can't parse: " + gmlGeometry,e);
87
                }
88
                return null;
89
        }
90
        */
91

    
92
        /*
93
         * (non-Javadoc)
94
         * @see org.gvsig.remoteClient.gml.factories.IGeometriesFactory#createMultipoint2D(double[], double[])
95
         */
96
        public Object createMultipoint2D(double[] x, double[] y) {
97
                double xTotal = 0;
98
                double yTotal = 0;
99
                for (int i=0 ; i<x.length ; i++){
100
                        xTotal = xTotal + x[i];
101
                        yTotal = yTotal + y[i];
102
                }
103
                if (x.length > 0){
104
                        return new Point2D.Double(xTotal/x.length,
105
                                        yTotal/y.length);
106
                }
107
                return new Point2D.Double(0,
108
                                0);
109
        }
110

    
111
        /*
112
         * (non-Javadoc)
113
         * @see org.gvsig.remoteClient.gml.factories.IGeometriesFactory#createPoint2D(java.awt.geom.Point2D)
114
         */
115
        public Object createPoint2D(Point2D point) {
116
                return point;
117
        }
118

    
119
        /*
120
         * (non-Javadoc)
121
         * @see org.gvsig.remoteClient.gml.factories.IGeometriesFactory#createPoint2D(double, double)
122
         */
123
        public Object createPoint2D(double x, double y) {
124
                return new Point2D.Double(x,y);
125
        }
126

    
127
        /*
128
         * (non-Javadoc)
129
         * @see org.gvsig.remoteClient.gml.factories.IGeometriesFactory#createSimpleFeature(java.lang.String, org.gvsig.remoteClient.gml.types.IXMLType, java.util.Map, java.lang.Object)
130
         */
131
        public Object createSimpleFeature(String element, IXSTypeDefinition type,Map values,Object geometry) {
132
                String sGeoname = element;
133
                if (attName != null){
134
                        if (values.get(attName) != null){
135
                                ArrayList array = (ArrayList)values.get(attName);
136
                                if (array.size() > 0){
137
                                        sGeoname = (String)array.get(0);
138
                                }
139
                        }
140
                }
141
                return new Feature(null,
142
                                sGeoname,
143
                                sGeoname,
144
                                (Point)geometry);
145
        }
146

    
147
        /*
148
         * (non-Javadoc)
149
         * @see org.gvsig.remoteClient.gml.factories.IGeometriesFactory#createPolygon2D(double[], double[])
150
         */
151
        public Object createPolygon2D(double[] x, double[] y) {
152
                double avX = 0;
153
                double avY = 0;
154
                for (int i=0 ; i<x.length ; i++){
155
                        avX = avX + x[i];
156
                        avY = avY + y[i];
157
                }
158
                if (x.length > 0){
159
                        avX = avX/x.length;
160
                        avY = avY/y.length;
161
                }
162
                return new Point2D.Double(avX, avY);
163
        }
164
}