-
Notifications
You must be signed in to change notification settings - Fork 54
/
GeoPackageGetMapOutputFormatTest.java
141 lines (120 loc) · 4.62 KB
/
GeoPackageGetMapOutputFormatTest.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
132
133
134
135
136
137
138
139
140
141
/* (c) 2014 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 gov.nasa.worldwind.gs.geopkg;
import static org.junit.Assert.*;
import static org.geoserver.data.test.MockData.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.xml.namespace.QName;
import org.geoserver.data.test.SystemTestData;
import org.geoserver.gwc.GWC;
import org.geoserver.wms.GetMapRequest;
import org.geoserver.wms.WMSMapContent;
import org.geoserver.wms.WMSTestSupport;
import org.geoserver.wms.WebMap;
import org.geoserver.wms.map.RawMap;
import org.geotools.geopkg.GeoPackage;
import org.junit.Before;
import org.junit.Test;
import com.vividsolutions.jts.geom.Envelope;
/**
*
* Test For WMS GetMap Output Format for GeoPackage
*
* @author Justin Deoliveira, Boundless
*
*/
public class GeoPackageGetMapOutputFormatTest extends WMSTestSupport {
GeoPackageGetMapOutputFormat format;
/**
* Setup a GeoPackageGetMapOutputFormat for each test using WMSTestSupport.
*/
@Before
public void setUpFormat() throws IOException {
// getWebMapService() - The global web map service singleton from the application context.
// getWMS() - The global wms singleton from the application context.
// GWC.get() - Spring bean acting as a mediator between GeoWebCache and GeoServer
format = new GeoPackageGetMapOutputFormat(getWebMapService(), getWMS(), GWC.get());
}
/**
* Adds default set of raster layers to the test data.
*
* @param testData
* @throws Exception
*/
@Override
protected void setUpTestData(SystemTestData testData) throws Exception {
super.setUpTestData(testData);
testData.setUpDefaultRasterLayers();
}
@Test
public void testTileEntries() throws Exception {
WMSMapContent mapContent = createMapContent(WORLD, LAKES);
mapContent.getRequest().setBbox(
new Envelope(-0.17578125, -0.087890625, 0.17578125, 0.087890625));
mapContent.getRequest().getFormatOptions().put("min_zoom", "10");
mapContent.getRequest().getFormatOptions().put("max_zoom", "11");
WebMap map = format.produceMap(mapContent);
GeoPackage geopkg = createGeoPackage(map);
assertTrue(geopkg.features().isEmpty());
assertEquals(1, geopkg.tiles().size());
assertNotNull(geopkg.tile("World_Lakes"));
}
GeoPackage createGeoPackage(WebMap map) throws IOException {
assertTrue(map instanceof RawMap);
RawMap rawMap = (RawMap) map;
File f = File.createTempFile("temp", ".gpkg", new File("target"));
FileOutputStream fout = new FileOutputStream(f);
rawMap.writeTo(fout);
fout.flush();
fout.close();
return new GeoPackage(f);
// File f = File.createTempFile("geopkg", "zip", new File("target"));
// FileOutputStream fout = new FileOutputStream(f);
// rawMap.writeTo(fout);
// fout.flush();
// fout.close();
//
// File g = File.createTempFile("geopkg", "db", new File("target"));
// g.delete();
// g.mkdir();
//
// IOUtils.decompress(f, g);
// return new GeoPackage(g.listFiles(new FileFilter() {
// @Override
// public boolean accept(File file) {
// return file.getName().endsWith(".geopackage");
// }
// })[0]);
}
protected GetMapRequest createGetMapRequest(QName[] layerNames) {
GetMapRequest request = super.createGetMapRequest(layerNames);
request.setBbox(new Envelope(-180, 180, -90, 90));
return request;
};
WMSMapContent createMapContent(QName... layers) throws IOException {
GetMapRequest mapRequest = createGetMapRequest(layers);
WMSMapContent map = new WMSMapContent(mapRequest);
for (QName l : layers) {
map.addLayer(createMapLayer(l));
}
return map;
}
/*public static void main(String[] args) throws Exception {
GeoPackage geopkg = new GeoPackage(new File(
"/Users/jdeolive/geopkg.db"));;
File d = new File("/Users/jdeolive/tiles");
d.mkdir();
TileEntry te = geopkg.tiles().get(0);
TileReader r = geopkg.reader(te, null, null, null, null, null, null);
while(r.hasNext()) {
Tile t = r.next();
File f = new File(d, String.format("%d-%d-%d.png", t.getZoom(), t.getColumn(), t.getRow()));
FileUtils.writeByteArrayToFile(f, t.getData());
}
}*/
}