Shared Samples

Build, modify and run workflows on geospatial data using Spatial Modeler SDK. Build complex algorithms or run routine tasks, and build add-ons to ERDAS IMAGINE and GeoMedia.
Showing results for 
Search instead for 
Do you mean 

Coordinate Transformation

by Technical Evangelist ‎09-30-2019 04:52 AM - edited ‎09-30-2019 06:12 AM (105 Views)

Abstract

The coordinate transformation sample is intended to make beginners familiar with MAE Client programming. A simple plugin is created to show the WGS84 representation of a captured point in a simple dialog. 

 

Bitbucket Link

https://bitbucket.org/HGDN/hgdn_mae/src/master/Desktop/CoordinateTransformation/

 

Description

The CoordinateTransformationPlugin offers an action to start the geometry capture process. Whenever an extension is needed that should capture a geometry without actually manipulating an item of an existing layer, a GeometryCapture instance is needed. In this case, the only event we are interested in is the onGeometriesCaptured event. So whenever a user captures a point, a new TransformationResultDialog is shown, displaying the coordinates of the captured point in WGS84 representation.  

 

public class CoordinateTransformationPlugin implements Plugin {

  @Action(actionLocation = ActionLocation.PluginTab.class)
  public void startWGS84Converter() {
    GeometryCaptureListener<Point> geometryCaptureListener = new GeometryCaptureListener<Point>() {

      ...

      @Override
      public void onGeometriesCaptured(GeometryCapture source, Stream<Point> geometries) {
        geometries.findFirst().ifPresent(g -> {
          TransformationResultDialog dialog =
              new TransformationResultDialog(Envelope.center(g.getEnvelope()));

          dialog.setVisible(true);

        });
      }
    };

    ...
  }
}

 

The TransformationResultDialog itself is a simple dialog that extends the DefaultDialog containing a JPanel to show the point coordinates in the project coordinate system and the WGS84 representation.  

public class TransformationResultDialog extends DefaultDialog {
...
  @Override
  protected JComponent getDisplayView() {
    JPanel panel = new JPanel(new MigLayout("ins 0", "[grow]", "[][grow]"));
    panel.setOpaque(false);

    panel.add(new JLabel("hor: " + coordinateToTransform.getX()), "grow, wrap");
    panel.add(new JLabel("vert: " + coordinateToTransform.getY()), "grow, wrap");
    panel.add(new JLabel("<html><br><strong>Result:</strong></html>"), "grow, wrap");

    panel.add(new JLabel("Latitude :" + transformedCoordinate.getX()), "grow, wrap");
    panel.add(new JLabel("Longitude :" + transformedCoordinate.getY()), "grow, wrap");

    return panel;
  }
...
}

 

Overview
Contributors