Class GridCoordSys

  • All Implemented Interfaces:
    GridCoordSystem

    public class GridCoordSys
    extends CoordinateSystem
    implements GridCoordSystem
    A georeferencing "gridded" CoordinateSystem. This describes a "grid" of coordinates, which implies a connected topology such that values next to each other in index space are next to each other in coordinate space.

    This currently assumes that the CoordinateSystem

    1. is georeferencing (has Lat, Lon or GeoX, GeoY axes)
    2. x, y are 1 or 2-dimensional axes.
    3. rt, z, e are 1-dimensional axes.
    4. t is 1 or 2 dimensional. if 2d, then rt exists

    This is the common case for georeferencing coordinate systems. Mathematically it is a product set: {X,Y} x {Z} x {T}. The x and y axes may be 1 or 2 dimensional.

    A CoordinateSystem may have multiple horizontal and vertical axes. GridCoordSys chooses one axis corresponding to X, Y, Z, and T. It gives preference to one dimensional axes (CoordinateAxis1D).

    • Constructor Detail

      • GridCoordSys

        public GridCoordSys​(CoordinateSystem cs,
                            Formatter sbuff)
        Create a GridCoordSys from an existing Coordinate System. This will choose which axes are the XHoriz, YHoriz, Vertical, Time, RunTIme, Ensemble. If theres a Projection, it will set its map area
        Parameters:
        cs - create from this Coordinate System
        sbuff - place information messages here, may be null
      • GridCoordSys

        public GridCoordSys​(GridCoordSys from,
                            Range t_range,
                            Range z_range,
                            Range y_range,
                            Range x_range)
                     throws InvalidRangeException
        Create a GridCoordSys as a section of an existing GridCoordSys. This will create sections of the corresponding CoordinateAxes.
        Parameters:
        from - copy this GridCoordSys
        t_range - subset the time dimension, or null if you want all of it
        z_range - subset the vertical dimension, or null if you want all of it
        y_range - subset the y dimension, or null if you want all of it
        x_range - subset the x dimension, or null if you want all of it
        Throws:
        InvalidRangeException - if any of the ranges are illegal
      • GridCoordSys

        public GridCoordSys​(GridCoordSys from,
                            Range rt_range,
                            Range e_range,
                            Range t_range,
                            Range z_range,
                            Range y_range,
                            Range x_range)
                     throws InvalidRangeException
        Create a GridCoordSys as a section of an existing GridCoordSys. This will create sections of the corresponding CoordinateAxes.
        Parameters:
        from - copy this GridCoordSys
        rt_range - subset the runtime dimension, or null if you want all of it
        e_range - subset the ensemble dimension, or null if you want all of it
        t_range - subset the time dimension, or null if you want all of it
        z_range - subset the vertical dimension, or null if you want all of it
        y_range - subset the y dimension, or null if you want all of it
        x_range - subset the x dimension, or null if you want all of it
        Throws:
        InvalidRangeException - if any of the ranges are illegal
    • Method Detail

      • isGridCoordSys

        public static boolean isGridCoordSys​(Formatter sbuff,
                                             CoordinateSystem cs,
                                             VariableEnhanced ve)
        Determine if this CoordinateSystem can be made into a GridCoordSys. Optionally for a given variable. This currently assumes that the CoordinateSystem:
        1. is georeferencing (cs.isGeoReferencing())
        2. x, y are 1 or 2-dimensional axes.
        3. z, t, if they exist, are 1-dimensional axes.
        4. domain rank > 1
        Parameters:
        sbuff - place information messages here, may be null
        cs - the CoordinateSystem to test
        ve - can it be used for this variable; v may be null
        Returns:
        true if it can be made into a GridCoordSys.
        See Also:
        CoordinateSystem.isGeoReferencing()
      • makeGridCoordSys

        public static GridCoordSys makeGridCoordSys​(Formatter sbuff,
                                                    CoordinateSystem cs,
                                                    VariableEnhanced v)
        Determine if the CoordinateSystem cs can be made into a GridCoordSys for the Variable v.
        Parameters:
        sbuff - put debug information into this StringBuffer; may be null.
        cs - CoordinateSystem to check.
        v - Variable to check.
        Returns:
        the GridCoordSys made from cs, else null.
      • getVerticalCT

        public VerticalCT getVerticalCT()
        Get the Coordinate Transform description.
        Specified by:
        getVerticalCT in interface GridCoordSystem
        Returns:
        Coordinate Transform description, or null if none
      • setProjectionBoundingBox

        public void setProjectionBoundingBox()
        Description copied from interface: GridCoordSystem
        Use the bounding box to set the defaule map are of the projection. This can be expensive if its a 2D coordinate system.
        Specified by:
        setProjectionBoundingBox in interface GridCoordSystem
      • isGlobalLon

        public boolean isGlobalLon()
        Is this a global coverage over longitude ?
        Specified by:
        isGlobalLon in interface GridCoordSystem
        Returns:
        true if isLatLon and longitude wraps
      • isZPositive

        public boolean isZPositive()
        true if increasing z coordinate values means "up" in altitude
        Specified by:
        isZPositive in interface GridCoordSystem
        Returns:
        true if increasing z coordinate values means "up" in altitude
      • isRegularSpatial

        public boolean isRegularSpatial()
        true if x and y axes are CoordinateAxis1D and are regular
        Specified by:
        isRegularSpatial in interface GridCoordSystem
        Returns:
        true if both X and Y axes are 1 dimensional and are regularly spaced.
      • setHorizStaggerType

        public void setHorizStaggerType​(String horizStaggerType)
      • findXYindexFromCoord

        public int[] findXYindexFromCoord​(double x_coord,
                                          double y_coord,
                                          int[] result)
        Given a point in x,y coordinate space, find the x,y index in the coordinate system.
        Specified by:
        findXYindexFromCoord in interface GridCoordSystem
        Parameters:
        x_coord - position in x coordinate space.
        y_coord - position in y coordinate space.
        result - put result (x,y) index in here, may be null
        Returns:
        int[2], 0=x,1=y indices in the coordinate system of the point. These will be -1 if out of range.
      • findXYindexFromCoordBounded

        public int[] findXYindexFromCoordBounded​(double x_coord,
                                                 double y_coord,
                                                 int[] result)
        Given a point in x,y coordinate space, find the x,y index in the coordinate system. If outside the range, the closest point is returned, eg, 0 or n-1 depending on if the coordinate is too small or too large.
        Specified by:
        findXYindexFromCoordBounded in interface GridCoordSystem
        Parameters:
        x_coord - position in x coordinate space.
        y_coord - position in y coordinate space.
        result - put result in here, may be null
        Returns:
        int[2], 0=x,1=y indices in the coordinate system of the point.
      • findXYindexFromLatLon

        public int[] findXYindexFromLatLon​(double lat,
                                           double lon,
                                           int[] result)
        Given a lat,lon point, find the x,y index in the coordinate system.
        Specified by:
        findXYindexFromLatLon in interface GridCoordSystem
        Parameters:
        lat - latitude position.
        lon - longitude position.
        result - put result in here, may be null
        Returns:
        int[2], 0=x,1=y indices in the coordinate system of the point. These will be -1 if out of range.
      • findXYindexFromLatLonBounded

        public int[] findXYindexFromLatLonBounded​(double lat,
                                                  double lon,
                                                  int[] result)
        Given a lat,lon point, find the x,y index in the coordinate system. If outside the range, the closest point is returned
        Specified by:
        findXYindexFromLatLonBounded in interface GridCoordSystem
        Parameters:
        lat - latitude position.
        lon - longitude position.
        result - put result in here, may be null
        Returns:
        int[2], 0=x,1=y indices in the coordinate system of the point.
      • hasTimeAxis1D

        public boolean hasTimeAxis1D()
        True if there is a Time Axis and it is 1D.
        Specified by:
        hasTimeAxis1D in interface GridCoordSystem
        Returns:
        true if there is a Time Axis and it is 1D.
      • getTimeAxisForRun

        public CoordinateAxis1DTime getTimeAxisForRun​(int run_index)
        Deprecated.
        doesnt work correctly for intervals
        Description copied from interface: GridCoordSystem
        This is the case of a 2D time axis, which depends on the run index. A time coordinate must be a udunit date or ISO String, so it can always be converted to a Date.
        Specified by:
        getTimeAxisForRun in interface GridCoordSystem
        Parameters:
        run_index - which run?
        Returns:
        1D time axis for that run. Null if not 2D time
      • getLatLon

        public LatLonPoint getLatLon​(int xindex,
                                     int yindex)
        Get the Lat/Lon coordinates of the midpoint of a grid cell, using the x,y indices
        Specified by:
        getLatLon in interface GridCoordSystem
        Parameters:
        xindex - x index
        yindex - y index
        Returns:
        lat/lon coordinate of the midpoint of the cell
      • getLatLon

        public LatLonPoint getLatLon​(double xcoord,
                                     double ycoord)
      • getLatLonBoundingBox

        public LatLonRect getLatLonBoundingBox()
        Get horizontal bounding box in lat, lon coordinates. If projection coordinates are used, the lat/ lon box is calculated from the perimeter of the projection coordinates box
        Specified by:
        getLatLonBoundingBox in interface GridCoordSystem
        Returns:
        lat, lon bounding box.
      • getRangesFromLatLonRect

        public List<Range> getRangesFromLatLonRect​(LatLonRect rect)
                                            throws InvalidRangeException
        Get Index Ranges for the given lat, lon bounding box. For projection, only an approximation based on latlon corners. Must have CoordinateAxis1D or 2D for x and y axis.
        Specified by:
        getRangesFromLatLonRect in interface GridCoordSystem
        Parameters:
        rect - the requested lat/lon bounding box
        Returns:
        list of 2 Range objects, first y then x.
        Throws:
        InvalidRangeException - if llbb generates bad ranges
      • getLevels

        @Deprecated
        public List<NamedObject> getLevels()
        Deprecated.
        will move in ver 6
        Get the list of level names, to be used for user selection. The ith one refers to the ith level coordinate.
        Returns:
        List of ucar.nc2.util.NamedObject, or empty list.
      • getLevelName

        public String getLevelName​(int index)
        Get the String name for the ith level(z) coordinate.
        Parameters:
        index - which level coordinate
        Returns:
        level name
      • getLevelIndex

        public int getLevelIndex​(String name)
        Get the index corresponding to the level name.
        Parameters:
        name - level name
        Returns:
        level index, or -1 if not found
      • getTimes

        @Deprecated
        public List<NamedObject> getTimes()
        Deprecated.
        will move in ver 6
        Get the list of time names, to be used for user selection. The ith one refers to the ith time coordinate.
        Returns:
        List of ucar.nc2.util.NamedObject, or empty list.
      • findXYCoordElement

        public int[] findXYCoordElement​(double x_coord,
                                        double y_coord,
                                        int[] result)
        Deprecated.
        use findXYindexFromCoord
        Given a point in x,y coordinate space, find the x,y index in the coordinate system.
      • getDateRange

        public DateRange getDateRange()
        Deprecated.
        use getCalendarDateRange
        Get the date range
        Specified by:
        getDateRange in interface GridCoordSystem
        Returns:
        date range
      • getTimeDates

        public Date[] getTimeDates()
        Deprecated.
        use getCalendarDates
        Get the list of times as Dates. If 2D, return list of unique dates.
        Returns:
        array of java.util.Date, or Date[0].
      • getTimeName

        public String getTimeName​(int index)
        Deprecated.
        Get the string name for the ith time coordinate.
        Parameters:
        index - which time coordinate
        Returns:
        time name.
      • getTimeIndex

        public int getTimeIndex​(String name)
        Deprecated.
        Get the index corresponding to the time name.
        Parameters:
        name - time name
        Returns:
        time index, or -1 if not found
      • findTimeIndexFromDate

        public int findTimeIndexFromDate​(Date d)
        Deprecated.
        use CoordinateAxis1DTime.findTimeIndexFromDate
        Only works if coordsys has 1d time axis
      • getLatLonBoundingBox

        @Deprecated
        public static LatLonRect getLatLonBoundingBox​(Projection proj,
                                                      double startx,
                                                      double starty,
                                                      double endx,
                                                      double endy)
        Deprecated.
        use Projection.projToLatlonBB