add 3.0 branch

This commit is contained in:
wyq 2021-03-04 23:26:35 +08:00
parent b44995be9a
commit b8a2415501
267 changed files with 41008 additions and 52798 deletions

8
.idea/compiler.xml generated
View File

@ -6,16 +6,20 @@
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="meteoinfo-ndarray" />
<module name="MeteoInfoLab" />
<module name="MeteoInfoLib" />
<module name="meteoinfo-math" />
<module name="MeteoInfoMap" />
<module name="meteoinfo-console" />
<module name="meteoinfo-ndarray" />
<module name="meteoinfo-common" />
<module name="MeteoInfoLib" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="MeteoInfo" target="1.8" />
<module name="meteoinfo-common" target="1.8" />
<module name="meteoinfo-console" target="1.8" />
<module name="meteoinfo-math" target="1.8" />
<module name="meteoinfo-ndarray" target="1.8" />
<module name="MeteoInfoLab" target="1.8" />
<module name="MeteoInfoLib" target="1.8" />

4
.idea/encodings.xml generated
View File

@ -11,8 +11,12 @@
<file url="file://$PROJECT_DIR$/MeteoInfoMap" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/MeteoInfoMap/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/MeteoInfoMap/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/meteoinfo-common/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/meteoinfo-common/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/meteoinfo-console/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/meteoinfo-console/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/meteoinfo-math/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/meteoinfo-math/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/meteoinfo-ndarray/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/meteoinfo-ndarray/src/main/resources" charset="UTF-8" />
</component>

2
.idea/modules.xml generated
View File

@ -6,7 +6,9 @@
<module fileurl="file://$PROJECT_DIR$/MeteoInfoLab/MeteoInfoLab.iml" filepath="$PROJECT_DIR$/MeteoInfoLab/MeteoInfoLab.iml" />
<module fileurl="file://$PROJECT_DIR$/MeteoInfoLib/MeteoInfoLib.iml" filepath="$PROJECT_DIR$/MeteoInfoLib/MeteoInfoLib.iml" />
<module fileurl="file://$PROJECT_DIR$/MeteoInfoMap/MeteoInfoMap.iml" filepath="$PROJECT_DIR$/MeteoInfoMap/MeteoInfoMap.iml" />
<module fileurl="file://$PROJECT_DIR$/meteoinfo-common/meteoinfo-common.iml" filepath="$PROJECT_DIR$/meteoinfo-common/meteoinfo-common.iml" />
<module fileurl="file://$PROJECT_DIR$/meteoinfo-console/meteoinfo-console.iml" filepath="$PROJECT_DIR$/meteoinfo-console/meteoinfo-console.iml" />
<module fileurl="file://$PROJECT_DIR$/meteoinfo-math/meteoinfo-math.iml" filepath="$PROJECT_DIR$/meteoinfo-math/meteoinfo-math.iml" />
<module fileurl="file://$PROJECT_DIR$/meteoinfo-ndarray/meteoinfo-ndarray.iml" filepath="$PROJECT_DIR$/meteoinfo-ndarray/meteoinfo-ndarray.iml" />
</modules>
</component>

View File

@ -22,6 +22,15 @@
</library>
</orderEntry>
<orderEntry type="module" module-name="MeteoInfoLib" />
<orderEntry type="module" module-name="meteoinfo-math" />
<orderEntry type="module" module-name="meteoinfo-common" />
<orderEntry type="library" name="Maven: com.google.guava:guava:28.0-jre" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:failureaccess:1.0.1" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava" level="project" />
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:2.8.1" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.3.2" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.17" level="project" />
<orderEntry type="module" module-name="meteoinfo-ndarray" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.2" level="project" />
<orderEntry type="library" name="Maven: edu.ucar:netcdfAll:5.4.1" level="project" />

View File

@ -1,29 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\netcdf">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\linalg"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite\calipso"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\burf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\grib"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\radar"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\wrf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\interpolation"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\hdf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite\modis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\netcdf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\city_streamslice_zslice_index.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\netcdf\dimension_reverse.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\meteo\hdivg.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot_cuace_3d_particles_relief.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\city_streamslice_zslice_index.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\netcdf\dimension_reverse.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\meteo\hdivg.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot_cuace_3d_particles_relief.py"/>
</RecentFiles>
</File>
<Font>

View File

@ -1,5 +1,6 @@
import midata
from .midata import *
import ncutil
from .dimvariable import DimVariable
__all__ = ['ncutil', 'DimVariable']

View File

@ -6,7 +6,7 @@
#-----------------------------------------------------
from org.meteoinfo.ndarray import Dimension, DimensionType, Range, Array, MAMath
from org.meteoinfo.math import ArrayMath, ArrayUtil
from org.meteoinfo.global import PointD
from org.meteoinfo.common import PointD
from org.meteoinfo.projection import KnownCoordinateSystems, Reproject
from org.meteoinfo.data.meteodata import Attribute
from ucar.nc2 import Attribute as NCAttribute

View File

@ -1,58 +1,58 @@
#-----------------------------------------------------
# Author: Yaqiang Wang
# Date: 2017-11-28
# Purpose: MeteoInfo geoutil module
# Note: Jython
#-----------------------------------------------------
from org.meteoinfo.shape import ShapeUtil, PointShape
from org.meteoinfo.global import PointD
import mipylib.numeric as np
__all__ = [
'makeshapes'
]
def makeshapes(x, y, type=None, z=None, m=None):
"""
Make shapes by x and y coordinates.
:param x: (*array_like*) X coordinates.
:param y: (*array_like*) Y coordinates.
:param type: (*string*) Shape type [point | line | polygon].
:param z: (*array_like*) Z coordinates.
:param m: (*array_like*) M coordinates.
:returns: Shapes
"""
shapes = []
if isinstance(x, (int, float)):
shape = PointShape()
shape.setPoint(PointD(x, y))
shapes.append(shape)
else:
x = np.asarray(x)._array
y = np.asarray(y)._array
if not z is None:
if m is None:
m = np.zeros(len(z))._array
else:
m = np.asarray(m)._array
z = np.asarray(z)._array
if type == 'point':
if z is None:
shapes = ShapeUtil.createPointShapes(x, y)
else:
shapes = ShapeUtil.createPointShapes(x, y, z, m)
elif type == 'line':
if z is None:
shapes = ShapeUtil.createPolylineShapes(x, y)
else:
shapes = ShapeUtil.createPolylineShapes(x, y, z, m)
elif type == 'polygon':
if z is None:
shapes = ShapeUtil.createPolygonShapes(x, y)
else:
shapes = ShapeUtil.createPolygonShape(x, y, z, m)
return shapes
#-----------------------------------------------------
# Author: Yaqiang Wang
# Date: 2017-11-28
# Purpose: MeteoInfo geoutil module
# Note: Jython
#-----------------------------------------------------
from org.meteoinfo.shape import ShapeUtil, PointShape
from org.meteoinfo.common import PointD
import mipylib.numeric as np
__all__ = [
'makeshapes'
]
def makeshapes(x, y, type=None, z=None, m=None):
"""
Make shapes by x and y coordinates.
:param x: (*array_like*) X coordinates.
:param y: (*array_like*) Y coordinates.
:param type: (*string*) Shape type [point | line | polygon].
:param z: (*array_like*) Z coordinates.
:param m: (*array_like*) M coordinates.
:returns: Shapes
"""
shapes = []
if isinstance(x, (int, float)):
shape = PointShape()
shape.setPoint(PointD(x, y))
shapes.append(shape)
else:
x = np.asarray(x)._array
y = np.asarray(y)._array
if not z is None:
if m is None:
m = np.zeros(len(z))._array
else:
m = np.asarray(m)._array
z = np.asarray(z)._array
if type == 'point':
if z is None:
shapes = ShapeUtil.createPointShapes(x, y)
else:
shapes = ShapeUtil.createPointShapes(x, y, z, m)
elif type == 'line':
if z is None:
shapes = ShapeUtil.createPolylineShapes(x, y)
else:
shapes = ShapeUtil.createPolylineShapes(x, y, z, m)
elif type == 'polygon':
if z is None:
shapes = ShapeUtil.createPolygonShapes(x, y)
else:
shapes = ShapeUtil.createPolygonShape(x, y, z, m)
return shapes

View File

@ -16,8 +16,8 @@ from org.meteoinfo.math import ArrayMath, ArrayUtil
from org.meteoinfo.data.mapdata import MapDataManage, AttributeTable
from org.meteoinfo.projection import KnownCoordinateSystems, Reproject
from org.meteoinfo.projection.info import ProjectionInfo
from org.meteoinfo.global import PointD
from org.meteoinfo.io import IOUtil
from org.meteoinfo.common import PointD
from org.meteoinfo.common.io import IOUtil
from org.meteoinfo.geoprocess.analysis import ResampleMethods
from milayer import MILayer

View File

@ -5,8 +5,8 @@
# Note: Jython
#-----------------------------------------------------
from org.meteoinfo.global import PointD
from org.meteoinfo.global.util import JDateUtil
from org.meteoinfo.common import PointD
from org.meteoinfo.common.util import JDateUtil
from org.meteoinfo.ndarray import Complex
from org.meteoinfo.shape import PointShape, ShapeUtil
from java.util import Locale

View File

@ -9,7 +9,7 @@ from org.meteoinfo.data import GridData, GridArray
from org.meteoinfo.math import ArrayMath, ArrayUtil
from org.meteoinfo.geoprocess import GeometryUtil
from org.meteoinfo.geoprocess.analysis import ResampleMethods
from org.meteoinfo.global import PointD
from org.meteoinfo.common import PointD
from org.meteoinfo.ndarray import Array, Range, MAMath, DataType, Dimension, DimensionType
from multiarray import NDArray
import math

View File

@ -14,7 +14,7 @@ from org.meteoinfo.chart.axis import Axis, LonLatAxis, TimeAxis, LogAxis
from org.meteoinfo.legend import LegendManage, BarBreak, PolygonBreak, PolylineBreak, \
PointBreak, LineStyles, PointStyle, LegendScheme, LegendType
from org.meteoinfo.shape import ShapeTypes, Graphic, GraphicCollection
from org.meteoinfo.global import MIMath, Extent
from org.meteoinfo.common import MIMath, Extent
from org.meteoinfo.layer import MapLayer
from java.awt import Font, Color, BasicStroke

View File

@ -16,7 +16,7 @@ from org.meteoinfo.map import MapView
from org.meteoinfo.legend import BreakTypes, LegendManage, LegendScheme, LegendType
from org.meteoinfo.shape import Shape, PolylineShape, PolygonShape, ShapeTypes, Graphic
from org.meteoinfo.projection.info import ProjectionInfo
from org.meteoinfo.global import Extent
from org.meteoinfo.common import Extent
from org.meteoinfo.layer import LayerTypes, WebMapLayer
from org.meteoinfo.data.mapdata.webmap import WebMapProvider
from org.meteoinfo.layout import ScaleBarType

View File

@ -21,9 +21,9 @@ import com.formdev.flatlaf.FlatDarculaLaf;
import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatIntelliJLaf;
import com.formdev.flatlaf.FlatLightLaf;
import org.meteoinfo.common.util.GlobalUtil;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.global.util.FontUtil;
import org.meteoinfo.global.util.GlobalUtil;
import org.meteoinfo.laboratory.gui.FrmMain;
import org.meteoinfo.console.jython.MyPythonInterpreter;
import org.python.core.Py;

View File

@ -22,7 +22,7 @@ import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import com.formdev.flatlaf.extras.FlatSVGIcon;
import org.meteoinfo.global.util.JDateUtil;
import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.laboratory.event.CurrentPathChangedEvent;
import org.meteoinfo.laboratory.event.ICurrentPathChangedListener;
import org.meteoinfo.table.IconRenderer;

View File

@ -4,6 +4,8 @@
*/
package org.meteoinfo.laboratory.gui;
import org.meteoinfo.common.util.GlobalUtil;
import java.awt.Cursor;
import java.awt.Desktop;
import java.io.IOException;
@ -11,7 +13,6 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.global.util.GlobalUtil;
/**
*

View File

@ -15,9 +15,10 @@ import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.xml.parsers.ParserConfigurationException;
import org.meteoinfo.common.util.GlobalUtil;
import org.meteoinfo.laboratory.application.Application;
import org.meteoinfo.laboratory.application.AppCollection;
import org.meteoinfo.global.util.GlobalUtil;
import org.meteoinfo.plugin.IPlugin;
import org.meteoinfo.ui.CheckBoxListEntry;
import org.python.core.PyObject;

View File

@ -12,6 +12,15 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="meteoinfo-math" />
<orderEntry type="module" module-name="meteoinfo-common" />
<orderEntry type="library" name="Maven: com.google.guava:guava:28.0-jre" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:failureaccess:1.0.1" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava" level="project" />
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:2.8.1" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.3.2" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.17" level="project" />
<orderEntry type="module" module-name="meteoinfo-ndarray" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.2" level="project" />
<orderEntry type="library" name="Maven: edu.ucar:netcdfAll:5.4.1" level="project" />

View File

@ -47,6 +47,11 @@
</repositories>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>meteoinfo-math</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>meteoinfo-ndarray</artifactId>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -17,10 +17,10 @@ import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.chart.plot.XAlign;
import org.meteoinfo.chart.plot.YAlign;
import org.meteoinfo.common.PointD;
import org.meteoinfo.common.PointF;
import org.meteoinfo.drawing.Draw;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.global.PointD;
import org.meteoinfo.global.PointF;
import org.meteoinfo.legend.ColorBreak;
import org.meteoinfo.legend.LegendScheme;
import org.meteoinfo.legend.LegendType;

View File

@ -1,335 +1,336 @@
/* Copyright 2012 Yaqiang Wang,
* yaqiang.wang@gmail.com
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*/
package org.meteoinfo.chart;
import org.meteoinfo.global.event.ILocationChangedListener;
import org.meteoinfo.global.event.ISizeChangedListener;
import org.meteoinfo.global.event.LocationChangedEvent;
import org.meteoinfo.global.event.SizeChangedEvent;
import org.meteoinfo.global.PointF;
import java.awt.Color;
import java.awt.Rectangle;
import javax.swing.event.EventListenerList;
import org.meteoinfo.layout.ResizeAbility;
/**
*
* @author yaqiang
*/
public abstract class ChartElement {
// <editor-fold desc="Events">
public void addLocationChangedListener(ILocationChangedListener listener) {
this._listeners.add(ILocationChangedListener.class, listener);
}
public void removeLocationChangedListener(ILocationChangedListener listener) {
this._listeners.remove(ILocationChangedListener.class, listener);
}
public void fireLocationChangedEvent() {
fireLocationChangedEvent(new LocationChangedEvent(this));
}
private void fireLocationChangedEvent(LocationChangedEvent event) {
Object[] listeners = _listeners.getListenerList();
for (int i = 0; i < listeners.length; i = i + 2) {
if (listeners[i] == ILocationChangedListener.class) {
((ILocationChangedListener) listeners[i + 1]).locationChangedEvent(event);
}
}
}
public void addSizeChangedListener(ISizeChangedListener listener) {
this._listeners.add(ISizeChangedListener.class, listener);
}
public void removeSizeChangedListener(ISizeChangedListener listener) {
this._listeners.remove(ISizeChangedListener.class, listener);
}
public void fireSizeChangedEvent() {
fireSizeChangedEvent(new SizeChangedEvent(this));
}
private void fireSizeChangedEvent(SizeChangedEvent event) {
Object[] listeners = _listeners.getListenerList();
for (int i = 0; i < listeners.length; i = i + 2) {
if (listeners[i] == ISizeChangedListener.class) {
((ISizeChangedListener) listeners[i + 1]).sizeChangedEvent(event);
}
}
}
// </editor-fold>
// <editor-fold desc="Variables">
private final EventListenerList _listeners = new EventListenerList();
protected float x;
protected float y;
protected float width;
protected float height;
protected Color _foreColor;
protected Color _backColor;
private boolean _selected;
private ResizeAbility _resizeAbility;
private boolean _visible = true;
private boolean drawBackColor = false;
// </editor-fold>
// <editor-fold desc="Constructor">
public ChartElement() {
_foreColor = Color.black;
_backColor = Color.white;
_selected = false;
_resizeAbility = ResizeAbility.None;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get if visible
*
* @return Boolean
*/
public boolean isVisible() {
return _visible;
}
/**
* Set if visible
*
* @param istrue Boolean
*/
public void setVisible(boolean istrue) {
_visible = istrue;
}
/**
* Get x
*
* @return x
*/
public float getX() {
return x;
}
/**
* Set left
*
* @param left
*/
public void setX(float left) {
x = left;
this.fireLocationChangedEvent();
}
/**
* Get y
*
* @return Y
*/
public float getY() {
return y;
}
/**
* Set y
*
* @param top Y
*/
public void setY(float top) {
y = top;
this.fireLocationChangedEvent();
}
/**
* Get width
*
* @return Width
*/
public float getWidth() {
return width;
}
/**
* Set width
*
* @param width Width
*/
public void setWidth(float width) {
this.width = width;
this.fireSizeChangedEvent();
}
/**
* Get height
*
* @return Height
*/
public float getHeight() {
return height;
}
/**
* Set height
*
* @param height Height
*/
public void setHeight(float height) {
this.height = height;
this.fireSizeChangedEvent();
}
/**
* Get right
*
* @return Right
*/
public float getRight() {
return x + width;
}
/**
* Get bottom
*
* @return Bottom
*/
public float getBottom() {
return y + height;
}
/**
* Get bounds rectangle
*
* @return Bounds rectangle
*/
public Rectangle.Float getBounds() {
return new Rectangle.Float(x, y, width, height);
}
/**
* Get foreground color
*
* @return Foreground color
*/
public Color getForeground() {
return _foreColor;
}
/**
* Set foreground color
*
* @param color Foreground color
*/
public void setForeground(Color color) {
_foreColor = color;
}
/**
* Get background color
*
* @return Background color
*/
public Color getBackground() {
return _backColor;
}
/**
* Set background color
*
* @param color Background color
*/
public void setBackground(Color color) {
_backColor = color;
}
/**
* Get if is selected
*
* @return Boolean
*/
public boolean isSelected() {
return _selected;
}
/**
* Set if is selected
*
* @param istrue Boolean
*/
public void setSelected(boolean istrue) {
_selected = istrue;
}
/**
* Get resize ability
*
* @return Resize ability
*/
public ResizeAbility getResizeAbility() {
return _resizeAbility;
}
/**
* Set resize ability
*
* @param ra Resize ability
*/
public void setResizeAbility(ResizeAbility ra) {
_resizeAbility = ra;
}
/**
* Get is draw backcolor
* @return Boolean
*/
public boolean isDrawBackColor(){
return drawBackColor;
}
/**
* Set is draw backcolor
* @param value Boolean
*/
public void setDrawBackColor(boolean value){
drawBackColor = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Move update method
*/
public abstract void moveUpdate();
/**
* Resize update method
*/
public abstract void resizeUpdate();
/**
* Page to screen
*
* @param pageX Page X
* @param pageY Page Y
* @param pageLocation Page location
* @param zoom Zoom
* @return Screen point
*/
public PointF pageToScreen(float pageX, float pageY, PointF pageLocation, float zoom) {
float x = pageX * zoom + pageLocation.X;
float y = pageY * zoom + pageLocation.Y;
return (new PointF(x, y));
}
// </editor-fold>
}
/* Copyright 2012 Yaqiang Wang,
* yaqiang.wang@gmail.com
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*/
package org.meteoinfo.chart;
import org.meteoinfo.common.PointF;
import org.meteoinfo.global.event.ILocationChangedListener;
import org.meteoinfo.global.event.ISizeChangedListener;
import org.meteoinfo.global.event.LocationChangedEvent;
import org.meteoinfo.global.event.SizeChangedEvent;
import java.awt.Color;
import java.awt.Rectangle;
import javax.swing.event.EventListenerList;
import org.meteoinfo.layout.ResizeAbility;
/**
*
* @author yaqiang
*/
public abstract class ChartElement {
// <editor-fold desc="Events">
public void addLocationChangedListener(ILocationChangedListener listener) {
this._listeners.add(ILocationChangedListener.class, listener);
}
public void removeLocationChangedListener(ILocationChangedListener listener) {
this._listeners.remove(ILocationChangedListener.class, listener);
}
public void fireLocationChangedEvent() {
fireLocationChangedEvent(new LocationChangedEvent(this));
}
private void fireLocationChangedEvent(LocationChangedEvent event) {
Object[] listeners = _listeners.getListenerList();
for (int i = 0; i < listeners.length; i = i + 2) {
if (listeners[i] == ILocationChangedListener.class) {
((ILocationChangedListener) listeners[i + 1]).locationChangedEvent(event);
}
}
}
public void addSizeChangedListener(ISizeChangedListener listener) {
this._listeners.add(ISizeChangedListener.class, listener);
}
public void removeSizeChangedListener(ISizeChangedListener listener) {
this._listeners.remove(ISizeChangedListener.class, listener);
}
public void fireSizeChangedEvent() {
fireSizeChangedEvent(new SizeChangedEvent(this));
}
private void fireSizeChangedEvent(SizeChangedEvent event) {
Object[] listeners = _listeners.getListenerList();
for (int i = 0; i < listeners.length; i = i + 2) {
if (listeners[i] == ISizeChangedListener.class) {
((ISizeChangedListener) listeners[i + 1]).sizeChangedEvent(event);
}
}
}
// </editor-fold>
// <editor-fold desc="Variables">
private final EventListenerList _listeners = new EventListenerList();
protected float x;
protected float y;
protected float width;
protected float height;
protected Color _foreColor;
protected Color _backColor;
private boolean _selected;
private ResizeAbility _resizeAbility;
private boolean _visible = true;
private boolean drawBackColor = false;
// </editor-fold>
// <editor-fold desc="Constructor">
public ChartElement() {
_foreColor = Color.black;
_backColor = Color.white;
_selected = false;
_resizeAbility = ResizeAbility.None;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get if visible
*
* @return Boolean
*/
public boolean isVisible() {
return _visible;
}
/**
* Set if visible
*
* @param istrue Boolean
*/
public void setVisible(boolean istrue) {
_visible = istrue;
}
/**
* Get x
*
* @return x
*/
public float getX() {
return x;
}
/**
* Set left
*
* @param left
*/
public void setX(float left) {
x = left;
this.fireLocationChangedEvent();
}
/**
* Get y
*
* @return Y
*/
public float getY() {
return y;
}
/**
* Set y
*
* @param top Y
*/
public void setY(float top) {
y = top;
this.fireLocationChangedEvent();
}
/**
* Get width
*
* @return Width
*/
public float getWidth() {
return width;
}
/**
* Set width
*
* @param width Width
*/
public void setWidth(float width) {
this.width = width;
this.fireSizeChangedEvent();
}
/**
* Get height
*
* @return Height
*/
public float getHeight() {
return height;
}
/**
* Set height
*
* @param height Height
*/
public void setHeight(float height) {
this.height = height;
this.fireSizeChangedEvent();
}
/**
* Get right
*
* @return Right
*/
public float getRight() {
return x + width;
}
/**
* Get bottom
*
* @return Bottom
*/
public float getBottom() {
return y + height;
}
/**
* Get bounds rectangle
*
* @return Bounds rectangle
*/
public Rectangle.Float getBounds() {
return new Rectangle.Float(x, y, width, height);
}
/**
* Get foreground color
*
* @return Foreground color
*/
public Color getForeground() {
return _foreColor;
}
/**
* Set foreground color
*
* @param color Foreground color
*/
public void setForeground(Color color) {
_foreColor = color;
}
/**
* Get background color
*
* @return Background color
*/
public Color getBackground() {
return _backColor;
}
/**
* Set background color
*
* @param color Background color
*/
public void setBackground(Color color) {
_backColor = color;
}
/**
* Get if is selected
*
* @return Boolean
*/
public boolean isSelected() {
return _selected;
}
/**
* Set if is selected
*
* @param istrue Boolean
*/
public void setSelected(boolean istrue) {
_selected = istrue;
}
/**
* Get resize ability
*
* @return Resize ability
*/
public ResizeAbility getResizeAbility() {
return _resizeAbility;
}
/**
* Set resize ability
*
* @param ra Resize ability
*/
public void setResizeAbility(ResizeAbility ra) {
_resizeAbility = ra;
}
/**
* Get is draw backcolor
* @return Boolean
*/
public boolean isDrawBackColor(){
return drawBackColor;
}
/**
* Set is draw backcolor
* @param value Boolean
*/
public void setDrawBackColor(boolean value){
drawBackColor = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Move update method
*/
public abstract void moveUpdate();
/**
* Resize update method
*/
public abstract void resizeUpdate();
/**
* Page to screen
*
* @param pageX Page X
* @param pageY Page Y
* @param pageLocation Page location
* @param zoom Zoom
* @return Screen point
*/
public PointF pageToScreen(float pageX, float pageY, PointF pageLocation, float zoom) {
float x = pageX * zoom + pageLocation.X;
float y = pageY * zoom + pageLocation.Y;
return (new PointF(x, y));
}
// </editor-fold>
}

File diff suppressed because it is too large Load Diff

View File

@ -1,298 +1,298 @@
/* Copyright 2012 Yaqiang Wang,
* yaqiang.wang@gmail.com
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*/
package org.meteoinfo.chart;
import com.l2fprod.common.beans.BaseBeanInfo;
import org.meteoinfo.drawing.Draw;
import org.meteoinfo.global.PointF;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import org.meteoinfo.chart.plot.MapPlot;
import org.meteoinfo.layout.NorthArrowType;
/**
*
* @author Yaqiang Wang
*/
public class ChartNorthArrow extends ChartElement {
// <editor-fold desc="Variables">
private MapPlot mapPlot;
private boolean _antiAlias;
private float lineWidth;
private boolean _drawNeatLine;
private Color _neatLineColor;
private float _neatLineSize;
private NorthArrowType _northArrowType;
private float _angle;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*
* @param mapPlot The map plot
*/
public ChartNorthArrow(MapPlot mapPlot) {
super();
this.setWidth(50);
this.setHeight(50);
this.mapPlot = mapPlot;
this.lineWidth = 1;
_antiAlias = true;
_drawNeatLine = false;
_neatLineColor = Color.black;
_neatLineSize = 1;
_northArrowType = NorthArrowType.NORTHARROW_1;
_angle = 0;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get map plot
*
* @return The map plot
*/
public MapPlot getMapPlot() {
return this.mapPlot;
}
/**
* Get line widht
* @return Line width
*/
public float getLineWidth() {
return this.lineWidth;
}
/**
* Set line width
* @param value Line width
*/
public void setLineWidth(float value) {
this.lineWidth = value;
}
/**
* Get if draw neat line
*
* @return If draw neat line
*/
public boolean isDrawNeatLine() {
return _drawNeatLine;
}
/**
* Set if draw neat line
*
* @param istrue If draw neat line
*/
public void setDrawNeatLine(boolean istrue) {
_drawNeatLine = istrue;
}
/**
* Get neat line color
*
* @return Neat line color
*/
public Color getNeatLineColor() {
return _neatLineColor;
}
/**
* Set neat line color
*
* @param color Neat line color
*/
public void setNeatLineColor(Color color) {
_neatLineColor = color;
}
/**
* Get neat line size
*
* @return Neat line size
*/
public float getNeatLineSize() {
return _neatLineSize;
}
/**
* Set neat line size
*
* @param size Neat line size
*/
public void setNeatLineSize(float size) {
_neatLineSize = size;
}
/**
* Get angle
*
* @return Angle
*/
public float getAngle() {
return _angle;
}
/**
* Set angle
*
* @param angle The angle
*/
public void setAngle(float angle) {
_angle = angle;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Draw text
*
* @param g Graphics2D
* @param x X
* @param y Y
*/
public void draw(Graphics2D g, float x, float y) {
AffineTransform oldMatrix = g.getTransform();
g.translate(x, y);
if (_angle != 0) {
g.rotate(_angle);
}
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackground());
g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
}
drawNorthArrow(g);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
/**
* Paint graphics
*
* @param g Graphics
* @param pageLocation Page location
* @param zoom Zoom
*/
public void paintGraphics(Graphics2D g, PointF pageLocation, float zoom) {
AffineTransform oldMatrix = g.getTransform();
PointF aP = pageToScreen(this.getX(), this.getY(), pageLocation, zoom);
g.translate(aP.X, aP.Y);
g.scale(zoom, zoom);
if (_angle != 0) {
g.rotate(_angle);
}
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackground());
g.fill(new Rectangle.Float(0, 0, this.getWidth() * zoom, this.getHeight() * zoom));
}
drawNorthArrow(g);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize) * zoom, (this.getHeight() - _neatLineSize) * zoom);
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
private void drawNorthArrow(Graphics2D g) {
switch (_northArrowType) {
case NORTHARROW_1:
drawNorthArrow1(g);
break;
}
}
private void drawNorthArrow1(Graphics2D g) {
g.setColor(this.getForeground());
g.setStroke(new BasicStroke(this.lineWidth));
//Draw N symbol
PointF[] points = new PointF[4];
float x = this.getWidth() / 2;
float y = this.getHeight() / 6;
float w = this.getWidth() / 6;
float h = this.getHeight() / 4;
points[0] = new PointF(x - w / 2, y + h / 2);
points[1] = new PointF(x - w / 2, y - h / 2);
points[2] = new PointF(x + w / 2, y + h / 2);
points[3] = new PointF(x + w / 2, y - h / 2);
Draw.drawPolyline(points, g);
//Draw arrow
w = this.getWidth() / 2;
h = this.getHeight() * 2 / 3;
points = new PointF[3];
points[0] = new PointF(x - w / 2, this.getHeight());
points[1] = new PointF(x, this.getHeight() - h / 2);
points[2] = new PointF(x, this.getHeight() - h);
Draw.fillPolygon(points, g, null);
Draw.drawPolyline(points, g);
points = new PointF[4];
points[0] = new PointF(x + w / 2, this.getHeight());
points[1] = new PointF(x, this.getHeight() - h / 2);
points[2] = new PointF(x, this.getHeight() - h);
points[3] = points[0];
Draw.drawPolyline(points, g);
}
@Override
public void moveUpdate() {
}
@Override
public void resizeUpdate() {
}
// </editor-fold>
}
/* Copyright 2012 Yaqiang Wang,
* yaqiang.wang@gmail.com
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*/
package org.meteoinfo.chart;
import org.meteoinfo.common.PointF;
import org.meteoinfo.drawing.Draw;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import org.meteoinfo.chart.plot.MapPlot;
import org.meteoinfo.layout.NorthArrowType;
/**
*
* @author Yaqiang Wang
*/
public class ChartNorthArrow extends ChartElement {
// <editor-fold desc="Variables">
private MapPlot mapPlot;
private boolean _antiAlias;
private float lineWidth;
private boolean _drawNeatLine;
private Color _neatLineColor;
private float _neatLineSize;
private NorthArrowType _northArrowType;
private float _angle;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*
* @param mapPlot The map plot
*/
public ChartNorthArrow(MapPlot mapPlot) {
super();
this.setWidth(50);
this.setHeight(50);
this.mapPlot = mapPlot;
this.lineWidth = 1;
_antiAlias = true;
_drawNeatLine = false;
_neatLineColor = Color.black;
_neatLineSize = 1;
_northArrowType = NorthArrowType.NORTHARROW_1;
_angle = 0;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get map plot
*
* @return The map plot
*/
public MapPlot getMapPlot() {
return this.mapPlot;
}
/**
* Get line widht
* @return Line width
*/
public float getLineWidth() {
return this.lineWidth;
}
/**
* Set line width
* @param value Line width
*/
public void setLineWidth(float value) {
this.lineWidth = value;
}
/**
* Get if draw neat line
*
* @return If draw neat line
*/
public boolean isDrawNeatLine() {
return _drawNeatLine;
}
/**
* Set if draw neat line
*
* @param istrue If draw neat line
*/
public void setDrawNeatLine(boolean istrue) {
_drawNeatLine = istrue;
}
/**
* Get neat line color
*
* @return Neat line color
*/
public Color getNeatLineColor() {
return _neatLineColor;
}
/**
* Set neat line color
*
* @param color Neat line color
*/
public void setNeatLineColor(Color color) {
_neatLineColor = color;
}
/**
* Get neat line size
*
* @return Neat line size
*/
public float getNeatLineSize() {
return _neatLineSize;
}
/**
* Set neat line size
*
* @param size Neat line size
*/
public void setNeatLineSize(float size) {
_neatLineSize = size;
}
/**
* Get angle
*
* @return Angle
*/
public float getAngle() {
return _angle;
}
/**
* Set angle
*
* @param angle The angle
*/
public void setAngle(float angle) {
_angle = angle;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Draw text
*
* @param g Graphics2D
* @param x X
* @param y Y
*/
public void draw(Graphics2D g, float x, float y) {
AffineTransform oldMatrix = g.getTransform();
g.translate(x, y);
if (_angle != 0) {
g.rotate(_angle);
}
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackground());
g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
}
drawNorthArrow(g);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
/**
* Paint graphics
*
* @param g Graphics
* @param pageLocation Page location
* @param zoom Zoom
*/
public void paintGraphics(Graphics2D g, PointF pageLocation, float zoom) {
AffineTransform oldMatrix = g.getTransform();
PointF aP = pageToScreen(this.getX(), this.getY(), pageLocation, zoom);
g.translate(aP.X, aP.Y);
g.scale(zoom, zoom);
if (_angle != 0) {
g.rotate(_angle);
}
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackground());
g.fill(new Rectangle.Float(0, 0, this.getWidth() * zoom, this.getHeight() * zoom));
}
drawNorthArrow(g);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize) * zoom, (this.getHeight() - _neatLineSize) * zoom);
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
private void drawNorthArrow(Graphics2D g) {
switch (_northArrowType) {
case NORTHARROW_1:
drawNorthArrow1(g);
break;
}
}
private void drawNorthArrow1(Graphics2D g) {
g.setColor(this.getForeground());
g.setStroke(new BasicStroke(this.lineWidth));
//Draw N symbol
PointF[] points = new PointF[4];
float x = this.getWidth() / 2;
float y = this.getHeight() / 6;
float w = this.getWidth() / 6;
float h = this.getHeight() / 4;
points[0] = new PointF(x - w / 2, y + h / 2);
points[1] = new PointF(x - w / 2, y - h / 2);
points[2] = new PointF(x + w / 2, y + h / 2);
points[3] = new PointF(x + w / 2, y - h / 2);
Draw.drawPolyline(points, g);
//Draw arrow
w = this.getWidth() / 2;
h = this.getHeight() * 2 / 3;
points = new PointF[3];
points[0] = new PointF(x - w / 2, this.getHeight());
points[1] = new PointF(x, this.getHeight() - h / 2);
points[2] = new PointF(x, this.getHeight() - h);
Draw.fillPolygon(points, g, null);
Draw.drawPolyline(points, g);
points = new PointF[4];
points[0] = new PointF(x + w / 2, this.getHeight());
points[1] = new PointF(x, this.getHeight() - h / 2);
points[2] = new PointF(x, this.getHeight() - h);
points[3] = points[0];
Draw.drawPolyline(points, g);
}
@Override
public void moveUpdate() {
}
@Override
public void resizeUpdate() {
}
// </editor-fold>
}

View File

@ -81,11 +81,11 @@ import org.meteoinfo.chart.plot.AbstractPlot2D;
import org.meteoinfo.chart.plot.Plot3D;
import org.meteoinfo.chart.plot.PlotType;
import org.meteoinfo.chart.plot3d.Projector;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.GenericFileFilter;
import org.meteoinfo.common.PointF;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.data.mapdata.Field;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.GenericFileFilter;
import org.meteoinfo.global.PointF;
import org.meteoinfo.image.ImageUtil;
import org.meteoinfo.layer.LayerTypes;
import org.meteoinfo.layer.MapLayer;

View File

@ -1,457 +1,457 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.chart;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
import org.meteoinfo.chart.plot.MapPlot;
import org.meteoinfo.global.PointF;
import org.meteoinfo.layout.ScaleBarType;
import org.meteoinfo.layout.ScaleBarUnits;
/**
*
* @author Yaqiang Wang
*/
public class ChartScaleBar extends ChartElement {
// <editor-fold desc="Variables">
private MapPlot mapPlot;
private boolean _antiAlias;
private float lineWidth;
private Font _font;
private ScaleBarType _scaleBarType;
private ScaleBarUnits _unit;
private String _unitText;
private int _numBreaks;
private boolean _drawNeatLine;
private Color _neatLineColor;
private float _neatLineSize;
private boolean _drawScaleText;
private float _yShiftScale = 2.0f;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*
* @param mapPlot The map plot
*/
public ChartScaleBar(MapPlot mapPlot) {
super();
//this.setElementType(ElementType.LayoutScaleBar);
//this.setResizeAbility(ResizeAbility.ResizeAll);
this.width = 200;
this.height = 50;
this.mapPlot = mapPlot;
_antiAlias = true;
_scaleBarType = ScaleBarType.SCALELINE_1;
lineWidth = 1;
_drawNeatLine = false;
_neatLineColor = Color.black;
_neatLineSize = 1;
_font = new Font("Arial", Font.PLAIN, 12);
_unit = ScaleBarUnits.KILOMETERS;
_unitText = "km";
_numBreaks = 4;
_drawScaleText = false;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get map plot
*
* @return The map plot
*/
public MapPlot getMapPlot() {
return mapPlot;
}
/**
* Get line widht
* @return Line width
*/
public float getLineWidth() {
return this.lineWidth;
}
/**
* Set line width
* @param value Line width
*/
public void setLineWidth(float value) {
this.lineWidth = value;
}
/**
* Get scale bar type
*
* @return Scale bar type
*/
public ScaleBarType getScaleBarType() {
return _scaleBarType;
}
/**
* Set scale bar type
*
* @param type Scale bar type
*/
public void setScaleBarType(ScaleBarType type) {
_scaleBarType = type;
}
/**
* Get if draw neat line
*
* @return If draw neat line
*/
public boolean isDrawNeatLine() {
return _drawNeatLine;
}
/**
* Set if draw neat line
*
* @param istrue If draw neat line
*/
public void setDrawNeatLine(boolean istrue) {
_drawNeatLine = istrue;
}
/**
* Get neat line color
*
* @return Neat line color
*/
public Color getNeatLineColor() {
return _neatLineColor;
}
/**
* Set neat line color
*
* @param color Neat line color
*/
public void setNeatLineColor(Color color) {
_neatLineColor = color;
}
/**
* Get neat line size
*
* @return Neat line size
*/
public float getNeatLineSize() {
return _neatLineSize;
}
/**
* Set neat line size
*
* @param size Neat line size
*/
public void setNeatLineSize(float size) {
_neatLineSize = size;
}
/**
* Get font
*
* @return The font
*/
public Font getFont() {
return _font;
}
/**
* Set font
*
* @param font The font
*/
public void setFont(Font font) {
_font = font;
}
/**
* Get break number
*
* @return The break number
*/
public int getBreakNumber() {
return _numBreaks;
}
/**
* Set break number
*
* @param num Break number
*/
public void setBreakNumber(int num) {
_numBreaks = num;
}
/**
* Get if draw scale text
*
* @return If draw scale text
*/
public boolean isDrawScaleText() {
return _drawScaleText;
}
/**
* Set if draw scale text
*
* @param istrue If draw scale text
*/
public void setDrawScaleText(boolean istrue) {
_drawScaleText = istrue;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Draw text
*
* @param g Graphics2D
* @param x X
* @param y Y
*/
public void draw(Graphics2D g, float x, float y) {
AffineTransform oldMatrix = g.getTransform();
g.translate(x, y);
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackground());
g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
}
drawScaleBar(g);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
/**
* Paint graphics
*
* @param g Graphics
* @param pageLocation Page location
* @param zoom Zoom
*/
public void paintGraphics(Graphics2D g, PointF pageLocation) {
AffineTransform oldMatrix = g.getTransform();
PointF aP = pageToScreen(this.getX(), this.getY(), pageLocation, 1);
g.translate(aP.X, aP.Y);
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackground());
g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
}
drawScaleBar(g);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
private void drawScaleBar(Graphics2D g) {
//Calculates the width of one break in greographic units
FontMetrics metrics = g.getFontMetrics(this._font);
float unitLegnth = metrics.stringWidth(_unitText) * 2;
float widthNoUnit = (this.getWidth() - unitLegnth);
long geoBreakWidth = (long) (getGeoWidth(widthNoUnit / _numBreaks));
//If the geobreakWidth is less than 1 we return and don't draw anything
if (geoBreakWidth < 1) {
return;
}
double n = Math.pow(10, String.valueOf(geoBreakWidth).length() - 1);
geoBreakWidth = (long) (Math.floor(geoBreakWidth / n) * n);
long breakWidth = (long) (getWidth(geoBreakWidth));
FontMetrics metrics1 = g.getFontMetrics(_font);
float fontHeight = metrics1.getHeight();
float leftStart = metrics1.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
//Draw scale text
double scale = geoBreakWidth * getConversionFactor(_unit) * 100 / (breakWidth / 96 * 2.539999918);
if (_drawScaleText) {
g.setFont(this._font);
g.setColor(this.getForeground());
g.drawString("1 : " + String.format("{0:0,0}", scale),
leftStart - (metrics.stringWidth(String.valueOf(Math.abs(0))) / 2), fontHeight * 2.5F);
}
//Draw scale bar
switch (_scaleBarType) {
case SCALELINE_1:
drawScaleLine1(g, breakWidth, geoBreakWidth);
break;
case SCALELINE_2:
drawScaleLine2(g, breakWidth, geoBreakWidth);
break;
case ALTERNATING_BAR:
drawAlternatingBar(g, breakWidth, geoBreakWidth);
break;
}
}
private double getConversionFactor(ScaleBarUnits unit) {
switch (unit) {
case KILOMETERS:
return 1000;
default:
return 1;
}
}
private double getGeoWidth(double width) {
double geoWidth = width / mapPlot.getMapFrame().getMapView().getXScale() / getConversionFactor(_unit);
if (mapPlot.getMapFrame().getMapView().getProjection().isLonLatMap()) {
geoWidth = geoWidth * getLonDistScale();
}
return geoWidth;
}
private double getWidth(double geoWidth) {
double width = geoWidth * mapPlot.getMapFrame().getMapView().getXScale() * getConversionFactor(_unit);
if (mapPlot.getMapFrame().getMapView().getProjection().isLonLatMap()) {
width = width / getLonDistScale();
}
return width;
}
private double getLonDistScale() {
//Get meters of one longitude degree
double pY = (mapPlot.getMapFrame().getMapView().getViewExtent().maxY + mapPlot.getMapFrame().getMapView().getViewExtent().minY) / 2;
double ProjX = 0, ProjY = pY, pProjX = 1, pProjY = pY;
double dx = Math.abs(ProjX - pProjX);
double dy = Math.abs(ProjY - pProjY);
double dist;
double y = (ProjY + pProjY) / 2;
double factor = Math.cos(y * Math.PI / 180);
dx *= factor;
dist = Math.sqrt(dx * dx + dy * dy);
dist = dist * 111319.5;
return dist;
}
private void drawScaleLine1(Graphics2D g, long breakWidth, long geoBreakWidth) {
FontMetrics metrics = g.getFontMetrics(_font);
float fontHeight = metrics.getHeight();
float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
int yShift = 10;
g.setColor(this.getForeground());
g.setStroke(new BasicStroke(this.lineWidth));
g.draw(new Line2D.Float(leftStart, fontHeight * 1.6f + yShift, leftStart + (breakWidth * _numBreaks), fontHeight * 1.6f + yShift));
g.setFont(this._font);
for (int i = 0; i <= _numBreaks; i++) {
g.draw(new Line2D.Float(leftStart, fontHeight * 1.1f + yShift, leftStart, fontHeight * 1.6f + yShift));
g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
leftStart - (metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
leftStart = leftStart + breakWidth;
}
g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
}
private void drawScaleLine2(Graphics2D g, long breakWidth, long geoBreakWidth) {
FontMetrics metrics = g.getFontMetrics(_font);
float fontHeight = metrics.getHeight();
float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
int yShift = 5;
g.setColor(this.getForeground());
g.setStroke(new BasicStroke(this.lineWidth));
g.draw(new Line2D.Float(leftStart, fontHeight * 1.6f + yShift, leftStart + (breakWidth * _numBreaks), fontHeight * 1.6f + yShift));
g.setFont(this._font);
for (int i = 0; i <= _numBreaks; i++) {
g.draw(new Line2D.Float(leftStart, fontHeight * 1.1f + yShift, leftStart, fontHeight + (fontHeight * 1.1f) + yShift));
g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
leftStart - (metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
leftStart = leftStart + breakWidth;
}
g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
}
private void drawAlternatingBar(Graphics2D g, long breakWidth, long geoBreakWidth) {
FontMetrics metrics = g.getFontMetrics(_font);
float fontHeight = metrics.getHeight();
float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
int yShift = 5;
float rHeight = fontHeight / 2;
boolean isFill = false;
g.setStroke(new BasicStroke(this.lineWidth));
g.setColor(this.getForeground());
g.setFont(this._font);
for (int i = 0; i <= _numBreaks; i++) {
if (i < _numBreaks) {
if (isFill) {
g.fill(new Rectangle.Float(leftStart, fontHeight * 1.1f + yShift, breakWidth, rHeight));
}
g.draw(new Rectangle.Float(leftStart, fontHeight * 1.1f + yShift, breakWidth, rHeight));
}
g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
leftStart - (metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
leftStart = leftStart + breakWidth;
isFill = !isFill;
}
g.setColor(this.getForeground());
g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
}
@Override
public void moveUpdate() {
}
@Override
public void resizeUpdate() {
}
// </editor-fold>
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.chart;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
import org.meteoinfo.chart.plot.MapPlot;
import org.meteoinfo.common.PointF;
import org.meteoinfo.layout.ScaleBarType;
import org.meteoinfo.layout.ScaleBarUnits;
/**
*
* @author Yaqiang Wang
*/
public class ChartScaleBar extends ChartElement {
// <editor-fold desc="Variables">
private MapPlot mapPlot;
private boolean _antiAlias;
private float lineWidth;
private Font _font;
private ScaleBarType _scaleBarType;
private ScaleBarUnits _unit;
private String _unitText;
private int _numBreaks;
private boolean _drawNeatLine;
private Color _neatLineColor;
private float _neatLineSize;
private boolean _drawScaleText;
private float _yShiftScale = 2.0f;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*
* @param mapPlot The map plot
*/
public ChartScaleBar(MapPlot mapPlot) {
super();
//this.setElementType(ElementType.LayoutScaleBar);
//this.setResizeAbility(ResizeAbility.ResizeAll);
this.width = 200;
this.height = 50;
this.mapPlot = mapPlot;
_antiAlias = true;
_scaleBarType = ScaleBarType.SCALELINE_1;
lineWidth = 1;
_drawNeatLine = false;
_neatLineColor = Color.black;
_neatLineSize = 1;
_font = new Font("Arial", Font.PLAIN, 12);
_unit = ScaleBarUnits.KILOMETERS;
_unitText = "km";
_numBreaks = 4;
_drawScaleText = false;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get map plot
*
* @return The map plot
*/
public MapPlot getMapPlot() {
return mapPlot;
}
/**
* Get line widht
* @return Line width
*/
public float getLineWidth() {
return this.lineWidth;
}
/**
* Set line width
* @param value Line width
*/
public void setLineWidth(float value) {
this.lineWidth = value;
}
/**
* Get scale bar type
*
* @return Scale bar type
*/
public ScaleBarType getScaleBarType() {
return _scaleBarType;
}
/**
* Set scale bar type
*
* @param type Scale bar type
*/
public void setScaleBarType(ScaleBarType type) {
_scaleBarType = type;
}
/**
* Get if draw neat line
*
* @return If draw neat line
*/
public boolean isDrawNeatLine() {
return _drawNeatLine;
}
/**
* Set if draw neat line
*
* @param istrue If draw neat line
*/
public void setDrawNeatLine(boolean istrue) {
_drawNeatLine = istrue;
}
/**
* Get neat line color
*
* @return Neat line color
*/
public Color getNeatLineColor() {
return _neatLineColor;
}
/**
* Set neat line color
*
* @param color Neat line color
*/
public void setNeatLineColor(Color color) {
_neatLineColor = color;
}
/**
* Get neat line size
*
* @return Neat line size
*/
public float getNeatLineSize() {
return _neatLineSize;
}
/**
* Set neat line size
*
* @param size Neat line size
*/
public void setNeatLineSize(float size) {
_neatLineSize = size;
}
/**
* Get font
*
* @return The font
*/
public Font getFont() {
return _font;
}
/**
* Set font
*
* @param font The font
*/
public void setFont(Font font) {
_font = font;
}
/**
* Get break number
*
* @return The break number
*/
public int getBreakNumber() {
return _numBreaks;
}
/**
* Set break number
*
* @param num Break number
*/
public void setBreakNumber(int num) {
_numBreaks = num;
}
/**
* Get if draw scale text
*
* @return If draw scale text
*/
public boolean isDrawScaleText() {
return _drawScaleText;
}
/**
* Set if draw scale text
*
* @param istrue If draw scale text
*/
public void setDrawScaleText(boolean istrue) {
_drawScaleText = istrue;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Draw text
*
* @param g Graphics2D
* @param x X
* @param y Y
*/
public void draw(Graphics2D g, float x, float y) {
AffineTransform oldMatrix = g.getTransform();
g.translate(x, y);
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackground());
g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
}
drawScaleBar(g);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
/**
* Paint graphics
*
* @param g Graphics
* @param pageLocation Page location
* @param zoom Zoom
*/
public void paintGraphics(Graphics2D g, PointF pageLocation) {
AffineTransform oldMatrix = g.getTransform();
PointF aP = pageToScreen(this.getX(), this.getY(), pageLocation, 1);
g.translate(aP.X, aP.Y);
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackground());
g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
}
drawScaleBar(g);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
private void drawScaleBar(Graphics2D g) {
//Calculates the width of one break in greographic units
FontMetrics metrics = g.getFontMetrics(this._font);
float unitLegnth = metrics.stringWidth(_unitText) * 2;
float widthNoUnit = (this.getWidth() - unitLegnth);
long geoBreakWidth = (long) (getGeoWidth(widthNoUnit / _numBreaks));
//If the geobreakWidth is less than 1 we return and don't draw anything
if (geoBreakWidth < 1) {
return;
}
double n = Math.pow(10, String.valueOf(geoBreakWidth).length() - 1);
geoBreakWidth = (long) (Math.floor(geoBreakWidth / n) * n);
long breakWidth = (long) (getWidth(geoBreakWidth));
FontMetrics metrics1 = g.getFontMetrics(_font);
float fontHeight = metrics1.getHeight();
float leftStart = metrics1.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
//Draw scale text
double scale = geoBreakWidth * getConversionFactor(_unit) * 100 / (breakWidth / 96 * 2.539999918);
if (_drawScaleText) {
g.setFont(this._font);
g.setColor(this.getForeground());
g.drawString("1 : " + String.format("{0:0,0}", scale),
leftStart - (metrics.stringWidth(String.valueOf(Math.abs(0))) / 2), fontHeight * 2.5F);
}
//Draw scale bar
switch (_scaleBarType) {
case SCALELINE_1:
drawScaleLine1(g, breakWidth, geoBreakWidth);
break;
case SCALELINE_2:
drawScaleLine2(g, breakWidth, geoBreakWidth);
break;
case ALTERNATING_BAR:
drawAlternatingBar(g, breakWidth, geoBreakWidth);
break;
}
}
private double getConversionFactor(ScaleBarUnits unit) {
switch (unit) {
case KILOMETERS:
return 1000;
default:
return 1;
}
}
private double getGeoWidth(double width) {
double geoWidth = width / mapPlot.getMapFrame().getMapView().getXScale() / getConversionFactor(_unit);
if (mapPlot.getMapFrame().getMapView().getProjection().isLonLatMap()) {
geoWidth = geoWidth * getLonDistScale();
}
return geoWidth;
}
private double getWidth(double geoWidth) {
double width = geoWidth * mapPlot.getMapFrame().getMapView().getXScale() * getConversionFactor(_unit);
if (mapPlot.getMapFrame().getMapView().getProjection().isLonLatMap()) {
width = width / getLonDistScale();
}
return width;
}
private double getLonDistScale() {
//Get meters of one longitude degree
double pY = (mapPlot.getMapFrame().getMapView().getViewExtent().maxY + mapPlot.getMapFrame().getMapView().getViewExtent().minY) / 2;
double ProjX = 0, ProjY = pY, pProjX = 1, pProjY = pY;
double dx = Math.abs(ProjX - pProjX);
double dy = Math.abs(ProjY - pProjY);
double dist;
double y = (ProjY + pProjY) / 2;
double factor = Math.cos(y * Math.PI / 180);
dx *= factor;
dist = Math.sqrt(dx * dx + dy * dy);
dist = dist * 111319.5;
return dist;
}
private void drawScaleLine1(Graphics2D g, long breakWidth, long geoBreakWidth) {
FontMetrics metrics = g.getFontMetrics(_font);
float fontHeight = metrics.getHeight();
float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
int yShift = 10;
g.setColor(this.getForeground());
g.setStroke(new BasicStroke(this.lineWidth));
g.draw(new Line2D.Float(leftStart, fontHeight * 1.6f + yShift, leftStart + (breakWidth * _numBreaks), fontHeight * 1.6f + yShift));
g.setFont(this._font);
for (int i = 0; i <= _numBreaks; i++) {
g.draw(new Line2D.Float(leftStart, fontHeight * 1.1f + yShift, leftStart, fontHeight * 1.6f + yShift));
g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
leftStart - (metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
leftStart = leftStart + breakWidth;
}
g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
}
private void drawScaleLine2(Graphics2D g, long breakWidth, long geoBreakWidth) {
FontMetrics metrics = g.getFontMetrics(_font);
float fontHeight = metrics.getHeight();
float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
int yShift = 5;
g.setColor(this.getForeground());
g.setStroke(new BasicStroke(this.lineWidth));
g.draw(new Line2D.Float(leftStart, fontHeight * 1.6f + yShift, leftStart + (breakWidth * _numBreaks), fontHeight * 1.6f + yShift));
g.setFont(this._font);
for (int i = 0; i <= _numBreaks; i++) {
g.draw(new Line2D.Float(leftStart, fontHeight * 1.1f + yShift, leftStart, fontHeight + (fontHeight * 1.1f) + yShift));
g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
leftStart - (metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
leftStart = leftStart + breakWidth;
}
g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
}
private void drawAlternatingBar(Graphics2D g, long breakWidth, long geoBreakWidth) {
FontMetrics metrics = g.getFontMetrics(_font);
float fontHeight = metrics.getHeight();
float leftStart = metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth))) / 2F;
int yShift = 5;
float rHeight = fontHeight / 2;
boolean isFill = false;
g.setStroke(new BasicStroke(this.lineWidth));
g.setColor(this.getForeground());
g.setFont(this._font);
for (int i = 0; i <= _numBreaks; i++) {
if (i < _numBreaks) {
if (isFill) {
g.fill(new Rectangle.Float(leftStart, fontHeight * 1.1f + yShift, breakWidth, rHeight));
}
g.draw(new Rectangle.Float(leftStart, fontHeight * 1.1f + yShift, breakWidth, rHeight));
}
g.drawString(String.valueOf(Math.abs(geoBreakWidth * i)),
leftStart - (metrics.stringWidth(String.valueOf(Math.abs(geoBreakWidth * i))) / 2), yShift * _yShiftScale);
leftStart = leftStart + breakWidth;
isFill = !isFill;
}
g.setColor(this.getForeground());
g.drawString(_unitText, leftStart - breakWidth + (fontHeight / 2), fontHeight * 1.1f + yShift * _yShiftScale);
}
@Override
public void moveUpdate() {
}
@Override
public void resizeUpdate() {
}
// </editor-fold>
}

File diff suppressed because it is too large Load Diff

View File

@ -1,127 +1,127 @@
/* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*/
package org.meteoinfo.chart;
import java.awt.Point;
import org.meteoinfo.chart.plot3d.Projector;
import org.meteoinfo.data.DataMath;
import org.meteoinfo.global.Extent3D;
import org.meteoinfo.shape.PointZ;
/**
*
* @author Yaqiang Wang
* yaqiang.wang@gmail.com
*/
public class ChartText3D extends ChartText {
private double z;
private PointZ zdir = null;
/**
* Get z coordinate value
* @return Z coordinate value
*/
public double getZ(){
return this.z;
}
/**
* Set z coordinate value
* @param value Z coordinate value
*/
public void setZ(double value){
this.z = value;
}
/**
* Get zdir point
* @return ZDir point
*/
public PointZ getZDir(){
return zdir;
}
/**
* Set zdir point
* @param value ZDir point
*/
public void setZDir(PointZ value){
this.zdir = value;
}
/**
* Set zdir point
* @param x X coordinate value
* @param y Y coordinate value
* @param z Z coordinate value
*/
public void setZDir(float x, float y, float z){
if (x == 0 && y == 0 && z == 0)
this.zdir = null;
else
this.zdir = new PointZ(x, y, z);
}
/**
* Set zdir point
* @param value ZDir point
*/
public void setZDir(String value){
float x1 = 0, y1 = 0, z1 = 0;
switch(value.toLowerCase()){
case "x":
x1 = 1;
break;
case "y":
y1 = 1;
break;
case "z":
z1 = 1;
break;
}
this.setZDir(x1, y1, z1);
}
/**
* Set point
*
* @param x X
* @param y Y
* @param z Z
*/
public void setPoint(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
Extent3D aExtent = new Extent3D();
aExtent.minX = x;
aExtent.maxX = x;
aExtent.minY = y;
aExtent.maxY = y;
aExtent.minZ = z;
aExtent.maxZ = z;
this.setExtent(aExtent);
}
/**
* Update angle
* @param projector Projector
*/
public void updateAngle(Projector projector){
if (this.zdir == null)
return;
Point p0 = projector.project(0, 0, 0);
Point p1 = projector.project((float)this.zdir.X, (float)this.zdir.Y, (float)this.zdir.Z);
double[] value = DataMath.getDSFromUV(p1.x - p0.x, p1.y - p0.y);
this.angle = (float)value[0];
}
}
/* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*/
package org.meteoinfo.chart;
import java.awt.Point;
import org.meteoinfo.chart.plot3d.Projector;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.data.DataMath;
import org.meteoinfo.shape.PointZ;
/**
*
* @author Yaqiang Wang
* yaqiang.wang@gmail.com
*/
public class ChartText3D extends ChartText {
private double z;
private PointZ zdir = null;
/**
* Get z coordinate value
* @return Z coordinate value
*/
public double getZ(){
return this.z;
}
/**
* Set z coordinate value
* @param value Z coordinate value
*/
public void setZ(double value){
this.z = value;
}
/**
* Get zdir point
* @return ZDir point
*/
public PointZ getZDir(){
return zdir;
}
/**
* Set zdir point
* @param value ZDir point
*/
public void setZDir(PointZ value){
this.zdir = value;
}
/**
* Set zdir point
* @param x X coordinate value
* @param y Y coordinate value
* @param z Z coordinate value
*/
public void setZDir(float x, float y, float z){
if (x == 0 && y == 0 && z == 0)
this.zdir = null;
else
this.zdir = new PointZ(x, y, z);
}
/**
* Set zdir point
* @param value ZDir point
*/
public void setZDir(String value){
float x1 = 0, y1 = 0, z1 = 0;
switch(value.toLowerCase()){
case "x":
x1 = 1;
break;
case "y":
y1 = 1;
break;
case "z":
z1 = 1;
break;
}
this.setZDir(x1, y1, z1);
}
/**
* Set point
*
* @param x X
* @param y Y
* @param z Z
*/
public void setPoint(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
Extent3D aExtent = new Extent3D();
aExtent.minX = x;
aExtent.maxX = x;
aExtent.minY = y;
aExtent.maxY = y;
aExtent.minZ = z;
aExtent.maxZ = z;
this.setExtent(aExtent);
}
/**
* Update angle
* @param projector Projector
*/
public void updateAngle(Projector projector){
if (this.zdir == null)
return;
Point p0 = projector.project(0, 0, 0);
Point p1 = projector.project((float)this.zdir.X, (float)this.zdir.Y, (float)this.zdir.Z);
double[] value = DataMath.getDSFromUV(p1.x - p0.x, p1.y - p0.y);
this.angle = (float)value[0];
}
}

View File

@ -1,390 +1,391 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.chart;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Rectangle2D;
import org.meteoinfo.drawing.Draw;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.global.PointF;
import org.meteoinfo.layer.VectorLayer;
import org.meteoinfo.legend.ArrowBreak;
import org.meteoinfo.shape.GraphicCollection;
import org.meteoinfo.shape.WindArrow;
/**
*
* @author Yaqiang Wang
*/
public class ChartWindArrow {
// <editor-fold desc="Variables">
private final WindArrow windArrow;
private ArrowBreak arrowBreak;
private Font font;
//private Color color;
private Color labelColor;
private float x;
private float y;
private String label;
private int labelSep;
private Object layer;
private Color background;
private boolean drawBackground;
private boolean drawNeatline;
private Color neatLineColor;
private float neatLineSize;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public ChartWindArrow() {
this.windArrow = new WindArrow();
this.windArrow.angle = 270;
this.windArrow.length = 20;
this.arrowBreak = new ArrowBreak();
this.font = new Font("Arial", Font.PLAIN, 12);
//this.color = Color.black;
this.labelColor = Color.black;
this.labelSep = 5;
this.background = Color.white;
this.drawBackground = false;
this.drawNeatline = false;
this.neatLineColor = Color.black;
this.neatLineSize = 1.0f;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get wind arrow
*
* @return Wind arrow
*/
public WindArrow getWindArrow() {
return this.windArrow;
}
/**
* Get arrow break
* @return Arrow break
*/
public ArrowBreak getArrowBreak() {
return this.arrowBreak;
}
/**
* Set arrow break
* @param value Arrow break
*/
public void setArrowBreak(ArrowBreak value) {
this.arrowBreak = value;
}
/**
* Get length
*
* @return Length
*/
public float getLength() {
return this.windArrow.length;
}
/**
* Set length
*
* @param value Length
*/
public void setLength(float value) {
this.windArrow.length = value;
this.label = String.valueOf(value);
this.label = DataConvert.removeTailingZeros(this.label);
}
/**
* Get angle
*
* @return Angle
*/
public double getAngle() {
return this.windArrow.angle;
}
/**
* Set angle
*
* @param value Angle
*/
public void setAngle(double value) {
this.windArrow.angle = value;
}
/**
* Get layer
*
* @return Layer
*/
public Object getLayer() {
return this.layer;
}
/**
* Set layer
*
* @param value Layer
*/
public void setLayer(Object value) {
this.layer = value;
}
/**
* Get font
*
* @return Font
*/
public Font getFont() {
return font;
}
/**
* Set font
*
* @param value Font
*/
public void setFont(Font value) {
font = value;
}
/**
* Get label color
*
* @return Label color
*/
public Color getLabelColor() {
return this.labelColor;
}
/**
* Set label color
*
* @param value Label color
*/
public void setLabelColor(Color value) {
this.labelColor = value;
}
/**
* Get the distance between arrow and label
* @return Distance between arrow and label
*/
public int getLabelSep(){
return this.labelSep;
}
/**
* Set the distance between arrow and label
* @param value Distance between arrow and label
*/
public void setLabelSep(int value) {
this.labelSep = value;
}
/**
* Get x
*
* @return X
*/
public float getX() {
return this.x;
}
/**
* Set x
*
* @param value X
*/
public void setX(float value) {
this.x = value;
}
/**
* Get y
*
* @return Y
*/
public float getY() {
return this.y;
}
/**
* Set y
*
* @param value Y
*/
public void setY(float value) {
this.y = value;
}
/**
* Get label
*
* @return Label
*/
public String getLabel() {
return this.label;
}
/**
* Set label
*
* @param value Label
*/
public void setLabel(String value) {
this.label = value;
}
/**
* Get background color
*
* @return Background color
*/
public Color getBackground() {
return this.background;
}
/**
* Set background color
*
* @param value Background color
*/
public void setBackground(Color value) {
this.background = value;
}
/**
* Get if is fill background
*
* @return Boolean
*/
public boolean isFill() {
return this.drawBackground;
}
/**
* Set fill background or not
*
* @param value Boolean
*/
public void setFill(boolean value) {
this.drawBackground = value;
}
/**
* Get draw neatline or not
*
* @return Boolean
*/
public boolean isDrawNeatline() {
return this.drawNeatline;
}
/**
* Set draw neatline or not
*
* @param value Boolean
*/
public void setDrawNeatline(boolean value) {
this.drawNeatline = value;
}
/**
* Get neatline color
*
* @return Neatline color
*/
public Color getNeatlineColor() {
return this.neatLineColor;
}
/**
* Set neatline color
*
* @param value Neatline color
*/
public void setNeatlineColor(Color value) {
this.neatLineColor = value;
}
/**
* Get neatline size
*
* @return Neatline size
*/
public float getNeatlineSize() {
return this.neatLineSize;
}
/**
* Set neatline size
*
* @param value Neatline size
*/
public void setNeatlineSize(float value) {
this.neatLineSize = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Draw text
*
* @param g Graphics2D
* @param x X
* @param y Y
*/
public void draw(Graphics2D g, float x, float y) {
Object rendering = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
float zoom = 1.0f;
if (this.layer != null) {
if (this.layer instanceof VectorLayer) {
zoom = ((VectorLayer) this.layer).getDrawingZoom();
} else if (this.layer instanceof GraphicCollection) {
zoom = ((GraphicCollection) this.layer).getArrowZoom();
}
}
g.setFont(this.font);
//String drawStr = this.label wa.getLabel();
Dimension dim = Draw.getStringDimension(this.label, g);
if (this.drawBackground || this.drawNeatline) {
Rectangle2D rect = Draw.getArrawBorder(new PointF(x, y), this.windArrow, g, zoom);
double gap = 5;
double width = Math.max(rect.getWidth(), dim.getWidth());
rect.setRect(rect.getX() - gap, rect.getY() - gap - 2, width + gap * 2,
rect.getHeight() + dim.height + this.labelSep + gap + 2);
if (this.drawBackground) {
g.setColor(this.background);
g.fill(rect);
}
if (this.drawNeatline) {
g.setColor(this.neatLineColor);
g.draw(rect);
}
}
//Draw.drawArraw(this.color, new PointF(x, y), this.windArrow, g, zoom);
Draw.drawArraw(new PointF(x, y), windArrow, arrowBreak, g, zoom);
g.setColor(this.labelColor);
Draw.drawString(g, this.label, x, y + dim.height + this.labelSep);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rendering);
}
// </editor-fold>
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.chart;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Rectangle2D;
import org.meteoinfo.common.PointF;
import org.meteoinfo.drawing.Draw;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.layer.VectorLayer;
import org.meteoinfo.legend.ArrowBreak;
import org.meteoinfo.shape.GraphicCollection;
import org.meteoinfo.shape.WindArrow;
/**
*
* @author Yaqiang Wang
*/
public class ChartWindArrow {
// <editor-fold desc="Variables">
private final WindArrow windArrow;
private ArrowBreak arrowBreak;
private Font font;
//private Color color;
private Color labelColor;
private float x;
private float y;
private String label;
private int labelSep;
private Object layer;
private Color background;
private boolean drawBackground;
private boolean drawNeatline;
private Color neatLineColor;
private float neatLineSize;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public ChartWindArrow() {
this.windArrow = new WindArrow();
this.windArrow.angle = 270;
this.windArrow.length = 20;
this.arrowBreak = new ArrowBreak();
this.font = new Font("Arial", Font.PLAIN, 12);
//this.color = Color.black;
this.labelColor = Color.black;
this.labelSep = 5;
this.background = Color.white;
this.drawBackground = false;
this.drawNeatline = false;
this.neatLineColor = Color.black;
this.neatLineSize = 1.0f;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get wind arrow
*
* @return Wind arrow
*/
public WindArrow getWindArrow() {
return this.windArrow;
}
/**
* Get arrow break
* @return Arrow break
*/
public ArrowBreak getArrowBreak() {
return this.arrowBreak;
}
/**
* Set arrow break
* @param value Arrow break
*/
public void setArrowBreak(ArrowBreak value) {
this.arrowBreak = value;
}
/**
* Get length
*
* @return Length
*/
public float getLength() {
return this.windArrow.length;
}
/**
* Set length
*
* @param value Length
*/
public void setLength(float value) {
this.windArrow.length = value;
this.label = String.valueOf(value);
this.label = DataConvert.removeTailingZeros(this.label);
}
/**
* Get angle
*
* @return Angle
*/
public double getAngle() {
return this.windArrow.angle;
}
/**
* Set angle
*
* @param value Angle
*/
public void setAngle(double value) {
this.windArrow.angle = value;
}
/**
* Get layer
*
* @return Layer
*/
public Object getLayer() {
return this.layer;
}
/**
* Set layer
*
* @param value Layer
*/
public void setLayer(Object value) {
this.layer = value;
}
/**
* Get font
*
* @return Font
*/
public Font getFont() {
return font;
}
/**
* Set font
*
* @param value Font
*/
public void setFont(Font value) {
font = value;
}
/**
* Get label color
*
* @return Label color
*/
public Color getLabelColor() {
return this.labelColor;
}
/**
* Set label color
*
* @param value Label color
*/
public void setLabelColor(Color value) {
this.labelColor = value;
}
/**
* Get the distance between arrow and label
* @return Distance between arrow and label
*/
public int getLabelSep(){
return this.labelSep;
}
/**
* Set the distance between arrow and label
* @param value Distance between arrow and label
*/
public void setLabelSep(int value) {
this.labelSep = value;
}
/**
* Get x
*
* @return X
*/
public float getX() {
return this.x;
}
/**
* Set x
*
* @param value X
*/
public void setX(float value) {
this.x = value;
}
/**
* Get y
*
* @return Y
*/
public float getY() {
return this.y;
}
/**
* Set y
*
* @param value Y
*/
public void setY(float value) {
this.y = value;
}
/**
* Get label
*
* @return Label
*/
public String getLabel() {
return this.label;
}
/**
* Set label
*
* @param value Label
*/
public void setLabel(String value) {
this.label = value;
}
/**
* Get background color
*
* @return Background color
*/
public Color getBackground() {
return this.background;
}
/**
* Set background color
*
* @param value Background color
*/
public void setBackground(Color value) {
this.background = value;
}
/**
* Get if is fill background
*
* @return Boolean
*/
public boolean isFill() {
return this.drawBackground;
}
/**
* Set fill background or not
*
* @param value Boolean
*/
public void setFill(boolean value) {
this.drawBackground = value;
}
/**
* Get draw neatline or not
*
* @return Boolean
*/
public boolean isDrawNeatline() {
return this.drawNeatline;
}
/**
* Set draw neatline or not
*
* @param value Boolean
*/
public void setDrawNeatline(boolean value) {
this.drawNeatline = value;
}
/**
* Get neatline color
*
* @return Neatline color
*/
public Color getNeatlineColor() {
return this.neatLineColor;
}
/**
* Set neatline color
*
* @param value Neatline color
*/
public void setNeatlineColor(Color value) {
this.neatLineColor = value;
}
/**
* Get neatline size
*
* @return Neatline size
*/
public float getNeatlineSize() {
return this.neatLineSize;
}
/**
* Set neatline size
*
* @param value Neatline size
*/
public void setNeatlineSize(float value) {
this.neatLineSize = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Draw text
*
* @param g Graphics2D
* @param x X
* @param y Y
*/
public void draw(Graphics2D g, float x, float y) {
Object rendering = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
float zoom = 1.0f;
if (this.layer != null) {
if (this.layer instanceof VectorLayer) {
zoom = ((VectorLayer) this.layer).getDrawingZoom();
} else if (this.layer instanceof GraphicCollection) {
zoom = ((GraphicCollection) this.layer).getArrowZoom();
}
}
g.setFont(this.font);
//String drawStr = this.label wa.getLabel();
Dimension dim = Draw.getStringDimension(this.label, g);
if (this.drawBackground || this.drawNeatline) {
Rectangle2D rect = Draw.getArrawBorder(new PointF(x, y), this.windArrow, g, zoom);
double gap = 5;
double width = Math.max(rect.getWidth(), dim.getWidth());
rect.setRect(rect.getX() - gap, rect.getY() - gap - 2, width + gap * 2,
rect.getHeight() + dim.height + this.labelSep + gap + 2);
if (this.drawBackground) {
g.setColor(this.background);
g.fill(rect);
}
if (this.drawNeatline) {
g.setColor(this.neatLineColor);
g.draw(rect);
}
}
//Draw.drawArraw(this.color, new PointF(x, y), this.windArrow, g, zoom);
Draw.drawArraw(new PointF(x, y), windArrow, arrowBreak, g, zoom);
g.setColor(this.labelColor);
Draw.drawString(g, this.label, x, y + dim.height + this.labelSep);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rendering);
}
// </editor-fold>
}

View File

@ -23,10 +23,10 @@ import org.meteoinfo.chart.Location;
import org.meteoinfo.chart.plot.AbstractPlot2D;
import org.meteoinfo.chart.plot.XAlign;
import org.meteoinfo.chart.plot.YAlign;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.drawing.Draw;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.global.util.JDateUtil;
import org.meteoinfo.legend.LineStyles;
import org.meteoinfo.ndarray.util.BigDecimalUtil;

View File

@ -1,83 +1,83 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.chart.axis;
import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.chart.ChartText;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.global.MIMath;
/**
*
* @author Yaqiang Wang
*/
public class LogAxis extends Axis {
// <editor-fold desc="Variables">
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
* @param axis Axis
*/
public LogAxis(Axis axis){
super(axis);
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Update tick values
*/
@Override
public void updateTickValues() {
double[] r = MIMath.getIntervalValues_Log(this.getMinValue(), this.getMaxValue());
this.setTickValues((double[]) r);
this.setTickDeltaValue(1);
}
@Override
public void updateTickLabels(){
List<ChartText> tls = new ArrayList<>();
String lab;
if (this.isAutoTick()) {
if (this.getTickValues() == null) {
return;
}
for (double value : this.getTickValues()) {
lab = String.valueOf(value);
lab = DataConvert.removeTailingZeros(lab);
tls.add(new ChartText(lab));
}
List<Double> values = new ArrayList<>();
for (ChartText tl : tls){
values.add(Double.parseDouble(tl.getText()));
}
tls.clear();
int e;
for (Double v : values){
e = (int) Math.floor(Math.log10(v));
tls.add(new ChartText("$10^{" + String.valueOf(e) + "}$"));
}
} else {
for (int i = 0; i < this.getTickLocations().size(); i++) {
if (i >= this.getTickLabels().size()) {
break;
}
double v = this.getTickLocations().get(i);
if (v >= this.getMinValue() && v <= this.getMaxValue()) {
tls.add(this.getTickLabels().get(i));
}
}
}
this.setTickLabels(tls);
}
// </editor-fold>
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.chart.axis;
import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.chart.ChartText;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.global.DataConvert;
/**
*
* @author Yaqiang Wang
*/
public class LogAxis extends Axis {
// <editor-fold desc="Variables">
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
* @param axis Axis
*/
public LogAxis(Axis axis){
super(axis);
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Update tick values
*/
@Override
public void updateTickValues() {
double[] r = MIMath.getIntervalValues_Log(this.getMinValue(), this.getMaxValue());
this.setTickValues((double[]) r);
this.setTickDeltaValue(1);
}
@Override
public void updateTickLabels(){
List<ChartText> tls = new ArrayList<>();
String lab;
if (this.isAutoTick()) {
if (this.getTickValues() == null) {
return;
}
for (double value : this.getTickValues()) {
lab = String.valueOf(value);
lab = DataConvert.removeTailingZeros(lab);
tls.add(new ChartText(lab));
}
List<Double> values = new ArrayList<>();
for (ChartText tl : tls){
values.add(Double.parseDouble(tl.getText()));
}
tls.clear();
int e;
for (Double v : values){
e = (int) Math.floor(Math.log10(v));
tls.add(new ChartText("$10^{" + String.valueOf(e) + "}$"));
}
} else {
for (int i = 0; i < this.getTickLocations().size(); i++) {
if (i >= this.getTickLabels().size()) {
break;
}
double v = this.getTickLocations().get(i);
if (v >= this.getMinValue() && v <= this.getMaxValue()) {
tls.add(this.getTickLabels().get(i));
}
}
}
this.setTickLabels(tls);
}
// </editor-fold>
}

View File

@ -1,174 +1,174 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.chart.axis;
import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.chart.ChartText;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.projection.KnownCoordinateSystems;
import org.meteoinfo.projection.info.ProjectionInfo;
import org.meteoinfo.projection.Reproject;
/**
*
* @author Yaqiang Wang
*/
public class ProjLonLatAxis extends LonLatAxis{
// <editor-fold desc="Variables">
private ProjectionInfo proj;
private double x_y;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
* @param label Label
* @param isX Is x/longitude axis or not
* @param proj Projection
*/
public ProjLonLatAxis(String label, boolean isX, ProjectionInfo proj){
super(label, isX, isX);
this.proj = proj;
}
/**
* Constructor
* @param label Label
* @param isX Is x/longitude axis or not
* @param proj Projection
* @param xy X or Y value of the axis - using for projection
*/
public ProjLonLatAxis(String label, boolean isX, ProjectionInfo proj, double xy){
super(label, isX);
this.proj = proj;
this.x_y = xy;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get projection
* @return Projection
*/
public ProjectionInfo getProject(){
return this.proj;
}
/**
* Set projection
* @param value Projection
*/
public void setProject(ProjectionInfo value){
this.proj = value;
}
/**
* Get x_y value
* @return x_y value
*/
public double getX_Y(){
return this.x_y;
}
/**
* Set x_y value
* @param value x_y value
*/
public void setX_Y(double value){
this.x_y = value;
//this.updateTickValues();
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Update tick values
*/
@Override
public void updateTickValues() {
if (this.proj == null)
return;
double min = this.getMinValue();
double max = this.getMaxValue();
//Calculate min and max lon or lat
ProjectionInfo toproj = KnownCoordinateSystems.geographic.world.WGS1984;
double minv, maxv;
double[][] points = new double[2][];
if (this.isXAxis()){
points[0] = new double[]{min, this.x_y};
points[1] = new double[]{max, this.x_y};
Reproject.reprojectPoints(points, this.proj, toproj);
minv = points[0][0];
maxv = points[1][0];
} else {
points[0] = new double[]{this.x_y, min};
points[1] = new double[]{this.x_y, max};
Reproject.reprojectPoints(points, this.proj, toproj);
minv = points[0][1];
maxv = points[1][1];
}
//Get tick values
List<Object> r = MIMath.getIntervalValues1(minv, maxv);
double[] values = (double[])r.get(0);
double[] tickValues = new double[values.length];
this.setTickValues((double[]) r.get(0));
this.setTickDeltaValue((Double) r.get(1));
}
/**
* Get tick labels
*
*/
@Override
public void updateTickLabels() {
List<ChartText> tls = new ArrayList<>();
String lab;
for (double v : this.getTickValues()) {
double value = v;
if (value > 180) {
value = value - 360;
}
lab = String.valueOf(value);
lab = DataConvert.removeTailingZeros(lab);
if (this.isXAxis()) {
if (value == -180) {
lab = "180";
} else if (!(value == 0 || value == 180)) {
if (lab.substring(0, 1).equals("-")) {
lab = lab.substring(1) + "W";
} else {
lab = lab + "E";
}
}
} else {
if (!(value == 0)) {
if (lab.substring(0, 1).equals("-")) {
lab = lab.substring(1) + "S";
} else {
lab = lab + "N";
}
}
}
if (this.isDrawDegreeSymbol()) {
if (lab.endsWith("E") || lab.endsWith("W") || lab.endsWith("N") || lab.endsWith("S")) {
lab = lab.substring(0, lab.length() - 1) + String.valueOf((char) 186) + lab.substring(lab.length() - 1);
} else {
lab = lab + String.valueOf((char) 186);
}
}
tls.add(new ChartText(lab));
}
this.setTickLabels(tls);
}
@Override
public Object clone() throws CloneNotSupportedException {
return (ProjLonLatAxis)super.clone();
}
// </editor-fold>
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.chart.axis;
import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.chart.ChartText;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.projection.KnownCoordinateSystems;
import org.meteoinfo.projection.info.ProjectionInfo;
import org.meteoinfo.projection.Reproject;
/**
*
* @author Yaqiang Wang
*/
public class ProjLonLatAxis extends LonLatAxis{
// <editor-fold desc="Variables">
private ProjectionInfo proj;
private double x_y;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
* @param label Label
* @param isX Is x/longitude axis or not
* @param proj Projection
*/
public ProjLonLatAxis(String label, boolean isX, ProjectionInfo proj){
super(label, isX, isX);
this.proj = proj;
}
/**
* Constructor
* @param label Label
* @param isX Is x/longitude axis or not
* @param proj Projection
* @param xy X or Y value of the axis - using for projection
*/
public ProjLonLatAxis(String label, boolean isX, ProjectionInfo proj, double xy){
super(label, isX);
this.proj = proj;
this.x_y = xy;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get projection
* @return Projection
*/
public ProjectionInfo getProject(){
return this.proj;
}
/**
* Set projection
* @param value Projection
*/
public void setProject(ProjectionInfo value){
this.proj = value;
}
/**
* Get x_y value
* @return x_y value
*/
public double getX_Y(){
return this.x_y;
}
/**
* Set x_y value
* @param value x_y value
*/
public void setX_Y(double value){
this.x_y = value;
//this.updateTickValues();
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Update tick values
*/
@Override
public void updateTickValues() {
if (this.proj == null)
return;
double min = this.getMinValue();
double max = this.getMaxValue();
//Calculate min and max lon or lat
ProjectionInfo toproj = KnownCoordinateSystems.geographic.world.WGS1984;
double minv, maxv;
double[][] points = new double[2][];
if (this.isXAxis()){
points[0] = new double[]{min, this.x_y};
points[1] = new double[]{max, this.x_y};
Reproject.reprojectPoints(points, this.proj, toproj);
minv = points[0][0];
maxv = points[1][0];
} else {
points[0] = new double[]{this.x_y, min};
points[1] = new double[]{this.x_y, max};
Reproject.reprojectPoints(points, this.proj, toproj);
minv = points[0][1];
maxv = points[1][1];
}
//Get tick values
List<Object> r = MIMath.getIntervalValues1(minv, maxv);
double[] values = (double[])r.get(0);
double[] tickValues = new double[values.length];
this.setTickValues((double[]) r.get(0));
this.setTickDeltaValue((Double) r.get(1));
}
/**
* Get tick labels
*
*/
@Override
public void updateTickLabels() {
List<ChartText> tls = new ArrayList<>();
String lab;
for (double v : this.getTickValues()) {
double value = v;
if (value > 180) {
value = value - 360;
}
lab = String.valueOf(value);
lab = DataConvert.removeTailingZeros(lab);
if (this.isXAxis()) {
if (value == -180) {
lab = "180";
} else if (!(value == 0 || value == 180)) {
if (lab.substring(0, 1).equals("-")) {
lab = lab.substring(1) + "W";
} else {
lab = lab + "E";
}
}
} else {
if (!(value == 0)) {
if (lab.substring(0, 1).equals("-")) {
lab = lab.substring(1) + "S";
} else {
lab = lab + "N";
}
}
}
if (this.isDrawDegreeSymbol()) {
if (lab.endsWith("E") || lab.endsWith("W") || lab.endsWith("N") || lab.endsWith("S")) {
lab = lab.substring(0, lab.length() - 1) + String.valueOf((char) 186) + lab.substring(lab.length() - 1);
} else {
lab = lab + String.valueOf((char) 186);
}
}
tls.add(new ChartText(lab));
}
this.setTickLabels(tls);
}
@Override
public Object clone() throws CloneNotSupportedException {
return (ProjLonLatAxis)super.clone();
}
// </editor-fold>
}

View File

@ -8,10 +8,9 @@ package org.meteoinfo.chart.axis;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.meteoinfo.chart.ChartText;
import org.meteoinfo.global.util.JDateUtil;
import org.meteoinfo.common.util.JDateUtil;
/**
*

View File

@ -18,7 +18,6 @@ import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.*;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
import javax.imageio.stream.ImageOutputStream;
@ -26,7 +25,7 @@ import javax.swing.*;
import org.meteoinfo.chart.IChartPanel;
import org.meteoinfo.chart.MouseMode;
import org.meteoinfo.global.Extent3D;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.image.ImageUtil;
import org.w3c.dom.Element;

View File

@ -1,58 +1,59 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.chart.jogl;
import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.chart.plot3d.GraphicCollection3D;
import org.meteoinfo.global.Extent3D;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.shape.PointZ;
/**
*
* @author yaqiang
*/
public class IsosurfaceGraphics extends GraphicCollection3D {
private List<PointZ[]> triangles = new ArrayList<>();
/**
* Constructor
*/
public IsosurfaceGraphics() {
super();
this.allTriangle = true;
}
/**
* Get triangles
* @return Triangles
*/
public List<PointZ[]> getTriangles() {
return this.triangles;
}
/**
* Set triangles
* @param value Triangles
*/
public void setTriangles(List<PointZ[]> value) {
this.triangles = value;
}
/**
* Add a triangle
* @param triangle Triangle
*/
public void addTriangle(PointZ[] triangle) {
this.triangles.add(triangle);
Extent3D extent = MIMath.getExtent(triangle);
if (this.triangles.size() == 1)
this.setExtent(extent);
else
this.setExtent(MIMath.getLagerExtent(extent, this.getExtent()));
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.chart.jogl;
import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.chart.plot3d.GraphicCollection3D;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.geoprocess.GeometryUtil;
import org.meteoinfo.shape.PointZ;
/**
*
* @author yaqiang
*/
public class IsosurfaceGraphics extends GraphicCollection3D {
private List<PointZ[]> triangles = new ArrayList<>();
/**
* Constructor
*/
public IsosurfaceGraphics() {
super();
this.allTriangle = true;
}
/**
* Get triangles
* @return Triangles
*/
public List<PointZ[]> getTriangles() {
return this.triangles;
}
/**
* Set triangles
* @param value Triangles
*/
public void setTriangles(List<PointZ[]> value) {
this.triangles = value;
}
/**
* Add a triangle
* @param triangle Triangle
*/
public void addTriangle(PointZ[] triangle) {
this.triangles.add(triangle);
Extent3D extent = GeometryUtil.getExtent(triangle);
if (this.triangles.size() == 1)
this.setExtent(extent);
else
this.setExtent(MIMath.getLagerExtent(extent, this.getExtent()));
}
}

View File

@ -15,8 +15,8 @@ import java.util.Random;
import org.meteoinfo.chart.jogl.mc.MarchingCubes;
import org.meteoinfo.chart.jogl.mc.CallbackMC;
import org.meteoinfo.chart.plot3d.GraphicCollection3D;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.Extent3D;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.layer.ImageLayer;
import org.meteoinfo.legend.ColorBreak;
import org.meteoinfo.legend.LegendScheme;

View File

@ -6,15 +6,12 @@
package org.meteoinfo.chart.jogl;
import com.jogamp.opengl.*;
import com.jogamp.opengl.fixedfunc.GLLightingFunc;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUquadric;
import com.jogamp.opengl.glu.GLUtessellator;
import com.jogamp.opengl.glu.GLUtessellatorCallback;
import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
import com.jogamp.opengl.util.awt.TextRenderer;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureCoords;
import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
import com.jogamp.opengl.util.gl2.GLUT;
import com.jogamp.opengl.math.VectorUtil;
@ -33,7 +30,6 @@ import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import jogamp.opengl.glu.tessellator.GLUtessellatorImpl;
import org.meteoinfo.chart.ChartColorBar;
import org.meteoinfo.chart.ChartLegend;
import org.meteoinfo.chart.ChartText;
@ -41,23 +37,18 @@ import org.meteoinfo.chart.ChartText3D;
import org.meteoinfo.chart.Margin;
import org.meteoinfo.chart.axis.Axis;
import org.meteoinfo.chart.jogl.tessellator.Primitive;
import org.meteoinfo.chart.jogl.tessellator.PrimitiveTessellator;
import org.meteoinfo.chart.jogl.tessellator.TessPolygon;
import org.meteoinfo.chart.jogl.tessellator.TriangleTessellator;
import org.meteoinfo.chart.plot.*;
import org.meteoinfo.chart.plot3d.GraphicCollection3D;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.data.Dataset;
import org.meteoinfo.geoprocess.GeometryUtil;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.Extent3D;
import org.meteoinfo.global.util.FontUtil;
import org.meteoinfo.legend.*;
import org.meteoinfo.math.meteo.MeteoMath;
import org.meteoinfo.shape.*;
import static org.meteoinfo.shape.ShapeTypes.PointZ;
/**
*
* @author wyq

View File

@ -6,7 +6,7 @@
package org.meteoinfo.chart.jogl;
import org.meteoinfo.chart.plot3d.GraphicCollection3D;
import org.meteoinfo.global.Extent3D;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.legend.ColorBreak;
import org.meteoinfo.legend.LegendScheme;
import org.meteoinfo.legend.PolygonBreak;

View File

@ -1,6 +1,6 @@
package org.meteoinfo.chart.jogl;
import org.meteoinfo.global.Extent3D;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.shape.PointZ;
public class Transform {

View File

@ -27,11 +27,9 @@ import org.meteoinfo.chart.Location;
import org.meteoinfo.chart.Margin;
import org.meteoinfo.chart.axis.Axis;
import org.meteoinfo.chart.axis.LogAxis;
import static org.meteoinfo.chart.plot.Plot.MINIMUM_HEIGHT_TO_DRAW;
import static org.meteoinfo.chart.plot.Plot.MINIMUM_WIDTH_TO_DRAW;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.PointF;
import org.meteoinfo.drawing.Draw;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.PointF;
/**
*

View File

@ -18,20 +18,19 @@ import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
import org.meteoinfo.chart.ChartText;
import org.meteoinfo.chart.plot3d.GraphicCollection3D;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.math.ArrayUtil;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.PointD;
import org.meteoinfo.data.GridArray;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.XYListDataset;
import org.meteoinfo.data.analysis.Statistics;
import org.meteoinfo.drawing.ContourDraw;
import org.meteoinfo.drawing.Draw;
import org.meteoinfo.geoprocess.GeometryUtil;
import org.meteoinfo.legend.PointStyle;
import org.meteoinfo.geoprocess.GeoComputation;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.Extent3D;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.global.PointD;
import org.meteoinfo.layer.ImageLayer;
import org.meteoinfo.layer.VectorLayer;
import org.meteoinfo.legend.ArrowLineBreak;
@ -48,6 +47,8 @@ import org.meteoinfo.legend.PointBreak;
import org.meteoinfo.legend.PolygonBreak;
import org.meteoinfo.legend.PolylineBreak;
import org.meteoinfo.legend.StreamlineBreak;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.math.ArrayUtil;
import org.meteoinfo.math.meteo.MeteoMath;
import org.meteoinfo.ndarray.*;
import org.meteoinfo.ndarray.util.BigDecimalUtil;
@ -3100,7 +3101,7 @@ public class GraphicFactory {
}
aPolyline.setPoints(pList);
aPolyline.setValue(v);
aPolyline.setExtent(MIMath.getPointsExtent(pList));
aPolyline.setExtent(GeometryUtil.getPointsExtent(pList));
switch (ls.getLegendType()) {
case UniqueValue:
@ -3216,7 +3217,7 @@ public class GraphicFactory {
}
aPolyline.setPoints(pList);
aPolyline.setValue(v);
aPolyline.setExtent(MIMath.getPointsExtent(pList));
aPolyline.setExtent(GeometryUtil.getPointsExtent(pList));
cbb = ls.findLegendBreak(v);
graphics.add(new Graphic(aPolyline, cbb));
}
@ -3325,7 +3326,7 @@ public class GraphicFactory {
}
aPolyline.setPoints(pList);
aPolyline.setValue(v);
aPolyline.setExtent(MIMath.getPointsExtent(pList));
aPolyline.setExtent(GeometryUtil.getPointsExtent(pList));
cbb = ls.findLegendBreak(v);
graphics.add(new Graphic(aPolyline, cbb));
}
@ -3391,7 +3392,7 @@ public class GraphicFactory {
}
PolygonShape aPolygonShape = new PolygonShape();
aPolygonShape.setPoints(pList);
aPolygonShape.setExtent(MIMath.getPointsExtent(pList));
aPolygonShape.setExtent(GeometryUtil.getPointsExtent(pList));
aPolygonShape.lowValue = v;
if (poly.HasHoles()) {
for (PolyLine holeLine : poly.HoleLines) {
@ -3555,7 +3556,7 @@ public class GraphicFactory {
}
PolygonZShape aPolygonShape = new PolygonZShape();
aPolygonShape.setPoints(pList);
aPolygonShape.setExtent(MIMath.getPointsExtent(pList));
aPolygonShape.setExtent(GeometryUtil.getPointsExtent(pList));
aPolygonShape.lowValue = v;
if (poly.HasHoles()) {
switch (zdir) {
@ -3734,7 +3735,7 @@ public class GraphicFactory {
}
PolygonZShape aPolygonShape = new PolygonZShape();
aPolygonShape.setPoints(pList);
aPolygonShape.setExtent(MIMath.getPointsExtent(pList));
aPolygonShape.setExtent(GeometryUtil.getPointsExtent(pList));
aPolygonShape.lowValue = v;
if (poly.HasHoles()) {
switch (zdir) {

View File

@ -28,15 +28,14 @@ import org.meteoinfo.chart.ChartScaleBar;
import org.meteoinfo.chart.ChartText;
import org.meteoinfo.chart.Location;
import org.meteoinfo.chart.axis.LonLatAxis;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.PointD;
import org.meteoinfo.common.PointF;
import org.meteoinfo.data.Dataset;
import org.meteoinfo.data.mapdata.webmap.IWebMapPanel;
import org.meteoinfo.data.mapdata.webmap.TileLoadListener;
import org.meteoinfo.drawing.Draw;
import org.meteoinfo.global.Direction;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.global.PointD;
import org.meteoinfo.global.PointF;
import org.meteoinfo.layer.LayerCollection;
import org.meteoinfo.layer.MapLayer;
import org.meteoinfo.legend.LabelBreak;

View File

@ -1,160 +1,161 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.chart.plot;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import org.meteoinfo.drawing.Draw;
import org.meteoinfo.global.PointF;
import org.meteoinfo.legend.ColorBreak;
import org.meteoinfo.legend.PolygonBreak;
import org.meteoinfo.shape.ArcShape;
import org.meteoinfo.shape.Graphic;
import org.meteoinfo.shape.GraphicCollection;
import org.meteoinfo.shape.Shape;
/**
*
* @author Yaqiang Wang
*/
public class PiePlot extends Plot2D {
// <editor-fold desc="Variables">
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public PiePlot(){
super();
this.setAutoAspect(false);
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
// </editor-fold>
// <editor-fold desc="Methods">
@Override
void drawGraph(Graphics2D g, Rectangle2D area) {
AffineTransform oldMatrix = g.getTransform();
//Rectangle oldRegion = g.getClipBounds();
//g.setClip(area);
g.translate(area.getX(), area.getY());
//Draw background
if (this.background != null) {
g.setColor(this.getBackground());
g.fill(new Rectangle2D.Double(0, 0, area.getWidth(), area.getHeight()));
}
for (int m = 0; m < this.getGraphics().getNumGraphics(); m++) {
Graphic graphic = this.getGraphics().get(m);
ColorBreak cb = graphic.getLegend();
float dist = 5;
float ex = this.getExplode();
Font labelFont = ((GraphicCollection)graphic).getLabelSet().getLabelFont();
Color labelColor = ((GraphicCollection)graphic).getLabelSet().getLabelColor();
for (int i = 0; i < graphic.getNumGraphics(); i++) {
Graphic gg = graphic.getGraphicN(i);
if (!graphic.isSingleLegend()) {
cb = gg.getLegend();
}
Shape shape = gg.getShape();
this.drawArc(g, (ArcShape) shape, (PolygonBreak) cb, area, dist, ex, labelFont,
labelColor);
}
}
g.setTransform(oldMatrix);
//g.setClip(oldRegion);
}
private float getExplode() {
Graphic graphic = this.getGraphics().get(0);
float ex = 0;
for (int i = 0; i < graphic.getNumGraphics(); i++) {
Graphic gg = graphic.getGraphicN(i);
ArcShape shape = (ArcShape) gg.getShape();
if (shape.getExplode() > 0) {
ex = 10;
break;
}
}
return ex;
}
private void drawArc(Graphics2D g, ArcShape aShape, PolygonBreak aPGB,
Rectangle2D area, float dist, float ex, Font labelFont, Color labelColor) {
float startAngle = aShape.getStartAngle();
float sweepAngle = aShape.getSweepAngle();
float angle = startAngle + sweepAngle / 2;
float space = 20;
Rectangle2D rect = new Rectangle2D.Double(area.getX() + ex + space, area.getY() + ex + space, area.getWidth() - ex - space,
area.getHeight() - ex - space);
double dx = 0, dy = 0;
if (aShape.getExplode() > 0) {
dx = ex * Math.cos((360 - angle) * Math.PI / 180);
dy = ex * Math.sin((360 - angle) * Math.PI / 180);
rect.setRect(rect.getX() + dx, rect.getY() + dy, rect.getWidth(), rect.getHeight());
}
float sx = (float) (rect.getX() - area.getX());
float sy = (float) (rect.getY() - area.getY());
Draw.drawPie(new PointF(sx, sy), (float) rect.getWidth(), (float) rect.getHeight(),
startAngle, sweepAngle, aPGB, g);
//Draw label
//Rectangle clip = g.getClipBounds();
//if (clip != null) {
// g.setClip(null);
//}
float x, y, w, h;
PointF sPoint = new PointF((float) (rect.getWidth() * 0.5 + sx), (float) (rect.getHeight() * 0.5 + sy));
String label = aPGB.getCaption();
if (angle > 360) {
angle = angle - 360;
}
float r = (float) (rect.getWidth() * 0.5) + dist;
PointF lPoint = Draw.getPieLabelPoint(sPoint, r, angle);
x = lPoint.X;
y = lPoint.Y;
Dimension dim = Draw.getStringDimension(label, g);
h = dim.height;
w = dim.width;
if ((angle >= 0 && angle < 45)) {
//x = x + dis;
y = y - h;
} else if (angle >= 45 && angle < 90) {
//y = y - dis;
} else if (angle >= 90 && angle < 135) {
x = x - w;
//y = y - dis;
} else if (angle >= 135 && angle < 225) {
x = x - w - 3;
y = y + h / 2;
} else if (angle >= 225 && angle < 270) {
x = x - w / 2;
y = y + h;
} else if (angle >= 270 && angle < 315) {
//x = x + dis;
y = y + h;
} else {
//x = x + dis;
y = y + h / 2;
}
g.setFont(labelFont);
g.setColor(labelColor);
//g.drawOval((int)(x - 3), (int)(y - 3), 6, 6);
g.drawString(label, x, y);
//if (clip != null) {
// g.setClip(clip);
//}
}
// </editor-fold>
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.chart.plot;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import org.meteoinfo.common.PointF;
import org.meteoinfo.drawing.Draw;
import org.meteoinfo.legend.ColorBreak;
import org.meteoinfo.legend.PolygonBreak;
import org.meteoinfo.shape.ArcShape;
import org.meteoinfo.shape.Graphic;
import org.meteoinfo.shape.GraphicCollection;
import org.meteoinfo.shape.Shape;
/**
*
* @author Yaqiang Wang
*/
public class PiePlot extends Plot2D {
// <editor-fold desc="Variables">
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public PiePlot(){
super();
this.setAutoAspect(false);
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
// </editor-fold>
// <editor-fold desc="Methods">
@Override
void drawGraph(Graphics2D g, Rectangle2D area) {
AffineTransform oldMatrix = g.getTransform();
//Rectangle oldRegion = g.getClipBounds();
//g.setClip(area);
g.translate(area.getX(), area.getY());
//Draw background
if (this.background != null) {
g.setColor(this.getBackground());
g.fill(new Rectangle2D.Double(0, 0, area.getWidth(), area.getHeight()));
}
for (int m = 0; m < this.getGraphics().getNumGraphics(); m++) {
Graphic graphic = this.getGraphics().get(m);
ColorBreak cb = graphic.getLegend();
float dist = 5;
float ex = this.getExplode();
Font labelFont = ((GraphicCollection)graphic).getLabelSet().getLabelFont();
Color labelColor = ((GraphicCollection)graphic).getLabelSet().getLabelColor();
for (int i = 0; i < graphic.getNumGraphics(); i++) {
Graphic gg = graphic.getGraphicN(i);
if (!graphic.isSingleLegend()) {
cb = gg.getLegend();
}
Shape shape = gg.getShape();
this.drawArc(g, (ArcShape) shape, (PolygonBreak) cb, area, dist, ex, labelFont,
labelColor);
}
}
g.setTransform(oldMatrix);
//g.setClip(oldRegion);
}
private float getExplode() {
Graphic graphic = this.getGraphics().get(0);
float ex = 0;
for (int i = 0; i < graphic.getNumGraphics(); i++) {
Graphic gg = graphic.getGraphicN(i);
ArcShape shape = (ArcShape) gg.getShape();
if (shape.getExplode() > 0) {
ex = 10;
break;
}
}
return ex;
}
private void drawArc(Graphics2D g, ArcShape aShape, PolygonBreak aPGB,
Rectangle2D area, float dist, float ex, Font labelFont, Color labelColor) {
float startAngle = aShape.getStartAngle();
float sweepAngle = aShape.getSweepAngle();
float angle = startAngle + sweepAngle / 2;
float space = 20;
Rectangle2D rect = new Rectangle2D.Double(area.getX() + ex + space, area.getY() + ex + space, area.getWidth() - ex - space,
area.getHeight() - ex - space);
double dx = 0, dy = 0;
if (aShape.getExplode() > 0) {
dx = ex * Math.cos((360 - angle) * Math.PI / 180);
dy = ex * Math.sin((360 - angle) * Math.PI / 180);
rect.setRect(rect.getX() + dx, rect.getY() + dy, rect.getWidth(), rect.getHeight());
}
float sx = (float) (rect.getX() - area.getX());
float sy = (float) (rect.getY() - area.getY());
Draw.drawPie(new PointF(sx, sy), (float) rect.getWidth(), (float) rect.getHeight(),
startAngle, sweepAngle, aPGB, g);
//Draw label
//Rectangle clip = g.getClipBounds();
//if (clip != null) {
// g.setClip(null);
//}
float x, y, w, h;
PointF sPoint = new PointF((float) (rect.getWidth() * 0.5 + sx), (float) (rect.getHeight() * 0.5 + sy));
String label = aPGB.getCaption();
if (angle > 360) {
angle = angle - 360;
}
float r = (float) (rect.getWidth() * 0.5) + dist;
PointF lPoint = Draw.getPieLabelPoint(sPoint, r, angle);
x = lPoint.X;
y = lPoint.Y;
Dimension dim = Draw.getStringDimension(label, g);
h = dim.height;
w = dim.width;
if ((angle >= 0 && angle < 45)) {
//x = x + dis;
y = y - h;
} else if (angle >= 45 && angle < 90) {
//y = y - dis;
} else if (angle >= 90 && angle < 135) {
x = x - w;
//y = y - dis;
} else if (angle >= 135 && angle < 225) {
x = x - w - 3;
y = y + h / 2;
} else if (angle >= 225 && angle < 270) {
x = x - w / 2;
y = y + h;
} else if (angle >= 270 && angle < 315) {
//x = x + dis;
y = y + h;
} else {
//x = x + dis;
y = y + h / 2;
}
g.setFont(labelFont);
g.setColor(labelColor);
//g.drawOval((int)(x - 3), (int)(y - 3), 6, 6);
g.drawString(label, x, y);
//if (clip != null) {
// g.setClip(clip);
//}
}
// </editor-fold>
}

View File

@ -35,16 +35,17 @@ import org.meteoinfo.chart.ChartLegend;
import org.meteoinfo.chart.ChartText;
import org.meteoinfo.chart.axis.LogAxis;
import org.meteoinfo.chart.axis.TimeAxis;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.PointD;
import org.meteoinfo.common.PointF;
import org.meteoinfo.data.Dataset;
import org.meteoinfo.drawing.Draw;
import static org.meteoinfo.drawing.Draw.getHatchImage;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.global.PointD;
import org.meteoinfo.global.PointF;
import org.meteoinfo.geoprocess.GeometryUtil;
import org.meteoinfo.legend.ArrowBreak;
import org.meteoinfo.legend.BarBreak;
import static org.meteoinfo.legend.BreakTypes.LabelBreak;
import org.meteoinfo.legend.ColorBreak;
import org.meteoinfo.legend.ColorBreakCollection;
import org.meteoinfo.legend.LabelBreak;
@ -767,7 +768,7 @@ public class Plot2D extends AbstractPlot2D {
aY = (float) sXY[1];
points.add(new PointD(aX, aY));
}
Extent aExtent = MIMath.getPointsExtent(points);
Extent aExtent = GeometryUtil.getPointsExtent(points);
rect.x = (int) aExtent.minX;
rect.y = (int) aExtent.minY;
rect.width = (int) (aExtent.maxX - aExtent.minX);
@ -779,7 +780,7 @@ public class Plot2D extends AbstractPlot2D {
}
private List<PointF> drawPolygon(Graphics2D g, Polygon aPG, PolygonBreak aPGB,
boolean isSelected, Rectangle2D area) {
boolean isSelected, Rectangle2D area) {
int len = aPG.getOutLine().size();
GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, len);
PointD wPoint;

View File

@ -10,7 +10,6 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
@ -31,13 +30,13 @@ import org.meteoinfo.chart.axis.Axis;
import org.meteoinfo.chart.axis.LogAxis;
import org.meteoinfo.chart.plot3d.GraphicCollection3D;
import org.meteoinfo.chart.plot3d.Projector;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.Extent3D;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.PointF;
import org.meteoinfo.data.DataMath;
import org.meteoinfo.data.Dataset;
import org.meteoinfo.drawing.Draw;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.Extent3D;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.global.PointF;
import org.meteoinfo.legend.*;
import org.meteoinfo.math.sort.QuickSort;
import org.meteoinfo.shape.*;

View File

@ -16,11 +16,11 @@ import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.chart.Margin;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.drawing.Draw;
import static org.meteoinfo.drawing.Draw.getDashPattern;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.legend.LineStyles;
import org.meteoinfo.shape.Graphic;
import org.meteoinfo.shape.GraphicCollection;

View File

@ -14,9 +14,10 @@
package org.meteoinfo.data;
import java.util.ArrayList;
import org.meteoinfo.global.MIMath;
import java.util.Arrays;
import java.util.List;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.table.ColumnData;
/**

View File

@ -1,96 +1,96 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import org.meteoinfo.global.MIMath;
/**
*
* @author wyq
*/
public class DataRange {
// <editor-fold desc="Variables">
private double min;
private double max;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public DataRange(){
}
/**
* Constructor
* @param min Minimum value
* @param max Maximum value
*/
public DataRange(double min, double max){
this.min = min;
this.max = max;
}
/**
* Constructor
* @param value Data value
*/
public DataRange(double value){
this.min = value;
this.max = value;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get minimum value
* @return Minimum value
*/
public double getMin(){
return this.min;
}
/**
* Set minimum value
* @param value Minimum value
*/
public void setMin(double value){
this.min = value;
}
/**
* Get maximum value
* @return Maximum value
*/
public double getMax(){
return this.max;
}
/**
* Set maximum value
* @param value Maximum value
*/
public void setMax(double value) {
this.max = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Get data range
* @return Data range
*/
public double getRange(){
return this.max - this.min;
}
/**
* Get if the data range is zero
* @return Boolean
*/
public boolean isFixed(){
return MIMath.doubleEquals(max, min);
}
// </editor-fold>
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import org.meteoinfo.common.MIMath;
/**
*
* @author wyq
*/
public class DataRange {
// <editor-fold desc="Variables">
private double min;
private double max;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public DataRange(){
}
/**
* Constructor
* @param min Minimum value
* @param max Maximum value
*/
public DataRange(double min, double max){
this.min = min;
this.max = max;
}
/**
* Constructor
* @param value Data value
*/
public DataRange(double value){
this.min = value;
this.max = value;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get minimum value
* @return Minimum value
*/
public double getMin(){
return this.min;
}
/**
* Set minimum value
* @param value Minimum value
*/
public void setMin(double value){
this.min = value;
}
/**
* Get maximum value
* @return Maximum value
*/
public double getMax(){
return this.max;
}
/**
* Set maximum value
* @param value Maximum value
*/
public void setMax(double value) {
this.max = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Get data range
* @return Data range
*/
public double getRange(){
return this.max - this.min;
}
/**
* Get if the data range is zero
* @return Boolean
*/
public boolean isFixed(){
return MIMath.doubleEquals(max, min);
}
// </editor-fold>
}

View File

@ -13,16 +13,13 @@
*/
package org.meteoinfo.data;
import org.meteoinfo.math.ArrayUtil;
import org.meteoinfo.math.ArrayMath;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.MIMath;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
@ -31,6 +28,10 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.math.ArrayUtil;
import org.meteoinfo.ndarray.*;
import org.meteoinfo.ndarray.util.BigDecimalUtil;
import org.meteoinfo.data.meteodata.GridDataSetting;

View File

@ -14,10 +14,12 @@
package org.meteoinfo.data;
import java.io.BufferedReader;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.PointD;
import org.meteoinfo.geoprocess.GeoComputation;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.global.PointD;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.File;

View File

@ -1,164 +1,165 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import org.meteoinfo.math.ArrayMath;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.meteoinfo.ndarray.Array;
/**
*
* @author Yaqiang Wang
*/
public class SeriesUtil {
/**
* Get indices
* @param index Index array
* @param labels Labels
* @return Indices
*/
public static Object[] getIndices(List<Object> index, Array labels) {
return getIndices(index, ArrayMath.asList(labels));
}
/**
* Get indices
* @param index Index array
* @param labels Labels
* @return Indices
*/
public static Object[] getIndices(Array index, Array labels) {
return getIndices(ArrayMath.asList(index), ArrayMath.asList(labels));
}
/**
* Get indices
* @param index Index array
* @param labels Labels
* @return Indices
*/
public static Object[] getIndices(List<Object> index, List<Object> labels) {
List<Integer> r = new ArrayList<>();
List<Object> rIndex = new ArrayList<>();
List<Integer> rData = new ArrayList<>();
List<Object> rrIndex = new ArrayList<>();
Object[] rr;
List<Integer> r1;
List<Object> rIndex1;
for (Object l : labels){
rr = getIndices(index, l);
r1 = (ArrayList<Integer>)rr[0];
rIndex1 = (ArrayList<Object>)rr[1];
if (r1.isEmpty()){
rData.add(0);
rrIndex.add(l);
} else {
r.addAll(r1);
rIndex.addAll(rIndex1);
for (Iterator<Integer> it = r1.iterator(); it.hasNext();) {
it.next();
rData.add(1);
rrIndex.add(l);
}
}
}
return new Object[]{r, rIndex, rData, rrIndex};
}
/**
* Get indices
* @param index Index array
* @param label Label
* @return Indices
*/
public static Object[] getIndices(List<Object> index, Object label) {
List<Integer> r = new ArrayList<>();
List<Object> rIndex = new ArrayList<>();
for (int i = 0; i < index.size(); i++){
if (index.get(i).equals(label)){
r.add(i);
rIndex.add(index.get(i));
}
}
return new Object[]{r, rIndex};
}
/**
* Sub list by index
* @param list The list
* @param index The index
* @return Result list
*/
public static List subList(List list, List<Integer> index){
List r = new ArrayList<>();
for (int i : index){
r.add(list.get(i));
}
return r;
}
// /**
// * Fill key list
// * @param data Valid data array
// * @param rrdata Result data flags
// * @return Result data array with same length as key list
// */
// public static Array fillKeyList(Array data, List<Integer> rrdata){
// Array kdata = Array.factory(data.getDataType(), new int[]{rrdata.size()});
// Object nanObj = null;
// switch (data.getDataType()){
// case FLOAT:
// nanObj = Float.NaN;
// break;
// case DOUBLE:
// nanObj = Double.NaN;
// break;
// }
// int idx = 0;
// int i = 0;
// for (int f : rrdata){
// if (f == 0)
// kdata.setObject(i, nanObj);
// else {
// kdata.setObject(i, data.getObject(idx));
// idx += 1;
// }
// i += 1;
// }
//
// return kdata;
// }
/**
* Fill key list
* @param data Valid data array
* @param rrdata Result data flags
* @return Result data array with same length as key list
*/
public static Array fillKeyList(Array data, List<Integer> rrdata){
Array kdata = Array.factory(data.getDataType(), new int[]{rrdata.size()});
int idx = 0;
int i = 0;
for (int f : rrdata){
if (f == 0)
kdata.setObject(i, Double.NaN);
else {
kdata.setObject(i, data.getObject(idx));
idx += 1;
}
i += 1;
}
return kdata;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.ndarray.Array;
/**
*
* @author Yaqiang Wang
*/
public class SeriesUtil {
/**
* Get indices
* @param index Index array
* @param labels Labels
* @return Indices
*/
public static Object[] getIndices(List<Object> index, Array labels) {
return getIndices(index, ArrayMath.asList(labels));
}
/**
* Get indices
* @param index Index array
* @param labels Labels
* @return Indices
*/
public static Object[] getIndices(Array index, Array labels) {
return getIndices(ArrayMath.asList(index), ArrayMath.asList(labels));
}
/**
* Get indices
* @param index Index array
* @param labels Labels
* @return Indices
*/
public static Object[] getIndices(List<Object> index, List<Object> labels) {
List<Integer> r = new ArrayList<>();
List<Object> rIndex = new ArrayList<>();
List<Integer> rData = new ArrayList<>();
List<Object> rrIndex = new ArrayList<>();
Object[] rr;
List<Integer> r1;
List<Object> rIndex1;
for (Object l : labels){
rr = getIndices(index, l);
r1 = (ArrayList<Integer>)rr[0];
rIndex1 = (ArrayList<Object>)rr[1];
if (r1.isEmpty()){
rData.add(0);
rrIndex.add(l);
} else {
r.addAll(r1);
rIndex.addAll(rIndex1);
for (Iterator<Integer> it = r1.iterator(); it.hasNext();) {
it.next();
rData.add(1);
rrIndex.add(l);
}
}
}
return new Object[]{r, rIndex, rData, rrIndex};
}
/**
* Get indices
* @param index Index array
* @param label Label
* @return Indices
*/
public static Object[] getIndices(List<Object> index, Object label) {
List<Integer> r = new ArrayList<>();
List<Object> rIndex = new ArrayList<>();
for (int i = 0; i < index.size(); i++){
if (index.get(i).equals(label)){
r.add(i);
rIndex.add(index.get(i));
}
}
return new Object[]{r, rIndex};
}
/**
* Sub list by index
* @param list The list
* @param index The index
* @return Result list
*/
public static List subList(List list, List<Integer> index){
List r = new ArrayList<>();
for (int i : index){
r.add(list.get(i));
}
return r;
}
// /**
// * Fill key list
// * @param data Valid data array
// * @param rrdata Result data flags
// * @return Result data array with same length as key list
// */
// public static Array fillKeyList(Array data, List<Integer> rrdata){
// Array kdata = Array.factory(data.getDataType(), new int[]{rrdata.size()});
// Object nanObj = null;
// switch (data.getDataType()){
// case FLOAT:
// nanObj = Float.NaN;
// break;
// case DOUBLE:
// nanObj = Double.NaN;
// break;
// }
// int idx = 0;
// int i = 0;
// for (int f : rrdata){
// if (f == 0)
// kdata.setObject(i, nanObj);
// else {
// kdata.setObject(i, data.getObject(idx));
// idx += 1;
// }
// i += 1;
// }
//
// return kdata;
// }
/**
* Fill key list
* @param data Valid data array
* @param rrdata Result data flags
* @return Result data array with same length as key list
*/
public static Array fillKeyList(Array data, List<Integer> rrdata){
Array kdata = Array.factory(data.getDataType(), new int[]{rrdata.size()});
int idx = 0;
int i = 0;
for (int f : rrdata){
if (f == 0)
kdata.setObject(i, Double.NaN);
else {
kdata.setObject(i, data.getObject(idx));
idx += 1;
}
i += 1;
}
return kdata;
}
}

View File

@ -17,17 +17,19 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.PointD;
import org.meteoinfo.data.meteodata.GridDataSetting;
import org.meteoinfo.geoprocess.analysis.InterpolationSetting;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.MIMath;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.geoprocess.GeoComputation;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.global.PointD;
import org.meteoinfo.layer.VectorLayer;
import org.meteoinfo.projection.info.ProjectionInfo;
import org.meteoinfo.projection.Reproject;

View File

@ -1,202 +1,203 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import org.meteoinfo.global.util.GlobalUtil;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.projection.KnownCoordinateSystems;
import org.meteoinfo.projection.info.ProjectionInfo;
/**
*
* @author yaqiang
*/
public class StationTableData extends TableData{
// <editor-fold desc="Variables">
private ProjectionInfo projInfo;
private int stIdx;
private int lonIdx;
private int latIdx;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public StationTableData(){
this.projInfo = KnownCoordinateSystems.geographic.world.WGS1984;
stIdx = 0;
lonIdx = 1;
latIdx = 2;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get projection info
* @return Projection info
*/
public ProjectionInfo getProjectionInfo(){
return this.projInfo;
}
/**
* Set projection info
* @param value Projection info
*/
public void setProjectionInfo(ProjectionInfo value){
this.projInfo = value;
}
/**
* Get station column index
* @return Station column index
*/
public int getStationIndex(){
return this.stIdx;
}
/**
* Set station column index
* @param value Statin column index
*/
public void setStationIndex(int value){
this.stIdx = value;
}
/**
* Get longitude column index
* @return Longitude column index
*/
public int getLonIndex(){
return this.lonIdx;
}
/**
* Set longitude column index
* @param value Longitude column index
*/
public void setLonIndex(int value){
this.latIdx = value;
}
/**
* Get latitude column index
* @return Latitude column index
*/
public int getLatIndex(){
return this.latIdx;
}
/**
* Set Latitude column index
* @param value Latitude column index
*/
public void setLatIndex(int value){
this.lonIdx = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Read data table from ASCII file
*
* @param fileName File name
* @param lonIdx Longitude index
* @param latIdx Latitude index
* @throws java.io.FileNotFoundException
*/
public void readASCIIFile(String fileName, int lonIdx, int latIdx) throws FileNotFoundException, IOException, Exception {
this.readASCIIFile(fileName, 0, lonIdx, latIdx);
}
/**
* Read data table from ASCII file
*
* @param fileName File name
* @param stIdx Station column index
* @param lonIdx Longitude column index
* @param latIdx Latitude column index
* @throws java.io.FileNotFoundException
*/
public void readASCIIFile(String fileName, int stIdx, int lonIdx, int latIdx) throws FileNotFoundException, IOException, Exception {
this.lonIdx = lonIdx;
this.latIdx = latIdx;
//DataTable dTable = new DataTable();
BufferedReader sr = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "utf-8"));
String title = sr.readLine().trim();
//Determine separator
String separator = GlobalUtil.getDelimiter(title);
String[] titleArray = GlobalUtil.split(title, separator);
if (titleArray.length < 2) {
JOptionPane.showMessageDialog(null, "File Format Error!");
sr.close();
} else {
//Get fields
List<Integer> dataIdxs = new ArrayList<>();
String fieldName;
for (int i = 0; i < titleArray.length; i++) {
fieldName = titleArray[i];
if (i == lonIdx || i == latIdx)
this.addColumn(fieldName, DataType.FLOAT);
else
this.addColumn(fieldName, DataType.STRING);
dataIdxs.add(i);
}
String[] dataArray;
int rn = 0;
String line = sr.readLine();
while (line != null) {
line = line.trim();
if (line.isEmpty()) {
continue;
}
dataArray = GlobalUtil.split(line, separator);
this.addRow();
int cn = 0;
for (int idx : dataIdxs) {
if (idx == lonIdx || idx == latIdx)
this.setValue(rn, cn, Float.parseFloat(dataArray[idx]));
else
this.setValue(rn, cn, dataArray[idx]);
cn++;
}
rn += 1;
line = sr.readLine();
}
//dataTable = dTable;
sr.close();
}
}
/**
* Clone
* @return Cloned StationTableData object
*/
@Override
public Object clone(){
StationTableData std = new StationTableData();
std = (StationTableData)super.clone();
//std.dataTable = (DataTable)this.dataTable.clone();
std.missingValue = this.missingValue;
std.projInfo = this.projInfo;
std.stIdx = this.stIdx;
std.lonIdx = this.lonIdx;
std.latIdx = this.latIdx;
return std;
}
// </editor-fold>
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import org.meteoinfo.common.util.GlobalUtil;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.projection.KnownCoordinateSystems;
import org.meteoinfo.projection.info.ProjectionInfo;
/**
*
* @author yaqiang
*/
public class StationTableData extends TableData{
// <editor-fold desc="Variables">
private ProjectionInfo projInfo;
private int stIdx;
private int lonIdx;
private int latIdx;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public StationTableData(){
this.projInfo = KnownCoordinateSystems.geographic.world.WGS1984;
stIdx = 0;
lonIdx = 1;
latIdx = 2;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get projection info
* @return Projection info
*/
public ProjectionInfo getProjectionInfo(){
return this.projInfo;
}
/**
* Set projection info
* @param value Projection info
*/
public void setProjectionInfo(ProjectionInfo value){
this.projInfo = value;
}
/**
* Get station column index
* @return Station column index
*/
public int getStationIndex(){
return this.stIdx;
}
/**
* Set station column index
* @param value Statin column index
*/
public void setStationIndex(int value){
this.stIdx = value;
}
/**
* Get longitude column index
* @return Longitude column index
*/
public int getLonIndex(){
return this.lonIdx;
}
/**
* Set longitude column index
* @param value Longitude column index
*/
public void setLonIndex(int value){
this.latIdx = value;
}
/**
* Get latitude column index
* @return Latitude column index
*/
public int getLatIndex(){
return this.latIdx;
}
/**
* Set Latitude column index
* @param value Latitude column index
*/
public void setLatIndex(int value){
this.lonIdx = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Read data table from ASCII file
*
* @param fileName File name
* @param lonIdx Longitude index
* @param latIdx Latitude index
* @throws java.io.FileNotFoundException
*/
public void readASCIIFile(String fileName, int lonIdx, int latIdx) throws FileNotFoundException, IOException, Exception {
this.readASCIIFile(fileName, 0, lonIdx, latIdx);
}
/**
* Read data table from ASCII file
*
* @param fileName File name
* @param stIdx Station column index
* @param lonIdx Longitude column index
* @param latIdx Latitude column index
* @throws java.io.FileNotFoundException
*/
public void readASCIIFile(String fileName, int stIdx, int lonIdx, int latIdx) throws FileNotFoundException, IOException, Exception {
this.lonIdx = lonIdx;
this.latIdx = latIdx;
//DataTable dTable = new DataTable();
BufferedReader sr = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "utf-8"));
String title = sr.readLine().trim();
//Determine separator
String separator = GlobalUtil.getDelimiter(title);
String[] titleArray = GlobalUtil.split(title, separator);
if (titleArray.length < 2) {
JOptionPane.showMessageDialog(null, "File Format Error!");
sr.close();
} else {
//Get fields
List<Integer> dataIdxs = new ArrayList<>();
String fieldName;
for (int i = 0; i < titleArray.length; i++) {
fieldName = titleArray[i];
if (i == lonIdx || i == latIdx)
this.addColumn(fieldName, DataType.FLOAT);
else
this.addColumn(fieldName, DataType.STRING);
dataIdxs.add(i);
}
String[] dataArray;
int rn = 0;
String line = sr.readLine();
while (line != null) {
line = line.trim();
if (line.isEmpty()) {
continue;
}
dataArray = GlobalUtil.split(line, separator);
this.addRow();
int cn = 0;
for (int idx : dataIdxs) {
if (idx == lonIdx || idx == latIdx)
this.setValue(rn, cn, Float.parseFloat(dataArray[idx]));
else
this.setValue(rn, cn, dataArray[idx]);
cn++;
}
rn += 1;
line = sr.readLine();
}
//dataTable = dTable;
sr.close();
}
}
/**
* Clone
* @return Cloned StationTableData object
*/
@Override
public Object clone(){
StationTableData std = new StationTableData();
std = (StationTableData)super.clone();
//std.dataTable = (DataTable)this.dataTable.clone();
std.missingValue = this.missingValue;
std.projInfo = this.projInfo;
std.stIdx = this.stIdx;
std.lonIdx = this.lonIdx;
std.latIdx = this.latIdx;
return std;
}
// </editor-fold>
}

View File

@ -26,9 +26,10 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.JOptionPane;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.util.GlobalUtil;
import org.meteoinfo.data.analysis.Statistics;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.global.util.GlobalUtil;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.table.DataColumn;
import org.meteoinfo.table.DataRow;

View File

@ -15,8 +15,9 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.meteoinfo.common.util.GlobalUtil;
import org.meteoinfo.data.analysis.Statistics;
import org.meteoinfo.global.util.GlobalUtil;
import org.meteoinfo.table.DataColumn;
import org.meteoinfo.table.DataRow;
import org.meteoinfo.table.DataTable;

View File

@ -17,11 +17,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.JOptionPane;
import org.meteoinfo.common.util.GlobalUtil;
import org.meteoinfo.data.analysis.Statistics;
import org.meteoinfo.table.DataColumn;
import org.meteoinfo.table.DataRow;
import org.meteoinfo.table.DataTable;
import org.meteoinfo.global.util.GlobalUtil;
import org.meteoinfo.ndarray.DataType;
/**

View File

@ -1,342 +1,343 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.MIMath;
/**
*
* @author wyq
*/
public class XYArrayDataset extends XYDataset {
// <editor-fold desc="Variables">
private final double[][] xValues;
private final double[][] yValues;
private final int seriesCount;
private final int itemCount;
private String[] seriesKeys;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*
* @param seriesNum Series number
* @param itemNum Item number
*/
public XYArrayDataset(int seriesNum, int itemNum) {
this.seriesCount = seriesNum;
this.itemCount = itemNum;
xValues = new double[seriesNum][itemNum];
yValues = new double[seriesNum][itemNum];
seriesKeys = new String[seriesNum];
}
/**
* Constructor
*
* @param xdata X station data
* @param ydata Y station data
* @param seriesKey Series key
*/
public XYArrayDataset(StationData xdata, StationData ydata, String seriesKey) {
List<double[]> vdata = new ArrayList<>();
double v1, v2;
for (int i = 0; i < xdata.getStNum(); i++) {
v1 = xdata.getValue(i);
if (MIMath.doubleEquals(v1, xdata.missingValue)) {
continue;
}
v2 = ydata.getValue(i);
if (MIMath.doubleEquals(v2, ydata.missingValue)) {
continue;
}
vdata.add(new double[]{v1, v2});
}
seriesCount = 1;
seriesKeys = new String[seriesCount];
seriesKeys[0] = seriesKey;
itemCount = vdata.size();
xValues = new double[seriesCount][itemCount];
yValues = new double[seriesCount][itemCount];
for (int i = 0; i < seriesCount; i++) {
for (int j = 0; j < itemCount; j++) {
xValues[i][j] = vdata.get(j)[0];
yValues[i][j] = vdata.get(j)[1];
}
}
}
/**
* Constructor
*
* @param xdata X data
* @param ydata Y data
* @param seriesKey Series key
*/
public XYArrayDataset(List<Number> xdata, List<Number> ydata, String seriesKey) {
List<Double> nxdata = new ArrayList<>();
List<Double> nydata = new ArrayList<>();
for (int i = 0; i < xdata.size(); i++) {
nxdata.add(Double.parseDouble(xdata.get(i).toString()));
nydata.add(Double.parseDouble(ydata.get(i).toString()));
}
List<double[]> vdata = new ArrayList<>();
double v1, v2;
for (int i = 0; i < xdata.size(); i++) {
v1 = nxdata.get(i);
v2 = nydata.get(i);
vdata.add(new double[]{v1, v2});
}
seriesCount = 1;
seriesKeys = new String[seriesCount];
seriesKeys[0] = seriesKey;
itemCount = vdata.size();
xValues = new double[seriesCount][itemCount];
yValues = new double[seriesCount][itemCount];
for (int i = 0; i < seriesCount; i++) {
for (int j = 0; j < itemCount; j++) {
xValues[i][j] = vdata.get(j)[0];
yValues[i][j] = vdata.get(j)[1];
}
}
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get series count
* @return Series count
*/
@Override
public int getSeriesCount() {
return this.seriesCount;
}
/**
* Get series key by index
* @param seriesIdx Series index
* @return Series key
*/
@Override
public String getSeriesKey(int seriesIdx) {
return seriesKeys[seriesIdx];
}
/**
* Set series key by index
* @param seriesIdx Series index
* @param seriesKey Series key
*/
@Override
public void setSeriesKey(int seriesIdx, String seriesKey){
this.seriesKeys[seriesIdx] = seriesKey;
}
/**
* Get item count
* @return Item count
*/
@Override
public int getItemCount() {
return this.itemCount;
}
/**
* Get item count
* @param seriesIdx Series index
* @return Item count
*/
@Override
public int getItemCount(int seriesIdx){
return this.itemCount;
}
/**
* Get x values
* @param seriesIdx Series index
* @return X values
*/
@Override
public double[] getXValues(int seriesIdx){
return this.xValues[seriesIdx];
}
/**
* Get y values
* @param seriesIdx Series index
* @return Y values
*/
@Override
public double[] getYValues(int seriesIdx){
return this.yValues[seriesIdx];
}
/**
* Get x value
* @param seriesIdx Series index
* @param itemIdx Item index
* @return X value
*/
@Override
public double getX(int seriesIdx, int itemIdx) {
return xValues[seriesIdx][itemIdx];
}
/**
* Set x value
* @param seriesIdx Series index
* @param itemIdx Item index
* @param value X value
*/
@Override
public void setX(int seriesIdx, int itemIdx, double value){
xValues[seriesIdx][itemIdx] = value;
}
/**
* Get Y value
* @param seriesIdx Series index
* @param itemIdx Item index
* @return Y value
*/
@Override
public double getY(int seriesIdx, int itemIdx) {
return yValues[seriesIdx][itemIdx];
}
/**
* Set Y value
* @param seriesIdx Series index
* @param itemIdx Item index
* @param value Y value
*/
@Override
public void setY(int seriesIdx, int itemIdx, double value){
yValues[seriesIdx][itemIdx] = value;
}
/**
* Get series keys
* @return Series keys
*/
@Override
public List<String> getSeriesKeys(){
return Arrays.asList(this.seriesKeys);
}
/**
* Set series keys
* @param value Series keys
*/
public void setSeriesKeys(String[] value){
this.seriesKeys = value;
}
/**
* Set series keys
* @param value Series keys
*/
@Override
public void setSeriesKeys(List<String> value){
this.seriesKeys = (String[])value.toArray(new String[value.size()]);
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Get data extent
* @return Data extent
*/
@Override
public Extent getDataExtent() {
Extent cET = new Extent();
double x, y;
int n = 0;
for (int i = 0; i < this.seriesCount; i++) {
for (int j = 0; j < this.itemCount; j++) {
x = xValues[i][j];
y = yValues[i][j];
if (MIMath.doubleEquals(y, this.getMissingValue()) || MIMath.doubleEquals(x, this.getMissingValue()))
continue;
if (n == 0) {
cET.minX = x;
cET.maxX = x;
cET.minY = y;
cET.maxY = y;
} else {
if (cET.minX > x) {
cET.minX = x;
} else if (cET.maxX < x) {
cET.maxX = x;
}
if (cET.minY > y) {
cET.minY = y;
} else if (cET.maxY < y) {
cET.maxY = y;
}
}
n ++;
}
}
return cET;
}
/**
* Select data points
* @param extent Selection extent
* @return Selected data points
*/
@Override
public List<int[]> selectPoints(Extent extent){
List<int[]> selIdxs = new ArrayList<int[]>();
double x, y;
for (int i = 0; i < this.seriesCount; i++){
for (int j = 0; j < this.itemCount; j++){
x = this.getX(i, j);
if (x >= extent.minX && x <= extent.maxX){
y = this.getY(i, j);
if (y >= extent.minY && y <= extent.maxY){
selIdxs.add(new int[]{i, j});
}
}
}
}
return selIdxs;
}
/**
* Get missing value index list
* @param seriesIdx Series index
* @return Missing value index list
*/
@Override
public List<Integer> getMissingValueIndex(int seriesIdx){
List<Integer> mvidx = new ArrayList<Integer>();
double[] xvs = this.getXValues(seriesIdx);
double[] yvs = this.getYValues(seriesIdx);
for (int i = 0; i < this.itemCount; i++){
if (MIMath.doubleEquals(xvs[i], this.getMissingValue()) || MIMath.doubleEquals(yvs[i], this.getMissingValue()))
mvidx.add(i);
}
return mvidx;
}
// </editor-fold>
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.MIMath;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
*
* @author wyq
*/
public class XYArrayDataset extends XYDataset {
// <editor-fold desc="Variables">
private final double[][] xValues;
private final double[][] yValues;
private final int seriesCount;
private final int itemCount;
private String[] seriesKeys;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*
* @param seriesNum Series number
* @param itemNum Item number
*/
public XYArrayDataset(int seriesNum, int itemNum) {
this.seriesCount = seriesNum;
this.itemCount = itemNum;
xValues = new double[seriesNum][itemNum];
yValues = new double[seriesNum][itemNum];
seriesKeys = new String[seriesNum];
}
/**
* Constructor
*
* @param xdata X station data
* @param ydata Y station data
* @param seriesKey Series key
*/
public XYArrayDataset(StationData xdata, StationData ydata, String seriesKey) {
List<double[]> vdata = new ArrayList<>();
double v1, v2;
for (int i = 0; i < xdata.getStNum(); i++) {
v1 = xdata.getValue(i);
if (MIMath.doubleEquals(v1, xdata.missingValue)) {
continue;
}
v2 = ydata.getValue(i);
if (MIMath.doubleEquals(v2, ydata.missingValue)) {
continue;
}
vdata.add(new double[]{v1, v2});
}
seriesCount = 1;
seriesKeys = new String[seriesCount];
seriesKeys[0] = seriesKey;
itemCount = vdata.size();
xValues = new double[seriesCount][itemCount];
yValues = new double[seriesCount][itemCount];
for (int i = 0; i < seriesCount; i++) {
for (int j = 0; j < itemCount; j++) {
xValues[i][j] = vdata.get(j)[0];
yValues[i][j] = vdata.get(j)[1];
}
}
}
/**
* Constructor
*
* @param xdata X data
* @param ydata Y data
* @param seriesKey Series key
*/
public XYArrayDataset(List<Number> xdata, List<Number> ydata, String seriesKey) {
List<Double> nxdata = new ArrayList<>();
List<Double> nydata = new ArrayList<>();
for (int i = 0; i < xdata.size(); i++) {
nxdata.add(Double.parseDouble(xdata.get(i).toString()));
nydata.add(Double.parseDouble(ydata.get(i).toString()));
}
List<double[]> vdata = new ArrayList<>();
double v1, v2;
for (int i = 0; i < xdata.size(); i++) {
v1 = nxdata.get(i);
v2 = nydata.get(i);
vdata.add(new double[]{v1, v2});
}
seriesCount = 1;
seriesKeys = new String[seriesCount];
seriesKeys[0] = seriesKey;
itemCount = vdata.size();
xValues = new double[seriesCount][itemCount];
yValues = new double[seriesCount][itemCount];
for (int i = 0; i < seriesCount; i++) {
for (int j = 0; j < itemCount; j++) {
xValues[i][j] = vdata.get(j)[0];
yValues[i][j] = vdata.get(j)[1];
}
}
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get series count
* @return Series count
*/
@Override
public int getSeriesCount() {
return this.seriesCount;
}
/**
* Get series key by index
* @param seriesIdx Series index
* @return Series key
*/
@Override
public String getSeriesKey(int seriesIdx) {
return seriesKeys[seriesIdx];
}
/**
* Set series key by index
* @param seriesIdx Series index
* @param seriesKey Series key
*/
@Override
public void setSeriesKey(int seriesIdx, String seriesKey){
this.seriesKeys[seriesIdx] = seriesKey;
}
/**
* Get item count
* @return Item count
*/
@Override
public int getItemCount() {
return this.itemCount;
}
/**
* Get item count
* @param seriesIdx Series index
* @return Item count
*/
@Override
public int getItemCount(int seriesIdx){
return this.itemCount;
}
/**
* Get x values
* @param seriesIdx Series index
* @return X values
*/
@Override
public double[] getXValues(int seriesIdx){
return this.xValues[seriesIdx];
}
/**
* Get y values
* @param seriesIdx Series index
* @return Y values
*/
@Override
public double[] getYValues(int seriesIdx){
return this.yValues[seriesIdx];
}
/**
* Get x value
* @param seriesIdx Series index
* @param itemIdx Item index
* @return X value
*/
@Override
public double getX(int seriesIdx, int itemIdx) {
return xValues[seriesIdx][itemIdx];
}
/**
* Set x value
* @param seriesIdx Series index
* @param itemIdx Item index
* @param value X value
*/
@Override
public void setX(int seriesIdx, int itemIdx, double value){
xValues[seriesIdx][itemIdx] = value;
}
/**
* Get Y value
* @param seriesIdx Series index
* @param itemIdx Item index
* @return Y value
*/
@Override
public double getY(int seriesIdx, int itemIdx) {
return yValues[seriesIdx][itemIdx];
}
/**
* Set Y value
* @param seriesIdx Series index
* @param itemIdx Item index
* @param value Y value
*/
@Override
public void setY(int seriesIdx, int itemIdx, double value){
yValues[seriesIdx][itemIdx] = value;
}
/**
* Get series keys
* @return Series keys
*/
@Override
public List<String> getSeriesKeys(){
return Arrays.asList(this.seriesKeys);
}
/**
* Set series keys
* @param value Series keys
*/
public void setSeriesKeys(String[] value){
this.seriesKeys = value;
}
/**
* Set series keys
* @param value Series keys
*/
@Override
public void setSeriesKeys(List<String> value){
this.seriesKeys = (String[])value.toArray(new String[value.size()]);
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Get data extent
* @return Data extent
*/
@Override
public Extent getDataExtent() {
Extent cET = new Extent();
double x, y;
int n = 0;
for (int i = 0; i < this.seriesCount; i++) {
for (int j = 0; j < this.itemCount; j++) {
x = xValues[i][j];
y = yValues[i][j];
if (MIMath.doubleEquals(y, this.getMissingValue()) || MIMath.doubleEquals(x, this.getMissingValue()))
continue;
if (n == 0) {
cET.minX = x;
cET.maxX = x;
cET.minY = y;
cET.maxY = y;
} else {
if (cET.minX > x) {
cET.minX = x;
} else if (cET.maxX < x) {
cET.maxX = x;
}
if (cET.minY > y) {
cET.minY = y;
} else if (cET.maxY < y) {
cET.maxY = y;
}
}
n ++;
}
}
return cET;
}
/**
* Select data points
* @param extent Selection extent
* @return Selected data points
*/
@Override
public List<int[]> selectPoints(Extent extent){
List<int[]> selIdxs = new ArrayList<int[]>();
double x, y;
for (int i = 0; i < this.seriesCount; i++){
for (int j = 0; j < this.itemCount; j++){
x = this.getX(i, j);
if (x >= extent.minX && x <= extent.maxX){
y = this.getY(i, j);
if (y >= extent.minY && y <= extent.maxY){
selIdxs.add(new int[]{i, j});
}
}
}
}
return selIdxs;
}
/**
* Get missing value index list
* @param seriesIdx Series index
* @return Missing value index list
*/
@Override
public List<Integer> getMissingValueIndex(int seriesIdx){
List<Integer> mvidx = new ArrayList<Integer>();
double[] xvs = this.getXValues(seriesIdx);
double[] yvs = this.getYValues(seriesIdx);
for (int i = 0; i < this.itemCount; i++){
if (MIMath.doubleEquals(xvs[i], this.getMissingValue()) || MIMath.doubleEquals(yvs[i], this.getMissingValue()))
mvidx.add(i);
}
return mvidx;
}
// </editor-fold>
}

View File

@ -1,155 +1,156 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import java.util.List;
import org.meteoinfo.global.Extent;
/**
*
* @author yaqiang
*/
public abstract class XYDataset extends Dataset{
private double missingValue = -9999.0;
/**
* Get missing value
* @return Missing value
*/
public double getMissingValue(){
return this.missingValue;
}
/**
* Set missing value
* @param value Missing value
*/
public void setMissingValue(double value){
this.missingValue = value;
}
/**
* Get dataset type
* @return Dataset type
*/
@Override
public DatasetType getDatasetType() {
return DatasetType.XY;
}
/**
* Get series count
* @return Series count
*/
public abstract int getSeriesCount();
/**
* Get item count
* @return Item count
*/
public abstract int getItemCount();
/**
* Get item count by series index
* @param seriesIdx Series index
* @return Item count
*/
public abstract int getItemCount(int seriesIdx);
/**
* Get x value
* @param seriesIdx Series index
* @param itemIdx Item index
* @return X value
*/
public abstract double getX(int seriesIdx, int itemIdx);
/**
* Get y value
* @param seriesIdx Series index
* @param itemIdx Item index
* @return Y value
*/
public abstract double getY(int seriesIdx, int itemIdx);
/**
* Set x value
* @param seriesIdx Series index
* @param itemIdx Item index
* @param value X value
*/
public abstract void setX(int seriesIdx, int itemIdx, double value);
/**
* Set y value
* @param seriesIdx Series index
* @param itemIdx Item index
* @param value Y value
*/
public abstract void setY(int seriesIdx, int itemIdx, double value);
/**
* Get x values
* @param seriesIdx Series index
* @return X values
*/
public abstract double[] getXValues(int seriesIdx);
/**
* Get y values
* @param seriesIdx Series index
* @return Y values
*/
public abstract double[] getYValues(int seriesIdx);
/**
* Get series key by index
* @param seriesIdx Series index
* @return Series key
*/
public abstract String getSeriesKey(int seriesIdx);
/**
* Set series key by index
* @param seriesIdx Series index
* @param seriesKey Series key
*/
public abstract void setSeriesKey(int seriesIdx, String seriesKey);
/**
* Get series keys
* @return Series keys
*/
public abstract List<String> getSeriesKeys();
/**
* Set series keys
* @param keys Keys
*/
public abstract void setSeriesKeys(List<String> keys);
/**
* Get data extent
* @return Data extent
*/
public abstract Extent getDataExtent();
/**
* Get missing value index list
* @param seriesIdx Series index
* @return Missing value index list
*/
public abstract List<Integer> getMissingValueIndex(int seriesIdx);
/**
* Select data points
* @param extent Selection extent
* @return Selected data points
*/
public abstract List<int[]> selectPoints(Extent extent);
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import org.meteoinfo.common.Extent;
import java.util.List;
/**
*
* @author yaqiang
*/
public abstract class XYDataset extends Dataset{
private double missingValue = -9999.0;
/**
* Get missing value
* @return Missing value
*/
public double getMissingValue(){
return this.missingValue;
}
/**
* Set missing value
* @param value Missing value
*/
public void setMissingValue(double value){
this.missingValue = value;
}
/**
* Get dataset type
* @return Dataset type
*/
@Override
public DatasetType getDatasetType() {
return DatasetType.XY;
}
/**
* Get series count
* @return Series count
*/
public abstract int getSeriesCount();
/**
* Get item count
* @return Item count
*/
public abstract int getItemCount();
/**
* Get item count by series index
* @param seriesIdx Series index
* @return Item count
*/
public abstract int getItemCount(int seriesIdx);
/**
* Get x value
* @param seriesIdx Series index
* @param itemIdx Item index
* @return X value
*/
public abstract double getX(int seriesIdx, int itemIdx);
/**
* Get y value
* @param seriesIdx Series index
* @param itemIdx Item index
* @return Y value
*/
public abstract double getY(int seriesIdx, int itemIdx);
/**
* Set x value
* @param seriesIdx Series index
* @param itemIdx Item index
* @param value X value
*/
public abstract void setX(int seriesIdx, int itemIdx, double value);
/**
* Set y value
* @param seriesIdx Series index
* @param itemIdx Item index
* @param value Y value
*/
public abstract void setY(int seriesIdx, int itemIdx, double value);
/**
* Get x values
* @param seriesIdx Series index
* @return X values
*/
public abstract double[] getXValues(int seriesIdx);
/**
* Get y values
* @param seriesIdx Series index
* @return Y values
*/
public abstract double[] getYValues(int seriesIdx);
/**
* Get series key by index
* @param seriesIdx Series index
* @return Series key
*/
public abstract String getSeriesKey(int seriesIdx);
/**
* Set series key by index
* @param seriesIdx Series index
* @param seriesKey Series key
*/
public abstract void setSeriesKey(int seriesIdx, String seriesKey);
/**
* Get series keys
* @return Series keys
*/
public abstract List<String> getSeriesKeys();
/**
* Set series keys
* @param keys Keys
*/
public abstract void setSeriesKeys(List<String> keys);
/**
* Get data extent
* @return Data extent
*/
public abstract Extent getDataExtent();
/**
* Get missing value index list
* @param seriesIdx Series index
* @return Missing value index list
*/
public abstract List<Integer> getMissingValueIndex(int seriesIdx);
/**
* Select data points
* @param extent Selection extent
* @return Selected data points
*/
public abstract List<int[]> selectPoints(Extent extent);
}

View File

@ -1,443 +1,444 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.ndarray.Array;
/**
*
* @author wyq
*/
public class XYListDataset extends XYDataset {
// <editor-fold desc="Variables">
//private List<double[]> xValues;
//private List<double[]> yValues;
//private List<String> seriesKeys;
private List<XYSeriesData> dataset;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public XYListDataset(){
//xValues = new ArrayList<>();
//yValues = new ArrayList<>();
//seriesKeys = new ArrayList<>();
dataset = new ArrayList<>();
}
/**
* Constructor
*
* @param seriesNum Series number
* @param itemNum Item number
*/
public XYListDataset(int seriesNum, int itemNum) {
this();
for (int i = 0; i < seriesNum; i++){
//xValues.add(new double[itemNum]);
//yValues.add(new double[itemNum]);
//seriesKeys.add("");
dataset.add(new XYSeriesData());
}
}
/**
* Constructor
* @param xdata X station data
* @param ydata Y station data
* @param seriesKey Series key
*/
public XYListDataset(StationData xdata, StationData ydata, String seriesKey){
this();
List<double[]> vdata = new ArrayList<>();
double v1, v2;
for (int i = 0; i < xdata.getStNum(); i++) {
v1 = xdata.getValue(i);
if (MIMath.doubleEquals(v1, xdata.missingValue)) {
continue;
}
v2 = ydata.getValue(i);
if (MIMath.doubleEquals(v2, ydata.missingValue)) {
continue;
}
vdata.add(new double[]{v1, v2});
}
int n = vdata.size();
double[] xvs = new double[n];
double[] yvs = new double[n];
for (int i = 0; i < n; i++){
xvs[i] = vdata.get(i)[0];
yvs[i] = vdata.get(i)[1];
}
//this.xValues.add(xvs);
//this.yValues.add(yvs);
//this.seriesKeys.add(seriesKey);
XYSeriesData sdata = new XYSeriesData(seriesKey, xvs, yvs);
this.dataset.add(sdata);
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get series data
* @param seriesIdx Series index
* @return Series data
*/
public XYSeriesData getSeriesData(int seriesIdx){
return this.dataset.get(seriesIdx);
}
@Override
public int getSeriesCount() {
//return this.xValues.size();
return this.dataset.size();
}
@Override
public String getSeriesKey(int seriesIdx) {
//return this.seriesKeys.get(seriesIdx);
return this.dataset.get(seriesIdx).getKey();
}
/**
* Set series key by index
* @param seriesIdx Series index
* @param seriesKey Series key
*/
@Override
public void setSeriesKey(int seriesIdx, String seriesKey){
//this.seriesKeys.set(seriesIdx, seriesKey);
this.dataset.get(seriesIdx).setKey(seriesKey);
}
/**
* Get series keys
* @return Series keys
*/
@Override
public List<String> getSeriesKeys(){
//return this.seriesKeys;
List<String> keys = new ArrayList<>();
for (XYSeriesData d :this.dataset){
keys.add(d.getKey());
}
return keys;
}
/**
* Set series keys
* @param value Series keys
*/
@Override
public void setSeriesKeys(List<String> value){
//this.seriesKeys = value;
int i = 0;
for (XYSeriesData d :this.dataset){
d.setKey(value.get(i));
i++;
}
}
@Override
public int getItemCount(){
int n = this.getItemCount(0);
if (this.getSeriesCount() > 1){
for (int i = 1; i < this.getSeriesCount(); i++){
int nn = this.getItemCount(i);
if (n < nn)
n = nn;
}
}
return n;
}
@Override
public int getItemCount(int seriesIdx) {
//return this.xValues.get(seriesIdx).length;
return this.dataset.get(seriesIdx).dataLength();
}
@Override
public double[] getXValues(int seriesIdx){
//return this.xValues.get(seriesIdx);
return this.dataset.get(seriesIdx).getXdata();
}
@Override
public double[] getYValues(int seriesIdx){
//return this.yValues.get(seriesIdx);
return this.dataset.get(seriesIdx).getYdata();
}
@Override
public double getX(int seriesIdx, int itemIdx) {
//return this.xValues.get(seriesIdx)[itemIdx];
return this.dataset.get(seriesIdx).getXdata()[itemIdx];
}
@Override
public double getY(int seriesIdx, int itemIdx) {
//return this.yValues.get(seriesIdx)[itemIdx];
return this.dataset.get(seriesIdx).getYdata()[itemIdx];
}
@Override
public void setX(int seriesIdx, int itemIdx, double value){
//this.xValues.get(seriesIdx)[itemIdx] = value;
this.dataset.get(seriesIdx).getXdata()[itemIdx] = value;
}
@Override
public void setY(int seriesIdx, int itemIdx, double value){
//this.yValues.get(seriesIdx)[itemIdx] = value;
this.dataset.get(seriesIdx).getYdata()[itemIdx] = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Add a series data
* @param sdata Series data
*/
public void addSeries(XYSeriesData sdata){
this.dataset.add(sdata);
}
/**
* Add a series data
* @param seriesKey Series key
* @param xvs X value array
* @param yvs Y value array
*/
public void addSeries(String seriesKey, double[] xvs, double[] yvs){
//this.seriesKeys.add(seriesKey);
//this.xValues.add(xvs);
//this.yValues.add(yvs);
XYSeriesData sdata = new XYSeriesData(seriesKey, xvs, yvs);
this.dataset.add(sdata);
}
/**
* Add a series data
* @param seriesKey Series key
* @param xvs X value array
* @param yvs Y value array
*/
public void addSeries(String seriesKey, List<Number> xvs, List<Number> yvs){
double[] nxvs = new double[xvs.size()];
double[] nyvs = new double[yvs.size()];
double v;
for (int i = 0; i < xvs.size(); i++){
v = xvs.get(i).doubleValue();
if (Double.isNaN(v))
nxvs[i] = this.getMissingValue();
else
nxvs[i] = xvs.get(i).doubleValue();
}
for (int i = 0; i < yvs.size(); i++){
v = yvs.get(i).doubleValue();
if (Double.isNaN(v))
nyvs[i] = this.getMissingValue();
else
nyvs[i] = v;
}
this.addSeries(seriesKey, nxvs, nyvs);
}
/**
* Add a series data
* @param seriesKey Series key
* @param xvs X value array
* @param yvs Y value array
*/
public void addSeries(String seriesKey, List<Number> xvs, Array yvs){
int xn = (int)xvs.size();
int yn = (int)yvs.getSize();
double[] nxvs = new double[xn];
double[] nyvs = new double[yn];
double v;
for (int i = 0; i < xn; i++)
nxvs[i] = xvs.get(i).doubleValue();
for (int i = 0; i < yn; i++) {
v = yvs.getDouble(i);
if (Double.isNaN(v))
nyvs[i] = this.getMissingValue();
else
nyvs[i] = v;
}
this.addSeries(seriesKey, nxvs, nyvs);
}
/**
* Add a series data
* @param seriesKey Series key
* @param xvs X value array
* @param yvs Y value array
*/
public void addSeries(String seriesKey, Array xvs, Array yvs){
int xn = (int)xvs.getSize();
int yn = (int)yvs.getSize();
double[] nxvs = new double[xn];
double[] nyvs = new double[yn];
double v;
for (int i = 0; i < xn; i++)
nxvs[i] = xvs.getDouble(i);
for (int i = 0; i < yn; i++){
v = yvs.getDouble(i);
if (Double.isNaN(v))
nyvs[i] = this.getMissingValue();
else
nyvs[i] = v;
}
this.addSeries(seriesKey, nxvs, nyvs);
}
/**
* Add a series data
* @param seriesKey Series key
* @param xvs X value array
* @param yvs Y value array
*/
public void addSeries(String seriesKey, Array xvs, List<Number> yvs){
int xn = (int)xvs.getSize();
int yn = yvs.size();
double[] nxvs = new double[xn];
double[] nyvs = new double[yn];
double v;
for (int i = 0; i < xn; i++)
nxvs[i] = xvs.getDouble(i);
for (int i = 0; i < yn; i++){
v = yvs.get(i).doubleValue();
if (Double.isNaN(v))
nyvs[i] = this.getMissingValue();
else
nyvs[i] = v;
}
this.addSeries(seriesKey, nxvs, nyvs);
}
/**
* Remove a series data
* @param seriesIdx Series data
*/
public void removeSeries(int seriesIdx){
//this.seriesKeys.remove(seriesIdx);
//this.xValues.remove(seriesIdx);
//this.yValues.remove(seriesIdx);
this.dataset.remove(seriesIdx);
}
/**
* Remove a series data
* @param seriesKey Series key
*/
public void removeSeries(String seriesKey){
List<String> keys = this.getSeriesKeys();
int idx = keys.indexOf(seriesKey);
if (idx >= 0){
this.removeSeries(idx);
}
}
/**
* Get data extent
* @return Data extent
*/
@Override
public Extent getDataExtent() {
Extent cET = new Extent();
double xmin, xmax, ymin, ymax;
int n = 0;
for (int i = 0; i < this.getSeriesCount(); i++) {
XYSeriesData sdata = this.dataset.get(i);
for (int j = 0; j < this.getItemCount(i); j++) {
xmin = sdata.getX_min(j);
xmax = sdata.getX_max(j);
ymin = sdata.getY_min(j);
ymax = sdata.getY_max(j);
if (Double.isNaN(sdata.getX(j)) || Double.isNaN(sdata.getY(j)))
continue;
if (MIMath.doubleEquals(sdata.getX(j), this.getMissingValue()) || MIMath.doubleEquals(sdata.getY(j), this.getMissingValue()))
continue;
if (n == 0) {
cET.minX = xmin;
cET.maxX = xmax;
cET.minY = ymin;
cET.maxY = ymax;
} else {
if (cET.minX > xmin) {
cET.minX = xmin;
} else if (cET.maxX < xmax) {
cET.maxX = xmax;
}
if (cET.minY > ymin) {
cET.minY = ymin;
} else if (cET.maxY < ymax) {
cET.maxY = ymax;
}
}
n ++;
}
}
return cET;
}
/**
* Get missing value index list
* @param seriesIdx Series index
* @return Missing value index list
*/
@Override
public List<Integer> getMissingValueIndex(int seriesIdx){
List<Integer> mvidx = new ArrayList<>();
double[] xvs = this.getXValues(seriesIdx);
double[] yvs = this.getYValues(seriesIdx);
for (int i = 0; i < yvs.length; i++){
if (MIMath.doubleEquals(xvs[i], this.getMissingValue()) || MIMath.doubleEquals(yvs[i], this.getMissingValue()))
mvidx.add(i);
}
return mvidx;
}
/**
* Select data points
* @param extent Selection extent
* @return Selected data points
*/
@Override
public List<int[]> selectPoints(Extent extent){
List<int[]> selIdxs = new ArrayList<>();
double x, y;
for (int i = 0; i < this.getSeriesCount(); i++){
for (int j = 0; j < this.getItemCount(i); j++){
x = this.getX(i, j);
if (x >= extent.minX && x <= extent.maxX){
y = this.getY(i, j);
if (y >= extent.minY && y <= extent.maxY){
selIdxs.add(new int[]{i, j});
}
}
}
}
return selIdxs;
}
// </editor-fold>
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.ndarray.Array;
/**
*
* @author wyq
*/
public class XYListDataset extends XYDataset {
// <editor-fold desc="Variables">
//private List<double[]> xValues;
//private List<double[]> yValues;
//private List<String> seriesKeys;
private List<XYSeriesData> dataset;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public XYListDataset(){
//xValues = new ArrayList<>();
//yValues = new ArrayList<>();
//seriesKeys = new ArrayList<>();
dataset = new ArrayList<>();
}
/**
* Constructor
*
* @param seriesNum Series number
* @param itemNum Item number
*/
public XYListDataset(int seriesNum, int itemNum) {
this();
for (int i = 0; i < seriesNum; i++){
//xValues.add(new double[itemNum]);
//yValues.add(new double[itemNum]);
//seriesKeys.add("");
dataset.add(new XYSeriesData());
}
}
/**
* Constructor
* @param xdata X station data
* @param ydata Y station data
* @param seriesKey Series key
*/
public XYListDataset(StationData xdata, StationData ydata, String seriesKey){
this();
List<double[]> vdata = new ArrayList<>();
double v1, v2;
for (int i = 0; i < xdata.getStNum(); i++) {
v1 = xdata.getValue(i);
if (MIMath.doubleEquals(v1, xdata.missingValue)) {
continue;
}
v2 = ydata.getValue(i);
if (MIMath.doubleEquals(v2, ydata.missingValue)) {
continue;
}
vdata.add(new double[]{v1, v2});
}
int n = vdata.size();
double[] xvs = new double[n];
double[] yvs = new double[n];
for (int i = 0; i < n; i++){
xvs[i] = vdata.get(i)[0];
yvs[i] = vdata.get(i)[1];
}
//this.xValues.add(xvs);
//this.yValues.add(yvs);
//this.seriesKeys.add(seriesKey);
XYSeriesData sdata = new XYSeriesData(seriesKey, xvs, yvs);
this.dataset.add(sdata);
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get series data
* @param seriesIdx Series index
* @return Series data
*/
public XYSeriesData getSeriesData(int seriesIdx){
return this.dataset.get(seriesIdx);
}
@Override
public int getSeriesCount() {
//return this.xValues.size();
return this.dataset.size();
}
@Override
public String getSeriesKey(int seriesIdx) {
//return this.seriesKeys.get(seriesIdx);
return this.dataset.get(seriesIdx).getKey();
}
/**
* Set series key by index
* @param seriesIdx Series index
* @param seriesKey Series key
*/
@Override
public void setSeriesKey(int seriesIdx, String seriesKey){
//this.seriesKeys.set(seriesIdx, seriesKey);
this.dataset.get(seriesIdx).setKey(seriesKey);
}
/**
* Get series keys
* @return Series keys
*/
@Override
public List<String> getSeriesKeys(){
//return this.seriesKeys;
List<String> keys = new ArrayList<>();
for (XYSeriesData d :this.dataset){
keys.add(d.getKey());
}
return keys;
}
/**
* Set series keys
* @param value Series keys
*/
@Override
public void setSeriesKeys(List<String> value){
//this.seriesKeys = value;
int i = 0;
for (XYSeriesData d :this.dataset){
d.setKey(value.get(i));
i++;
}
}
@Override
public int getItemCount(){
int n = this.getItemCount(0);
if (this.getSeriesCount() > 1){
for (int i = 1; i < this.getSeriesCount(); i++){
int nn = this.getItemCount(i);
if (n < nn)
n = nn;
}
}
return n;
}
@Override
public int getItemCount(int seriesIdx) {
//return this.xValues.get(seriesIdx).length;
return this.dataset.get(seriesIdx).dataLength();
}
@Override
public double[] getXValues(int seriesIdx){
//return this.xValues.get(seriesIdx);
return this.dataset.get(seriesIdx).getXdata();
}
@Override
public double[] getYValues(int seriesIdx){
//return this.yValues.get(seriesIdx);
return this.dataset.get(seriesIdx).getYdata();
}
@Override
public double getX(int seriesIdx, int itemIdx) {
//return this.xValues.get(seriesIdx)[itemIdx];
return this.dataset.get(seriesIdx).getXdata()[itemIdx];
}
@Override
public double getY(int seriesIdx, int itemIdx) {
//return this.yValues.get(seriesIdx)[itemIdx];
return this.dataset.get(seriesIdx).getYdata()[itemIdx];
}
@Override
public void setX(int seriesIdx, int itemIdx, double value){
//this.xValues.get(seriesIdx)[itemIdx] = value;
this.dataset.get(seriesIdx).getXdata()[itemIdx] = value;
}
@Override
public void setY(int seriesIdx, int itemIdx, double value){
//this.yValues.get(seriesIdx)[itemIdx] = value;
this.dataset.get(seriesIdx).getYdata()[itemIdx] = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Add a series data
* @param sdata Series data
*/
public void addSeries(XYSeriesData sdata){
this.dataset.add(sdata);
}
/**
* Add a series data
* @param seriesKey Series key
* @param xvs X value array
* @param yvs Y value array
*/
public void addSeries(String seriesKey, double[] xvs, double[] yvs){
//this.seriesKeys.add(seriesKey);
//this.xValues.add(xvs);
//this.yValues.add(yvs);
XYSeriesData sdata = new XYSeriesData(seriesKey, xvs, yvs);
this.dataset.add(sdata);
}
/**
* Add a series data
* @param seriesKey Series key
* @param xvs X value array
* @param yvs Y value array
*/
public void addSeries(String seriesKey, List<Number> xvs, List<Number> yvs){
double[] nxvs = new double[xvs.size()];
double[] nyvs = new double[yvs.size()];
double v;
for (int i = 0; i < xvs.size(); i++){
v = xvs.get(i).doubleValue();
if (Double.isNaN(v))
nxvs[i] = this.getMissingValue();
else
nxvs[i] = xvs.get(i).doubleValue();
}
for (int i = 0; i < yvs.size(); i++){
v = yvs.get(i).doubleValue();
if (Double.isNaN(v))
nyvs[i] = this.getMissingValue();
else
nyvs[i] = v;
}
this.addSeries(seriesKey, nxvs, nyvs);
}
/**
* Add a series data
* @param seriesKey Series key
* @param xvs X value array
* @param yvs Y value array
*/
public void addSeries(String seriesKey, List<Number> xvs, Array yvs){
int xn = (int)xvs.size();
int yn = (int)yvs.getSize();
double[] nxvs = new double[xn];
double[] nyvs = new double[yn];
double v;
for (int i = 0; i < xn; i++)
nxvs[i] = xvs.get(i).doubleValue();
for (int i = 0; i < yn; i++) {
v = yvs.getDouble(i);
if (Double.isNaN(v))
nyvs[i] = this.getMissingValue();
else
nyvs[i] = v;
}
this.addSeries(seriesKey, nxvs, nyvs);
}
/**
* Add a series data
* @param seriesKey Series key
* @param xvs X value array
* @param yvs Y value array
*/
public void addSeries(String seriesKey, Array xvs, Array yvs){
int xn = (int)xvs.getSize();
int yn = (int)yvs.getSize();
double[] nxvs = new double[xn];
double[] nyvs = new double[yn];
double v;
for (int i = 0; i < xn; i++)
nxvs[i] = xvs.getDouble(i);
for (int i = 0; i < yn; i++){
v = yvs.getDouble(i);
if (Double.isNaN(v))
nyvs[i] = this.getMissingValue();
else
nyvs[i] = v;
}
this.addSeries(seriesKey, nxvs, nyvs);
}
/**
* Add a series data
* @param seriesKey Series key
* @param xvs X value array
* @param yvs Y value array
*/
public void addSeries(String seriesKey, Array xvs, List<Number> yvs){
int xn = (int)xvs.getSize();
int yn = yvs.size();
double[] nxvs = new double[xn];
double[] nyvs = new double[yn];
double v;
for (int i = 0; i < xn; i++)
nxvs[i] = xvs.getDouble(i);
for (int i = 0; i < yn; i++){
v = yvs.get(i).doubleValue();
if (Double.isNaN(v))
nyvs[i] = this.getMissingValue();
else
nyvs[i] = v;
}
this.addSeries(seriesKey, nxvs, nyvs);
}
/**
* Remove a series data
* @param seriesIdx Series data
*/
public void removeSeries(int seriesIdx){
//this.seriesKeys.remove(seriesIdx);
//this.xValues.remove(seriesIdx);
//this.yValues.remove(seriesIdx);
this.dataset.remove(seriesIdx);
}
/**
* Remove a series data
* @param seriesKey Series key
*/
public void removeSeries(String seriesKey){
List<String> keys = this.getSeriesKeys();
int idx = keys.indexOf(seriesKey);
if (idx >= 0){
this.removeSeries(idx);
}
}
/**
* Get data extent
* @return Data extent
*/
@Override
public Extent getDataExtent() {
Extent cET = new Extent();
double xmin, xmax, ymin, ymax;
int n = 0;
for (int i = 0; i < this.getSeriesCount(); i++) {
XYSeriesData sdata = this.dataset.get(i);
for (int j = 0; j < this.getItemCount(i); j++) {
xmin = sdata.getX_min(j);
xmax = sdata.getX_max(j);
ymin = sdata.getY_min(j);
ymax = sdata.getY_max(j);
if (Double.isNaN(sdata.getX(j)) || Double.isNaN(sdata.getY(j)))
continue;
if (MIMath.doubleEquals(sdata.getX(j), this.getMissingValue()) || MIMath.doubleEquals(sdata.getY(j), this.getMissingValue()))
continue;
if (n == 0) {
cET.minX = xmin;
cET.maxX = xmax;
cET.minY = ymin;
cET.maxY = ymax;
} else {
if (cET.minX > xmin) {
cET.minX = xmin;
} else if (cET.maxX < xmax) {
cET.maxX = xmax;
}
if (cET.minY > ymin) {
cET.minY = ymin;
} else if (cET.maxY < ymax) {
cET.maxY = ymax;
}
}
n ++;
}
}
return cET;
}
/**
* Get missing value index list
* @param seriesIdx Series index
* @return Missing value index list
*/
@Override
public List<Integer> getMissingValueIndex(int seriesIdx){
List<Integer> mvidx = new ArrayList<>();
double[] xvs = this.getXValues(seriesIdx);
double[] yvs = this.getYValues(seriesIdx);
for (int i = 0; i < yvs.length; i++){
if (MIMath.doubleEquals(xvs[i], this.getMissingValue()) || MIMath.doubleEquals(yvs[i], this.getMissingValue()))
mvidx.add(i);
}
return mvidx;
}
/**
* Select data points
* @param extent Selection extent
* @return Selected data points
*/
@Override
public List<int[]> selectPoints(Extent extent){
List<int[]> selIdxs = new ArrayList<>();
double x, y;
for (int i = 0; i < this.getSeriesCount(); i++){
for (int j = 0; j < this.getItemCount(i); j++){
x = this.getX(i, j);
if (x >= extent.minX && x <= extent.maxX){
y = this.getY(i, j);
if (y >= extent.minY && y <= extent.maxY){
selIdxs.add(new int[]{i, j});
}
}
}
}
return selIdxs;
}
// </editor-fold>
}

View File

@ -1,258 +1,259 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.global.MIMath;
import ucar.ma2.Array;
/**
*
* @author yaqiang
*/
public class XYSeriesData {
// <editor-fold desc="Variables">
private String key;
private double[] xdata;
private double[] ydata;
private double missingValue = -9999.0;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public XYSeriesData(){
}
/**
* Constructor
* @param key Key
*/
public XYSeriesData(String key){
this.key = key;
}
/**
* Constructor
* @param key Series key
* @param xdata X data
* @param ydata Y data
*/
public XYSeriesData(String key, double[] xdata, double[] ydata){
this.key = key;
this.xdata = xdata;
this.ydata = ydata;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get series key
* @return Series key
*/
public String getKey(){
return key;
}
/**
* Set series key
* @param value Series key
*/
public void setKey(String value){
key = value;
}
/**
* Get X data
* @return X data
*/
public double[] getXdata(){
return this.xdata;
}
/**
* Set X data
* @param value X data
*/
public void setXdata(double[] value){
this.xdata = value;
}
/**
* Set X data
* @param value X data
*/
public void setXdata(List<Number> value){
this.xdata = new double[value.size()];
double v;
for (int i = 0; i < value.size(); i++){
v = value.get(i).doubleValue();
if (Double.isNaN(v))
xdata[i] = this.missingValue;
else
xdata[i] = v;
}
}
/**
* Set X data
* @param value X data
*/
public void setXdata(Array value){
this.xdata = new double[(int)value.getSize()];
double v;
for (int i = 0; i < xdata.length; i++){
v = value.getDouble(i);
if (Double.isNaN(v))
xdata[i] = this.missingValue;
else
xdata[i] = v;
}
}
/**
* Get Y data
* @return Y data
*/
public double[] getYdata(){
return this.ydata;
}
/**
* Set Y data
* @param value Y data
*/
public void setYdata(double[] value){
this.ydata = value;
}
/**
* Set Y data
* @param value Y data
*/
public void setYdata(List<Number> value){
this.ydata = new double[value.size()];
double v;
for (int i = 0; i < value.size(); i++){
v = value.get(i).doubleValue();
if (Double.isNaN(v))
ydata[i] = this.missingValue;
else
ydata[i] = v;
}
}
/**
* Set Y data
* @param value Y data
*/
public void setYdata(Array value){
this.ydata = new double[(int)value.getSize()];
double v;
for (int i = 0; i < ydata.length; i++){
v = value.getDouble(i);
if (Double.isNaN(v))
ydata[i] = this.missingValue;
else
ydata[i] = v;
}
}
/**
* Get missing value
* @return Missing value
*/
public double getMissingValue(){
return this.missingValue;
}
/**
* Set missing value
* @param value Missing value
*/
public void setMissingValue(double value){
this.missingValue = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Get data length
* @return Data length
*/
public int dataLength(){
return this.xdata.length;
}
/**
* Get x value
* @param idx Index
* @return X value
*/
public double getX(int idx){
return this.xdata[idx];
}
/**
* Get x - error value
* @param idx Index
* @return X - error value
*/
public double getX_min(int idx){
return this.xdata[idx];
}
/**
* Get x + error value
* @param idx Index
* @return X + error value
*/
public double getX_max(int idx){
return this.xdata[idx];
}
/**
* Get y value
* @param idx Index
* @return Y value
*/
public double getY(int idx){
return this.ydata[idx];
}
/**
* Get y - error value
* @param idx Index
* @return Y - error value
*/
public double getY_min(int idx){
return this.ydata[idx];
}
/**
* Get y + error value
* @param idx Index
* @return Y + error value
*/
public double getY_max(int idx){
return this.ydata[idx];
}
/**
* Get missing value index list
* @return Missing value index list
*/
public List<Integer> getMissingValueIndex(){
List<Integer> mvidx = new ArrayList<>();
for (int i = 0; i < xdata.length; i++){
if (MIMath.doubleEquals(xdata[i], this.missingValue) || MIMath.doubleEquals(ydata[i], this.missingValue))
mvidx.add(i);
}
return mvidx;
}
// </editor-fold>
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data;
import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.common.MIMath;
import ucar.ma2.Array;
/**
*
* @author yaqiang
*/
public class XYSeriesData {
// <editor-fold desc="Variables">
private String key;
private double[] xdata;
private double[] ydata;
private double missingValue = -9999.0;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public XYSeriesData(){
}
/**
* Constructor
* @param key Key
*/
public XYSeriesData(String key){
this.key = key;
}
/**
* Constructor
* @param key Series key
* @param xdata X data
* @param ydata Y data
*/
public XYSeriesData(String key, double[] xdata, double[] ydata){
this.key = key;
this.xdata = xdata;
this.ydata = ydata;
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get series key
* @return Series key
*/
public String getKey(){
return key;
}
/**
* Set series key
* @param value Series key
*/
public void setKey(String value){
key = value;
}
/**
* Get X data
* @return X data
*/
public double[] getXdata(){
return this.xdata;
}
/**
* Set X data
* @param value X data
*/
public void setXdata(double[] value){
this.xdata = value;
}
/**
* Set X data
* @param value X data
*/
public void setXdata(List<Number> value){
this.xdata = new double[value.size()];
double v;
for (int i = 0; i < value.size(); i++){
v = value.get(i).doubleValue();
if (Double.isNaN(v))
xdata[i] = this.missingValue;
else
xdata[i] = v;
}
}
/**
* Set X data
* @param value X data
*/
public void setXdata(Array value){
this.xdata = new double[(int)value.getSize()];
double v;
for (int i = 0; i < xdata.length; i++){
v = value.getDouble(i);
if (Double.isNaN(v))
xdata[i] = this.missingValue;
else
xdata[i] = v;
}
}
/**
* Get Y data
* @return Y data
*/
public double[] getYdata(){
return this.ydata;
}
/**
* Set Y data
* @param value Y data
*/
public void setYdata(double[] value){
this.ydata = value;
}
/**
* Set Y data
* @param value Y data
*/
public void setYdata(List<Number> value){
this.ydata = new double[value.size()];
double v;
for (int i = 0; i < value.size(); i++){
v = value.get(i).doubleValue();
if (Double.isNaN(v))
ydata[i] = this.missingValue;
else
ydata[i] = v;
}
}
/**
* Set Y data
* @param value Y data
*/
public void setYdata(Array value){
this.ydata = new double[(int)value.getSize()];
double v;
for (int i = 0; i < ydata.length; i++){
v = value.getDouble(i);
if (Double.isNaN(v))
ydata[i] = this.missingValue;
else
ydata[i] = v;
}
}
/**
* Get missing value
* @return Missing value
*/
public double getMissingValue(){
return this.missingValue;
}
/**
* Set missing value
* @param value Missing value
*/
public void setMissingValue(double value){
this.missingValue = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Get data length
* @return Data length
*/
public int dataLength(){
return this.xdata.length;
}
/**
* Get x value
* @param idx Index
* @return X value
*/
public double getX(int idx){
return this.xdata[idx];
}
/**
* Get x - error value
* @param idx Index
* @return X - error value
*/
public double getX_min(int idx){
return this.xdata[idx];
}
/**
* Get x + error value
* @param idx Index
* @return X + error value
*/
public double getX_max(int idx){
return this.xdata[idx];
}
/**
* Get y value
* @param idx Index
* @return Y value
*/
public double getY(int idx){
return this.ydata[idx];
}
/**
* Get y - error value
* @param idx Index
* @return Y - error value
*/
public double getY_min(int idx){
return this.ydata[idx];
}
/**
* Get y + error value
* @param idx Index
* @return Y + error value
*/
public double getY_max(int idx){
return this.ydata[idx];
}
/**
* Get missing value index list
* @return Missing value index list
*/
public List<Integer> getMissingValueIndex(){
List<Integer> mvidx = new ArrayList<>();
for (int i = 0; i < xdata.length; i++){
if (MIMath.doubleEquals(xdata[i], this.missingValue) || MIMath.doubleEquals(ydata[i], this.missingValue))
mvidx.add(i);
}
return mvidx;
}
// </editor-fold>
}

View File

@ -1,267 +1,267 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data.dataframe;
import java.text.DecimalFormat;
import org.joda.time.DateTime;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;
/**
*
* @author Yaqiang Wang
*/
public class Column {
// <editor-fold desc="Variables">
protected String name;
protected DataType dataType;
protected String format;
protected int formatLen;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public Column(){
this("Column", DataType.OBJECT);
}
/**
* Constructor
* @param name Name
*/
public Column(String name){
this(name, DataType.OBJECT);
}
/**
* Constructor
* @param name Name
* @param dataType Data type
*/
public Column(String name, DataType dataType) {
this.name = name;
this.dataType = dataType;
this.updateFormat();
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get name
* @return Name
*/
public String getName(){
return this.name;
}
/**
* Set name
* @param value Name
*/
public void setName(String value){
this.name = value;
}
/**
* Get data type
* @return Data type
*/
public DataType getDataType(){
return this.dataType;
}
/**
* Set data type
* @param value Data type
*/
public void setDataType(DataType value) {
this.dataType = value;
}
/**
* Get format
* @return Format
*/
public String getFormat(){
return this.format;
}
/**
* Get Name format
* @return
*/
public String getNameFormat() {
return "%" + String.valueOf(this.formatLen) + "s";
}
/**
* Set format
* @param value Format
*/
public void setFormat(String value){
this.format = value;
}
/**
* Get format length
* @return Format length
*/
public int getFormatLen(){
return this.formatLen;
}
/**
* Set format length
* @param value Format length
*/
public void setFormatLen(int value) {
this.formatLen = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Factory method
* @param name Name
* @param dtype Data type
* @return Column
*/
public static Column factory(String name, DataType dtype){
return new Column(name, dtype);
}
/**
* Factory method
* @param name Name
* @param array Data array
* @return Column
*/
public static Column factory(String name, Array array){
DataType dtype = array.getDataType();
if (dtype == DataType.OBJECT && (array.getObject(0) instanceof DateTime)){
DateTimeColumn col = new DateTimeColumn(name);
col.updateFormat(array);
return col;
}
return new Column(name, dtype);
}
/**
* Update format
*/
public void updateFormat(){
this.format = null;
switch (this.dataType){
case FLOAT:
case DOUBLE:
this.format = "%f";
break;
}
this.formatLen = this.name.length();
}
/**
* Update format
* @param data Data array
*/
public void updateFormat(Array data) {
this.formatLen = this.name.length();
switch(this.dataType) {
case DOUBLE:
case FLOAT:
double dmax = ArrayMath.max(data).doubleValue();
DecimalFormat df = new DecimalFormat("0.0");
df.setMaximumFractionDigits(6);
int nf = 1, ci, nn;
String str;
for (int i = 0; i < data.getSize(); i++){
str = df.format(data.getDouble(i));
ci = str.indexOf(".");
nn = str.length() - ci - 1;
if (nf < nn) {
nf = nn;
if (nf == 6)
break;
}
}
String smax = df.format(dmax);
ci = smax.indexOf(".");
int len = ci + nf + 2;
formatLen = Math.max(formatLen, len);
this.format = "%" + String.valueOf(formatLen) + "." + String.valueOf(nf) + "f";
break;
case INT:
int imax = (int)ArrayMath.max(data);
smax = Integer.toString(imax);
formatLen = Math.max(formatLen, smax.length());
this.format = "%" + String.valueOf(formatLen) + "d";
break;
default:
String v;
for (int i = 0; i < data.getSize(); i++){
if (data.getObject(i) == null)
v = "null";
else
v = data.getObject(i).toString();
if (formatLen < v.length())
formatLen = v.length();
}
this.format = "%" + String.valueOf(formatLen) + "s";
break;
}
}
/**
* Convert input data to current data type
*
* @param value Object value
* @return Result object
*/
public Object convertTo(Object value) {
return DataConvert.convertTo(value, this.dataType, this.format);
}
/**
* Convert input data to current data type
* @param s Input string
* @return Result object
*/
public Object convertStringTo(String s) {
return DataConvert.convertStringTo(s, dataType, format);
}
@Override
public String toString(){
return this.name;
}
/**
* Convert an object (same datatype with this column) to string
* @param o
* @return String
*/
public String toString(Object o){
if (format == null)
return o.toString();
else
return String.format(format, o);
}
/**
*
* @return Column
*/
@Override
public Object clone() {
Column col = new Column(this.name, this.dataType);
col.setFormat(this.format);
col.setFormatLen(this.formatLen);
return col;
}
// </editor-fold>
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data.dataframe;
import java.text.DecimalFormat;
import org.joda.time.DateTime;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;
/**
*
* @author Yaqiang Wang
*/
public class Column {
// <editor-fold desc="Variables">
protected String name;
protected DataType dataType;
protected String format;
protected int formatLen;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public Column(){
this("Column", DataType.OBJECT);
}
/**
* Constructor
* @param name Name
*/
public Column(String name){
this(name, DataType.OBJECT);
}
/**
* Constructor
* @param name Name
* @param dataType Data type
*/
public Column(String name, DataType dataType) {
this.name = name;
this.dataType = dataType;
this.updateFormat();
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get name
* @return Name
*/
public String getName(){
return this.name;
}
/**
* Set name
* @param value Name
*/
public void setName(String value){
this.name = value;
}
/**
* Get data type
* @return Data type
*/
public DataType getDataType(){
return this.dataType;
}
/**
* Set data type
* @param value Data type
*/
public void setDataType(DataType value) {
this.dataType = value;
}
/**
* Get format
* @return Format
*/
public String getFormat(){
return this.format;
}
/**
* Get Name format
* @return
*/
public String getNameFormat() {
return "%" + String.valueOf(this.formatLen) + "s";
}
/**
* Set format
* @param value Format
*/
public void setFormat(String value){
this.format = value;
}
/**
* Get format length
* @return Format length
*/
public int getFormatLen(){
return this.formatLen;
}
/**
* Set format length
* @param value Format length
*/
public void setFormatLen(int value) {
this.formatLen = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Factory method
* @param name Name
* @param dtype Data type
* @return Column
*/
public static Column factory(String name, DataType dtype){
return new Column(name, dtype);
}
/**
* Factory method
* @param name Name
* @param array Data array
* @return Column
*/
public static Column factory(String name, Array array){
DataType dtype = array.getDataType();
if (dtype == DataType.OBJECT && (array.getObject(0) instanceof DateTime)){
DateTimeColumn col = new DateTimeColumn(name);
col.updateFormat(array);
return col;
}
return new Column(name, dtype);
}
/**
* Update format
*/
public void updateFormat(){
this.format = null;
switch (this.dataType){
case FLOAT:
case DOUBLE:
this.format = "%f";
break;
}
this.formatLen = this.name.length();
}
/**
* Update format
* @param data Data array
*/
public void updateFormat(Array data) {
this.formatLen = this.name.length();
switch(this.dataType) {
case DOUBLE:
case FLOAT:
double dmax = ArrayMath.max(data).doubleValue();
DecimalFormat df = new DecimalFormat("0.0");
df.setMaximumFractionDigits(6);
int nf = 1, ci, nn;
String str;
for (int i = 0; i < data.getSize(); i++){
str = df.format(data.getDouble(i));
ci = str.indexOf(".");
nn = str.length() - ci - 1;
if (nf < nn) {
nf = nn;
if (nf == 6)
break;
}
}
String smax = df.format(dmax);
ci = smax.indexOf(".");
int len = ci + nf + 2;
formatLen = Math.max(formatLen, len);
this.format = "%" + String.valueOf(formatLen) + "." + String.valueOf(nf) + "f";
break;
case INT:
int imax = (int)ArrayMath.max(data);
smax = Integer.toString(imax);
formatLen = Math.max(formatLen, smax.length());
this.format = "%" + String.valueOf(formatLen) + "d";
break;
default:
String v;
for (int i = 0; i < data.getSize(); i++){
if (data.getObject(i) == null)
v = "null";
else
v = data.getObject(i).toString();
if (formatLen < v.length())
formatLen = v.length();
}
this.format = "%" + String.valueOf(formatLen) + "s";
break;
}
}
/**
* Convert input data to current data type
*
* @param value Object value
* @return Result object
*/
public Object convertTo(Object value) {
return DataConvert.convertTo(value, this.dataType, this.format);
}
/**
* Convert input data to current data type
* @param s Input string
* @return Result object
*/
public Object convertStringTo(String s) {
return DataConvert.convertStringTo(s, dataType, format);
}
@Override
public String toString(){
return this.name;
}
/**
* Convert an object (same datatype with this column) to string
* @param o
* @return String
*/
public String toString(Object o){
if (format == null)
return o.toString();
else
return String.format(format, o);
}
/**
*
* @return Column
*/
@Override
public Object clone() {
Column col = new Column(this.name, this.dataType);
col.setFormat(this.format);
col.setFormatLen(this.formatLen);
return col;
}
// </editor-fold>
}

View File

@ -28,9 +28,9 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.global.util.JDateUtil;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.math.ArrayUtil;
import org.meteoinfo.common.util.GlobalUtil;
import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.common.util.TypeUtils;
import org.meteoinfo.data.dataframe.impl.Aggregation;
import org.meteoinfo.data.dataframe.impl.Function;
import org.meteoinfo.data.dataframe.impl.Grouping;
@ -40,8 +40,8 @@ import org.meteoinfo.data.dataframe.impl.Sorting;
import org.meteoinfo.data.dataframe.impl.Views;
import org.meteoinfo.data.dataframe.impl.WindowFunction;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.global.util.GlobalUtil;
import org.meteoinfo.global.util.TypeUtils;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.math.ArrayUtil;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.InvalidRangeException;
import org.meteoinfo.ndarray.Range;

View File

@ -13,11 +13,11 @@ import java.util.List;
import java.time.LocalDateTime;
import java.time.temporal.TemporalAmount;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.global.util.JDateUtil;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.math.ArrayMath;
/**
*

View File

@ -10,8 +10,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;

View File

@ -15,14 +15,15 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import org.meteoinfo.global.util.JDateUtil;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.data.dataframe.impl.Grouping;
import org.meteoinfo.data.dataframe.impl.KeyFunction;
import org.meteoinfo.data.dataframe.impl.TimeFunction;
import org.meteoinfo.data.dataframe.impl.TimeFunctions;
import org.meteoinfo.data.dataframe.impl.Views;
import org.meteoinfo.data.dataframe.impl.WindowFunction;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.ndarray.InvalidRangeException;

View File

@ -26,10 +26,11 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.meteoinfo.math.ArrayUtil;
import org.meteoinfo.data.dataframe.DataFrame;
import org.meteoinfo.data.dataframe.Series;
import org.meteoinfo.data.dataframe.impl.Transforms.CumulativeFunction;
import org.meteoinfo.math.ArrayUtil;
import org.meteoinfo.ndarray.Array;
public class Grouping

View File

@ -5,7 +5,7 @@
*/
package org.meteoinfo.data.dataframe.impl;
import org.meteoinfo.global.util.JDateUtil;
import org.meteoinfo.common.util.JDateUtil;
import java.time.LocalDateTime;
import java.time.Period;

View File

@ -17,7 +17,7 @@ import org.meteoinfo.table.DataColumn;
import org.meteoinfo.table.DataRow;
import org.meteoinfo.table.DataTable;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.io.EndianDataOutputStream;
import org.meteoinfo.common.io.EndianDataOutputStream;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;

View File

@ -13,13 +13,13 @@
*/
package org.meteoinfo.data.mapdata;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.PointD;
import org.meteoinfo.common.util.GlobalUtil;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.mapdata.geotiff.GeoTiff;
import org.meteoinfo.data.meteodata.DrawMeteoData;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.util.GlobalUtil;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.global.PointD;
import org.meteoinfo.geoprocess.GeometryUtil;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.layer.ImageLayer;
import org.meteoinfo.layer.LayerDrawType;
@ -53,7 +53,7 @@ import org.meteoinfo.data.meteodata.ascii.ASCIIGridDataInfo;
import org.meteoinfo.data.meteodata.ascii.SurferGridDataInfo;
import org.meteoinfo.data.meteodata.bandraster.BILDataInfo;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.io.IOUtil;
import org.meteoinfo.common.io.IOUtil;
import org.meteoinfo.layer.RasterLayer;
import org.meteoinfo.legend.LegendScheme;
import org.meteoinfo.legend.LegendType;
@ -293,7 +293,7 @@ public class MapDataManage {
PolylineShape aPolyline = new PolylineShape();
aPolyline.setValue(lineNum);
aPolyline.setPoints(pList);
aPolyline.setExtent(MIMath.getPointsExtent(pList));
aPolyline.setExtent(GeometryUtil.getPointsExtent(pList));
aPolyline.setPartNum(1);
aPolyline.parts = new int[1];
aPolyline.parts[0] = 0;
@ -521,7 +521,7 @@ public class MapDataManage {
}
PolylineShape aPLS = new PolylineShape();
aPLS.setValue(i);
aPLS.setExtent(MIMath.getPointsExtent(pList));
aPLS.setExtent(GeometryUtil.getPointsExtent(pList));
aPLS.setPoints(pList);
int sNum = aLayer.getShapeNum();
@ -554,7 +554,7 @@ public class MapDataManage {
PolygonShape aPGS = new PolygonShape();
aPGS.lowValue = i;
aPGS.highValue = i;
aPGS.setExtent(MIMath.getPointsExtent(pList));
aPGS.setExtent(GeometryUtil.getPointsExtent(pList));
aPGS.setPoints(pList);
int sNum = aLayer.getShapeNum();

View File

@ -28,12 +28,13 @@ import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.data.GridArray;
import org.meteoinfo.data.mapdata.geotiff.compression.CompressionDecoder;
import org.meteoinfo.data.mapdata.geotiff.compression.DeflateCompression;
import org.meteoinfo.data.mapdata.geotiff.compression.LZWCompression;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.ndarray.util.BigDecimalUtil;
import org.meteoinfo.projection.KnownCoordinateSystems;
import org.meteoinfo.projection.info.ProjectionInfo;

View File

@ -1,452 +1,452 @@
package org.meteoinfo.data.mapdata.webmap;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import org.meteoinfo.global.util.GeoUtil;
import org.meteoinfo.global.util.GraphicsUtilities;
/**
* The
* <code>AbstractTileFactory</code> provides a basic implementation for the
* TileFactory.
*/
public abstract class AbstractTileFactory extends TileFactory {
private static final Logger LOG = Logger.getLogger(AbstractTileFactory.class.getName());
/**
* Creates a new instance of DefaultTileFactory using the spcified
* TileFactoryInfo
*
* @param info a TileFactoryInfo to configure this TileFactory
*/
public AbstractTileFactory(TileFactoryInfo info) {
super(info);
}
//private static final boolean doEagerLoading = true;
private int threadPoolSize = 4;
private ExecutorService service;
//TODO the tile map should be static ALWAYS, regardless of the number
//of GoogleTileFactories because each tile is, really, a singleton.
private final Map<String, Tile> tileMap = new HashMap<>();
private TileCache cache = new TileCache();
/**
* Returns
*
* @param pixelCoordinate
* @return
*/
//public TilePoint getTileCoordinate(Point2D pixelCoordinate) {
// return GeoUtil.getTileCoordinate(pixelCoordinate, getInfo());
//}
/**
* Returns the tile that is located at the given tilePoint for this zoom.
* For example, if getMapSize() returns 10x20 for this zoom, and the
* tilePoint is (3,5), then the appropriate tile will be located and
* returned.
*
* @param x X index
* @param y Y index
* @param zoom Zoom value
* @return Tile
*/
@Override
public Tile getTile(int x, int y, int zoom) {
return getTile(x, y, zoom, true);
}
private Tile getTile(int tpx, int tpy, int zoom, boolean eagerLoad) {
//wrap the tiles horizontally --> mod the X with the max width
//and use that
int tileX = tpx;//tilePoint.getX();
int numTilesWide = (int) getMapSize(zoom).getWidth();
if (tileX < 0) {
tileX = numTilesWide - (Math.abs(tileX) % numTilesWide);
}
tileX = tileX % numTilesWide;
int tileY = tpy;
//TilePoint tilePoint = new TilePoint(tileX, tpy);
String url = getInfo().getTileUrl(tileX, tileY, zoom);//tilePoint);
//System.out.println("loading: " + url);
Tile.Priority pri = Tile.Priority.High;
if (!eagerLoad) {
pri = Tile.Priority.Low;
}
Tile tile = null;
//System.out.println("testing for validity: " + tilePoint + " zoom = " + zoom);
if (!tileMap.containsKey(url)) {
if (!GeoUtil.isValidTile(tileX, tileY, zoom, getInfo())) {
tile = new Tile(tileX, tileY, zoom);
} else {
tile = new Tile(tileX, tileY, zoom, url, pri, this);
//load(tile);
startLoading(tile);
}
tileMap.put(url, tile);
} else {
tile = tileMap.get(url);
// if its in the map but is low and isn't loaded yet
// but we are in high mode
if (tile.getPriority() == Tile.Priority.Low && eagerLoad && !tile.isLoaded()) {
//System.out.println("in high mode and want a low");
//tile.promote();
promote(tile);
}
}
/*
if (eagerLoad && doEagerLoading) {
for (int i = 0; i<1; i++) {
for (int j = 0; j<1; j++) {
// preload the 4 tiles under the current one
if(zoom > 0) {
eagerlyLoad(tilePoint.getX()*2, tilePoint.getY()*2, zoom-1);
eagerlyLoad(tilePoint.getX()*2+1, tilePoint.getY()*2, zoom-1);
eagerlyLoad(tilePoint.getX()*2, tilePoint.getY()*2+1, zoom-1);
eagerlyLoad(tilePoint.getX()*2+1, tilePoint.getY()*2+1, zoom-1);
}
}
}
}*/
return tile;
}
/*
private void eagerlyLoad(int x, int y, int zoom) {
TilePoint t1 = new TilePoint(x,y);
if(!isLoaded(t1,zoom)) {
getTile(t1,zoom,false);
}
}
*/
// private boolean isLoaded(int x, int y, int zoom) {
// String url = getInfo().getTileUrl(zoom,x,y);
// return tileMap.containsKey(url);
// }
public TileCache getTileCache() {
return cache;
}
public void setTileCache(TileCache cache) {
this.cache = cache;
}
/**
* ==== threaded tile loading stuff ===
*/
/**
* Thread pool for loading the tiles
*/
private static final BlockingQueue<Tile> tileQueue = new PriorityBlockingQueue<>(5,
new Comparator<Tile>() {
@Override
public int compare(Tile o1, Tile o2) {
if (o1.getPriority() == Tile.Priority.Low && o2.getPriority() == Tile.Priority.High) {
return 1;
}
if (o1.getPriority() == Tile.Priority.High && o2.getPriority() == Tile.Priority.Low) {
return -1;
}
return 0;
}
@Override
public boolean equals(Object obj) {
return obj == this;
}
});
/**
* Subclasses may override this method to provide their own executor
* services. This method will be called each time a tile needs to be loaded.
* Implementations should cache the ExecutorService when possible.
*
* @return ExecutorService to load tiles with
*/
protected synchronized ExecutorService getService() {
if (service == null) {
//System.out.println("creating an executor service with a threadpool of size " + threadPoolSize);
service = Executors.newFixedThreadPool(threadPoolSize, new ThreadFactory() {
private int count = 0;
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r, "tile-pool-" + count++);
t.setPriority(Thread.MIN_PRIORITY);
t.setDaemon(true);
return t;
}
});
}
return service;
}
/**
* Set the number of threads to use for loading the tiles. This controls the
* number of threads used by the ExecutorService returned from getService().
* Note, this method should be called before loading the first tile. Calls
* after the first tile are loaded will have no effect by default.
*
* @param size
*/
public void setThreadPoolSize(int size) {
if (size <= 0) {
throw new IllegalArgumentException("size invalid: " + size + ". The size of the threadpool must be greater than 0.");
}
threadPoolSize = size;
}
@SuppressWarnings("unchecked")
@Override
protected synchronized void startLoading(Tile tile) {
if (tile.isLoading()) {
System.out.println("already loading. bailing");
return;
}
tile.setLoading(true);
try {
tileQueue.put(tile);
getService().submit(createTileRunner(tile));
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public void load(Tile tile) {
/*
* 3 strikes and you're out. Attempt to load the url. If it fails,
* decrement the number of tries left and try again. Log failures.
* If I run out of try s just get out. This way, if there is some
* kind of serious failure, I can get out and let other tiles
* try to load.
*/
//final Tile tile = tileQueue.remove();
int trys = 3;
while (!tile.isLoaded() && trys > 0) {
try {
BufferedImage img = null;
URI uri = getURI(tile);
img = cache.get(uri);
if (img == null) {
byte[] bimg = cacheInputStream(uri.toURL());
img = GraphicsUtilities.loadCompatibleImage(new ByteArrayInputStream(bimg));//ImageIO.read(new URL(tile.url));
cache.put(uri, bimg, img);
img = cache.get(uri);
}
if (img == null) {
System.out.println("error loading: " + uri);
LOG.log(Level.INFO, "Failed to load: " + uri);
trys--;
} else {
final BufferedImage i = img;
tile.image = new SoftReference<>(i);
tile.setLoaded(true);
}
} catch (OutOfMemoryError memErr) {
cache.needMoreMemory();
} catch (Throwable e) {
LOG.log(Level.SEVERE,
"Failed to load a tile at url: " + tile.getURL() + ", retrying", e);
//temp
System.err.println("Failed to load a tile at url: " + tile.getURL());
e.printStackTrace();
///temp
Object oldError = tile.getError();
tile.setError(e);
tile.firePropertyChangeOnEDT("loadingError", oldError, e);
if (trys == 0) {
tile.firePropertyChangeOnEDT("unrecoverableError", null, e);
} else {
trys--;
}
}
}
tile.setLoading(false);
}
/**
* Gets the full URI of a tile.
*
* @param tile
* @throws java.net.URISyntaxException
* @return URI
*/
protected URI getURI(Tile tile) throws URISyntaxException {
if (tile.getURL() == null) {
return null;
}
return new URI(tile.getURL());
}
private byte[] cacheInputStream(URL url) throws IOException {
InputStream ins = url.openStream();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] buf = new byte[256];
while (true) {
int n = ins.read(buf);
if (n == -1) {
break;
}
bout.write(buf, 0, n);
}
return bout.toByteArray();
}
/**
* Subclasses can override this if they need custom TileRunners for some
* reason
*
* @param tile Tile
* @return Runnable
*/
protected Runnable createTileRunner(Tile tile) {
return new TileRunner();
}
/**
* Increase the priority of this tile so it will be loaded sooner.
* @param tile Tile
*/
public synchronized void promote(Tile tile) {
if (tileQueue.contains(tile)) {
try {
tileQueue.remove(tile);
tile.setPriority(Tile.Priority.High);
tileQueue.put(tile);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
/**
* An inner class which actually loads the tiles. Used by the thread queue.
* Subclasses can override this if necessary.
*/
private class TileRunner implements Runnable {
//private Tile tile;
//private BlockingQueue<Tile> tileQueue;
//public TileRunner(BlockingQueue<Tile> tileQueue) {
//this.tileQueue = tileQueue;
//this.tile = tile;
//}
/**
* Gets the full URI of a tile.
*
* @param tile
* @throws java.net.URISyntaxException
* @return
*/
protected URI getURI(Tile tile) throws URISyntaxException {
if (tile.getURL() == null) {
return null;
}
return new URI(tile.getURL());
}
/**
* implementation of the Runnable interface.
*/
@Override
public void run() {
/*
* 3 strikes and you're out. Attempt to load the url. If it fails,
* decrement the number of tries left and try again. Log failures.
* If I run out of try s just get out. This way, if there is some
* kind of serious failure, I can get out and let other tiles
* try to load.
*/
final Tile tile = tileQueue.remove();
int trys = 3;
while (!tile.isLoaded() && trys > 0) {
try {
BufferedImage img = null;
URI uri = getURI(tile);
img = cache.get(uri);
if (img == null) {
byte[] bimg = cacheInputStream(uri.toURL());
img = GraphicsUtilities.loadCompatibleImage(new ByteArrayInputStream(bimg));//ImageIO.read(new URL(tile.url));
cache.put(uri, bimg, img);
img = cache.get(uri);
}
if (img == null) {
System.out.println("error loading: " + uri);
LOG.log(Level.INFO, "Failed to load: " + uri);
trys--;
} else {
final BufferedImage i = img;
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
tile.image = new SoftReference<>(i);
tile.setLoaded(true);
}
});
}
} catch (OutOfMemoryError memErr) {
cache.needMoreMemory();
} catch (Throwable e) {
LOG.log(Level.SEVERE,
"Failed to load a tile at url: " + tile.getURL() + ", retrying", e);
//temp
System.err.println("Failed to load a tile at url: " + tile.getURL());
e.printStackTrace();
///temp
Object oldError = tile.getError();
tile.setError(e);
tile.firePropertyChangeOnEDT("loadingError", oldError, e);
if (trys == 0) {
tile.firePropertyChangeOnEDT("unrecoverableError", null, e);
} else {
trys--;
}
}
}
tile.setLoading(false);
}
private byte[] cacheInputStream(URL url) throws IOException {
InputStream ins = url.openStream();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] buf = new byte[256];
while (true) {
int n = ins.read(buf);
if (n == -1) {
break;
}
bout.write(buf, 0, n);
}
return bout.toByteArray();
}
}
}
package org.meteoinfo.data.mapdata.webmap;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import org.meteoinfo.common.util.GraphicsUtilities;
import org.meteoinfo.global.util.GeoUtil;
/**
* The
* <code>AbstractTileFactory</code> provides a basic implementation for the
* TileFactory.
*/
public abstract class AbstractTileFactory extends TileFactory {
private static final Logger LOG = Logger.getLogger(AbstractTileFactory.class.getName());
/**
* Creates a new instance of DefaultTileFactory using the spcified
* TileFactoryInfo
*
* @param info a TileFactoryInfo to configure this TileFactory
*/
public AbstractTileFactory(TileFactoryInfo info) {
super(info);
}
//private static final boolean doEagerLoading = true;
private int threadPoolSize = 4;
private ExecutorService service;
//TODO the tile map should be static ALWAYS, regardless of the number
//of GoogleTileFactories because each tile is, really, a singleton.
private final Map<String, Tile> tileMap = new HashMap<>();
private TileCache cache = new TileCache();
/**
* Returns
*
* @param pixelCoordinate
* @return
*/
//public TilePoint getTileCoordinate(Point2D pixelCoordinate) {
// return GeoUtil.getTileCoordinate(pixelCoordinate, getInfo());
//}
/**
* Returns the tile that is located at the given tilePoint for this zoom.
* For example, if getMapSize() returns 10x20 for this zoom, and the
* tilePoint is (3,5), then the appropriate tile will be located and
* returned.
*
* @param x X index
* @param y Y index
* @param zoom Zoom value
* @return Tile
*/
@Override
public Tile getTile(int x, int y, int zoom) {
return getTile(x, y, zoom, true);
}
private Tile getTile(int tpx, int tpy, int zoom, boolean eagerLoad) {
//wrap the tiles horizontally --> mod the X with the max width
//and use that
int tileX = tpx;//tilePoint.getX();
int numTilesWide = (int) getMapSize(zoom).getWidth();
if (tileX < 0) {
tileX = numTilesWide - (Math.abs(tileX) % numTilesWide);
}
tileX = tileX % numTilesWide;
int tileY = tpy;
//TilePoint tilePoint = new TilePoint(tileX, tpy);
String url = getInfo().getTileUrl(tileX, tileY, zoom);//tilePoint);
//System.out.println("loading: " + url);
Tile.Priority pri = Tile.Priority.High;
if (!eagerLoad) {
pri = Tile.Priority.Low;
}
Tile tile = null;
//System.out.println("testing for validity: " + tilePoint + " zoom = " + zoom);
if (!tileMap.containsKey(url)) {
if (!GeoUtil.isValidTile(tileX, tileY, zoom, getInfo())) {
tile = new Tile(tileX, tileY, zoom);
} else {
tile = new Tile(tileX, tileY, zoom, url, pri, this);
//load(tile);
startLoading(tile);
}
tileMap.put(url, tile);
} else {
tile = tileMap.get(url);
// if its in the map but is low and isn't loaded yet
// but we are in high mode
if (tile.getPriority() == Tile.Priority.Low && eagerLoad && !tile.isLoaded()) {
//System.out.println("in high mode and want a low");
//tile.promote();
promote(tile);
}
}
/*
if (eagerLoad && doEagerLoading) {
for (int i = 0; i<1; i++) {
for (int j = 0; j<1; j++) {
// preload the 4 tiles under the current one
if(zoom > 0) {
eagerlyLoad(tilePoint.getX()*2, tilePoint.getY()*2, zoom-1);
eagerlyLoad(tilePoint.getX()*2+1, tilePoint.getY()*2, zoom-1);
eagerlyLoad(tilePoint.getX()*2, tilePoint.getY()*2+1, zoom-1);
eagerlyLoad(tilePoint.getX()*2+1, tilePoint.getY()*2+1, zoom-1);
}
}
}
}*/
return tile;
}
/*
private void eagerlyLoad(int x, int y, int zoom) {
TilePoint t1 = new TilePoint(x,y);
if(!isLoaded(t1,zoom)) {
getTile(t1,zoom,false);
}
}
*/
// private boolean isLoaded(int x, int y, int zoom) {
// String url = getInfo().getTileUrl(zoom,x,y);
// return tileMap.containsKey(url);
// }
public TileCache getTileCache() {
return cache;
}
public void setTileCache(TileCache cache) {
this.cache = cache;
}
/**
* ==== threaded tile loading stuff ===
*/
/**
* Thread pool for loading the tiles
*/
private static final BlockingQueue<Tile> tileQueue = new PriorityBlockingQueue<>(5,
new Comparator<Tile>() {
@Override
public int compare(Tile o1, Tile o2) {
if (o1.getPriority() == Tile.Priority.Low && o2.getPriority() == Tile.Priority.High) {
return 1;
}
if (o1.getPriority() == Tile.Priority.High && o2.getPriority() == Tile.Priority.Low) {
return -1;
}
return 0;
}
@Override
public boolean equals(Object obj) {
return obj == this;
}
});
/**
* Subclasses may override this method to provide their own executor
* services. This method will be called each time a tile needs to be loaded.
* Implementations should cache the ExecutorService when possible.
*
* @return ExecutorService to load tiles with
*/
protected synchronized ExecutorService getService() {
if (service == null) {
//System.out.println("creating an executor service with a threadpool of size " + threadPoolSize);
service = Executors.newFixedThreadPool(threadPoolSize, new ThreadFactory() {
private int count = 0;
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r, "tile-pool-" + count++);
t.setPriority(Thread.MIN_PRIORITY);
t.setDaemon(true);
return t;
}
});
}
return service;
}
/**
* Set the number of threads to use for loading the tiles. This controls the
* number of threads used by the ExecutorService returned from getService().
* Note, this method should be called before loading the first tile. Calls
* after the first tile are loaded will have no effect by default.
*
* @param size
*/
public void setThreadPoolSize(int size) {
if (size <= 0) {
throw new IllegalArgumentException("size invalid: " + size + ". The size of the threadpool must be greater than 0.");
}
threadPoolSize = size;
}
@SuppressWarnings("unchecked")
@Override
protected synchronized void startLoading(Tile tile) {
if (tile.isLoading()) {
System.out.println("already loading. bailing");
return;
}
tile.setLoading(true);
try {
tileQueue.put(tile);
getService().submit(createTileRunner(tile));
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public void load(Tile tile) {
/*
* 3 strikes and you're out. Attempt to load the url. If it fails,
* decrement the number of tries left and try again. Log failures.
* If I run out of try s just get out. This way, if there is some
* kind of serious failure, I can get out and let other tiles
* try to load.
*/
//final Tile tile = tileQueue.remove();
int trys = 3;
while (!tile.isLoaded() && trys > 0) {
try {
BufferedImage img = null;
URI uri = getURI(tile);
img = cache.get(uri);
if (img == null) {
byte[] bimg = cacheInputStream(uri.toURL());
img = GraphicsUtilities.loadCompatibleImage(new ByteArrayInputStream(bimg));//ImageIO.read(new URL(tile.url));
cache.put(uri, bimg, img);
img = cache.get(uri);
}
if (img == null) {
System.out.println("error loading: " + uri);
LOG.log(Level.INFO, "Failed to load: " + uri);
trys--;
} else {
final BufferedImage i = img;
tile.image = new SoftReference<>(i);
tile.setLoaded(true);
}
} catch (OutOfMemoryError memErr) {
cache.needMoreMemory();
} catch (Throwable e) {
LOG.log(Level.SEVERE,
"Failed to load a tile at url: " + tile.getURL() + ", retrying", e);
//temp
System.err.println("Failed to load a tile at url: " + tile.getURL());
e.printStackTrace();
///temp
Object oldError = tile.getError();
tile.setError(e);
tile.firePropertyChangeOnEDT("loadingError", oldError, e);
if (trys == 0) {
tile.firePropertyChangeOnEDT("unrecoverableError", null, e);
} else {
trys--;
}
}
}
tile.setLoading(false);
}
/**
* Gets the full URI of a tile.
*
* @param tile
* @throws java.net.URISyntaxException
* @return URI
*/
protected URI getURI(Tile tile) throws URISyntaxException {
if (tile.getURL() == null) {
return null;
}
return new URI(tile.getURL());
}
private byte[] cacheInputStream(URL url) throws IOException {
InputStream ins = url.openStream();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] buf = new byte[256];
while (true) {
int n = ins.read(buf);
if (n == -1) {
break;
}
bout.write(buf, 0, n);
}
return bout.toByteArray();
}
/**
* Subclasses can override this if they need custom TileRunners for some
* reason
*
* @param tile Tile
* @return Runnable
*/
protected Runnable createTileRunner(Tile tile) {
return new TileRunner();
}
/**
* Increase the priority of this tile so it will be loaded sooner.
* @param tile Tile
*/
public synchronized void promote(Tile tile) {
if (tileQueue.contains(tile)) {
try {
tileQueue.remove(tile);
tile.setPriority(Tile.Priority.High);
tileQueue.put(tile);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
/**
* An inner class which actually loads the tiles. Used by the thread queue.
* Subclasses can override this if necessary.
*/
private class TileRunner implements Runnable {
//private Tile tile;
//private BlockingQueue<Tile> tileQueue;
//public TileRunner(BlockingQueue<Tile> tileQueue) {
//this.tileQueue = tileQueue;
//this.tile = tile;
//}
/**
* Gets the full URI of a tile.
*
* @param tile
* @throws java.net.URISyntaxException
* @return
*/
protected URI getURI(Tile tile) throws URISyntaxException {
if (tile.getURL() == null) {
return null;
}
return new URI(tile.getURL());
}
/**
* implementation of the Runnable interface.
*/
@Override
public void run() {
/*
* 3 strikes and you're out. Attempt to load the url. If it fails,
* decrement the number of tries left and try again. Log failures.
* If I run out of try s just get out. This way, if there is some
* kind of serious failure, I can get out and let other tiles
* try to load.
*/
final Tile tile = tileQueue.remove();
int trys = 3;
while (!tile.isLoaded() && trys > 0) {
try {
BufferedImage img = null;
URI uri = getURI(tile);
img = cache.get(uri);
if (img == null) {
byte[] bimg = cacheInputStream(uri.toURL());
img = GraphicsUtilities.loadCompatibleImage(new ByteArrayInputStream(bimg));//ImageIO.read(new URL(tile.url));
cache.put(uri, bimg, img);
img = cache.get(uri);
}
if (img == null) {
System.out.println("error loading: " + uri);
LOG.log(Level.INFO, "Failed to load: " + uri);
trys--;
} else {
final BufferedImage i = img;
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
tile.image = new SoftReference<>(i);
tile.setLoaded(true);
}
});
}
} catch (OutOfMemoryError memErr) {
cache.needMoreMemory();
} catch (Throwable e) {
LOG.log(Level.SEVERE,
"Failed to load a tile at url: " + tile.getURL() + ", retrying", e);
//temp
System.err.println("Failed to load a tile at url: " + tile.getURL());
e.printStackTrace();
///temp
Object oldError = tile.getError();
tile.setError(e);
tile.firePropertyChangeOnEDT("loadingError", oldError, e);
if (trys == 0) {
tile.firePropertyChangeOnEDT("unrecoverableError", null, e);
} else {
trys--;
}
}
}
tile.setLoading(false);
}
private byte[] cacheInputStream(URL url) throws IOException {
InputStream ins = url.openStream();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] buf = new byte[256];
while (true) {
int n = ins.read(buf);
if (n == -1) {
break;
}
bout.write(buf, 0, n);
}
return bout.toByteArray();
}
}
}

View File

@ -1,331 +1,330 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data.mathparser;
import java.beans.Expression;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Stack;
import org.meteoinfo.data.meteodata.MeteoDataInfo;
import org.meteoinfo.global.MIMath;
/**
*
* @author yaqiang
*/
public class MathParser {
// <editor-fold desc="Variables">
private boolean _isGridData;
private StringBuilder _buffer = new StringBuilder();
private Stack<String> _symbolStack = new Stack<String>();
private Queue<IExpression> _expressionQueue = new LinkedList<IExpression>();
private Map<String, IExpression> _expressionCache = new HashMap<String, IExpression>();
private Stack<Object> _calculationStack = new Stack<Object>();
private Stack<Object> _parameters = new Stack<Object>();
private List<String> _variables = new ArrayList<String>();
private StringReader _expressionReader;
private MeteoDataInfo _meteoDataInfo = null;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public MathParser() {
}
/**
* Constructor
*
* @param aDataInfo MeteoDataInfo
*/
public MathParser(MeteoDataInfo aDataInfo) {
_meteoDataInfo = aDataInfo;
_isGridData = aDataInfo.isGridData();
_variables = aDataInfo.getDataInfo().getVariableNames();
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Evaluates the specified expression
*
* @param expression The expression to evaluate
* @return The evaluated result
*/
public Object evaluate(String expression) throws ParseException, IOException {
if (expression == null || expression.isEmpty()) {
throw new java.lang.IllegalArgumentException("expression");
}
_expressionReader = new StringReader(expression);
_symbolStack.clear();
_expressionQueue.clear();
parseExpressionToQueue();
Object result = calculateFromQueue();
//_variables[AnswerVariable] = result;
return result;
}
private void parseExpressionToQueue() throws ParseException, IOException {
int ic;
char c;
while ((ic = _expressionReader.read()) != -1) {
c = (char) ic;
if (Character.isWhitespace(c)) {
continue;
}
if (tryNumber(c)) {
continue;
}
if (tryString(c)) {
continue;
}
if (tryStartGroup(c)) {
continue;
}
if (tryOperator(c)) {
continue;
}
if (tryEndGroup(c)) {
continue;
}
//if (TryConvert(c))
// continue;
throw new ParseException("Invalid character encountered" + c);
}
processSymbolStack();
}
private boolean tryNumber(char c) throws IOException, ParseException {
boolean isNumber = NumberExpression.isNumber(c);
boolean isNegative = false;
if (NumberExpression.isNegativeSign(c)) {
if (_expressionQueue.size() == 0) {
isNegative = true;
} else if (_expressionQueue.size() > 0 && _symbolStack.size() > 0) {
if (((String) _symbolStack.peek()).equals("(")) {
isNegative = true;
}
}
}
if (!isNumber && !isNegative) {
return false;
}
_buffer.setLength(0);
_buffer.append(c);
_expressionReader.mark(1);
char p = (char) _expressionReader.read();
while (NumberExpression.isNumber(p)) {
_buffer.append(p);
_expressionReader.mark(1);
p = (char) _expressionReader.read();
}
_expressionReader.reset();
double value;
try {
value = Double.parseDouble(_buffer.toString());
} catch (Exception e) {
throw new ParseException("Invalid number format: " + _buffer);
}
NumberExpression expression = new NumberExpression(value);
_expressionQueue.offer(expression);
return true;
}
private boolean tryString(char c) throws IOException, ParseException {
if (!Character.isLetter(c)) {
return false;
}
_buffer.setLength(0);
_buffer.append(c);
_expressionReader.mark(1);
char p = (char) _expressionReader.read();
while (Character.isLetterOrDigit(p) || p == '_' || p == '@' || p == '.') {
_buffer.append(p);
_expressionReader.mark(1);
p = (char) _expressionReader.read();
}
_expressionReader.reset();
if (_variables.contains(_buffer.toString())) {
Object value = getVariableValue(_buffer.toString());
NumberExpression expression = new NumberExpression(value);
_expressionQueue.offer(expression);
return true;
}
if (FunctionExpression.isFunction(_buffer.toString())) {
_symbolStack.push(_buffer.toString());
return true;
}
throw new ParseException("Invalid variable: " + _buffer);
}
private boolean tryStartGroup(char c) {
if (c != '(') {
return false;
}
_symbolStack.push(String.valueOf(c));
return true;
}
private boolean tryOperator(char c) throws ParseException {
if (!OperatorExpression.isSymbol(c)) {
return false;
}
boolean repeat;
String s = String.valueOf(c);
do {
String p = _symbolStack.size() == 0 ? "" : _symbolStack.peek();
repeat = false;
if (_symbolStack.size() == 0) {
_symbolStack.push(s);
} else if (p.equals("(")) {
_symbolStack.push(s);
} else if (precedence(s) > precedence(p)) {
_symbolStack.push(s);
} else {
IExpression e = getExpressionFromSymbol(_symbolStack.pop());
_expressionQueue.offer(e);
repeat = true;
}
} while (repeat);
return true;
}
private boolean tryEndGroup(char c) throws ParseException {
if (c != ')') {
return false;
}
boolean ok = false;
while (_symbolStack.size() > 0) {
String p = _symbolStack.pop();
if (p.equals("(")) {
ok = true;
break;
}
IExpression e = getExpressionFromSymbol(p);
_expressionQueue.offer(e);
}
if (!ok) {
throw new ParseException("Unbalance parenthese");
}
return true;
}
private void processSymbolStack() throws ParseException {
while (_symbolStack.size() > 0) {
String p = _symbolStack.pop();
if (p.length() == 1 && p.equals("(")) {
throw new ParseException("Unbalance parenthese");
}
IExpression e = getExpressionFromSymbol(p);
_expressionQueue.offer(e);
}
}
private static int precedence(String c) {
String s = c.substring(0, 1);
if (c.length() == 1 && s.equals("*") || s.equals("/") || s.equals("%")) {
return 2;
}
return 1;
}
private IExpression getExpressionFromSymbol(String p) throws ParseException {
IExpression e;
if (_expressionCache.containsKey(p)) {
e = _expressionCache.get(p);
} else if (OperatorExpression.isSymbol(p)) {
e = new OperatorExpression(p);
_expressionCache.put(p, e);
} else if (FunctionExpression.isFunction(p)) {
e = new FunctionExpression(p, false);
_expressionCache.put(p, e);
} //else if (ConvertExpression.IsConvertExpression(p))
//{
// e = new ConvertExpression(p);
// _expressionCache.Add(p, e);
//}
else {
throw new ParseException("Invalid symbol on stack" + p);
}
return e;
}
private Object calculateFromQueue() throws ParseException {
Object result;
_calculationStack.clear();
for (IExpression expression : _expressionQueue) {
if (_calculationStack.size() < expression.getArgumentCount()) {
throw new ParseException("Not enough numbers" + expression);
}
_parameters.clear();
for (int i = 0; i < expression.getArgumentCount(); i++) {
_parameters.push(_calculationStack.pop());
}
Object[] parameters = _parameters.toArray();
MIMath.arrayReverse(parameters);
_calculationStack.push(expression.evaluate(parameters));
}
result = _calculationStack.pop();
return result;
}
private Object getVariableValue(String varName) {
if (_meteoDataInfo == null) {
return 100;
} else {
if (_isGridData) {
return _meteoDataInfo.getGridData(varName);
} else {
return _meteoDataInfo.getStationData(varName);
}
}
}
// </editor-fold>
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.meteoinfo.data.mathparser;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Stack;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.data.meteodata.MeteoDataInfo;
/**
*
* @author yaqiang
*/
public class MathParser {
// <editor-fold desc="Variables">
private boolean _isGridData;
private StringBuilder _buffer = new StringBuilder();
private Stack<String> _symbolStack = new Stack<String>();
private Queue<IExpression> _expressionQueue = new LinkedList<IExpression>();
private Map<String, IExpression> _expressionCache = new HashMap<String, IExpression>();
private Stack<Object> _calculationStack = new Stack<Object>();
private Stack<Object> _parameters = new Stack<Object>();
private List<String> _variables = new ArrayList<String>();
private StringReader _expressionReader;
private MeteoDataInfo _meteoDataInfo = null;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public MathParser() {
}
/**
* Constructor
*
* @param aDataInfo MeteoDataInfo
*/
public MathParser(MeteoDataInfo aDataInfo) {
_meteoDataInfo = aDataInfo;
_isGridData = aDataInfo.isGridData();
_variables = aDataInfo.getDataInfo().getVariableNames();
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Evaluates the specified expression
*
* @param expression The expression to evaluate
* @return The evaluated result
*/
public Object evaluate(String expression) throws ParseException, IOException {
if (expression == null || expression.isEmpty()) {
throw new java.lang.IllegalArgumentException("expression");
}
_expressionReader = new StringReader(expression);
_symbolStack.clear();
_expressionQueue.clear();
parseExpressionToQueue();
Object result = calculateFromQueue();
//_variables[AnswerVariable] = result;
return result;
}
private void parseExpressionToQueue() throws ParseException, IOException {
int ic;
char c;
while ((ic = _expressionReader.read()) != -1) {
c = (char) ic;
if (Character.isWhitespace(c)) {
continue;
}
if (tryNumber(c)) {
continue;
}
if (tryString(c)) {
continue;
}
if (tryStartGroup(c)) {
continue;
}
if (tryOperator(c)) {
continue;
}
if (tryEndGroup(c)) {
continue;
}
//if (TryConvert(c))
// continue;
throw new ParseException("Invalid character encountered" + c);
}
processSymbolStack();
}
private boolean tryNumber(char c) throws IOException, ParseException {
boolean isNumber = NumberExpression.isNumber(c);
boolean isNegative = false;
if (NumberExpression.isNegativeSign(c)) {
if (_expressionQueue.size() == 0) {
isNegative = true;
} else if (_expressionQueue.size() > 0 && _symbolStack.size() > 0) {
if (((String) _symbolStack.peek()).equals("(")) {
isNegative = true;
}
}
}
if (!isNumber && !isNegative) {
return false;
}
_buffer.setLength(0);
_buffer.append(c);
_expressionReader.mark(1);
char p = (char) _expressionReader.read();
while (NumberExpression.isNumber(p)) {
_buffer.append(p);
_expressionReader.mark(1);
p = (char) _expressionReader.read();
}
_expressionReader.reset();
double value;
try {
value = Double.parseDouble(_buffer.toString());
} catch (Exception e) {
throw new ParseException("Invalid number format: " + _buffer);
}
NumberExpression expression = new NumberExpression(value);
_expressionQueue.offer(expression);
return true;
}
private boolean tryString(char c) throws IOException, ParseException {
if (!Character.isLetter(c)) {
return false;
}
_buffer.setLength(0);
_buffer.append(c);
_expressionReader.mark(1);
char p = (char) _expressionReader.read();
while (Character.isLetterOrDigit(p) || p == '_' || p == '@' || p == '.') {
_buffer.append(p);
_expressionReader.mark(1);
p = (char) _expressionReader.read();
}
_expressionReader.reset();
if (_variables.contains(_buffer.toString())) {
Object value = getVariableValue(_buffer.toString());
NumberExpression expression = new NumberExpression(value);
_expressionQueue.offer(expression);
return true;
}
if (FunctionExpression.isFunction(_buffer.toString())) {
_symbolStack.push(_buffer.toString());
return true;
}
throw new ParseException("Invalid variable: " + _buffer);
}
private boolean tryStartGroup(char c) {
if (c != '(') {
return false;
}
_symbolStack.push(String.valueOf(c));
return true;
}
private boolean tryOperator(char c) throws ParseException {
if (!OperatorExpression.isSymbol(c)) {
return false;
}
boolean repeat;
String s = String.valueOf(c);
do {
String p = _symbolStack.size() == 0 ? "" : _symbolStack.peek();
repeat = false;
if (_symbolStack.size() == 0) {
_symbolStack.push(s);
} else if (p.equals("(")) {
_symbolStack.push(s);
} else if (precedence(s) > precedence(p)) {
_symbolStack.push(s);
} else {
IExpression e = getExpressionFromSymbol(_symbolStack.pop());
_expressionQueue.offer(e);
repeat = true;
}
} while (repeat);
return true;
}
private boolean tryEndGroup(char c) throws ParseException {
if (c != ')') {
return false;
}
boolean ok = false;
while (_symbolStack.size() > 0) {
String p = _symbolStack.pop();
if (p.equals("(")) {
ok = true;
break;
}
IExpression e = getExpressionFromSymbol(p);
_expressionQueue.offer(e);
}
if (!ok) {
throw new ParseException("Unbalance parenthese");
}
return true;
}
private void processSymbolStack() throws ParseException {
while (_symbolStack.size() > 0) {
String p = _symbolStack.pop();
if (p.length() == 1 && p.equals("(")) {
throw new ParseException("Unbalance parenthese");
}
IExpression e = getExpressionFromSymbol(p);
_expressionQueue.offer(e);
}
}
private static int precedence(String c) {
String s = c.substring(0, 1);
if (c.length() == 1 && s.equals("*") || s.equals("/") || s.equals("%")) {
return 2;
}
return 1;
}
private IExpression getExpressionFromSymbol(String p) throws ParseException {
IExpression e;
if (_expressionCache.containsKey(p)) {
e = _expressionCache.get(p);
} else if (OperatorExpression.isSymbol(p)) {
e = new OperatorExpression(p);
_expressionCache.put(p, e);
} else if (FunctionExpression.isFunction(p)) {
e = new FunctionExpression(p, false);
_expressionCache.put(p, e);
} //else if (ConvertExpression.IsConvertExpression(p))
//{
// e = new ConvertExpression(p);
// _expressionCache.Add(p, e);
//}
else {
throw new ParseException("Invalid symbol on stack" + p);
}
return e;
}
private Object calculateFromQueue() throws ParseException {
Object result;
_calculationStack.clear();
for (IExpression expression : _expressionQueue) {
if (_calculationStack.size() < expression.getArgumentCount()) {
throw new ParseException("Not enough numbers" + expression);
}
_parameters.clear();
for (int i = 0; i < expression.getArgumentCount(); i++) {
_parameters.push(_calculationStack.pop());
}
Object[] parameters = _parameters.toArray();
MIMath.arrayReverse(parameters);
_calculationStack.push(expression.evaluate(parameters));
}
result = _calculationStack.pop();
return result;
}
private Object getVariableValue(String varName) {
if (_meteoDataInfo == null) {
return 100;
} else {
if (_isGridData) {
return _meteoDataInfo.getGridData(varName);
} else {
return _meteoDataInfo.getStationData(varName);
}
}
}
// </editor-fold>
}

View File

@ -19,7 +19,7 @@ import java.time.Period;
import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.global.util.JDateUtil;
import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.Dimension;
import org.meteoinfo.projection.KnownCoordinateSystems;

View File

@ -14,6 +14,9 @@
package org.meteoinfo.data.meteodata;
import org.apache.commons.lang3.ArrayUtils;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.PointD;
import org.meteoinfo.data.DataMath;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.StationData;
@ -21,10 +24,10 @@ import org.meteoinfo.data.dataframe.DataFrame;
import org.meteoinfo.data.mapdata.Field;
import org.meteoinfo.drawing.ContourDraw;
import org.meteoinfo.drawing.Draw;
import org.meteoinfo.geoprocess.GeometryUtil;
import org.meteoinfo.legend.MarkerType;
import org.meteoinfo.geoprocess.GeoComputation;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.global.PointD;
import org.meteoinfo.math.ArrayUtil;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.layer.LayerDrawType;
import org.meteoinfo.layer.VectorLayer;
@ -45,10 +48,9 @@ import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.math.ArrayUtil;
import org.meteoinfo.data.GridArray;
import org.meteoinfo.data.XYListDataset;
import org.meteoinfo.global.Extent;
import org.meteoinfo.layer.ImageLayer;
import org.meteoinfo.layer.RasterLayer;
import org.meteoinfo.layer.WorldFilePara;
@ -107,7 +109,7 @@ public class DrawMeteoData {
}
aPolyline.setPoints(pList);
aPolyline.setValue(i);
aPolyline.setExtent(MIMath.getPointsExtent(pList));
aPolyline.setExtent(GeometryUtil.getPointsExtent(pList));
int shapeNum = layer.getShapeNum();
try {
@ -157,7 +159,7 @@ public class DrawMeteoData {
}
aPolyline.setPoints(pList);
aPolyline.setValue(i);
aPolyline.setExtent(MIMath.getPointsExtent(pList));
aPolyline.setExtent(GeometryUtil.getPointsExtent(pList));
int shapeNum = layer.getShapeNum();
try {
@ -233,7 +235,7 @@ public class DrawMeteoData {
PolylineShape aPolyline = new PolylineShape();
aPolyline.setPoints(ps);
aPolyline.setValue(i);
aPolyline.setExtent(MIMath.getPointsExtent(ps));
aPolyline.setExtent(GeometryUtil.getPointsExtent(ps));
int shapeNum = layer.getShapeNum();
try {
@ -368,7 +370,7 @@ public class DrawMeteoData {
PolylineShape aPolyline = new PolylineShape();
aPolyline.setPoints(ps);
aPolyline.setValue(k);
aPolyline.setExtent(MIMath.getPointsExtent(ps));
aPolyline.setExtent(GeometryUtil.getPointsExtent(ps));
int shapeNum = layer.getShapeNum();
try {
@ -509,7 +511,7 @@ public class DrawMeteoData {
PolylineZShape aPolyline = new PolylineZShape();
aPolyline.setPoints(ps);
aPolyline.setValue(0);
aPolyline.setExtent(MIMath.getPointsExtent(ps));
aPolyline.setExtent(GeometryUtil.getPointsExtent(ps));
int shapeNum = layer.getShapeNum();
try {
@ -621,7 +623,7 @@ public class DrawMeteoData {
PolylineZShape aPolyline = new PolylineZShape();
aPolyline.setPoints(ps);
aPolyline.setValue(0);
aPolyline.setExtent(MIMath.getPointsExtent(ps));
aPolyline.setExtent(GeometryUtil.getPointsExtent(ps));
int shapeNum = layer.getShapeNum();
try {
@ -740,7 +742,7 @@ public class DrawMeteoData {
}
aPolyline.setPoints(pList);
aPolyline.setValue(aValue);
aPolyline.setExtent(MIMath.getPointsExtent(pList));
aPolyline.setExtent(GeometryUtil.getPointsExtent(pList));
int shapeNum = aLayer.getShapeNum();
try {
@ -826,7 +828,7 @@ public class DrawMeteoData {
}
aPolyline.setPoints(pList);
aPolyline.setValue(aValue);
aPolyline.setExtent(MIMath.getPointsExtent(pList));
aPolyline.setExtent(GeometryUtil.getPointsExtent(pList));
int shapeNum = aLayer.getShapeNum();
try {
if (aLayer.editInsertShape(aPolyline, shapeNum)) {
@ -968,7 +970,7 @@ public class DrawMeteoData {
}
PolygonShape aPolygonShape = new PolygonShape();
aPolygonShape.setPoints(pList);
aPolygonShape.setExtent(MIMath.getPointsExtent(pList));
aPolygonShape.setExtent(GeometryUtil.getPointsExtent(pList));
aPolygonShape.lowValue = aValue;
if (aPolygon.HasHoles()) {
for (PolyLine holeLine : aPolygon.HoleLines) {

View File

@ -1,36 +1,36 @@
/* Copyright 2012 Yaqiang Wang,
* yaqiang.wang@gmail.com
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*/
package org.meteoinfo.data.meteodata;
import org.meteoinfo.global.Extent;
/**
*
* @author yaqiang
*/
public class GridDataSetting {
/// <summary>
/// Data extent
/// </summary>
public Extent dataExtent = new Extent();
/// <summary>
/// X number
/// </summary>
public int xNum;
/// <summary>
/// Y number
/// </summary>
public int yNum;
}
/* Copyright 2012 Yaqiang Wang,
* yaqiang.wang@gmail.com
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*/
package org.meteoinfo.data.meteodata;
import org.meteoinfo.common.Extent;
/**
*
* @author yaqiang
*/
public class GridDataSetting {
/// <summary>
/// Data extent
/// </summary>
public Extent dataExtent = new Extent();
/// <summary>
/// X number
/// </summary>
public int xNum;
/// <summary>
/// Y number
/// </summary>
public int yNum;
}

View File

@ -14,6 +14,8 @@
package org.meteoinfo.data.meteodata;
import java.io.File;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.StationData;
import org.meteoinfo.data.meteodata.arl.ARLDataInfo;
@ -30,14 +32,15 @@ import java.io.IOException;
import java.time.LocalDateTime;
import java.time.Duration;
import java.util.ArrayList;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.projection.info.ProjectionInfo;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.data.meteodata.mm5.MM5DataInfo;
import org.meteoinfo.data.meteodata.mm5.MM5IMDataInfo;
import org.meteoinfo.global.MIMath;
import org.meteoinfo.data.mathparser.MathParser;
import org.meteoinfo.data.mathparser.ParseException;
import org.meteoinfo.data.meteodata.awx.AWXDataInfo;

View File

@ -1,100 +1,101 @@
/* Copyright 2012 Yaqiang Wang,
* yaqiang.wang@gmail.com
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*/
package org.meteoinfo.data.meteodata;
import org.meteoinfo.global.Extent;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author yaqiang
*/
public class StationModelData {
// <editor-fold desc="Variables">
private List<StationModel> _data = new ArrayList<>();
private Extent _dataExtent = new Extent();
private double _missingValue = -9999.0;
// </editor-fold>
// <editor-fold desc="Constructor">
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get data
*
* @return Data
*/
public List<StationModel> getData() {
return _data;
}
/**
* Set data
*
* @param value Data
*/
public void setData(List<StationModel> value) {
_data = value;
}
/**
* Get data extent
*
* @return Data extent
*/
public Extent getDataExtent() {
return _dataExtent;
}
/**
* Set data extent
*
* @param value Data extent
*/
public void setDataExtent(Extent value) {
_dataExtent = value;
}
/**
* Get missing data
*
* @return Missing data
*/
public double getMissingValue() {
return _missingValue;
}
/**
* Set missing data
*
* @param value Missing data
*/
public void setMissingValue(double value) {
_missingValue = value;
}
/**
* Get data number
*
* @return Data number
*/
public int getDataNum() {
return _data.size();
}
// </editor-fold>
// <editor-fold desc="Methods">
// </editor-fold>
}
/* Copyright 2012 Yaqiang Wang,
* yaqiang.wang@gmail.com
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*/
package org.meteoinfo.data.meteodata;
import org.meteoinfo.common.Extent;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author yaqiang
*/
public class StationModelData {
// <editor-fold desc="Variables">
private List<StationModel> _data = new ArrayList<>();
private Extent _dataExtent = new Extent();
private double _missingValue = -9999.0;
// </editor-fold>
// <editor-fold desc="Constructor">
// </editor-fold>
// <editor-fold desc="Get Set Methods">
/**
* Get data
*
* @return Data
*/
public List<StationModel> getData() {
return _data;
}
/**
* Set data
*
* @param value Data
*/
public void setData(List<StationModel> value) {
_data = value;
}
/**
* Get data extent
*
* @return Data extent
*/
public Extent getDataExtent() {
return _dataExtent;
}
/**
* Set data extent
*
* @param value Data extent
*/
public void setDataExtent(Extent value) {
_dataExtent = value;
}
/**
* Get missing data
*
* @return Missing data
*/
public double getMissingValue() {
return _missingValue;
}
/**
* Set missing data
*
* @param value Missing data
*/
public void setMissingValue(double value) {
_missingValue = value;
}
/**
* Get data number
*
* @return Data number
*/
public int getDataNum() {
return _data.size();
}
// </editor-fold>
// <editor-fold desc="Methods">
// </editor-fold>
}

View File

@ -13,13 +13,14 @@
*/
package org.meteoinfo.data.meteodata;
import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.ndarray.DimensionType;
import org.meteoinfo.ndarray.Dimension;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import org.meteoinfo.global.util.JDateUtil;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.ndarray.Range;
import org.meteoinfo.ndarray.Section;

View File

@ -13,17 +13,19 @@
*/
package org.meteoinfo.data.meteodata.arl;
import org.meteoinfo.bak.ArrayMath;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.util.GlobalUtil;
import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.meteodata.DataInfo;
import org.meteoinfo.global.util.JDateUtil;
import org.meteoinfo.ndarray.Dimension;
import org.meteoinfo.ndarray.DimensionType;
import org.meteoinfo.ndarray.util.BigDecimalUtil;
import org.meteoinfo.data.meteodata.IGridDataInfo;
import org.meteoinfo.data.meteodata.Variable;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.global.util.GlobalUtil;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
@ -40,7 +42,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.data.GridArray;
import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.global.MIMath;
import org.locationtech.proj4j.proj.Projection;
import org.meteoinfo.projection.KnownCoordinateSystems;
import org.meteoinfo.projection.info.ProjectionInfo;

View File

@ -13,13 +13,14 @@
*/
package org.meteoinfo.data.meteodata.ascii;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.meteodata.DataInfo;
import org.meteoinfo.ndarray.Dimension;
import org.meteoinfo.ndarray.DimensionType;
import org.meteoinfo.data.meteodata.IGridDataInfo;
import org.meteoinfo.data.meteodata.Variable;
import org.meteoinfo.global.MIMath;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;

View File

@ -13,14 +13,16 @@
*/
package org.meteoinfo.data.meteodata.ascii;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.util.GlobalUtil;
import org.meteoinfo.data.StationData;
import org.meteoinfo.data.meteodata.DataInfo;
import org.meteoinfo.data.meteodata.IStationDataInfo;
import org.meteoinfo.data.meteodata.StationInfoData;
import org.meteoinfo.data.meteodata.StationModelData;
import org.meteoinfo.data.meteodata.Variable;
import org.meteoinfo.global.Extent;
import org.meteoinfo.global.MIMath;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -34,8 +36,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.global.util.GlobalUtil;
import org.meteoinfo.io.FileCharsetDetector;
import org.meteoinfo.common.io.FileCharsetDetector;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.data.meteodata.Attribute;

View File

@ -15,6 +15,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.common.Extent;
import org.meteoinfo.data.GridArray;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.StationData;
@ -28,7 +30,6 @@ import org.meteoinfo.data.meteodata.StationInfoData;
import org.meteoinfo.data.meteodata.StationModelData;
import org.meteoinfo.data.meteodata.Variable;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.global.Extent;
import org.meteoinfo.layer.WorldFilePara;
import org.meteoinfo.projection.KnownCoordinateSystems;
import org.meteoinfo.projection.info.ProjectionInfo;

View File

@ -18,11 +18,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.data.GridArray;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.mapdata.geotiff.GeoTiff;
import org.meteoinfo.data.meteodata.DataInfo;
import org.meteoinfo.math.ArrayMath;
import org.meteoinfo.ndarray.Dimension;
import org.meteoinfo.ndarray.DimensionType;
import org.meteoinfo.data.meteodata.IGridDataInfo;
@ -149,7 +150,7 @@ public class GeoTiffDataInfo extends DataInfo implements IGridDataInfo {
public Array read(String varName, int[] origin, int[] size, int[] stride) {
try {
Array array = read(varName);
array = ArrayMath.section(array, origin, size, stride);
array = ArrayMath.section(array, origin, size, stride);
return array;
} catch (InvalidRangeException ex) {
Logger.getLogger(GeoTiffDataInfo.class.getName()).log(Level.SEVERE, null, ex);

View File

@ -13,6 +13,8 @@
*/
package org.meteoinfo.data.meteodata.grads;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.meteodata.DataInfo;
import org.meteoinfo.ndarray.Dimension;
@ -20,7 +22,7 @@ import org.meteoinfo.ndarray.DimensionType;
import org.meteoinfo.data.meteodata.IGridDataInfo;
import org.meteoinfo.data.meteodata.Variable;
import org.meteoinfo.global.DataConvert;
import org.meteoinfo.io.EndianDataOutputStream;
import org.meteoinfo.common.io.EndianDataOutputStream;
import org.meteoinfo.ndarray.util.BigDecimalUtil;
import org.meteoinfo.projection.KnownCoordinateSystems;
import org.meteoinfo.projection.info.ProjectionInfo;
@ -51,7 +53,6 @@ import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.data.meteodata.StationInfoData;
import org.meteoinfo.data.meteodata.StationModelData;
import org.meteoinfo.data.meteodata.arl.ARLDataInfo;
import org.meteoinfo.global.Extent;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.ndarray.IndexIterator;
@ -59,7 +60,6 @@ import org.meteoinfo.ndarray.InvalidRangeException;
import org.meteoinfo.ndarray.Range;
import org.meteoinfo.ndarray.Section;
import org.meteoinfo.data.meteodata.Attribute;
import org.meteoinfo.global.util.JDateUtil;
/**
*

View File

@ -11,6 +11,8 @@ import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.common.Bytes2Number;
import org.meteoinfo.data.DataMath;
import org.meteoinfo.data.GridArray;
import org.meteoinfo.data.GridData;
@ -18,7 +20,6 @@ import org.meteoinfo.data.meteodata.DataInfo;
import org.meteoinfo.data.meteodata.IGridDataInfo;
import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.data.meteodata.Variable;
import org.meteoinfo.global.Bytes2Number;
import org.meteoinfo.projection.info.ProjectionInfo;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.data.meteodata.Attribute;

View File

@ -13,10 +13,10 @@
*/
package org.meteoinfo.data.meteodata.hysplit;
import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.data.meteodata.ascii.ASCIIGridDataInfo;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.meteodata.DataInfo;
import org.meteoinfo.global.util.JDateUtil;
import org.meteoinfo.ndarray.Dimension;
import org.meteoinfo.ndarray.DimensionType;
import org.meteoinfo.data.meteodata.IGridDataInfo;

View File

@ -13,13 +13,14 @@
*/
package org.meteoinfo.data.meteodata.hysplit;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.data.StationData;
import org.meteoinfo.data.dataframe.Column;
import org.meteoinfo.data.dataframe.ColumnIndex;
import org.meteoinfo.data.dataframe.DataFrame;
import org.meteoinfo.data.dataframe.Index;
import org.meteoinfo.data.meteodata.DataInfo;
import org.meteoinfo.global.util.JDateUtil;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.ndarray.Dimension;
import org.meteoinfo.ndarray.DimensionType;
@ -27,7 +28,6 @@ import org.meteoinfo.data.meteodata.IStationDataInfo;
import org.meteoinfo.data.meteodata.StationInfoData;
import org.meteoinfo.data.meteodata.StationModelData;
import org.meteoinfo.data.meteodata.Variable;
import org.meteoinfo.global.Extent;
import java.io.IOException;
import java.io.RandomAccessFile;

Some files were not shown because too many files have changed in this diff Show More