📄 coverageutils.java
字号:
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
* This code is licensed under the GPL 2.0 license, availible at the root
* application directory.
*/
package org.vfny.geoserver.util;
import org.geotools.coverage.grid.GeneralGridGeometry;
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.factory.Hints;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.parameter.DefaultParameterDescriptor;
import org.geotools.referencing.CRS;
import org.geotools.referencing.operation.BufferedCoordinateOperationFactory;
import org.opengis.parameter.GeneralParameterValue;
import org.opengis.parameter.ParameterDescriptor;
import org.opengis.parameter.ParameterValue;
import org.opengis.parameter.ParameterValueGroup;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.CoordinateOperation;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.OperationNotFoundException;
import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* DOCUMENT ME!
*
* @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last
* modification)
* @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last
* modification)
*/
public class CoverageUtils {
private final static BufferedCoordinateOperationFactory operationFactory = new BufferedCoordinateOperationFactory(new Hints(
Hints.LENIENT_DATUM_SHIFT, Boolean.TRUE));
private final static Logger LOGGER = org.geotools.util.logging.Logging.getLogger(CoverageUtils.class.toString());
public static final int TRANSPARENT = 0;
public static final int OPAQUE = 1;
public static GeneralParameterValue[] getParameters(ParameterValueGroup params) {
final List parameters = new ArrayList();
final String readGeometryKey = AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString();
if ((params != null) && (params.values().size() > 0)) {
List list = params.values();
Iterator it = list.iterator();
ParameterDescriptor descr = null;
ParameterValue val = null;
while (it.hasNext()) {
val = (ParameterValue) it.next();
if (val != null) {
descr = (ParameterDescriptor) val.getDescriptor();
String _key = descr.getName().toString();
if ("namespace".equals(_key)) {
// skip namespace as it is *magic* and
// appears to be an entry used in all dataformats?
//
continue;
}
// /////////////////////////////////////////////////////////
//
// request param for better management of coverage
//
// /////////////////////////////////////////////////////////
if (_key.equalsIgnoreCase(readGeometryKey)) {
// IGNORING READ_GRIDGEOMETRY2D param
continue;
}
Object value = val.getValue();
parameters.add(new DefaultParameterDescriptor(_key, value.getClass(), null,
value).createValue());
}
}
return (!parameters.isEmpty())
? (GeneralParameterValue[]) parameters.toArray(new GeneralParameterValue[parameters.size()])
: null;
} else {
return null;
}
}
public static GeneralParameterValue[] getParameters(ParameterValueGroup params, Map values) {
return getParameters(params, values, false);
}
public static GeneralParameterValue[] getParameters(ParameterValueGroup params, Map values,
boolean readGeom) {
final List parameters = new ArrayList();
final String readGeometryKey = AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString();
if ((params != null) && (params.values().size() > 0)) {
List list = params.values();
Iterator it = list.iterator();
ParameterDescriptor descr = null;
ParameterValue val = null;
while (it.hasNext()) {
val = (ParameterValue) it.next();
if (val != null) {
descr = (ParameterDescriptor) val.getDescriptor();
String _key = descr.getName().toString();
if ("namespace".equals(_key)) {
// skip namespace as it is *magic* and
// appears to be an entry used in all dataformats?
//
continue;
}
// /////////////////////////////////////////////////////////
//
// request param for better management of coverage
//
// /////////////////////////////////////////////////////////
if (_key.equalsIgnoreCase(readGeometryKey) && !readGeom) {
// IGNORING READ_GRIDGEOMETRY2D param
continue;
}
// /////////////////////////////////////////////////////////
//
// format specific params
//
// /////////////////////////////////////////////////////////
Object value = CoverageUtils.getCvParamValue(_key, val, values);
if ((value == null)
&& (_key.equalsIgnoreCase("InputTransparentColor")
|| _key.equalsIgnoreCase("OutputTransparentColor"))) {
parameters.add(new DefaultParameterDescriptor(_key, Color.class, null, value)
.createValue());
} else {
parameters.add(new DefaultParameterDescriptor(_key, value.getClass(), null,
value).createValue());
}
}
}
return (!parameters.isEmpty())
? (GeneralParameterValue[]) parameters.toArray(new GeneralParameterValue[parameters.size()])
: null;
} else {
return null;
}
}
public static Map getParametersKVP(ParameterValueGroup params) {
final Map parameters = new HashMap();
final String readGeometryKey = AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString();
if ((params != null) && (params.values().size() > 0)) {
List list = params.values();
Iterator it = list.iterator();
ParameterDescriptor descr = null;
ParameterValue val = null;
while (it.hasNext()) {
val = (ParameterValue) it.next();
if (val != null) {
descr = (ParameterDescriptor) val.getDescriptor();
String _key = descr.getName().toString();
if ("namespace".equals(_key)) {
// skip namespace as it is *magic* and
// appears to be an entry used in all dataformats?
//
continue;
}
// /////////////////////////////////////////////////////////
//
// request param for better management of coverage
//
// /////////////////////////////////////////////////////////
if (_key.equalsIgnoreCase(readGeometryKey)) {
// IGNORING READ_GRIDGEOMETRY2D param
continue;
}
Object value = val.getValue();
String text = "";
if (value == null) {
text = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -