Statistics
| Revision:

root / branches / v10 / libraries / libArcIMS / src / org / gvsig / remoteClient / arcims / ArcXMLImage.java @ 20977

History | View | Annotate | Download (10.5 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Prodevelop Integraci?n de Tecnolog?as SL
34
 *   Conde Salvatierra de ?lava , 34-10
35
 *   46004 Valencia
36
 *   Spain
37
 *
38
 *   +34 963 510 612
39
 *   +34 963 510 968
40
 *   gis@prodevelop.es
41
 *   http://www.prodevelop.es
42
 */
43

    
44
package org.gvsig.remoteClient.arcims;
45

    
46
import org.gvsig.remoteClient.arcims.utils.ServiceInfoTags;
47
import org.gvsig.remoteClient.arcims.utils.ServiceInformation;
48

    
49
import java.awt.Color;
50
import java.awt.Dimension;
51
import java.awt.geom.Rectangle2D;
52

    
53
import java.text.DecimalFormat;
54
import java.text.DecimalFormatSymbols;
55

    
56
import java.util.Vector;
57

    
58

    
59
/**
60
 * Class that provides static methods to generate ImageServer related ArcXML requests
61
 * @author jsanz
62
 * @author jcarrasco
63
 */
64
public class ArcXMLImage extends ArcXML {
65
    /**
66
     * Creates a complete request in ArcXML for an ImageService
67
     * from an ArcImsStatus; including extent, format and so on
68
     * @see org.gvsig.remoteClient.arcims.ArcImsStatus
69
     * @param status
70
     * @return String
71
     */
72
    public static String getMapRequest(ArcImsStatus status) {
73
        /**
74
             * Layers that we want to request
75
             */
76
        Vector layers = status.getLayerIds();
77

    
78
        /**
79
             * The EPSG code that image requested will have,
80
             * the ArcIMS server will reproject data into this
81
             * code, see <a href="http://www.epsg.org">EPSG</a>
82
             */
83
        String srs = new String();
84

    
85
        /**
86
             * We suppose that status.getSrs() allways will give a
87
             * string started by this string
88
             */
89
        String ini_srs = ServiceInfoTags.vINI_SRS;
90

    
91
        /**
92
             * Gets de Decimal Separator from the status.ServiceInfo
93
             */
94
        ServiceInformation si = status.getServiceInfo();
95
        char ds = si.getSeparators().getDs();
96

    
97
        /**
98
             * Is the ServiceInfo FeatureCoordsys assumed?
99
             */
100
        boolean srsAssumed = si.isSrsAssumed();
101

    
102
        /**
103
             * Assign the srs from the status
104
             * @see org.gvsig.remoteClient.RemoteClientStatus#getSrs()
105
             */
106
        if (!srsAssumed && status.getSrs().startsWith(ini_srs)) {
107
            srs = status.getSrs().substring(ini_srs.length()).trim();
108
        } else {
109
            srs = "";
110
        }
111

    
112
        return getImageRequest(ArcXML.getEnvelope(status.getExtent(), ds), //envelope
113
            ArcXML.getFilterCoordsys(srs), //filter
114
            ArcXML.getFeatureCoordsys(srs), //feature
115
            status.getFormat(), //image format
116
            new Dimension(status.getWidth(), status.getHeight()), //image size
117
            layers //layers to draw                            
118
        );
119
    }
120

    
121
    /**
122
         * Creates a custom ArcXML request to obtain a request projected by
123
         * the ArcIms server
124
         * @param  srsInput The SRS of the coordinates provided
125
         * @param  srsOutput The SRS of the coordinates needed
126
         * @param  envelope Rectangle2D with the envelope provided
127
         * @param  ds Char with the Decimal Separator
128
         * @param imageSize Dimension object
129
         * @param oneLayerId A dumb layer identificator (but valid) of the service
130
         * @return String
131
         */
132
    public static String getCustomExtentRequest(String srsInput,
133
        Rectangle2D envelope, String srsOutput, char ds, Dimension imageSize,
134
        String format, String oneLayerId) {
135
        /**
136
             * The returned request
137
             */
138
        String request = new String();
139

    
140
        /**
141
              * To this request we only need a layer, i.e. the first of the service
142
              */
143
        Vector layer = new Vector(1);
144
        layer.add(oneLayerId);
145

    
146
        request = getImageRequest(ArcXML.getEnvelope(envelope, ds), //envelope
147
                ArcXML.getFilterCoordsys(srsInput), //filter
148
                ArcXML.getFeatureCoordsys(srsOutput), //feature
149
                format, //image format
150
                imageSize, //image size
151
                layer //layers to draw                            
152
            );
153

    
154
        return request;
155
    }
156

    
157
    /**
158
         * Creates a complete request in ArcXML for an ImageService. This private
159
         * method is used for every request that needs a GET_IMAGE.
160
         *
161
         * @see ArcImsStatus
162
         * @see org.gvsig.remoteClient.arcims.ArcImsProtImageHandler#getServiceExtent
163
         * @param envelope Envelope of the request
164
         * @param filterCoordsys SRS of input data
165
         * @param featureCoordsys SRS of output data
166
         * @param format Image format (PNG,..)
167
         * @param imageSize Dimension object with image size to be requested
168
         * @param layerIds Vector with layer Ids to retrieve
169
         * @return String
170
         */
171
    private static String getImageRequest(String envelope,
172
        String filterCoordsys, String featureCoordsys, String format,
173
        Dimension imageSize, Vector layerIds) {
174
        /**
175
             * Building the heading of the request
176
             */
177
        String request = new String();
178
        request = "<?xml version = '1.0' encoding = 'UTF-8'?>\r\n" +
179
            ArcXML.startRequest("1.1") +
180
            "\t\t<GET_IMAGE autoresize=\"false\" show=\"layers\">\r\n" +
181
            "\t\t\t<PROPERTIES>\r\n";
182

    
183
        if (!envelope.equals("")) {
184
            request += ("\t\t\t\t" + envelope + "\r\n");
185
        }
186

    
187
        if (imageSize != null) {
188
            request += ("\t\t\t\t" + ArcXML.getImageSize(imageSize) + "\r\n");
189
        }
190

    
191
        if (!featureCoordsys.equals("")) {
192
            request += ("\t\t\t\t" + featureCoordsys + "\r\n");
193
        }
194

    
195
        if (!filterCoordsys.equals("")) {
196
            request += ("\t\t\t\t" + filterCoordsys + "\r\n");
197
        }
198

    
199
        request += ("\t\t\t\t" +
200
        ArcXML.getBackground(Color.WHITE, Color.WHITE) + "\r\n");
201

    
202
        if (!format.equals("")) {
203
            request += ("\t\t\t\t" + "<OUTPUT type=\"" + format + "\"/>\r\n");
204
        }
205

    
206
        //Build the layerlist
207
        request += ("\t\t\t\t" + "<LAYERLIST order=\"true\">\r\n");
208

    
209
        //"\t\t\t\t\t"+"<LAYERDEF id=\""+status.getLayerNames()+"\" visible=\"true\"/>\r\n"+
210

    
211
        /**
212
                 * Building the string that specifies what layers
213
                 * will be requested
214
                 */
215
        for (int i = 0; i < layerIds.size(); i++) {
216
            request += ("\t\t\t\t\t<LAYERDEF id=\"" +
217
            layerIds.elementAt(i).toString() + "\" visible=\"true\" />\r\n");
218
        }
219

    
220
        /**
221
         * Building the end of the request
222
         */
223
        request += ("\t\t\t\t" + "</LAYERLIST>\r\n" +
224
        "\t\t\t</PROPERTIES>\r\n" + "\t\t</GET_IMAGE>\r\n" +
225
        ArcXML.endRequest());
226
        return request;
227
    }
228

    
229
    /**
230
         * Creates the ArcXML retrieve INFO of a specific location
231
         * dependig if the layer is a FEATURECLASS or a IMAGE
232
         * @see org.gvsig.remoteClient.arcims.ArcImsProtImageHandler#getElementInfo(ArcImsStatus, int, int, int)
233
         * @param layerType A String with the layer type @see org.gvsig.remoteClient.arcims.utils.ServiceInfoTags
234
         * @param id The layer id to request
235
         * @param coords A pair of coordinates with the center of the request
236
         * @param dists A pair of distances to extend the point to a BoundaryBox
237
         * @param coordsys A valid EPSG code
238
         * @return String with the ArcXML
239
         */
240
    public static String getInfoRequest(String layerType, String id,
241
        double[] coords, double[] dists, String coordsys, char ds) {
242
        StringBuffer sb = new StringBuffer();
243
        Rectangle2D rect = new Rectangle2D.Double();
244

    
245
        rect.setFrameFromDiagonal(coords[0] - dists[0], coords[1] - dists[1],
246
            coords[0] + dists[0], coords[1] + dists[1]);
247

    
248
        if (layerType.equals(ServiceInfoTags.vLAYERTYPE_F)) {
249
            sb.append(ArcXML.startRequest("1.1"));
250
            sb.append(
251
                "\t\t<GET_FEATURES outputmode=\"xml\" checkesc=\"true\" geometry=\"false\" envelope=\"false\">\r\n");
252
            sb.append("\t\t\t<LAYER id=\"" + id + "\" />\r\n");
253
            sb.append("\t\t\t<SPATIALQUERY subfields=\"#ALL#\" >\r\n");
254

    
255
            if (!coordsys.equals("")) {
256
                sb.append("\t\t\t\t" + ArcXML.getFeatureCoordsys(coordsys) +
257
                    "\r\n");
258
                sb.append("\t\t\t\t" + ArcXML.getFilterCoordsys(coordsys) +
259
                    "\r\n");
260
            }
261

    
262
            sb.append(
263
                "\t\t\t\t<SPATIALFILTER relation=\"area_intersection\">\r\n");
264
            sb.append(getEnvelope(rect, ds));
265
            sb.append("\t\t\t\t</SPATIALFILTER>\r\n");
266
            sb.append("\t\t\t</SPATIALQUERY>\r\n");
267
            sb.append("\t\t</GET_FEATURES>\r\n");
268
            sb.append(ArcXML.endRequest());
269
        } else if (layerType.equals(ServiceInfoTags.vLAYERTYPE_I)) {
270
            double xCenter = rect.getCenterX();
271
            double yCenter = rect.getCenterY();
272

    
273
            //We need to format these values into the correct encoding
274
            DecimalFormatSymbols dfs = new DecimalFormatSymbols();
275
            dfs.setDecimalSeparator(ds);
276

    
277
            DecimalFormat formatter = new DecimalFormat(PATRON, dfs);
278

    
279
            String xF = formatter.format(xCenter);
280
            String yF = formatter.format(yCenter);
281

    
282
            sb.append(ArcXML.startRequest("1.1"));
283
            sb.append("\t\t<GET_RASTER_INFO x=\"" + xF + "\" y=\"" + yF +
284
                "\" layerid=\"" + id + "\">\r\n");
285
            sb.append("\t\t\t<COORDSYS id=\"" + coordsys + "\"/>\r\n");
286
            sb.append("\t\t</GET_RASTER_INFO>\r\n");
287
            sb.append(ArcXML.endRequest());
288
        }
289

    
290
        return sb.toString();
291
    }
292
}