Get a list of suitable transformations for projecting a geometry between two spatial references with different horizontal datums.
Use case
Transformations (sometimes known as datum or geographic transformations) are used when projecting data from one spatial reference to another when there is a difference in the underlying datum of the spatial references. Transformations can be mathematically defined by specific equations (equation-based transformations), or may rely on external supporting files (grid-based transformations). Choosing the most appropriate transformation for a situation can ensure the best possible accuracy for this operation. Some users familiar with transformations may wish to control which transformation is used in an operation.
How to use the sample
Check the checkbox to order the list of transformations by suitability for the map extent, if desired. Select a transformation from the list to see the result of projecting the point from EPSG:27700 to EPSG:3857 using that transformation. The result is shown as a red cross; you can visually compare the original blue point with the projected red cross. If the selected transformation is not usable (has missing grid files) then an error is displayed.
How it works
- Pass the input and output spatial references to
TransformationCatalog.getTransformationsBySuitability
for transformations based on the map's spatial reference OR additionally provide an extent argument to only return transformations suitable to the extent. This returns a list of ranked transformations. - Use one of the
DatumTransformation
objects returned to project the input geometry to the output spatial reference.
Relevant API
- DatumTransformation
- GeographicTransformation
- GeographicTransformationStep
- GeometryEngine
- GeometryEngine.Project
- TransformationCatalog
Offline Data
- To use the Projection Engine in ArcGIS Runtime, extra resources are required. Download the data Projection Engine Data from ArcGIS for Developers.
- Extract the contents of the downloaded zip file to disk.
- Open your command prompt and navigate to the folder where you extracted the contents of the data from step 2.
- Push the data into the scoped storage of the sample app:
adb push PEDataRuntime /Android/data/com.esri.arcgisruntime.sample.transformsbysuitability/files/PEDataRuntime
Additional information
Some transformations aren't available until transformation data is provided.
This sample uses a GeographicTransformation
, which extends the DatumTransformation
class. As of 100.9, ArcGIS Runtime also includes a HorizontalVerticalTransformation
, which also extends DatumTransformation
. The HorizontalVerticalTransformation
class is used to transform coordinates of z-aware geometries between spatial references that have different geographic and/or vertical coordinate systems.
This sample can be used with or without provisioning projection engine data to your device. If you do not provision data, a limited number of transformations will be available.
About the data
The map starts out zoomed into the grounds of the Royal Observatory, Greenwich. The initial point is in the British National Grid spatial reference, which was created by the United Kingdom Ordnance Survey. The spatial reference after projection is in web mercator.
Tags
datum, geodesy, projection, spatial reference, transformation
Sample Code
/* Copyright 2017 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.esri.arcgisruntime.sample.transformsbysuitability;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.esri.arcgisruntime.geometry.DatumTransformation;
import com.esri.arcgisruntime.geometry.GeographicTransformation;
import com.esri.arcgisruntime.geometry.GeographicTransformationStep;
/**
* Adapter that takes an ArrayList of DatumTransformations and shows the name of each transformation, and details
* of missing grid files, if any.
*/
public class DatumTransformationAdapter extends ArrayAdapter<DatumTransformation> {
private DatumTransformation defaultValue;
public DatumTransformationAdapter(Context context, ArrayList<DatumTransformation> transformations) {
super(context, 0, transformations);
}
/**
* When default transformation is set, the default transformation will be shown in the list with a Bold font.
* @param defaultTransformation the default transformation
*/
public void setDefaultTransformation(DatumTransformation defaultTransformation) {
defaultValue = defaultTransformation;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.custom_list_item,
parent, false);
}
convertView.setEnabled(true);
// Lookup TextViews in this list item for displaying transform information
TextView tvName = convertView.findViewById(android.R.id.text1);
TextView tvFiles = convertView.findViewById(android.R.id.text2);
// Get the data item for this position
DatumTransformation transformation = getItem(position);
// Set the name of the transformation into the first TextView
tvName.setText(transformation.getName());
StringBuilder sb = new StringBuilder();
// Look for unusable transformations
if (transformation.isMissingProjectionEngineFiles()) {
sb.append(getContext().getResources().getString(R.string.adapter_missing_files));
if (transformation instanceof GeographicTransformation) {
GeographicTransformation gt = (GeographicTransformation)transformation;
// Get the names of missing grid files from the steps in this transformation.
// If there are multiple steps, one or more may report missing grid files
for (GeographicTransformationStep step : gt.getSteps()) {
if (step.isMissingProjectionEngineFiles()) {
// Add missing files to the list to be reported to the user
sb.append(": " );
sb.append(TextUtils.join(", ", step.getProjectionEngineFilenames()));
}
}
}
// List items for transformations with missing grid files appear different in the UI.
convertView.setEnabled(false);
}
// If the default transformation is set, then highlight the default transformation in the list
// by setting the font to Bold.
if ((defaultValue != null) && (defaultValue.equals(transformation) )) {
tvName.setTypeface(null, Typeface.BOLD);
} else {
tvName.setTypeface(null, Typeface.NORMAL);
}
// Update the second TextView to indicate if there are missing grid files or not.
tvFiles.setText(sb.toString());
// Return the completed view to render on screen
return convertView;
}
}