support both tiff and geotiff

This commit is contained in:
wyq 2021-11-29 23:49:28 +08:00
parent b43cff8162
commit d37ea500e5
16 changed files with 93 additions and 30 deletions

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.formdev:flatlaf:1.6.4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/formdev/flatlaf/1.6.4/flatlaf-1.6.4.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/formdev/flatlaf/1.6.4/flatlaf-1.6.4-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/formdev/flatlaf/1.6.4/flatlaf-1.6.4-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.formdev:flatlaf-extras:1.6.4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/formdev/flatlaf-extras/1.6.4/flatlaf-extras-1.6.4.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/formdev/flatlaf-extras/1.6.4/flatlaf-extras-1.6.4-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/formdev/flatlaf-extras/1.6.4/flatlaf-extras-1.6.4-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.apache.commons:commons-imaging:1.0-alpha1">
<library name="Maven: org.apache.commons:commons-imaging:1.0-alpha2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-imaging/1.0-alpha1/commons-imaging-1.0-alpha1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-imaging/1.0-alpha2/commons-imaging-1.0-alpha2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-imaging/1.0-alpha1/commons-imaging-1.0-alpha1-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-imaging/1.0-alpha2/commons-imaging-1.0-alpha2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-imaging/1.0-alpha1/commons-imaging-1.0-alpha1-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-imaging/1.0-alpha2/commons-imaging-1.0-alpha2-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -65,7 +65,7 @@
<orderEntry type="library" name="Maven: org.locationtech.jts:jts-core:1.17.0" level="project" />
<orderEntry type="module" module-name="meteoinfo-table" />
<orderEntry type="module" module-name="meteoinfo-image" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-imaging:1.0-alpha1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-imaging:1.0-alpha2" level="project" />
<orderEntry type="module" module-name="meteoinfo-data" />
<orderEntry type="module" module-name="meteoinfo-projection" />
<orderEntry type="library" name="Maven: org.locationtech.proj4j:proj4j:1.1.3" level="project" />

View File

@ -532,6 +532,28 @@ public class GeoTiff {
}
}
/**
* Check the tiff file is geotiff or not
* @param filename The tiff file name
* @return Is geotiff or not
*/
public static boolean isGeoTiff(String filename) {
try {
GeoTiff geoTiff = new GeoTiff(filename);
geoTiff.read();
IFDEntry modelTransformationTag = geoTiff.findTag(Tag.ModelTransformationTag);
if (modelTransformationTag != null) {
return true;
} else {
IFDEntry modelTiePointTag = geoTiff.findTag(Tag.ModelTiepointTag);
return modelTiePointTag != null;
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
/**
* Find tag
*
@ -676,7 +698,14 @@ public class GeoTiff {
int width = widthIFD.value[0];
int height = heightIFD.value[0];
GridArray gData = new GridArray();
gData.setData(readArray());
Array data = readArray();
if (data.getRank() == 3) {
int[] dShape = data.getShape();
int[] origin = new int[]{0, 0, 0};
int[] shape = new int[]{dShape[0], dShape[1], 1};
data = data.section(origin, shape);
}
gData.setData(data);
//Grid data coordinate
double[] X = new double[width];
@ -714,7 +743,7 @@ public class GeoTiff {
}
return gData;
} catch (IOException ex) {
} catch (IOException | InvalidRangeException ex) {
Logger.getLogger(GeoTiff.class.getName()).log(Level.SEVERE, null, ex);
return null;
}

View File

@ -74,7 +74,7 @@
<orderEntry type="library" name="Maven: org.locationtech.jts:jts-core:1.17.0" level="project" />
<orderEntry type="module" module-name="meteoinfo-table" />
<orderEntry type="module" module-name="meteoinfo-image" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-imaging:1.0-alpha1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-imaging:1.0-alpha2" level="project" />
<orderEntry type="module" module-name="meteoinfo-data" />
<orderEntry type="module" module-name="meteoinfo-projection" />
<orderEntry type="library" name="Maven: org.locationtech.proj4j:proj4j:1.1.3" level="project" />

View File

@ -13,6 +13,7 @@
*/
package org.meteoinfo.geo.mapdata;
import org.apache.commons.imaging.ImageReadException;
import org.meteoinfo.common.DataConvert;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.PointD;
@ -33,6 +34,7 @@ import org.meteoinfo.geometry.legend.LegendType;
import org.meteoinfo.geometry.shape.Shape;
import org.meteoinfo.geometry.shape.*;
import org.meteoinfo.geometry.geoprocess.GeometryUtil;
import org.meteoinfo.image.ImageUtil;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.projection.KnownCoordinateSystems;
@ -80,7 +82,10 @@ public class MapDataManage {
mdt = MapDataType.IMAGE;
break;
case "tif":
mdt = MapDataType.GEO_TIFF;
if (GeoTiff.isGeoTiff(fileName))
mdt = MapDataType.GEO_TIFF;
else
mdt = MapDataType.IMAGE;
break;
case "bil":
case "bip":
@ -322,13 +327,13 @@ public class MapDataManage {
* @return Image layer
* @throws IOException
*/
public static ImageLayer readImageFile(String aFile) throws IOException {
public static ImageLayer readImageFile(String aFile) throws IOException, ImageReadException {
String oEx = aFile.substring(aFile.lastIndexOf("."));
String last = oEx.substring(oEx.length() - 1);
String sEx = oEx.substring(0, oEx.length() - 2) + last;
sEx = sEx + "w";
String wFile = aFile.replace(oEx, sEx);
BufferedImage aImage = ImageIO.read(new File(aFile));
BufferedImage aImage = ImageUtil.imageLoad(aFile);
ImageLayer aImageLayer = new ImageLayer();
aImageLayer.setFileName(aFile);
aImageLayer.setWorldFileName(wFile);

View File

@ -18,6 +18,7 @@ import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfTemplate;
import com.itextpdf.text.pdf.PdfWriter;
import org.apache.commons.imaging.ImageReadException;
import org.meteoinfo.common.*;
import org.meteoinfo.common.util.GlobalUtil;
import org.meteoinfo.geo.mapdata.MapDataManage;
@ -9719,7 +9720,7 @@ public class MapView extends JPanel implements IWebMapPanel {
if (new File(aFile).exists()) {
try {
aLayer = MapDataManage.readImageFile(aFile);
} catch (IOException ex) {
} catch (IOException | ImageReadException ex) {
Logger.getLogger(MapView.class.getName()).log(Level.SEVERE, null, ex);
}
try {

View File

@ -68,6 +68,6 @@
<orderEntry type="library" name="Maven: org.bytedeco:openblas:macosx-x86_64:0.3.10-1.5.4" level="project" />
<orderEntry type="library" name="Maven: org.bytedeco:openblas:windows-x86:0.3.10-1.5.4" level="project" />
<orderEntry type="library" name="Maven: org.bytedeco:openblas:windows-x86_64:0.3.10-1.5.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-imaging:1.0-alpha1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-imaging:1.0-alpha2" level="project" />
</component>
</module>

View File

@ -25,7 +25,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-imaging</artifactId>
<version>1.0-alpha1</version>
<version>1.0-alpha2</version>
</dependency>
</dependencies>

View File

@ -75,7 +75,7 @@
<orderEntry type="library" name="Maven: org.locationtech.jts:jts-core:1.17.0" level="project" />
<orderEntry type="module" module-name="meteoinfo-table" />
<orderEntry type="module" module-name="meteoinfo-image" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-imaging:1.0-alpha1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-imaging:1.0-alpha2" level="project" />
<orderEntry type="module" module-name="meteoinfo-data" />
<orderEntry type="module" module-name="meteoinfo-projection" />
<orderEntry type="library" name="Maven: org.locationtech.proj4j:proj4j:1.1.3" level="project" />

View File

@ -1,32 +1,34 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox\miml\deep_learning\convolution"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox\miml\deep_learning"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox\miml\deep_learning\classification"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\map\geoshow">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\projection"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\taylor"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\wind"/>
<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"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\maskout"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\geoshow"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\interpolate"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\image"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\geotiff"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\geoshow"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\toolbox\miml\deep_learning\classification\saturn.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\contourfsclice_xy_2.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf_breather.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\image\imread_3.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\map\geoshow\georead_1.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\toolbox\miml\deep_learning\classification\saturn.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\contourfsclice_xy_2.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf_breather.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\image\imread_3.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\map\geoshow\georead_1.py"/>
</RecentFiles>
</File>
<Font>

View File

@ -68,13 +68,13 @@ def shaperead(fn, encoding=None):
raise
def georead(fn):
'''
Returns a layer readed from a supported geo-data file.
"""
Returns a layer read from a supported geo-data file.
:param fn: (*string*) The supported geo-data file name (shape file, wmp, geotiff, image, bil...).
:returns: (*MILayer*) The created layer.
'''
"""
if not os.path.exists(fn):
fn = os.path.join(migl.get_map_folder(), fn)
@ -89,7 +89,7 @@ def georead(fn):
except:
raise
else:
print 'File not exists: ' + fn
print('File not exists: ' + fn)
raise IOError
def geotiffread(filename):

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="config.xml" Type="configurefile">
<Path OpenPath="D:\Temp\traj\Sample"/>
<Path OpenPath="D:\Temp\image"/>
<Font>
<TextFont FontName="YaHei Consolas Hybrid" FontSize="14"/>
<LegendFont FontName="宋体" FontSize="12"/>

View File

@ -66,7 +66,7 @@
<orderEntry type="library" name="Maven: org.locationtech.jts:jts-core:1.17.0" level="project" />
<orderEntry type="module" module-name="meteoinfo-table" />
<orderEntry type="module" module-name="meteoinfo-image" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-imaging:1.0-alpha1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-imaging:1.0-alpha2" level="project" />
<orderEntry type="module" module-name="meteoinfo-data" />
<orderEntry type="module" module-name="meteoinfo-projection" />
<orderEntry type="library" name="Maven: org.locationtech.proj4j:proj4j:1.1.3" level="project" />