-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
CropCoverageTest.java
131 lines (115 loc) · 7.61 KB
/
CropCoverageTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* (c) 2014-2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.wps.gs;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import java.io.InputStream;
import org.geoserver.data.test.MockData;
import org.geoserver.data.test.SystemTestData;
import org.geoserver.platform.GeoServerExtensions;
import org.geoserver.wps.WPSTestSupport;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.gce.arcgrid.ArcGridFormat;
import org.geotools.geometry.DirectPosition2D;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import com.mockrunner.mock.web.MockHttpServletResponse;
import com.vividsolutions.jts.geom.Envelope;
public class CropCoverageTest extends WPSTestSupport {
@Override
protected void onSetUp(SystemTestData testData) throws Exception {
super.onSetUp(testData);
addWcs11Coverages(testData);
}
@Test
public void testCrop() throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<wps:Execute version=\"1.0.0\" service=\"WPS\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.opengis.net/wps/1.0.0\" xmlns:wfs=\"http://www.opengis.net/wfs\" xmlns:wps=\"http://www.opengis.net/wps/1.0.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:wcs=\"http://www.opengis.net/wcs/1.1.1\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xsi:schemaLocation=\"http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd\">\n"
+ " <ows:Identifier>gs:CropCoverage</ows:Identifier>\n"
+ " <wps:DataInputs>\n"
+ " <wps:Input>\n"
+ " <ows:Identifier>coverage</ows:Identifier>\n"
+ " <wps:Reference mimeType=\"image/tiff\" xlink:href=\"http://geoserver/wcs\" method=\"POST\">\n"
+ " <wps:Body>\n"
+ " <wcs:GetCoverage service=\"WCS\" version=\"1.1.1\">\n"
+ " <ows:Identifier>" + getLayerId(MockData.TASMANIA_DEM) + "</ows:Identifier>\n"
+ " <wcs:DomainSubset>\n"
+ " <gml:BoundingBox crs=\"http://www.opengis.net/gml/srs/epsg.xml#4326\">\n"
+ " <ows:LowerCorner>-180.0 -90.0</ows:LowerCorner>\n"
+ " <ows:UpperCorner>180.0 90.0</ows:UpperCorner>\n"
+ " </gml:BoundingBox>\n"
+ " </wcs:DomainSubset>\n"
+ " <wcs:Output format=\"image/tiff\"/>\n"
+ " </wcs:GetCoverage>\n"
+ " </wps:Body>\n"
+ " </wps:Reference>\n"
+ " </wps:Input>\n"
+ " <wps:Input>\n"
+ " <ows:Identifier>cropShape</ows:Identifier>\n"
+ " <wps:Data>\n"
+ " <wps:ComplexData mimeType=\"application/wkt\"><![CDATA[POLYGON((145.5 -41.9, 145.5 -42.1, 145.6 -42, 145.5 -41.9))]]></wps:ComplexData>\n"
+ " </wps:Data>\n" + " </wps:Input>\n" + " </wps:DataInputs>\n"
+ " <wps:ResponseForm>\n"
+ " <wps:RawDataOutput mimeType=\"application/arcgrid\">\n"
+ " <ows:Identifier>result</ows:Identifier>\n" + " </wps:RawDataOutput>\n"
+ " </wps:ResponseForm>\n" + "</wps:Execute>\n" + "\n" + "";
MockHttpServletResponse response = postAsServletResponse(root(), xml);
InputStream is = getBinaryInputStream(response);
ArcGridFormat format = new ArcGridFormat();
GridCoverage2D gc = format.getReader(is).read(null);
assertTrue(new Envelope(-145.4, 145.6, -41.8, -42.1).contains(new ReferencedEnvelope(gc.getEnvelope())));
double[] valueInside = (double[]) gc.evaluate(new DirectPosition2D(145.55, -42));
assertEquals(615.0, valueInside[0]);
double[] valueOutside = (double[]) gc.evaluate(new DirectPosition2D(145.57, -41.9));
// this should really be NoData... (-9999 & 0xFFFF)
assertEquals(55537.0, valueOutside[0]);
gc.dispose(true);
}
@Test
public void invalidCoverage() throws Exception {
// See GEOS-6921
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<wps:Execute version=\"1.0.0\" service=\"WPS\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.opengis.net/wps/1.0.0\" xmlns:wfs=\"http://www.opengis.net/wfs\" xmlns:wps=\"http://www.opengis.net/wps/1.0.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:wcs=\"http://www.opengis.net/wcs/1.1.1\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xsi:schemaLocation=\"http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd\">\n"
+ " <ows:Identifier>gs:CropCoverage</ows:Identifier>\n"
+ " <wps:DataInputs>\n"
+ " <wps:Input>\n"
+ " <ows:Identifier>coverage</ows:Identifier>\n"
+ " <wps:Reference mimeType=\"image/tiff\" xlink:href=\"http://geoserver/wcs\" method=\"POST\">\n"
+ " <wps:Body>\n"
+ " <wcs:GetCoverage service=\"WCS\" version=\"1.1.1\">\n"
+ " <ows:Identifier>" + getLayerId(MockData.TASMANIA_DEM) + "</ows:Identifier>\n"
+ " <wcs:DomainSubset>\n"
+ " <gml:BoundingBox crs=\"http://www.opengis.net/gml/srs/epsg.xml#4326\">\n"
+ " <ows:LowerCorner>180.0 -90.0</ows:LowerCorner>\n"
+ " <ows:UpperCorner>200.0 90.0</ows:UpperCorner>\n"
+ " </gml:BoundingBox>\n"
+ " </wcs:DomainSubset>\n"
+ " <wcs:Output format=\"image/tiff\"/>\n"
+ " </wcs:GetCoverage>\n"
+ " </wps:Body>\n"
+ " </wps:Reference>\n"
+ " </wps:Input>\n"
+ " <wps:Input>\n"
+ " <ows:Identifier>cropShape</ows:Identifier>\n"
+ " <wps:Data>\n"
+ " <wps:ComplexData mimeType=\"application/wkt\"><![CDATA[POLYGON((145.5 -41.9, 145.5 -42.1, 145.6 -42, 145.5 -41.9))]]></wps:ComplexData>\n"
+ " </wps:Data>\n" + " </wps:Input>\n" + " </wps:DataInputs>\n"
+ " <wps:ResponseForm>\n"
+ " <wps:RawDataOutput mimeType=\"application/arcgrid\">\n"
+ " <ows:Identifier>result</ows:Identifier>\n" + " </wps:RawDataOutput>\n"
+ " </wps:ResponseForm>\n" + "</wps:Execute>\n" + "\n" + "";
MockHttpServletResponse response = postAsServletResponse(root(), xml);
InputStream is = getBinaryInputStream(response);
Document dom = dom(is);
Element status = (Element) dom.getDocumentElement().getElementsByTagName("wps:Status").item(0);
Node child = status.getChildNodes().item(0);
assertEquals("wps:ProcessFailed", child.getNodeName() );
}
}