📄 imageserviceelevationcalculator.java
字号:
package com.esri.solutions.jitk.services.elevation;
import com.esri.arcgisws.EnvelopeN;
import com.esri.arcgisws.GeoImageDescription;
import com.esri.arcgisws.ImageServerBindingStub;
import com.esri.arcgisws.ImageServiceInfo;
import com.esri.solutions.jitk.services.common.ServicesException;
import com.esri.solutions.jitk.services.elevation.Elevation;
import com.esri.solutions.jitk.services.elevation.ElevationCalculator;
import com.esri.solutions.jitk.services.elevation.Point;
import org.apache.axis.AxisFault;
import org.apache.log4j.Logger;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
public class ImageServiceElevationCalculator implements ElevationCalculator {
private static final Logger _logger = Logger.getLogger(ImageServiceElevationCalculator.class);
private String _endpoint = null;
private ImageServerBindingStub _imageServer = null;
public Elevation calculateElevation(Point pt)
throws RemoteException, ServicesException {
GeoImageDescription desc = new GeoImageDescription();
ImageServiceInfo serviceInfo = null;
EnvelopeN envelope = null;
double deltax;
double deltay;
int pixelLocation;
int littleEndianValue;
double elevationMeters;
Elevation elevation = null;
byte[] image = null;
_logger.debug("Requesting imager service information");
serviceInfo = _imageServer.getServiceInfo();
deltax = 2.5 * serviceInfo.getPixelSizeX();
deltay = 2.5 * serviceInfo.getPixelSizeY();
envelope = new EnvelopeN();
envelope.setXMin(pt.getX() - deltax);
envelope.setYMin(pt.getY() - deltay);
envelope.setXMax(pt.getX() + deltax);
envelope.setYMax(pt.getY() + deltay);
desc.setExtent(envelope);
desc.setWidth(5);
desc.setHeight(5);
_logger.debug("Invoking Image Service GetImage");
image = _imageServer.getImage(desc);
_logger.debug("Successfully invoked Image Service GetImage");
// get the center pixel location of the 5x5 image
// The location of the pixel at band b, row I, and column j can be
// calculated using the following formula.
// pixel location = ((i*nCols+j)*nBands+b)*pixelsize(in bytes)
pixelLocation = ((((2 * 5) + 2) * 1) + 1) * 4;
byte[] pixelBytes = new byte[] {
image[pixelLocation], image[pixelLocation + 1],
image[pixelLocation + 2], image[pixelLocation + 3]
};
littleEndianValue = this.convertLittleEndianToInt(pixelBytes);
_logger.debug("Little Endian value of pixel data: " +
littleEndianValue);
if (littleEndianValue != -1) {
elevationMeters = littleEndianValue / 16384;
elevation = new Elevation(elevationMeters, 2);
_logger.debug("Successfully calculated elevation for point(" +
pt.getX() + ", " + pt.getY() + "): " + elevationMeters);
} else {
// create empty elevation
elevation = new Elevation();
}
return elevation;
}
public void setEndpoint(String endpoint) {
if ((_endpoint == null) || !_endpoint.equalsIgnoreCase(endpoint)) {
_endpoint = endpoint;
_imageServer = this.createStub();
}
}
private int convertLittleEndianToInt(byte[] littleEndian) {
int value = 0;
if (littleEndian == null) {
throw new NullPointerException("Little Endian value cannot be null");
}
if (littleEndian.length != 4) {
throw new IllegalArgumentException(
"Invalid value - cannot convert Little Endian bytes to integer value");
}
value = ((littleEndian[3] << 24) + (littleEndian[2] << 16) +
(littleEndian[1] << 8) + (littleEndian[0] << 0));
return value;
}
private ImageServerBindingStub createStub() {
ImageServerBindingStub stub = null;
try {
stub = new ImageServerBindingStub(new URL(_endpoint), null);
} catch (AxisFault af) {
_logger.warn(af);
} catch (MalformedURLException ex) {
_logger.warn(ex);
}
return stub;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -