Terrain analysis computations are based on the IlvAltitudeProviderProperty of the manager
and its underlying IlvAltitudeProvider, which is responsible
for providing altitudes for each point on a map.
The IlvJMouseCoordinateViewer bean uses altitude
property information to provide altitude information whenever the
mouse is over an altitude providing map object. Many other
features of JViews
Maps also use this information.
To access the altitude provider:
-
You can access the altitude provider by calling:
IlvAltitudeProvider provider = IlvAltitudeProviderProperty.GetAltitudeProvider(manager);
If you do not set a specific provider to this property, this method creates or returns an instance of IlvDefaultAltitudeProvider. -
To integrate another Digital Elevation Model, which provides the graphic objects with an IlvAltitudeDataSource property, see To retrieve the altitude attached to a graphic object below.
If you have read an image containing elevation data with an IlvRasterAbstractReader, for an example,
see Writing a raster reader for DEM data; you
can reuse its altitude information to provide altitude data by
using an IlvRasterAltitudeDataSource instance.
To attach an altitude data source to a
graphic object:
-
You first need to decide on the structure of the attribute property, for example, for a property containing only altitude data:
IlvAttributeInfoProperty info = new IlvAttributeInfoProperty( new String[] { "myAltitudeDataSourcePropertyName" }, new Class[] { IlvRasterAltitudeDataSource.class }, new boolean[] { true });
-
You can then reuse this structural information with different altitude data sources, and set it as the graphic object property:
IlvFeatureAttribute value[] = { new IlvRasterAltitudeDataSource(rasterImageReader, imageIndex) }; graphic.setNamedProperty(new IlvFeatureAttributeProperty(info, value);
If you use the default altitude management described in Using the altitude provider property, you
can also retrieve the altitude attached to an object as
described.
To retrieve the altitude attached to a
graphic object:
-
Get the attribute properties of the graphic object:
IlvAttributeProperty property = (IlvAttributeProperty) graphic.getNamedProperty(IlvAttributeProperty.NAME);
-
You should find the altitude data source in that property:
IlvAltitudeDataSource ads = (IlvAltitudeDataSource)property.getValue("myAltitudeDataSourcePropertyName") ;
-
As the data source object provides only altitude information for a specific latitude/longitude pair, you may need to transform the coordinates into latitude and longitude. Here is an example that converts a mouse location into such a pair:
// transform the mouse point into manager coordinates IlvPoint pt=new IlvPoint(mouseLocation.x,mouseLocation.y); view.getTransformer().inverse(pt); IlvProjectionUtil.invertY(pt); try { // compute the coordinate transformation from manager coordinates to lat/ lon IlvCoordinateSystem cs = IlvCoordinateSystemProperty.GetCoordinateSystem(view.getManager()); IlvCoordinateTransformation ct = IlvCoordinateTransformation.CreateTransformation(cs, IlvGeographicCoordinateSystem.KERNEL); // transform the point into lat/lon IlvCoordinate c = new IlvCoordinate(pt.x, pt.y); ct.transform(c, c); // retrieve the altitude } catch (IlvCoordinateTransformationException e) { }
-
You can then obtain the altitude. You should check if its value is a valid
double
, because the default data source and default provider of the manager return aDouble.NaN
value when there is no altitude information available.double alt = ads.getAltitude(c.x, c.y, 0); if(!Double.isNaN(alt)){ return alt; }
If the pixel values stored in the IlvRasterMappedBuffer are altitudes, you
can use the IlvRasterAltitudeDataSource class directly
as the altitude provider.
Use the IlvRasterAltitudeDataSource class in the IlvFeatureAttributeProperty of every image
that the reader creates.
To set altitudes use:
-
public IlvFeatureAttributeProperty getProperties(int imageIndex) { IlvAttributeInfoProperty info = new IlvAttributeInfoProperty( new String[] { " myAltitudeDataSourcePropertyName" }, new Class[] { IlvRasterAltitudeDataSource.class }, new boolean[] { true }); IlvFeatureAttribute values[] = new IlvFeatureAttribute[] { new IlvRasterAltitudeDataSource(this,imageIndex) }; return new IlvFeatureAttributeProperty(info, values); }
See also To attach an altitude data source to a graphic object.
You need to provide JViews
Maps with a way of knowing where the resulting image is placed.
This is done through two methods that return the transformation
and coordinate system used in the raster
property boundaries.
To manage coordinates:
-
Provide two methods as shown in the following example, which assumes that the bounds are given in degrees.
private static IlvCoordinateTransformation INTERNAL = IlvCoordinateTransformation.CreateTransformation (IlvGeographicCoordinateSystem.KERNEL, IlvGeographicCoordinateSystem.WGS84); public IlvCoordinateSystem getCoordinateSystem() { return INTERNAL.getTargetCS(); } public IlvMathTransform getInternalTransformation(int imageIndex) { return INTERNAL.getTransform(); }