Statistics
| Revision:

root / trunk / libraries / libArcIMS_old / src / org / gvsig / remoteClient / arcims / ArcXMLImage.java @ 11865

History | View | Annotate | Download (10.6 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
            //System.err.println("The ArcIMS Service doesn't provide a SRS");
112
        }
113

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

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

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

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

    
156
        return request;
157
    }
158

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

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

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

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

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

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

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

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

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

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

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

    
229
        //System.err.println(request);
230
        return request;
231
    }
232

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

    
249
        rect.setFrameFromDiagonal(coords[0] - dists[0], coords[1] - dists[1],
250
            coords[0] + dists[0], coords[1] + dists[1]);
251

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

    
259
            if (!coordsys.equals("")) {
260
                sb.append("\t\t\t\t" + ArcXML.getFeatureCoordsys(coordsys) +
261
                    "\r\n");
262
                sb.append("\t\t\t\t" + ArcXML.getFilterCoordsys(coordsys) +
263
                    "\r\n");
264
            }
265

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

    
277
            //We need to format these values into the correct encoding
278
            DecimalFormatSymbols dfs = new DecimalFormatSymbols();
279
            dfs.setDecimalSeparator(ds);
280

    
281
            DecimalFormat formatter = new DecimalFormat(PATRON, dfs);
282

    
283
            String xF = formatter.format(xCenter);
284
            String yF = formatter.format(yCenter);
285

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

    
293
            //                        System.err.println(sb.toString());
294
        }
295

    
296
        return sb.toString();
297
    }
298
}