Skip to content

Commit 9709cd7

Browse files
committed
Merge branch 'master' into 100.2.1
2 parents 757624c + f6b1f63 commit 9709cd7

File tree

3 files changed

+222
-0
lines changed

3 files changed

+222
-0
lines changed
128 KB
Loading
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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.geometry.list_transformations_by_suitability;
18+
19+
import java.util.List;
20+
21+
import javafx.application.Application;
22+
import javafx.event.ActionEvent;
23+
import javafx.geometry.Insets;
24+
import javafx.geometry.Pos;
25+
import javafx.scene.Scene;
26+
import javafx.scene.control.Button;
27+
import javafx.scene.control.CheckBox;
28+
import javafx.scene.control.ListCell;
29+
import javafx.scene.control.ListView;
30+
import javafx.scene.layout.StackPane;
31+
import javafx.scene.layout.VBox;
32+
import javafx.stage.Stage;
33+
34+
import com.esri.arcgisruntime.geometry.DatumTransformation;
35+
import com.esri.arcgisruntime.geometry.GeometryEngine;
36+
import com.esri.arcgisruntime.geometry.Point;
37+
import com.esri.arcgisruntime.geometry.SpatialReference;
38+
import com.esri.arcgisruntime.geometry.TransformationCatalog;
39+
import com.esri.arcgisruntime.mapping.ArcGISMap;
40+
import com.esri.arcgisruntime.mapping.Basemap;
41+
import com.esri.arcgisruntime.mapping.view.Graphic;
42+
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
43+
import com.esri.arcgisruntime.mapping.view.MapView;
44+
import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol;
45+
46+
public class ListTransformationsBySuitabilitySample extends Application {
47+
48+
private MapView mapView;
49+
50+
@Override
51+
public void start(Stage stage) throws Exception {
52+
53+
try {
54+
// create stack pane and application scene
55+
StackPane stackPane = new StackPane();
56+
Scene scene = new Scene(stackPane);
57+
scene.getStylesheets().add(getClass().getResource("/css/style.css").toExternalForm());
58+
59+
// set title, size, and add scene to stage
60+
stage.setTitle("List Transformations by Suitability Sample");
61+
stage.setWidth(800);
62+
stage.setHeight(700);
63+
stage.setScene(scene);
64+
stage.show();
65+
66+
// create a map with light gray canvas basemap and add it to the map view
67+
ArcGISMap map = new ArcGISMap(Basemap.createLightGrayCanvas());
68+
mapView = new MapView();
69+
mapView.setMap(map);
70+
71+
// create a graphics overlay to show the original graphic and the the transformed graphic
72+
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
73+
mapView.getGraphicsOverlays().add(graphicsOverlay);
74+
75+
// create a blue square graphic located in the Greenwich observatory courtyard in London, UK, the location of the
76+
// Greenwich prime meridian. This will be projected using the selected transformation.
77+
Point originalPoint = new Point(538985.355, 177329.516, SpatialReference.create(27700));
78+
Graphic originalGraphic = new Graphic(originalPoint, new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.SQUARE, 0xFF0000FF,
79+
10));
80+
graphicsOverlay.getGraphics().add(originalGraphic);
81+
82+
// create red cross graphic for transformed point
83+
Graphic transformedGraphic = new Graphic();
84+
transformedGraphic.setSymbol(new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CROSS, 0xFFFF0000, 10));
85+
transformedGraphic.setVisible(false);
86+
graphicsOverlay.getGraphics().add(transformedGraphic);
87+
88+
// zoom to the location of the original graphic
89+
mapView.setViewpointCenterAsync(originalPoint, 5000);
90+
91+
// create a list of transformations
92+
ListView<DatumTransformation> transformationsListView = new ListView<>();
93+
94+
// show the transformation name in the list
95+
transformationsListView.setCellFactory(list -> new ListCell<DatumTransformation>() {
96+
97+
@Override
98+
protected void updateItem(DatumTransformation transformation, boolean bln) {
99+
100+
super.updateItem(transformation, bln);
101+
if (transformation != null) {
102+
setText(transformation.getName());
103+
}
104+
}
105+
106+
});
107+
108+
// if the checkbox is not selected, transformations should be ordered by suitability for the whole
109+
// spatial reference. If checked, then transformations will be ordered by suitability for the map extent.
110+
CheckBox suitabilityCheckBox = new CheckBox("Order by extent suitability");
111+
suitabilityCheckBox.setOnAction(e -> {
112+
transformationsListView.getItems().clear();
113+
List<DatumTransformation> transformations;
114+
if (suitabilityCheckBox.isSelected()) {
115+
transformations = TransformationCatalog.getTransformationsBySuitability(
116+
originalGraphic.getGeometry().getSpatialReference(), map.getSpatialReference(), mapView.getVisibleArea().getExtent());
117+
} else {
118+
transformations = TransformationCatalog.getTransformationsBySuitability(
119+
originalGraphic.getGeometry().getSpatialReference(), map.getSpatialReference());
120+
}
121+
transformationsListView.getItems().addAll(transformations);
122+
});
123+
124+
// trigger the event to load the initial transformations list when the map is loaded
125+
map.addDoneLoadingListener(() -> suitabilityCheckBox.fireEvent(new ActionEvent()));
126+
127+
// create a button that when clicked, shows a new graphic with the selected transformation applied
128+
Button transformButton = new Button("Transform");
129+
transformButton.setOnAction(e -> {
130+
DatumTransformation transformation = transformationsListView.getSelectionModel().getSelectedItem();
131+
if (transformation != null) {
132+
Point projectedPoint = (Point) GeometryEngine.project(originalGraphic.getGeometry(), mapView.getSpatialReference(),
133+
transformation);
134+
transformedGraphic.setVisible(true);
135+
transformedGraphic.setGeometry(projectedPoint);
136+
}
137+
});
138+
139+
// add the controls to the view
140+
VBox vBox = new VBox(6);
141+
vBox.setMaxSize(300, 500);
142+
vBox.getStyleClass().add("panel-region");
143+
vBox.getChildren().addAll(suitabilityCheckBox, transformationsListView, transformButton);
144+
145+
// add the map view to stack pane
146+
stackPane.getChildren().addAll(mapView, vBox);
147+
StackPane.setAlignment(vBox, Pos.TOP_LEFT);
148+
StackPane.setMargin(vBox, new Insets(10, 0, 0, 10));
149+
} catch (Exception e) {
150+
// on any error, display the stack trace.
151+
e.printStackTrace();
152+
}
153+
}
154+
155+
/**
156+
* Stops and releases all resources used in application.
157+
*/
158+
@Override
159+
public void stop() {
160+
161+
if (mapView != null) {
162+
mapView.dispose();
163+
}
164+
}
165+
166+
/**
167+
* Opens and runs application.
168+
*
169+
* @param args arguments passed to this application
170+
*/
171+
public static void main(String[] args) {
172+
173+
Application.launch(args);
174+
}
175+
176+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<h1>List Transformations By Suitability</h1>
2+
3+
<p>Demonstrates how to use the TransformationCatalog to get a list of available DatumTransformations that
4+
can be used to project a Geometry between two different SpatialReferences.</p>
5+
6+
<p>Transformations (sometimes known as datum or geographic transformations) are used when projecting data from one
7+
spatial reference to another, when there is a difference in the underlying datum of the spatial references.
8+
Transformations can be mathematically defined by specific equations (equation-based transformations), or may rely on
9+
external supporting files (grid-based transformations). Choosing the most appropriate transformation for a situation
10+
can ensure the best possible accuracy for this operation. Some users familiar with transformations may wish to
11+
control which transformation is used in an operation.</p>
12+
13+
<p><img src="ListTransformationsBySuitability.png"/></p>
14+
15+
<h2>How to use the sample</h2>
16+
17+
<p>The list displays all suitable tranformations between the graphic and the map. Once the transform button is clicked a new red graphic will appear showing where the original graphic whould be placed if transformation was applied.</p>
18+
19+
<p>Order by extent suitability, if checked, will find suitable transformations within the map's visible area. If not checked, will find suitable trnasformations using the whole map.</p>
20+
21+
<h2>How it works</h2>
22+
23+
<p>To get suitable transformations from one spatial reference to another:</p>
24+
25+
<ol>
26+
<li>Use <code>TransformationCatalog.getTransformationsBySuitability(inputSR, outputSR)</code> for transformations
27+
based on the map's spatial reference OR <code>TransformationCatalog.getTransformationsBySuitability(inputSR,
28+
outputSR, mapView.getCurrentVisibileArea().getExtent())</code> for transformations suitable to the current extent
29+
.</li>
30+
<li>Pick one of the <code>DatumTransformation</code>s returned. Use <code>GeometryEngine.project(inputGeometry,
31+
outputSR, datumTransformation)</code> to get the transformed geometry.</li>
32+
</ol>
33+
34+
<h2>Features</h2>
35+
<ul>
36+
<li>ArcGISMap</li>
37+
<li>Basemap</li>
38+
<li>DatumTransformation</li>
39+
<li>GeometryEngine</li>
40+
<li>Graphic</li>
41+
<li>GraphicsOverlay</li>
42+
<li>Point</li>
43+
<li>SimpleMarkerSymbol</li>
44+
<li>SpatialReference
45+
<li>TransformationCatalog</li>
46+
</ul>

0 commit comments

Comments
 (0)