ucar.unidata.geoloc.projection.convert.tcl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cdm Show documentation
Show all versions of cdm Show documentation
The NetCDF-Java Library is a Java interface to NetCDF files,
as well as to many other types of scientific data formats.
The newest version!
proc map {s from to} {
set len [string length $from]
while {1} {
set idx [string first $from $s]
if {$idx<0} {break}
set s "[string range $s 0 [expr {$idx-1}]]$to[string range $s [incr idx $len] end]"
}
set s
}
proc replace {template args} {
foreach {key value} $args {
set template [map $template $key $value ]
}
return $template
}
proc projToLatLon {prefix body} {
set ::projToLatLon(prefix) $prefix
set ::projToLatLon(body) $body
}
proc latLonToProj {prefix body} {
set ::latLonToProj(prefix) $prefix
set ::latLonToProj(body) $body
}
set singleTemplate {
/**
* Convert a LatLonPoint to projection coordinates
*
* @param latLon convert from these lat, lon coordinates
* @param result the object to write to
*
* @return the given result
*/
public ProjectionPoint latLonToProj (LatLonPoint latLon, ProjectionPointImpl result) {
double toX, toY;
double fromLat = latLon.getLatitude ();
double fromLon = latLon.getLongitude ();
%latLonToProj.prefix%
%latLonToProj.body%
result.setLocation (toX, toY);
return result;
}
/**
* Convert projection coordinates to a LatLonPoint
* Note: a new object is not created on each call for the return value.
*
* @param world convert from these projection coordinates
* @param result the object to write to
*
* @return LatLonPoint convert to these lat/lon coordinates
*/
public LatLonPoint projToLatLon(ProjectionPoint world, LatLonPointImpl result) {
double toLat, toLon;
double fromX = world.getX ();
double fromY = world.getY ();
%projToLatLon.prefix%
%projToLatLon.body%
result.setLatitude (toLat);
result.setLongitude (toLon);
return result;
}
}
set loopTemplate {
/**
* Convert lat/lon coordinates to projection coordinates.
*
* @param from array of lat/lon coordinates: from[2][n],
* where from[0][i], from[1][i] is the (lat,lon)
* coordinate of the ith point
* @param to resulting array of projection coordinates,
* where to[0][i], to[1][i] is the (x,y) coordinate
* of the ith point
* @param latIndex index of latitude in "from"
* @param lonIndex index of longitude in "from"
*
* @return the "to" array.
*/
public %type%[][] latLonToProj(%type%[][] from, %type%[][] to, int latIndex, int lonIndex) {
int cnt = from[0].length;
%type% []fromLatA = from[latIndex];
%type% []fromLonA = from[lonIndex];
%type% []resultXA = to[INDEX_X];
%type% []resultYA = to[INDEX_Y];
double toX, toY;
%latLonToProj.prefix%
for (int i=0; i
© 2015 - 2024 Weber Informatics LLC | Privacy Policy