Skip to content

Commit 7b3ca50

Browse files
authored
Update geopackage sample (#374)
* patch-closest-facility-static-readme (#363) * delete sample calculate distance 3D (#365) * Patch/ClosestFacilityStatic- Edit readme 'how to use' (#364) * patch oAuth sample custom challengehandler (#366) * implement fix for javafx webengine * formatting * add fix for create and save map sample * markdown to html formatting * update read geopackage design * update readme code snippets * improve comments * remove unneeded comments * comment wording * implement review corrections * whitespace * remove unrelated files * implement review changes * remove css stylesheet * clean up some comments
1 parent f295325 commit 7b3ca50

File tree

3 files changed

+55
-157
lines changed

3 files changed

+55
-157
lines changed

map/read-geopackage/README.md

+29-19
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
1-
# Read GeoPackage
1+
# Read a GeoPackage
22

3-
Display rasters and features from local GeoPackages.
3+
Add rasters and feature tables from a GeoPackage to a map.
44

5-
![](ReadGeoPackage.png)
5+
![](ReadGeoPackage.jpg)
6+
7+
## Use case
8+
9+
The OGC GeoPackage specification defines an open standard for sharing raster and vector data. You may want to use GeoPackage files to support file-based sharing of geographic data.
610

711
## How to use the sample
812

9-
The layers in the geoPackage, which have not been added to the map are shown in the bottom list. Click an item to show it as a layer in the map. Layers in the map are listed in the top list. Click layers from the top list to remove them from the map.
13+
When the sample loads, the feature layers and rasters from the GeoPackage will be shown on the map.
1014

1115
## How it works
1216

13-
To read layers from a geoPackage and show them in a map:
14-
15-
1. Create a `GeoPackage` with the path to the local geoPackage file.
16-
2. Load the `GeoPackage` with `GeoPackage.loadAsync`.
17-
3. Create raster layers for each of these with `new RasterLayer(geoPackageRaster)`.
18-
4. Add each layer to the map as an operational layer with `map.getOperationalLayers().add(layer)`.
19-
5. When it's done loading, get the `GeoPackageFeatureTable`s inside with `geoPackage.getGeoPackageFeatureTables()`.
20-
6. For each feature table, create a feature layer with `new FeatureLayer(featureTable)`.
21-
7. You can also get the `GeoPackageRaster`s inside using `GeoPackage.getGeoPackageRasters()`.
17+
1. Get the GeoPackage and load it using `geoPackage.loadAsync()`.
18+
2. Iterate through available rasters, exposed by `geopackage.getGeoPackageRasters()`. For each raster, create a raster layer using `new RasterLayer(geopackageRaster)`, then add it to the map.
19+
3. Iterate through available feature tables, exposed by `geopackage.getGeoPackageFeatureTables()`. For each feature table, create a feature layer using `new FeatureLayer(geopackageFeatureTable)`, then add it to the map.
2220

2321
## Relevant API
2422

25-
* ArcGISMap
26-
* Basemap
27-
* FeatureLayer
2823
* GeoPackage
29-
* Layer
30-
* MapView
31-
* RasterLayer
24+
* GeoPackageRaster
25+
* GeoPackageFeatureTable
26+
27+
## Offline data
28+
29+
Find this item on [ArcGIS Online](https://arcgisruntime.maps.arcgis.com/home/item.html?id=68ec42517cdd439e81b036210483e8e7).
30+
31+
## About the data
32+
33+
This sample features a GeoPackage with datasets that cover Aurora, Colorado: Public art (points), Bike trails (lines), Subdivisions (polygons), Airport noise (raster), and liquour license density (raster).
34+
35+
## Additional information
36+
37+
GeoPackage uses a single SQLite file (.gpkg) that conforms to the OGC GeoPackage Standard. You can create a GeoPackage file (.gpkg) from your own data using the create a SQLite Database tool in ArcGIS Pro.
38+
39+
## Tags
40+
41+
container, layers, maps, OGC, package, rasters, tables

map/read-geopackage/src/main/java/com/esri/samples/read_geopackage/ReadGeoPackageSample.java

+26-111
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,15 @@
1919
import java.io.File;
2020

2121
import javafx.application.Application;
22-
import javafx.geometry.Insets;
23-
import javafx.geometry.Pos;
2422
import javafx.scene.Scene;
25-
import javafx.scene.control.Label;
26-
import javafx.scene.control.ListCell;
27-
import javafx.scene.control.ListView;
28-
import javafx.scene.input.MouseButton;
29-
import javafx.scene.layout.Background;
30-
import javafx.scene.layout.BackgroundFill;
31-
import javafx.scene.layout.CornerRadii;
23+
import javafx.scene.control.Alert;
3224
import javafx.scene.layout.StackPane;
33-
import javafx.scene.layout.VBox;
34-
import javafx.scene.paint.Paint;
3525
import javafx.stage.Stage;
36-
import javafx.util.Callback;
3726

3827
import com.esri.arcgisruntime.data.GeoPackage;
3928
import com.esri.arcgisruntime.layers.FeatureLayer;
40-
import com.esri.arcgisruntime.layers.Layer;
4129
import com.esri.arcgisruntime.layers.RasterLayer;
30+
import com.esri.arcgisruntime.loadable.LoadStatus;
4231
import com.esri.arcgisruntime.mapping.ArcGISMap;
4332
import com.esri.arcgisruntime.mapping.Basemap;
4433
import com.esri.arcgisruntime.mapping.view.MapView;
@@ -54,7 +43,6 @@ public void start(Stage stage) {
5443
// create stack pane and application scene
5544
StackPane stackPane = new StackPane();
5645
Scene scene = new Scene(stackPane);
57-
scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm());
5846

5947
// set title, size, and add scene to stage
6048
stage.setTitle("Read GeoPackage Sample");
@@ -68,108 +56,35 @@ public void start(Stage stage) {
6856
mapView = new MapView();
6957
mapView.setMap(map);
7058

71-
// create two list views, one showing the layers in the map,
72-
// the other, showing the layers in the geoPackage not yet added to the map
73-
ListView<Layer> mapLayers = new ListView<>();
74-
ListView<Layer> geoPackageLayers = new ListView<>();
75-
76-
// create labels for the lists
77-
Label mapLayersLabel = new Label("Map layers");
78-
Label geoPackageLayersLabel = new Label("GeoPackage layers (not in the map)");
79-
mapLayersLabel.getStyleClass().add("panel-label");
80-
geoPackageLayersLabel.getStyleClass().add("panel-label");
81-
82-
// create a control panel
83-
VBox controlsVBox = new VBox(6);
84-
controlsVBox.setBackground(new Background(new BackgroundFill(Paint.valueOf("rgba(0,0,0,0.3)"), CornerRadii.EMPTY,
85-
Insets.EMPTY)));
86-
controlsVBox.setPadding(new Insets(10.0));
87-
controlsVBox.setMaxSize(250, 260);
88-
controlsVBox.getStyleClass().add("panel-region");
89-
90-
// add labels and lists to the control panel
91-
controlsVBox.getChildren().addAll(mapLayersLabel, mapLayers, geoPackageLayersLabel, geoPackageLayers);
92-
93-
// create a cell factory to show the layer names in the list view
94-
Callback<ListView<Layer>, ListCell<Layer>> cellFactory = list -> new ListCell<Layer>() {
95-
96-
@Override
97-
protected void updateItem(Layer layer, boolean bln) {
98-
99-
super.updateItem(layer, bln);
100-
if (layer != null) {
101-
if (layer instanceof FeatureLayer) {
102-
FeatureLayer featureLayer = (FeatureLayer) layer;
103-
setText(featureLayer.getName());
104-
} else if (layer instanceof RasterLayer) {
105-
RasterLayer rasterLayer = (RasterLayer) layer;
106-
// use the raster file name if the raster layer name is empty
107-
String path = rasterLayer.getRaster().getPath();
108-
setText(rasterLayer.getName().isEmpty() ? path.substring(path.lastIndexOf('/') + 1) : rasterLayer.getName());
109-
}
110-
} else {
111-
setText(null);
112-
}
113-
}
114-
115-
};
116-
117-
mapLayers.setCellFactory(cellFactory);
118-
geoPackageLayers.setCellFactory(cellFactory);
119-
120-
// when you click on a layer in the geopackage layers list view, add it to the map
121-
geoPackageLayers.setOnMouseClicked(e -> {
122-
if (e.isStillSincePress() && e.getButton() == MouseButton.PRIMARY) {
123-
// get selected layer
124-
Layer layer = geoPackageLayers.getSelectionModel().getSelectedItem();
125-
if (layer != null) {
126-
// add it to the map and the top of the map layers list
127-
map.getOperationalLayers().add(layer);
128-
mapLayers.getItems().add(0, layer);
129-
// remove it from the geoPackage layers list
130-
geoPackageLayers.getItems().remove(layer);
131-
}
132-
}
133-
});
134-
135-
// when you click on a layer in the map layers list view, remove it from the map
136-
mapLayers.setOnMouseClicked(e -> {
137-
if (e.isStillSincePress() && e.getButton() == MouseButton.PRIMARY) {
138-
// get selected layer
139-
Layer layer = mapLayers.getSelectionModel().getSelectedItem();
140-
if (layer != null) {
141-
// remove it from the map and the map layers list
142-
map.getOperationalLayers().remove(layer);
143-
mapLayers.getItems().remove(layer);
144-
// add it back to the geoPackage layers list
145-
geoPackageLayers.getItems().add(layer);
146-
}
147-
}
148-
});
149-
150-
// read the raster and feature layers from the geoPackage and show them in the list view
59+
// load the local GeoPackage
15160
File geoPackageFile = new File("./samples-data/auroraCO/AuroraCO.gpkg");
15261
GeoPackage geoPackage = new GeoPackage(geoPackageFile.getAbsolutePath());
15362
geoPackage.loadAsync();
15463
geoPackage.addDoneLoadingListener(() -> {
155-
geoPackage.getGeoPackageRasters().forEach(raster -> {
156-
RasterLayer rasterLayer = new RasterLayer(raster);
157-
rasterLayer.loadAsync();
158-
// make the raster layer semi-transparent so we can see layers below it
159-
rasterLayer.setOpacity(0.5f);
160-
geoPackageLayers.getItems().add(rasterLayer);
161-
});
162-
geoPackage.getGeoPackageFeatureTables().forEach(table -> {
163-
FeatureLayer featureLayer = new FeatureLayer(table);
164-
featureLayer.loadAsync();
165-
geoPackageLayers.getItems().add(featureLayer);
166-
});
64+
if (geoPackage.getLoadStatus() == LoadStatus.LOADED) {
65+
// add raster layers from the rasters in the GeoPackage
66+
geoPackage.getGeoPackageRasters().forEach(raster -> {
67+
RasterLayer rasterLayer = new RasterLayer(raster);
68+
// make the layer semi-transparent to see through it
69+
rasterLayer.setOpacity(0.5f);
70+
71+
map.getOperationalLayers().add(rasterLayer);
72+
});
73+
74+
// add feature layers from the feature tables in the GeoPackage
75+
geoPackage.getGeoPackageFeatureTables().forEach(table -> {
76+
FeatureLayer featureLayer = new FeatureLayer(table);
77+
78+
map.getOperationalLayers().add(featureLayer);
79+
});
80+
} else {
81+
new Alert(Alert.AlertType.ERROR, "GeoPackage failed to load").show();
82+
}
16783
});
16884

169-
// add the map view and control box to stack pane
170-
stackPane.getChildren().addAll(mapView, controlsVBox);
171-
StackPane.setAlignment(controlsVBox, Pos.TOP_LEFT);
172-
StackPane.setMargin(controlsVBox, new Insets(10, 0, 0, 10));
85+
// add the map view to the stack pane
86+
stackPane.getChildren().add(mapView);
87+
17388
} catch (Exception e) {
17489
// on any error, display the stack trace
17590
e.printStackTrace();
@@ -197,4 +112,4 @@ public static void main(String[] args) {
197112
Application.launch(args);
198113
}
199114

200-
}
115+
}

map/read-geopackage/src/main/resources/style.css

-27
This file was deleted.

0 commit comments

Comments
 (0)