/** * Indicates if a VisAD MathType is compatible with this instance. A RealType is compatible if its * {@link RealType#equalsExceptNameButUnits} method returns true when given the return value of * {@link #getRealType()} and if this quantity has no coordinate system transformation. A * RealTupleType is compatible if its {@link RealTupleType#equalsExceptNameButUnits} method * returns true when given the return value of {@link #getRealTupleType()} and if the coordinate * system transformations are compatible. A SetType is compatible if its RealTupleType is * compatible. A FunctionType is compatible if the MathType of its range is compatible. All other * MathTypes are incompatible. * * @param type The VisAD MathType to examine for compatibility. * @return <code>true</code> if and only if the MathType is compatible with this instance. * @throws VisADException VisAD failure. */ public boolean isCompatible(MathType type) throws VisADException { boolean isCompatible; if (type instanceof RealType) { isCompatible = ((RealType) type).equalsExceptNameButUnits(realType) && (getRealTupleType().getCoordinateSystem() == null); } else if (type instanceof RealTupleType) { RealTupleType thisTupleType = getRealTupleType(); RealTupleType thatTupleType = (RealTupleType) type; if (!thatTupleType.equalsExceptNameButUnits(thisTupleType)) { isCompatible = false; } else { CoordinateSystem thisCS = thisTupleType.getCoordinateSystem(); CoordinateSystem thatCS = thatTupleType.getCoordinateSystem(); isCompatible = ((thisCS == null) ? thatCS == null : thisCS.getReference().equalsExceptNameButUnits(thatCS.getReference())); } } else if (type instanceof SetType) { isCompatible = isCompatible(((SetType) type).getDomain()); } else if (type instanceof FunctionType) { isCompatible = isCompatible(((FunctionType) type).getRange()); } else { isCompatible = false; } return isCompatible; }
private void extractCoordinateSystem() throws TransformationException { // To get the coordinate system we look at the CTYPEn, EQUINOX, RADESYSm String lonType = h.getStringValue("CTYPE" + lonAxis).substring(0, 4); String latType = h.getStringValue("CTYPE" + latAxis).substring(0, 4); String coordSym = null; CoordinateSystem coords; if (lonType.equals("RA--") && latType.equals("DEC-")) { coordSym = frame() + equinox(); } else { if (lonType.charAt(0) != latType.charAt(0)) { throw new TransformationException( "Inconsistent axes definitions:" + lonType + "," + latType); } if (lonType.equals("GLON")) { coordSym = "G"; } else if (lonType.equals("ELON")) { coordSym = "E" + equinox(); } else if (lonType.equals("HLON")) { coordSym = "H" + equinox(); } } coords = CoordinateSystem.factory(coordSym); this.csys = coords; add(coords.getSphereDistorter()); add(coords.getRotater()); }
/** Create a simple WCS given a scaler, CoordinateSystem and Projection. */ public WCS(CoordinateSystem csys, Projection proj, Scaler scale) throws TransformationException { this.csys = csys; this.proj = proj; this.scale = scale; add(csys.getSphereDistorter()); add(csys.getRotater()); add(proj.getRotater()); add(proj.getProjecter()); add(proj.getDistorter()); add(scale); setWCSScale(scale); }
private Projection test(String filename, String ctvName, String varName, Class projClass) throws IOException, InvalidRangeException { System.out.printf("Open= %s%n", filename); NetcdfDataset ncd = ucar.nc2.dataset.NetcdfDataset.openDataset(filename); Variable ctv = null; if (ctvName != null) { ctv = ncd.findVariable(ctvName); assert ctv != null; System.out.println(" dump of ctv = \n" + ctv); } VariableDS v = (VariableDS) ncd.findVariable(varName); assert v != null; List<CoordinateSystem> cList = v.getCoordinateSystems(); assert cList != null; assert cList.size() == 1; CoordinateSystem csys = cList.get(0); List<CoordinateTransform> pList = new ArrayList<CoordinateTransform>(); List<CoordinateTransform> tList = csys.getCoordinateTransforms(); assert tList != null; for (int i = 0; i < tList.size(); i++) { CoordinateTransform ct = tList.get(i); if (ct.getTransformType() == TransformType.Projection) pList.add(ct); } assert pList.size() == 1; CoordinateTransform ct = pList.get(0); assert ct.getTransformType() == TransformType.Projection; assert ct instanceof ProjectionCT; ProjectionCT vct = (ProjectionCT) ct; Projection proj = vct.getProjection(); assert proj != null; assert projClass.isInstance(proj) : proj.getClass().getName(); VariableDS ctvSyn = CoordTransBuilder.makeDummyTransformVariable(ncd, ct); System.out.println(" dump of equivilent ctv = \n" + ctvSyn); if (ctv != null) { Formatter f = new Formatter(System.out); CompareNetcdf.checkContains(ctv.getAttributes(), ctvSyn.getAttributes(), f); } ncd.close(); return proj; }
public float[][] fromReference(float[][] tuples) throws VisADException { if (tuples == null || tuples.length != dimension) { throw new CoordinateSystemException( "InverseCoordinateSystem." + "fromReference: tuples wrong dimension"); } return inverse.toReference(tuples); }
/** * Both points have to be in the same CoordinateSystem If the System is WGS84, a point in * latitude/longitude is assume If not, the euclidean distance is returned. */ public float getDistanceTo(Location other) { if (other == null || other.getClass() != Point.class) throw new IllegalArgumentException(); CoordinateSystem commonsys = CoordinateSystem.findCommonParentSystem( getCoordinateSystem(), ((Point) other).getCoordinateSystem()); Point p1 = this.getInHigherCoordinateSystem(commonsys); Point p2 = ((Point) other).getInHigherCoordinateSystem(commonsys); if (p1.getCoordinateSystem() == p2.getCoordinateSystem()) { if (this.getCoordinateSystem().getURI().indexOf("WGS84") > -1) { return (float) getDistanceFromLatLong(p1.get2DCoordinates(), p2.get2DCoordinates()); } else { double[] otherCoords = p2.get3DCoordinates(); double[] thisCoords = p1.get3DCoordinates(); double[] SolVec = { otherCoords[0] - thisCoords[0], otherCoords[1] - thisCoords[1], otherCoords[2] - thisCoords[2] }; double squaredEuclidean = Math.pow(SolVec[0], 2) + Math.pow(SolVec[1], 2); if (!Double.isNaN(SolVec[2])) squaredEuclidean += Math.pow(SolVec[2], 2); if (squaredEuclidean == 0) return 0; return (float) Math.sqrt(squaredEuclidean); } } return NOT_COMPUTABLE_DISTANCE; }
private String tryGrid(VariableEnhanced v) { Formatter buff = new Formatter(); buff.format("%s:", v.getFullName()); List<CoordinateSystem> csList = v.getCoordinateSystems(); if (csList.size() == 0) buff.format(" No Coord System found"); else { for (CoordinateSystem cs : csList) { buff.format("%s:", cs.getName()); if (GridCoordSys.isGridCoordSys(buff, cs, v)) { buff.format("GRID OK%n"); } else { buff.format(" NOT GRID"); } } } return buff.toString(); }
/** * @param heightAxis defining the name and the units of the 'vertical' axis * @param underlyingCRS the crs to which the height axis is added, only geographic, geocentric or * projected crs are valid. * @param defaultHeight of the any coordinate which does not have a height-axis-value. * @param identity containing the identifiable values. * @throws IllegalArgumentException if the underlying crs is not of type geographic, geocentric or * projected or one of the other values is <code>null</code>. */ public CompoundCRS( Axis heightAxis, CoordinateSystem underlyingCRS, double defaultHeight, Identifiable identity) throws IllegalArgumentException { super(underlyingCRS.getGeodeticDatum(), underlyingCRS.getAxis(), identity); int tmp = underlyingCRS.getType(); if (tmp != CoordinateSystem.GEOCENTRIC_CRS && tmp != CoordinateSystem.PROJECTED_CRS && tmp != CoordinateSystem.GEOGRAPHIC_CRS) { throw new IllegalArgumentException( "A compound crs can only have a geographic, projected or geocentric crs as underlying coordinate system."); } checkForNullObject(heightAxis, "CompoundCRS", "heightAxis"); this.underlyingCRS = underlyingCRS; axis = new Axis[3]; axis[0] = underlyingCRS.getAxis()[0]; axis[1] = underlyingCRS.getAxis()[1]; axis[2] = heightAxis; this.defaultHeight = defaultHeight; }
public VariableBean(VariableEnhanced v) { this.ve = v; setName(v.getFullName()); setDescription(v.getDescription()); setUnits(v.getUnitsString()); // collect dimensions StringBuilder lens = new StringBuilder(); StringBuilder names = new StringBuilder(); java.util.List dims = v.getDimensions(); for (int j = 0; j < dims.size(); j++) { ucar.nc2.Dimension dim = (ucar.nc2.Dimension) dims.get(j); if (j > 0) { lens.append(","); names.append(","); } String name = dim.isShared() ? dim.getShortName() : "anon"; names.append(name); lens.append(dim.getLength()); } setDims(names.toString()); setShape(lens.toString()); StringBuilder buff = new StringBuilder(); List<CoordinateSystem> csList = v.getCoordinateSystems(); for (CoordinateSystem cs : csList) { if (firstCoordSys == null) firstCoordSys = cs; else buff.append("; "); buff.append(cs.getName()); Formatter gridBuff = new Formatter(); if (GridCoordSys.isGridCoordSys(gridBuff, cs, v)) { addDataType("grid"); } /* else if (PointDatasetDefaultHandler.isPointFeatureDataset(ds)) { addDataType("point"); } */ } setCoordSys(buff.toString()); }
/** * set the default sampling; this is an unavoidable violation of MathType immutability - a * RealTupleType must be an argument (directly or through a SetType) to the constructor of its * default Set; this method throws an Exception if getDefaultSet has previously been invoked */ public synchronized void setDefaultSet(Set sampling) throws VisADException { if (sampling.getDimension() != getDimension()) { throw new SetException("RealTupleType.setDefaultSet: dimensions don't match"); } if (DefaultSetEverAccessed) { throw new TypeException("RealTupleType: DefaultSet already accessed" + " so cannot change"); } DefaultSet = sampling; /* WLH 4 Feb 98 copied from constructor */ if (DefaultSet != null && !Unit.canConvertArray(DefaultSet.getSetUnits(), DefaultUnits)) { throw new UnitException( "RealTupleType: default Set Units must be " + "convertable with default Units"); } if (DefaultCoordinateSystem != null && DefaultSet != null) { CoordinateSystem cs = DefaultSet.getCoordinateSystem(); if (cs != null && !cs.getReference().equals(DefaultCoordinateSystem.getReference())) { throw new CoordinateSystemException( "RealTupleType: Default coordinate system " + DefaultCoordinateSystem.getReference() + " must match" + " default set CoordinateSystem " + (cs == null ? null : cs.getReference())); } if (!Unit.canConvertArray( DefaultCoordinateSystem.getCoordinateSystemUnits(), DefaultSet.getSetUnits())) { throw new UnitException( "RealTupleType: CoordinateSystem Units must be " + "convertable with default Set Units"); } } }
private boolean isTargetCRS(Feature feature, CoordinateSystem targetCRS) throws CRSTransformationException, GeometryException { FeatureProperty[] fp = feature.getProperties(); for (int i = 0; i < fp.length; i++) { if (fp[i].getValue() instanceof Geometry) { Geometry geom = (Geometry) fp[i].getValue(); if (!targetCRS.equals(geom.getCoordinateSystem())) { LOG.logInfo(geom.getCoordinateSystem().getIdentifier()); LOG.logInfo(" - " + targetCRS.getIdentifier()); return false; } } else if (fp[i].getValue() instanceof Feature) { if (!isTargetCRS((Feature) fp[i].getValue(), targetCRS)) { return false; } } } return true; }
public CoordinateSystem.Coordinate getRandomHumpLocation(O o1, O o2) { if (!this.contains(o1)) return null; if (!this.contains(o2)) return null; Set<CoordinateSystem.Coordinate> neigh1 = this.getLocation(o1).neighbors(this.settings.getSpawnDistance()); Set<CoordinateSystem.Coordinate> neigh2 = this.getLocation(o2).neighbors(this.settings.getSpawnDistance()); Set<CoordinateSystem.Coordinate> intersection = neigh1; intersection.retainAll(neigh2); intersection = CoordinateSystem.filter(intersection, this.settings.getSpawnFilter().concretize(this)); return Distribution.uniform(intersection).getRandom(); }
private void setSelectedCoordinateAxes(CoordinateSystem cs) { List axesList = cs.getCoordinateAxes(); if (axesList.size() == 0) return; CoordinateAxis axis = (CoordinateAxis) axesList.get(0); List beans = axisTable.getBeans(); for (Object bean1 : beans) { AxisBean bean = (AxisBean) bean1; if (bean.axis == axis) { axisTable.setSelectedBean(bean); return; } } }
/** trusted constructor for initializers */ RealTupleType(RealType[] types, CoordinateSystem coord_sys, boolean b) { super(types, b); DefaultCoordinateSystem = coord_sys; DefaultSet = null; DefaultSetEverAccessed = false; setDefaultUnits(types); if (DefaultCoordinateSystem != null && !Unit.canConvertArray( DefaultCoordinateSystem.getCoordinateSystemUnits(), DefaultUnits)) { throw new VisADError( "RealTupleType (trusted): CoordinateSystem Units " + "must be convertable with default Units"); } }
/** * construct a CoordinateSystem that whose transforms invert the transforms of inverse (i.e., * toReference and fromReference are switched); for example, this could be used to define * Cartesian coordinates releative to a refernce in spherical coordinates */ public InverseCoordinateSystem(RealTupleType reference, CoordinateSystem inv) throws VisADException { super(reference, inv.getReference().getDefaultUnits()); inverse = inv; dimension = reference.getDimension(); Unit[] inv_units = inv.getCoordinateSystemUnits(); Unit[] ref_units = reference.getDefaultUnits(); if (inv_units.length != dimension) { throw new CoordinateSystemException("InverseCoordinateSystem: " + "dimensions don't match"); } for (int i = 0; i < inv_units.length; i++) { if ((inv_units[i] == null && ref_units[i] != null) || (inv_units[i] != null && !inv_units[i].equals(ref_units[i]))) { throw new CoordinateSystemException( "InverseCoordinateSystem: " + "Units don't match " + i + " " + inv_units[i] + " " + ref_units[i]); } } }
/** * array of component types; default CoordinateSystem for values of this type (including Function * domains) and may be null; default Set used when this type is a FunctionType domain and may be * null */ public RealTupleType(RealType[] types, CoordinateSystem coord_sys, Set set) throws VisADException { super(types); if (coord_sys != null && types.length != coord_sys.getDimension()) { throw new CoordinateSystemException("RealTupleType: bad CoordinateSystem dimension"); } DefaultCoordinateSystem = coord_sys; DefaultSet = set; DefaultSetEverAccessed = false; setDefaultUnits(types); if (DefaultCoordinateSystem != null && !Unit.canConvertArray( DefaultCoordinateSystem.getCoordinateSystemUnits(), DefaultUnits)) { throw new UnitException( "RealTupleType: CoordinateSystem Units must be " + "convertable with default Units"); } if (DefaultSet != null && !Unit.canConvertArray(DefaultSet.getSetUnits(), DefaultUnits)) { throw new UnitException( "RealTupleType: default Set Units must be " + "convertable with default Units"); } if (DefaultCoordinateSystem != null && DefaultSet != null) { CoordinateSystem cs = DefaultSet.getCoordinateSystem(); if (cs != null && !cs.getReference().equals(DefaultCoordinateSystem.getReference())) { throw new CoordinateSystemException( "RealTupleType: Default coordinate system " + (coord_sys == null ? null : coord_sys.getReference()) + " must match" + " default set CoordinateSystem " + (cs == null ? null : cs.getReference())); } if (!Unit.canConvertArray( DefaultCoordinateSystem.getCoordinateSystemUnits(), DefaultSet.getSetUnits())) { throw new UnitException( "RealTupleType: CoordinateSystem Units must be " + "convertable with default Set Units"); } } }
public CoordinateSystemBean(CoordinateSystem cs) { this.coordSys = cs; setCoordSys(cs.getName()); setGeoXY(cs.isGeoXY()); setLatLon(cs.isLatLon()); setProductSet(cs.isProductSet()); setRegular(cs.isRegular()); setDomainRank(cs.getDomain().size()); setRangeRank(cs.getCoordinateAxes().size()); coverageType = CoverageCSFactory.describe(null, cs); if (GridCoordSys.isGridCoordSys(parseInfo, cs, null)) { addDataType("grid"); } if (RadialCoordSys.isRadialCoordSys(parseInfo, cs)) { addDataType("radial"); } StringBuilder buff = new StringBuilder(); List ctList = cs.getCoordinateTransforms(); for (int i = 0; i < ctList.size(); i++) { CoordinateTransform ct = (CoordinateTransform) ctList.get(i); if (i > 0) buff.append(" "); buff.append(ct.getTransformType()); if (ct instanceof VerticalCT) buff.append("(").append(((VerticalCT) ct).getVerticalTransformType()).append(")"); if (ct instanceof ProjectionCT) { ProjectionCT pct = (ProjectionCT) ct; if (pct.getProjection() != null) { buff.append("(").append(pct.getProjection().getClassName()).append(")"); } } } setCoordTransforms(buff.toString()); }
public synchronized void drag_direct(VisADRay ray, boolean first, int mouseModifiers) { if (barbValues == null || ref == null || shadow == null) return; if (first) { stop = false; } else { if (stop) return; } // modify direction if mshift != 0 // modify speed if mctrl != 0 // modify speed and direction if neither int mshift = mouseModifiers & InputEvent.SHIFT_MASK; int mctrl = mouseModifiers & InputEvent.CTRL_MASK; float o_x = (float) ray.position[0]; float o_y = (float) ray.position[1]; float o_z = (float) ray.position[2]; float d_x = (float) ray.vector[0]; float d_y = (float) ray.vector[1]; float d_z = (float) ray.vector[2]; if (pickCrawlToCursor) { if (first) { offset_count = OFFSET_COUNT_INIT; } else { if (offset_count > 0) offset_count--; } if (offset_count > 0) { float mult = ((float) offset_count) / ((float) OFFSET_COUNT_INIT); o_x += mult * offsetx; o_y += mult * offsety; o_z += mult * offsetz; } } if (first || refirst) { point_x = barbValues[2]; point_y = barbValues[3]; point_z = 0.0f; line_x = 0.0f; line_y = 0.0f; line_z = 1.0f; // lineAxis == 2 in DataRenderer.drag_direct } // end if (first || refirst) float[] x = new float[3]; // x marks the spot // DirectManifoldDimension = 2 // intersect ray with plane float dot = (point_x - o_x) * line_x + (point_y - o_y) * line_y + (point_z - o_z) * line_z; float dot2 = d_x * line_x + d_y * line_y + d_z * line_z; if (dot2 == 0.0) return; dot = dot / dot2; // x is intersection x[0] = o_x + dot * d_x; x[1] = o_y + dot * d_y; x[2] = o_z + dot * d_z; /* System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ try { Tuple data = (Tuple) link.getData(); int n = ((TupleType) data.getType()).getNumberOfRealComponents(); Real[] reals = new Real[n]; int k = 0; int m = data.getDimension(); for (int i = 0; i < m; i++) { Data component = data.getComponent(i); if (component instanceof Real) { reals[k++] = (Real) component; } else if (component instanceof RealTuple) { for (int j = 0; j < ((RealTuple) component).getDimension(); j++) { reals[k++] = (Real) ((RealTuple) component).getComponent(j); } } } if (first || refirst) { // get first Data flow vector for (int i = 0; i < 3; i++) { int j = flowToComponent[i]; data_flow[i] = (j >= 0) ? (float) reals[j].getValue() : 0.0f; } if (coord != null) { float[][] ds = {{data_flow[0]}, {data_flow[1]}, {data_flow[2]}}; ds = coord.toReference(ds); data_flow[0] = ds[0][0]; data_flow[1] = ds[1][0]; data_flow[2] = ds[2][0]; } data_speed = (float) Math.sqrt( data_flow[0] * data_flow[0] + data_flow[1] * data_flow[1] + data_flow[2] * data_flow[2]); float barb0 = barbValues[2] - barbValues[0]; float barb1 = barbValues[3] - barbValues[1]; /* System.out.println("data_flow = " + data_flow[0] + " " + data_flow[1] + " " + data_flow[2]); System.out.println("barbValues = " + barbValues[0] + " " + barbValues[1] + " " + barbValues[2] + " " + barbValues[3]); System.out.println("data_speed = " + data_speed); */ } // end if (first || refirst) // convert x to a flow vector, and from spatial to earth if (getRealVectorTypes(which_barb) instanceof EarthVectorType) { // don't worry about vector magnitude - // data_speed & display_speed take care of that float eps = 0.0001f; // estimate derivative with a little vector float[][] spatial_locs = { {barbValues[0], barbValues[0] + eps * (x[0] - barbValues[0])}, {barbValues[1], barbValues[1] + eps * (x[1] - barbValues[1])}, {0.0f, 0.0f} }; /* System.out.println("spatial_locs = " + spatial_locs[0][0] + " " + spatial_locs[0][1] + " " + spatial_locs[1][0] + " " + spatial_locs[1][1]); */ float[][] earth_locs = spatialToEarth(spatial_locs); // WLH - 18 Aug 99 if (earth_locs == null) return; /* System.out.println("earth_locs = " + earth_locs[0][0] + " " + earth_locs[0][1] + " " + earth_locs[1][0] + " " + earth_locs[1][1]); */ x[2] = 0.0f; x[0] = (earth_locs[1][1] - earth_locs[1][0]) * ((float) Math.cos(Data.DEGREES_TO_RADIANS * earth_locs[0][0])); x[1] = earth_locs[0][1] - earth_locs[0][0]; /* System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ } else { // if (!(getRealVectorTypes(which_barb) instanceof EarthVectorType)) // convert x to vector x[0] -= barbValues[0]; x[1] -= barbValues[1]; // adjust for spatial map scalings but don't worry about vector // magnitude - data_speed & display_speed take care of that // also, spatial is Cartesian double[] ranges = getRanges(); for (int i = 0; i < 3; i++) { x[i] /= ranges[i]; } /* System.out.println("ranges = " + ranges[0] + " " + ranges[1] + " " + ranges[2]); System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ } // WLH 6 August 99 x[0] = -x[0]; x[1] = -x[1]; x[2] = -x[2]; /* may need to do this for performance float[] xx = {x[0], x[1], x[2]}; addPoint(xx); */ float x_speed = (float) Math.sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]); /* WLH 16 April 2002 - from Ken if (x_speed < 0.000001f) x_speed = 0.000001f; */ if (x_speed < 0.01f) x_speed = 0.01f; if (first || refirst) { display_speed = x_speed; } refirst = false; if (mshift != 0) { // only modify data_flow direction float ratio = data_speed / x_speed; x[0] *= ratio; x[1] *= ratio; x[2] *= ratio; /* System.out.println("direction, ratio = " + ratio + " " + data_speed + " " + x_speed); System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ } else if (mctrl != 0) { // only modify data_flow speed float ratio = x_speed / display_speed; if (data_speed < EPS) { data_flow[0] = 2.0f * EPS; refirst = true; } x[0] = ratio * data_flow[0]; x[1] = ratio * data_flow[1]; x[2] = ratio * data_flow[2]; /* System.out.println("speed, ratio = " + ratio + " " + x_speed + " " + display_speed); System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ } else { // modify data_flow speed and direction float ratio = data_speed / display_speed; /* System.out.println("data_speed = " + data_speed + " display_speed = " + display_speed + " ratio = " + ratio + " EPS = " + EPS); System.out.println("x = " + x[0] + " " + x[1] +" " + x[2] + " x_speed = " + x_speed); data_speed = 21.213203 display_speed = 0.01 ratio = 2121.3203 EPS = 0.2 x = 1.6170928E-4 1.6021729E-4 -0.0 x_speed = 0.01 wind = (0.3430372, 0.33987218) at (-35.0, 5.0) */ if (data_speed < EPS) { data_flow[0] = 2.0f * EPS; x[0] = data_flow[0]; x[1] = data_flow[1]; x[2] = data_flow[2]; refirst = true; } else { x[0] *= ratio; x[1] *= ratio; x[2] *= ratio; } } if (coord != null) { float[][] xs = {{x[0]}, {x[1]}, {x[2]}}; xs = coord.fromReference(xs); x[0] = xs[0][0]; x[1] = xs[1][0]; x[2] = xs[2][0]; } // now replace flow values Vector vect = new Vector(); for (int i = 0; i < 3; i++) { int j = flowToComponent[i]; if (j >= 0) { RealType rtype = (RealType) reals[j].getType(); reals[j] = new Real(rtype, (double) x[i], rtype.getDefaultUnit(), null); // WLH 31 Aug 2000 Real r = reals[j]; Unit overrideUnit = null; if (directMap[i] != null) { overrideUnit = directMap[i].getOverrideUnit(); } Unit rtunit = rtype.getDefaultUnit(); // units not part of Time string if (overrideUnit != null && !overrideUnit.equals(rtunit) && !RealType.Time.equals(rtype)) { double d = (float) overrideUnit.toThis((double) x[0], rtunit); r = new Real(rtype, d, overrideUnit); String valueString = r.toValueString(); vect.addElement(rtype.getName() + " = " + valueString); } else { // create location string vect.addElement(rtype.getName() + " = " + x[i]); } } } getDisplayRenderer().setCursorStringVector(vect); Data newData = null; // now build new RealTuple or Flat Tuple if (data instanceof RealTuple) { newData = new RealTuple( ((RealTupleType) data.getType()), reals, ((RealTuple) data).getCoordinateSystem()); } else { Data[] new_components = new Data[m]; k = 0; for (int i = 0; i < m; i++) { Data component = data.getComponent(i); if (component instanceof Real) { new_components[i] = reals[k++]; } else if (component instanceof RealTuple) { Real[] sub_reals = new Real[((RealTuple) component).getDimension()]; for (int j = 0; j < ((RealTuple) component).getDimension(); j++) { sub_reals[j] = reals[k++]; } new_components[i] = new RealTuple( ((RealTupleType) component.getType()), sub_reals, ((RealTuple) component).getCoordinateSystem()); } } newData = new Tuple(new_components, false); } ref.setData(newData); } catch (VisADException e) { // do nothing System.out.println("drag_direct " + e); e.printStackTrace(); } catch (RemoteException e) { // do nothing System.out.println("drag_direct " + e); e.printStackTrace(); } }
public boolean equals(Object cs) { return (cs instanceof InverseCoordinateSystem && inverse.equals(((InverseCoordinateSystem) cs).inverse)); }
/** * Make a grid with a Linear3DSet for the volume rendering * * @param grid grid to transform * @param cs coordinate system to transform to XYZ * @return transformed grid * @throws RemoteException Java RMI Exception * @throws VisADException problem creating grid */ private FieldImpl makeLinearGrid(FieldImpl grid, CoordinateSystem cs) throws VisADException, RemoteException { Trace.call1("VRC.makeLinearGrid"); GriddedSet domainSet = (GriddedSet) GridUtil.getSpatialDomain(grid); SampledSet ss = null; boolean latLonOrder = GridUtil.isLatLonOrder(domainSet); // System.out.println("grid is latLonOrder " + latLonOrder); Trace.call1("VRC.convertDomain"); if (latLonOrder) { ss = Util.convertDomain(domainSet, RealTupleType.LatitudeLongitudeAltitude, null); } else { ss = Util.convertDomain(domainSet, RealTupleType.SpatialEarth3DTuple, null); } Trace.call2("VRC.convertDomain"); float[][] refVals = ss.getSamples(true); MapProjectionDisplay mpd = (MapProjectionDisplay) getNavigatedDisplay(); MapProjection mp = mpd.getMapProjection(); boolean mapLatLonOrder = mp.isLatLonOrder(); // System.out.println("map is latLonOrder " + mapLatLonOrder); float[][] newVals = (latLonOrder) ? refVals : new float[][] {refVals[1], refVals[0], refVals[2]}; Trace.call1("VRC.toRef"); newVals = cs.toReference(newVals); Trace.call2("VRC.toRef"); Trace.call1("VRC.scaleVerticalValues"); newVals[2] = mpd.scaleVerticalValues(newVals[2]); Trace.call2("VRC.scaleVerticalValues"); int[] lengths = domainSet.getLengths(); // Misc.printArray("lengths",lengths); GriddedSet xyzSet = GriddedSet.create( RealTupleType.SpatialCartesian3DTuple, newVals, domainSet.getLengths(), (CoordinateSystem) null, (Unit[]) null, (ErrorEstimate[]) null, false, true); Trace.call1("VRC.setSpatialDomain"); FieldImpl newGrid = GridUtil.setSpatialDomain(grid, xyzSet); // , true); Trace.call2("VRC.setSpatialDomain"); float[] lows = xyzSet.getLow(); float[] highs = xyzSet.getHi(); // Misc.printArray("lows",lows); // Misc.printArray("highs",highs); Linear3DSet volumeXYZ = new Linear3DSet( RealTupleType.SpatialCartesian3DTuple, lows[0], highs[0], lengths[0], lows[1], highs[1], lengths[1], lows[2], highs[2], lengths[2]); // System.out.println(volumeXYZ); Trace.call1("VRC.resampleGrid"); newGrid = GridUtil.resampleGrid(newGrid, volumeXYZ); Trace.call2("VRC.resampleGrid"); Trace.call2("VRC.makeLinearGrid"); return newGrid; }
public boolean execute(PlugInContext context) throws Exception { // Don't make this plug-in undoable -- it's a lot of data to store in memory [Jon Aquino] context.getLayerManager().getUndoableEditReceiver().reportIrreversibleChange(); CoordinateSystem destination = (CoordinateSystem) JOptionPane.showInputDialog( (Component) context.getWorkbenchGuiComponent(), AppContext.getApplicationContext().getI18nString("SelectCoordinateReferenceSystem"), AppContext.getApplicationContext().getI18nString("CoordinateReferenceSystem"), JOptionPane.PLAIN_MESSAGE, null, new ArrayList( CoordinateSystemRegistry.instance( context.getWorkbenchContext().getBlackboard()) .getCoordinateSystems()) .toArray(), context.getLayerManager().getCoordinateSystem()); if (destination == null) { return false; } if (context.getLayerManager().getCoordinateSystem() == destination) { return true; } if (Reprojector.instance() .wouldChangeValues(context.getLayerManager().getCoordinateSystem(), destination)) { // Two-phase commit [Jon Aquino] ArrayList transactions = new ArrayList(); for (Iterator i = context.getLayerManager().iterator(); i.hasNext(); ) { Layer layer = (Layer) i.next(); EditTransaction transaction = new EditTransaction( layer.getFeatureCollectionWrapper().getFeatures(), getName(), layer, isRollingBackInvalidEdits(context), false, context.getLayerViewPanel()); for (int j = 0; j < transaction.size(); j++) { Reprojector.instance() .reproject( transaction.getGeometry(j), context.getLayerManager().getCoordinateSystem(), destination); } transactions.add(transaction); } EditTransaction.commit(transactions); } // cambia for (Iterator i = context.getLayerManager().iterator(); i.hasNext(); ) { Layer layer = (Layer) i.next(); layer.getFeatureCollectionWrapper().getFeatureSchema().setCoordinateSystem(destination); DataSourceQuery dsq = layer.getDataSourceQuery(); if (dsq != null) dsq.getDataSource() .getProperties() .put(DataSource.COORDINATE_SYSTEM_KEY, destination.getName()); } context.getLayerManager().setCoordinateSystem(destination); if (context.getLayerViewPanel() != null) { context.getLayerViewPanel().getViewport().zoomToFullExtent(); } return true; }
/** Handle the NEAT special projection */ private void doNeatWCS() throws TransformationException { // The NEAT transformation from the standard spherical system // includes: // Transformation to J2000 spherical coordinates (a null operation) // A tangent plane projection to the standard plane // A scaler transformation to corrected pixel coordinates. // A distorter to distorted pixel coordinates // A scaler transformation of distorted coordinates to actual pixels CoordinateSystem csys = CoordinateSystem.factory("J2000"); this.csys = csys; // The RA0/DEC0 pair are the actual center of the projection. double cv1 = toRadians(h.getDoubleValue("RA0")); double cv2 = toRadians(h.getDoubleValue("DEC0")); wcsKeys.put("CRVAL1", toDegrees(cv1)); wcsKeys.put("CRVAL2", toDegrees(cv2)); Projection proj = new Projection("Tan", new double[] {cv1, cv2}); this.proj = proj; double cd1 = toRadians(h.getDoubleValue("CDELT1")); double cd2 = toRadians(h.getDoubleValue("CDELT2")); wcsKeys.put("CDELT1", toDegrees(cd1)); wcsKeys.put("CDELT2", toDegrees(cd2)); wcsScale = abs(cd1); double cp1 = h.getDoubleValue("CRPIX1"); double cp2 = h.getDoubleValue("CRPIX2"); wcsKeys.put("CPRIX1", cp1); wcsKeys.put("CRPIX2", cp2); wcsKeys.put("CTYPE1", "RA---XTN"); wcsKeys.put("CTYPE2", "DEC--XTN"); Scaler s1 = new Scaler(0., 0., -1 / cd1, 0, 0, -1 / cd2); // Note that the the A0,A1,A2, B0,B1,B2 rotation // is relative to the original pixel values, so // we need to put this in the secondary scaler. // double x0 = h.getDoubleValue("X0"); double y0 = h.getDoubleValue("Y0"); Distorter dis = new skyview.geometry.distorter.Neat( h.getDoubleValue("RADIAL"), h.getDoubleValue("XRADIAL"), h.getDoubleValue("YRADIAL")); double a0 = h.getDoubleValue("A0"); double a1 = h.getDoubleValue("A1"); double a2 = h.getDoubleValue("A2"); double b0 = h.getDoubleValue("B0"); double b1 = h.getDoubleValue("B1"); double b2 = h.getDoubleValue("B2"); // The reference pixel is to be computed in the distorted frame. double[] cpix = new double[] {cp1, cp2}; double[] cout = new double[2]; dis.transform(cpix, cout); Scaler s2 = new Scaler( cout[0] - a0 - a1 * x0 - a2 * y0, cout[1] - b0 - b2 * x0 - b1 * y0, -(1 + a1), -a2, -b2, -(1 + b1)); wcsKeys.put("A0", a0); wcsKeys.put("A1", a1); wcsKeys.put("A2", a2); wcsKeys.put("B0", b0); wcsKeys.put("B1", b1); wcsKeys.put("B2", b2); this.distort = dis; add(csys.getSphereDistorter()); add(csys.getRotater()); add(proj.getRotater()); add(proj.getProjecter()); this.scale = s1; // Note that s1 is defined from the projection plane to the pixels coordinates, // so we don't need to invert it. // // But the second scaler, s2, used in the NEAT correction // is defined in the direction from pixels to sphere, so we // need to take its inverse. this.scale = this.scale.add(s2.inverse()); add(this.scale); add(dis); }
/** Get all the possible locations for spawning a new Organism near the given coordinate. */ public Set<CoordinateSystem.Coordinate> getSpawnLocations( CoordinateSystem.Coordinate coordinate) { return CoordinateSystem.filter( coordinate.neighbors(this.settings.getSpawnDistance()), this.settings.getSpawnFilter().concretize(this)); }
public boolean isImplicit() { return coordSys.isImplicit(); }
/** Handle a DSS projection */ private void doDSSWCS() throws TransformationException { double plateRA = h.getDoubleValue("PLTRAH") + h.getDoubleValue("PLTRAM") / 60 + h.getDoubleValue("PLTRAS") / 3600; plateRA = toRadians(15 * plateRA); wcsKeys.put("PLTRAH", h.getDoubleValue("PLTRAH")); wcsKeys.put("PLTRAM", h.getDoubleValue("PLTRAM")); wcsKeys.put("PLTRAS", h.getDoubleValue("PLTRAS")); double plateDec = h.getDoubleValue("PLTDECD") + h.getDoubleValue("PLTDECM") / 60 + h.getDoubleValue("PLTDECS") / 3600; plateDec = toRadians(plateDec); if (h.getStringValue("PLTDECSN").substring(0, 1).equals("-")) { plateDec = -plateDec; } wcsKeys.put("PLTDECD", h.getDoubleValue("PLTDECD")); wcsKeys.put("PLTDECM", h.getDoubleValue("PLTDECM")); wcsKeys.put("PLTDECS", h.getDoubleValue("PLTDECS")); wcsKeys.put("PLTDECSN", h.getStringValue("PLTDECSN")); double plateScale = h.getDoubleValue("PLTSCALE"); double xPixelSize = h.getDoubleValue("XPIXELSZ"); double yPixelSize = h.getDoubleValue("YPIXELSZ"); wcsKeys.put("PLTSCALE", plateScale); wcsKeys.put("XPIXELSZ", xPixelSize); wcsKeys.put("YPIXELSZ", yPixelSize); double[] xCoeff = new double[20]; double[] yCoeff = new double[20]; for (int i = 1; i <= 20; i += 1) { xCoeff[i - 1] = h.getDoubleValue("AMDX" + i); yCoeff[i - 1] = h.getDoubleValue("AMDY" + i); wcsKeys.put("AMDX" + i, xCoeff[i - 1]); wcsKeys.put("AMDY" + i, yCoeff[i - 1]); } double[] ppo = new double[6]; for (int i = 1; i <= 6; i += 1) { ppo[i - 1] = h.getDoubleValue("PPO" + i); wcsKeys.put("PPO" + i, ppo[i - 1]); } double plateCenterX = ppo[2]; double plateCenterY = ppo[5]; double cdelt1 = -plateScale / 1000 * xPixelSize / 3600; double cdelt2 = plateScale / 1000 * yPixelSize / 3600; wcsScale = abs(cdelt1); // This gives cdelts in degrees per pixel. // CNPIX pixels use a have the first pixel going from 1 - 2 so they are // off by 0.5 from FITS (which in turn is offset by 0.5 from the internal // scaling, but we handle that elsewhere). double crpix1 = plateCenterX / xPixelSize - h.getDoubleValue("CNPIX1", 0) - 0.5; double crpix2 = plateCenterY / yPixelSize - h.getDoubleValue("CNPIX2", 0) - 0.5; wcsKeys.put("CNPIX1", h.getDoubleValue("CNPIX1", 0)); wcsKeys.put("CNPIX2", h.getDoubleValue("CNPIX2", 0)); Projection proj = new Projection("Tan", new double[] {plateRA, plateDec}); this.proj = proj; CoordinateSystem coords = CoordinateSystem.factory("J2000"); this.csys = coords; cdelt1 = toRadians(cdelt1); cdelt2 = toRadians(cdelt2); Scaler s = new Scaler(-cdelt1 * crpix1, -cdelt2 * crpix2, cdelt1, 0, 0, cdelt2); // Got the transformers ready. Add them in properly. add(coords.getSphereDistorter()); add(coords.getRotater()); add(proj.getRotater()); add(proj.getProjecter()); this.distort = new skyview.geometry.distorter.DSS( plateRA, plateDec, xPixelSize, yPixelSize, plateScale, ppo, xCoeff, yCoeff); add(this.distort); this.scale = s.inverse(); add(this.scale); }