Working with the Coordinate System in 2D Windows

Coordinates can be expressed in pixels or model units within a layered window:

  • Coordinates in pixels starting from the layer origin are device coordinates. These coordinates do not depend on the scrolling status of the layered window.
  • Coordinates in pixels starting from the viewport origin are viewport coordinates. These coordinates depend on the scrolling status of the layered window.
  • Coordinates that are shown on the axes are model coordinates. These coordinates do not depend on the scrolling status of the layered window.

Converting between viewport and device coordinates

You can transform easily from viewport to device coordinates as follows:

    ISeismicLayer layer = ...
    int deviceX = viewportX + layer.getViewerWindow().getViewportOrigin().x;
    int deviceY = viewportY + layer.getViewerWindow().getViewportOrigin().y;

In this example:

  • viewportX is the value typically returned by the MouseEvent.getX() method
  • viewportY is the value typically returned by the MouseEvent.getY() method

Converting between device and model coordinates

Conversion between device and model coordinates can easily be done using ILayer2D method deviceToModel as shown below:

    import java.awt.Point;
    import java.awt.geom.Point2D;
    ...
    Point2D model = layer.deviceToModel(new Point(deviceX, deviceY));

See also modelToDevice for converting from model to device coordinates.

XSection windows

For XSection windows, the model coordinate system along the Y direction corresponds to time (or depth) units.

In the X direction, the model coordinate is virtual trace index. You can convert to real trace index using:

        ISeismicLayer layer = ...
        int tid = layer.modelToTraceIndex(model.getX());
        if (tid >=0 ) { // -1 for gaps
            // get the reader to be able to access the trace
            ISeismicReader reader = layer.getReader();
            ITrace trace = reader.getTrace(tid);
            ...
        }

When constant trace spacing is enabled (the default), the trace with the index 0 is displayed between the model coordinates 0 and 1. Its middle has the model coordinates of 0.5. However this is not true when variable trace spacing is enabled. This is why using modelToTraceIndex is the better way to convert model coordinates to trace indexes.

For a given set of key values such as inline and xline, there is a convenient search function that will return the first trace index matching those values.

    SeismicRangeQuery query = new SeismicRangeQuery();
    SeismicKeyRange inlineRange = new SeismicKeyRange(inlineName, (double) inline, (double) inline);
    query.addKeyRange(inlineRange);
    SeismicKeyRange xlineRange = new SeismicKeyRange(xlineName, (double) xline, (double) xline);
    query.addKeyRange(xlineRange);
    int tid = reader.findFirstTrace(query);

Please note that more that one trace may match the query. For example, if you apply this query to the reader of a layer displaying gathers, the trace index of the first trace in the gather will be returned. Also, note that -1 will be returned if not trace matching the query is found.

Map windows

For map windows, you can have 3 different display domains:

  • IMapWindow.IJ - for an Inline/Xline coordinate system
  • IMapWindow.XY - for a XY based coordinate system
  • IMapWindow.LAT_LONG - for a geodetic coordinate system

Transformation for a seismic ILayer2D are provided to convert from XY to IJ and reverse.

    IMapSeismicLayer layer = ...
    double x = ...
    double y = ...
    double inline;
    double xline;
    IJToXYTransformation ctr = layer.getIJToXYTransformation();
    double values[];
    if (ctr != null && ctr.isValidCoordMatrix()) {
        values = ctr.coordTrans(x, y);
        inline = values[0];
        xline = values[1];
    }

You can perform the invert transform using method invCoordTrans.

An extension mechanism is also provided to implement your own coordinate system.