Skip to content

Commit a2dd1e8

Browse files
authored
Merge pull request #209 from Esri/tyle8552/raster-layer-geopackage
raster layer geopackage sample
2 parents 4c0da74 + c7b8758 commit a2dd1e8

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<h1>Raster Layer GeoPackage</h1>
2+
3+
<p>Demonstrates how to show a raster layer using a geopackage.</p>
4+
5+
<p><img src="RasterLayerGeoPackage.png"/></p>
6+
7+
<h2>How it works</h2>
8+
9+
<p>To add a<code>RasterLayer</code> as an operational layer from a <code>GeoPackage</code>:</p>
10+
<ol>
11+
<li>Create and load a <code>GeoPackage</code>, specifying the path to the local .gpkg file.</li>
12+
<li>When it is done loading, get the <code>GeoPackageRaster</code>s inside with <code>geoPackage
13+
.getGeoPackageRasters()</code>.</li>
14+
<li>Construct a <code>RasterLayer</code> with the <code>GeoPackageRaster</code> in the list you want to use.</li>
15+
<li>Add the raster layer to the map as an operational layer <code>map.getOperationalLayers().add(rasterLayer)</code>.</li>
16+
</ol>
17+
18+
<h2>Features</h2>
19+
20+
<ul>
21+
<li>ArcGISMap</li>
22+
<li>Basemap</li>
23+
<li>GeoPackage</li>
24+
<li>GeoPackageRaster</li>
25+
<li>MapView</li>
26+
<li>RasterLayer</li>
27+
</ul>
63.5 KB
Loading
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright 2018 Esri.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package com.esri.samples.raster.raster_layer_geopackage;
18+
19+
import java.io.File;
20+
21+
import javafx.application.Application;
22+
import javafx.scene.Scene;
23+
import javafx.scene.control.Alert;
24+
import javafx.scene.layout.StackPane;
25+
import javafx.stage.Stage;
26+
27+
import com.esri.arcgisruntime.data.GeoPackage;
28+
import com.esri.arcgisruntime.layers.RasterLayer;
29+
import com.esri.arcgisruntime.loadable.LoadStatus;
30+
import com.esri.arcgisruntime.mapping.ArcGISMap;
31+
import com.esri.arcgisruntime.mapping.Basemap;
32+
import com.esri.arcgisruntime.mapping.view.MapView;
33+
import com.esri.arcgisruntime.raster.GeoPackageRaster;
34+
35+
public class RasterLayerGeoPackageSample extends Application {
36+
37+
private MapView mapView;
38+
39+
@Override
40+
public void start(Stage stage) throws Exception {
41+
42+
try {
43+
// create stack pane and application scene
44+
StackPane stackPane = new StackPane();
45+
Scene scene = new Scene(stackPane);
46+
47+
// set title, size, and add scene to stage
48+
stage.setTitle("Raster Layer GeoPackage");
49+
stage.setWidth(800);
50+
stage.setHeight(700);
51+
stage.setScene(scene);
52+
stage.show();
53+
54+
// create a map with light gray canvas vector basemap
55+
ArcGISMap map = new ArcGISMap(Basemap.createLightGrayCanvasVector());
56+
mapView = new MapView();
57+
mapView.setMap(map);
58+
59+
// create a geopackage from a local gpkg file
60+
GeoPackage geoPackage = new GeoPackage(new File("./samples-data/auroraCO/AuroraCO.gpkg").getAbsolutePath());
61+
62+
// load the geopackage
63+
geoPackage.loadAsync();
64+
geoPackage.addDoneLoadingListener(() -> {
65+
if (geoPackage.getLoadStatus() == LoadStatus.LOADED && geoPackage.getGeoPackageRasters().size() > 0) {
66+
// get the geopackage raster
67+
GeoPackageRaster raster = geoPackage.getGeoPackageRasters().get(0);
68+
69+
// create a raster layer and add it to the map
70+
RasterLayer rasterLayer = new RasterLayer(raster);
71+
map.getOperationalLayers().add(rasterLayer);
72+
73+
// set viewpoint on the raster layer
74+
rasterLayer.addDoneLoadingListener(() -> {
75+
if (rasterLayer.getLoadStatus() == LoadStatus.LOADED) {
76+
mapView.setViewpointGeometryAsync(rasterLayer.getFullExtent(), 150);
77+
} else {
78+
Alert alert = new Alert(Alert.AlertType.ERROR, "Failed to load raster layer");
79+
alert.show();
80+
}
81+
});
82+
83+
} else {
84+
Alert alert = new Alert(Alert.AlertType.ERROR, "Failed to load geopackage");
85+
alert.show();
86+
}
87+
});
88+
89+
// add the map view to stack pane
90+
stackPane.getChildren().addAll(mapView);
91+
} catch (Exception e) {
92+
// on any error, display the stack trace.
93+
e.printStackTrace();
94+
}
95+
}
96+
97+
/**
98+
* Stops and releases all resources used in application.
99+
*/
100+
@Override
101+
public void stop() {
102+
103+
if (mapView != null) {
104+
mapView.dispose();
105+
}
106+
}
107+
108+
/**
109+
* Opens and runs application.
110+
*
111+
* @param args arguments passed to this application
112+
*/
113+
public static void main(String[] args) {
114+
115+
Application.launch(args);
116+
}
117+
118+
}

0 commit comments

Comments
 (0)