Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.arcims / src / org / gvsig / remoteclient / arcims / ArcXMLImage.java @ 32538

History | View | Annotate | Download (10.4 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
 * 2010 Prodevelop S.L. main development
26
 * http://www.prodevelop.es
27
 */
28

    
29
package org.gvsig.remoteclient.arcims;
30

    
31
import org.gvsig.remoteclient.arcims.utils.ServiceInfoTags;
32
import org.gvsig.remoteclient.arcims.utils.ServiceInformation;
33

    
34
import java.awt.Color;
35
import java.awt.Dimension;
36
import java.awt.geom.Rectangle2D;
37

    
38
import java.text.DecimalFormat;
39
import java.text.DecimalFormatSymbols;
40

    
41
import java.util.Vector;
42

    
43

    
44
/**
45
 * Class that provides static methods to generate ImageServer related ArcXML requests
46
 * @author jsanz
47
 * @author jcarrasco
48
 */
49
public class ArcXMLImage extends ArcXML {
50
    /**
51
     * Creates a complete request in ArcXML for an ImageService
52
     * from an ArcImsStatus; including extent, format and so on
53
     * @see org.gvsig.remoteclient.arcims.ArcImsStatus
54
     * @param status
55
     * @return String
56
     */
57
    public static String getMapRequest(ArcImsStatus status) {
58
        /**
59
             * Layers that we want to request
60
             */
61
        Vector<String> layers = status.getLayersIdsSelected();
62

    
63
        /**
64
             * The EPSG code that image requested will have,
65
             * the ArcIMS server will reproject data into this
66
             * code, see <a href="http://www.epsg.org">EPSG</a>
67
             */
68
        String srs = new String();
69

    
70
        /**
71
             * We suppose that status.getSrs() allways will give a
72
             * string started by this string
73
             */
74
        String ini_srs = ServiceInfoTags.vINI_SRS;
75

    
76
        /**
77
             * Gets de Decimal Separator from the status.ServiceInfo
78
             */
79
        ServiceInformation si = status.getServiceInfo();
80
        char ds = si.getSeparators().getDs();
81

    
82
        /**
83
             * Is the ServiceInfo FeatureCoordsys assumed?
84
             */
85
        boolean srsAssumed = si.isSrsAssumed();
86

    
87
        /**
88
             * Assign the srs from the status
89
             * @see org.gvsig.remoteClient.RemoteClientStatus#getSrs()
90
             */
91
        if (!srsAssumed && status.getSrs().startsWith(ini_srs)) {
92
            srs = status.getSrs().substring(ini_srs.length()).trim();
93
        } else {
94
            srs = "";
95

    
96
            //System.err.println("The ArcIMS Service doesn't provide a SRS");
97
        }
98
        
99

    
100
        return getImageRequest(ArcXML.getEnvelope(status.getEnvelopeRect(), ds), //envelope
101
            ArcXML.getFilterCoordsys(srs), //filter
102
            ArcXML.getFeatureCoordsys(srs), //feature
103
            status.getFormat(), //image format
104
            new Dimension(status.getWidth(), status.getHeight()), //image size
105
            layers //layers to draw                            
106
        );
107
    }
108

    
109
    /**
110
         * Creates a custom ArcXML request to obtain a request projected by
111
         * the ArcIms server
112
         * @param  srsInput The SRS of the coordinates provided
113
         * @param  srsOutput The SRS of the coordinates needed
114
         * @param  envelope Rectangle2D with the envelope provided
115
         * @param  ds Char with the Decimal Separator
116
         * @param imageSize Dimension object
117
         * @param oneLayerId A dumb layer identificator (but valid) of the service
118
         * @return String
119
         */
120
    public static String getCustomExtentRequest(String srsInput,
121
        Rectangle2D envelope, String srsOutput, char ds, Dimension imageSize,
122
        String format, String oneLayerId) {
123
        /**
124
             * The returned request
125
             */
126
        String request = new String();
127

    
128
        /**
129
              * To this request we only need a layer, i.e. the first of the service
130
              */
131
        Vector<String> layer = new Vector<String>(1);
132
        layer.add(oneLayerId);
133

    
134
        request = getImageRequest(ArcXML.getEnvelope(envelope, ds), //envelope
135
                ArcXML.getFilterCoordsys(srsInput), //filter
136
                ArcXML.getFeatureCoordsys(srsOutput), //feature
137
                format, //image format
138
                imageSize, //image size
139
                layer //layers to draw                            
140
            );
141

    
142
        return request;
143
    }
144

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

    
171
        if (!envelope.equals("")) {
172
            request += ("\t\t\t\t" + envelope + "\r\n");
173
        }
174

    
175
        if (imageSize != null) {
176
            request += ("\t\t\t\t" + ArcXML.getImageSize(imageSize) + "\r\n");
177
        }
178

    
179
        if (!featureCoordsys.equals("")) {
180
            request += ("\t\t\t\t" + featureCoordsys + "\r\n");
181
        }
182

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

    
187
        request += ("\t\t\t\t" +
188
        ArcXML.getBackground(Color.WHITE, Color.WHITE) + "\r\n");
189

    
190
        if (!format.equals("")) {
191
            request += ("\t\t\t\t" + "<OUTPUT type=\"" + format + "\"/>\r\n");
192
        }
193

    
194
        //Build the layerlist
195
        request += ("\t\t\t\t" + "<LAYERLIST order=\"true\">\r\n");
196

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

    
199
        /**
200
                 * Building the string that specifies what layers
201
                 * will be requested
202
                 */
203
        for (int i = 0; i < layerIds.size(); i++) {
204
            request += ("\t\t\t\t\t<LAYERDEF id=\"" +
205
            layerIds.elementAt(i).toString() + "\" visible=\"true\" />\r\n");
206
        }
207

    
208
        /**
209
         * Building the end of the request
210
         */
211
        request += ("\t\t\t\t" + "</LAYERLIST>\r\n" +
212
        "\t\t\t</PROPERTIES>\r\n" + "\t\t</GET_IMAGE>\r\n" +
213
        ArcXML.endRequest());
214

    
215
        //System.err.println(request);
216
        return request;
217
    }
218

    
219
    /**
220
         * Creates the ArcXML retrieve INFO of a specific location
221
         * dependig if the layer is a FEATURECLASS or a IMAGE
222
         * @see org.gvsig.remoteclient.arcims.ArcImsProtImageHandler#getElementInfo(ArcImsStatus, int, int, int)
223
         * @param layerType A String with the layer type @see org.gvsig.remoteClient.arcims.utils.ServiceInfoTags
224
         * @param id The layer id to request
225
         * @param coords A pair of coordinates with the center of the request
226
         * @param dists A pair of distances to extend the point to a BoundaryBox
227
         * @param coordsys A valid EPSG code
228
         * @return String with the ArcXML
229
         */
230
    public static String getInfoRequest(String layerType, String id,
231
        double[] coords, double[] dists, String coordsys, char ds) {
232
        StringBuffer sb = new StringBuffer();
233
        Rectangle2D rect = new Rectangle2D.Double();
234

    
235
        rect.setFrameFromDiagonal(coords[0] - dists[0], coords[1] - dists[1],
236
            coords[0] + dists[0], coords[1] + dists[1]);
237

    
238
        if (layerType.equals(ServiceInfoTags.vLAYERTYPE_F)) {
239
            sb.append(ArcXML.startRequest("1.1"));
240
            sb.append(
241
                "\t\t<GET_FEATURES outputmode=\"xml\" checkesc=\"true\" geometry=\"false\" envelope=\"false\">\r\n");
242
            sb.append("\t\t\t<LAYER id=\"" + id + "\" />\r\n");
243
            sb.append("\t\t\t<SPATIALQUERY subfields=\"#ALL#\" >\r\n");
244

    
245
            if (!coordsys.equals("")) {
246
                sb.append("\t\t\t\t" + ArcXML.getFeatureCoordsys(coordsys) +
247
                    "\r\n");
248
                sb.append("\t\t\t\t" + ArcXML.getFilterCoordsys(coordsys) +
249
                    "\r\n");
250
            }
251

    
252
            sb.append(
253
                "\t\t\t\t<SPATIALFILTER relation=\"area_intersection\">\r\n");
254
            sb.append(getEnvelope(rect, ds));
255
            sb.append("\t\t\t\t</SPATIALFILTER>\r\n");
256
            sb.append("\t\t\t</SPATIALQUERY>\r\n");
257
            sb.append("\t\t</GET_FEATURES>\r\n");
258
            sb.append(ArcXML.endRequest());
259
        } else if (layerType.equals(ServiceInfoTags.vLAYERTYPE_I)) {
260
            double xCenter = rect.getCenterX();
261
            double yCenter = rect.getCenterY();
262

    
263
            //We need to format these values into the correct encoding
264
            DecimalFormatSymbols dfs = new DecimalFormatSymbols();
265
            dfs.setDecimalSeparator(ds);
266

    
267
            DecimalFormat formatter = new DecimalFormat(PATRON, dfs);
268

    
269
            String xF = formatter.format(xCenter);
270
            String yF = formatter.format(yCenter);
271

    
272
            sb.append(ArcXML.startRequest("1.1"));
273
            sb.append("\t\t<GET_RASTER_INFO x=\"" + xF + "\" y=\"" + yF +
274
                "\" layerid=\"" + id + "\">\r\n");
275
            sb.append("\t\t\t<COORDSYS id=\"" + coordsys + "\"/>\r\n");
276
            sb.append("\t\t</GET_RASTER_INFO>\r\n");
277
            sb.append(ArcXML.endRequest());
278

    
279
            //                        System.err.println(sb.toString());
280
        }
281

    
282
        return sb.toString();
283
    }
284
}