Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

handle all coordinate transforms #1197

Merged
merged 1 commit into from
Dec 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions cdm/src/main/java/ucar/nc2/dt/grid/CFGridWriter2.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

package ucar.nc2.dt.grid;

import org.w3c.dom.Attr;

import ucar.ma2.Array;
import ucar.ma2.DataType;
import ucar.ma2.InvalidRangeException;
Expand Down Expand Up @@ -509,14 +511,36 @@ private void addCoordinateAxis(GridCoordSystem gcs, List<String> varNameList, Li

private void addCoordinateTransform(GridCoordSystem gcs, NetcdfFile ncd, List<String> varNameList, List<Variable> varList) {

List<String> coordTransformNames = new ArrayList<>();

// look for variables detected as coordinate transforms
for (CoordinateTransform ct : gcs.getCoordinateTransforms()) {
Variable v = ncd.findVariable(ct.getName());
if (!varNameList.contains(ct.getName()) && (null != v)) {
varNameList.add(ct.getName());
varList.add(v);
coordTransformNames.add(ct.getName());
}

// At the very least, LatLon_Projection will not show up in the coordinate transforms,
// so inspect the variables in varNameList for a grid_mapping attribute, and make sure it
// gets picked up as well
// see https://github.com/Unidata/python-workshop/issues/372
for (String varName : varNameList) {
Variable v = ncd.findVariable(varName);
Attribute gridMapping = v.findAttributeIgnoreCase(CF.GRID_MAPPING);
if (gridMapping != null) {
String gridMappingName = gridMapping.getStringValue();
if ((gridMappingName != null) && (!coordTransformNames.contains(gridMappingName))) {
coordTransformNames.add(gridMappingName);
}
}
}

// add the coordinate transforms that we found
for (String ctVarName : coordTransformNames) {
Variable v = ncd.findVariable(ctVarName);
if (!varNameList.contains(ctVarName) && (null != v)) {
varNameList.add(ctVarName);
varList.add(v);
}
}
}


Expand Down