|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object insensa.optionfilechanger.AbstractOptionFileChanger insensa.optionfilechanger.CReplaceRasterFileValue
public class CReplaceRasterFileValue
This is a normalization
Field Summary | |
---|---|
private java.lang.String |
description
|
private java.lang.Float |
fFromValue
|
private java.lang.Float |
fReplaceValue
|
private java.lang.String |
fromValue
|
private java.lang.Float |
fToValue
|
static java.lang.String |
REPLACE_VALUE
|
private java.lang.String |
replaceValue
|
private java.lang.String |
toValue
|
Fields inherited from class insensa.optionfilechanger.AbstractOptionFileChanger |
---|
errorMessage, id, oldFileName, oldFilePath, oldRasterFile, processStatus, used, workerStatus, XML_ATTR_ID, XML_ATTR_OLD_NAME, XML_ATTR_OLD_PATH, XML_ATTR_USED, XML_ELEMENT_SOURCEFILE |
Constructor Summary | |
---|---|
CReplaceRasterFileValue()
|
Method Summary | |
---|---|
java.lang.String |
getDescription()
|
private float |
getFloatValue(java.lang.String value,
float noDataValue,
float minValue,
float maxValue)
|
java.lang.String |
getFromValue()
|
java.util.List<java.lang.String> |
getInfoDependencies()
|
org.jdom.Element |
getOptionElement()
Creates a new Element object that contains all
Information that should be saved in a configuration file. |
java.lang.String |
getOptionName()
Returns the name of the OptionFileChanger. |
java.lang.String |
getReplaceValue()
|
java.lang.String |
getToValue()
|
int |
getUsableCount()
|
void |
setDescription(java.lang.String description)
|
void |
setFromValue(java.lang.String fromValue)
|
void |
setOptionAttributes(org.jdom.Element eOption)
Sets all attributes that are saved in the configuration file. |
void |
setReplaceValue(java.lang.String replaceValue)
|
void |
setToValue(java.lang.String toValue)
|
java.lang.String |
toString()
|
void |
write()
This method will be executed from the ThreadPool There are several steps that must be followed: Get actual file . |
Methods inherited from class insensa.optionfilechanger.AbstractOptionFileChanger |
---|
checkApproval, getActualFile, getData, getErrorMessage, getId, getOldFileRelativeFilePath, getTemporaryFileName, isPublic, isUsed, run, saveRasterFile, setId, setOldRasterFile, setWorkerStatus, solveDependencies |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private java.lang.String description
public static final java.lang.String REPLACE_VALUE
private java.lang.String fromValue
private java.lang.String toValue
private java.lang.String replaceValue
private java.lang.Float fFromValue
private java.lang.Float fToValue
private java.lang.Float fReplaceValue
Constructor Detail |
---|
public CReplaceRasterFileValue()
Method Detail |
---|
public java.lang.String getDescription()
private float getFloatValue(java.lang.String value, float noDataValue, float minValue, float maxValue)
value
- noDataValue
- minValue
- maxValue
-
public java.lang.String getFromValue()
public java.util.List<java.lang.String> getInfoDependencies()
getInfoDependencies
in interface OptionFileChanger
getInfoDependencies
in class AbstractOptionFileChanger
AbstractOptionFileChanger.getInfoDependencies()
public org.jdom.Element getOptionElement()
OptionFileChanger
Element
object that contains all
Information that should be saved in a configuration file.extensions.xml
filegetOptionName
correctly,
you can use this function to get the name.
Element optionElement = new Element(this.getOptionName());
There are TWO attributes which should ALWAYS be saved, the status of the
execution (Therefore the same boolean expression that should be used in
the method isUsed
) and the id of the current optionFileChanger.
getOptionElement
in interface OptionFileChanger
getOptionElement
in class AbstractOptionFileChanger
Element
with all contents that should be saved
in the Configuration File AbstractOptionFileChanger
.used
is the
boolean expression
optionElement.setAttribute("used",Boolean.toString(used));
Besides the used state, you can save what ever you want and it is
possible to use the complex methods that jdom gives you.
For example: creating subElements (insensa.optionfilechanger.OptionFileChanger.setInfos
and
it can be fatal to use wrong keys
private final string XML_ATTR_USED = "used";
OptionFileChanger.getOptionElement()
public java.lang.String getOptionName()
OptionFileChanger
extensions.xml
or in EOption
OptionFileChanger.getOptionName()
public java.lang.String getReplaceValue()
public java.lang.String getToValue()
public int getUsableCount()
OptionFileChanger.getUsableCount()
public void setDescription(java.lang.String description)
description
- public void setFromValue(java.lang.String fromValue)
fromValue
- public void setOptionAttributes(org.jdom.Element eOption) throws java.io.IOException
OptionFileChanger
getOptionElement
.
setOptionAttributes
in interface OptionFileChanger
setOptionAttributes
in class AbstractOptionFileChanger
eOption
- the jdom.Element
which holds the attributes
java.io.IOException
- eOption
holds all information that was saved.
Attribute attrUsed = element.getAttribute(XML_ATTR_USED);
Attribute attrID = element.getAttribute(XML_ATTR_ID);
if(attrUsed==null || attrID==null)
throw new IOException("one ore more necessary attributes cannot be found");
try
{
used=attrUsed.getBooleanValue();
id=attrID.getIntegerValue();
}catch (DataConversionException e)
{
throw new IOException(e);
}
OptionFileChanger.setOptionAttributes(org.jdom.Element)
public void setReplaceValue(java.lang.String replaceValue)
replaceValue
- public void setToValue(java.lang.String toValue)
toValue
- public java.lang.String toString()
toString
in class AbstractOptionFileChanger
AbstractOptionFileChanger.toString()
public void write() throws java.io.IOException, org.jdom.JDOMException, CRasterFileException
OptionFileChanger
java.io.IOException
org.jdom.JDOMException
CRasterFileException
- AbstractOptionFileChanger.getActualFile()
AbstractOptionFileChanger.solveDependencies(CRasterFileInformation)
CRasterFileInformation actualRasterFile = getActualRasterFile()
In the next step it is important to be sure that all
dependencies previously defined in
getInfoDependencies
are available. the easiest way is
to use the method
AbstractOptionFileChanger.solveDependencies(CRasterFileInformation)
solveDependencies(actualRasterFile);
Lets assume we need the InfoReader minMaxValues.
CMinMaxValues minMaxValues = (CMinMaxValues)actualRasterFile.getInfoReader(EInfo.minMaxValue.toString());
if(minMaxValues==null)
throw new IOException("Can't solve minMaxValues")
If a WorkerStatus was defined we can tell it that the
progress began.
if(workerStatus!=null)
{
workerStatus.setProgressName("Starting replace zero");
workerStatus.startProcess();
}
Next we need to create a new temporary file as a copy of the
old file with a new name
Now we can get Excess to the gdal functions to create the data.String tmpName = getTemporaryFileName(actualRasterFile); CRasterFileInformation tmpRasterFile = new CRasterFileInformation(tmpName,actualRasterFile,false,false,false); int dataType = actualRasterFile.getBand().getDataType(); tmpRasterFile.createNewFile(actualRasterFile, dataType, actualRasterFile.getNoDataValue());
seeCRasterFileInformation#CRasterFileInformation(String, CRasterFileInformation, boolean, boolean, boolean)
andCRasterFile.createNewFile(insensa.CRasterFile, int, double)
for more information
Band band = actualRasterFile.getBand();
Dataset tmpDataset = tmpRasterFile.getDataset();
int xSize = band.GetXSize();
int ySize = band.getYSize();
float steps = 100.0F/ySize;
float[] fData= new float[xSize];
float readData;
for(int i=0;i < ySize;i++)
{
band.ReadRaster(0,i,xSize,1,fData);
for(int j=0;j < fData.length;j++)
{
readData=fData[j];
if(readData==actualRasterFile.getNoDataValue())
{
}
else
{
if(readData <=0.0f)
fData[j]=0.5f;
}
}
processStatus+=steps;
if(workerStatus!=null)
workerStatus.refreshPercentage(processStatus);
tmpDataset.GetRasterBand(1).WriteRaster(0,i,xSize,1,fData);
}
tmpDataset.FlushCache();
band.FlushCache();
tmpDataset=null;
band=null;
At least it is necessary to save the temporary file and set
the execution status:
saveRasterFile(tmpRasterFile, actualRasterFile);
used=true;
OptionFileChanger.write()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |