Revision: 5012
http://sourceforge.net/p/jump-pilot/code/5012
Author: michaudm
Date: 2016-09-10 09:54:12 +0000 (Sat, 10 Sep 2016)
Log Message:
-----------
Include SRSInfo reading in TiffTags.readMetadata()
Modified Paths:
--------------
core/trunk/src/org/openjump/core/rasterimage/GeoTiffConstants.java
core/trunk/src/org/openjump/core/rasterimage/TiffTags.java
Modified: core/trunk/src/org/openjump/core/rasterimage/GeoTiffConstants.java
===================================================================
--- core/trunk/src/org/openjump/core/rasterimage/GeoTiffConstants.java
2016-09-10 09:49:59 UTC (rev 5011)
+++ core/trunk/src/org/openjump/core/rasterimage/GeoTiffConstants.java
2016-09-10 09:54:12 UTC (rev 5012)
@@ -23,16 +23,107 @@
*/
public class GeoTiffConstants {
- //Here are all of the TIFF tags (and their owners) that are used to store
GeoTIFF information of any type. It is very unlikely that any other tags will
be necessary in the future (since most additional information will be encoded
as a GeoKey).
+ // Here are all of the TIFF tags (and their owners) that are used to store
GeoTIFF information of any type.
+ // It is very unlikely that any other tags will be necessary in the future
+ // (since most additional information will be encoded as a GeoKey).
+ // GeoKeys are taken from
http://gis.ess.washington.edu/data/raster/drg/docs/geotiff.txt
- public final static int ModelPixelScaleTag = 33550 ,//(SoftDesk)
- ModelTransformationTag = 34264 ,//(JPL Carto
Group)
- ModelTiepointTag = 33922 ,//(Intergraph)
- GeoKeyDirectoryTag = 34735 ,//(SPOT)
- GeoDoubleParamsTag = 34736 ,//(SPOT)
- GeoAsciiParamsTag = 34737 ,//(SPOT)
- //Obsoleted Implementation:
- IntergraphMatrixTag = 33920 ;//(Intergraph) --
Use ModelTransformationTag.
-
+ public final static int
+ ModelPixelScaleTag = 33550 ,//(SoftDesk)
+ ModelTransformationTag = 34264 ,//(JPL Carto Group)
+ ModelTiepointTag = 33922 ,//(Intergraph)
+ GeoKeyDirectoryTag = 34735 ,//(SPOT)
+ GeoDoubleParamsTag = 34736 ,//(SPOT)
+ GeoAsciiParamsTag = 34737 ,//(SPOT)
+ //Obsoleted Implementation:
+ IntergraphMatrixTag = 33920; //(Intergraph) -- Use
ModelTransformationTag.
+
+ public final static int UNDEFINED = 0;
+
+ public final static int USERDEFINED = 32767;
+
+ public final static int ModelTypeProjected = 1, ModelTypeGeographic = 2,
ModelTypeGeocentric = 3;
+
+ public final static int RasterPixelIsArea = 1, RasterPixelIsPoint = 2;
+
+ public final static int
+ Linear_Meter = 9001,
+ Linear_Foot = 9002,
+ Linear_Foot_US_Survey = 9003,
+ Linear_Foot_Modified_American = 9004,
+ Linear_Foot_Clarke = 9005,
+ Linear_Foot_Indian = 9006,
+ Linear_Link = 9007,
+ Linear_Link_Benoit = 9008,
+ Linear_Link_Sears = 9009,
+ Linear_Chain_Benoit = 9010,
+ Linear_Chain_Sears = 9011,
+ Linear_Yard_Sears = 9012,
+ Linear_Yard_Indian = 9013,
+ Linear_Fathom = 9014,
+ Linear_Mile_International_Nautical = 9015;
+
+ public final static int
+ Angular_Radian = 9101,
+ Angular_Degree = 9102,
+ Angular_Arc_Minute = 9103,
+ Angular_Arc_Second = 9104,
+ Angular_Grad = 9105,
+ Angular_Gon = 9106,
+ Angular_DMS = 9107,
+ Angular_DMS_Hemisphere = 9108;
+
+ // GeoKeys taken from
http://gis.ess.washington.edu/data/raster/drg/docs/geotiff.txt
+ public final static int
+ GTModelTypeGeoKey = 1024, /* Section 6.3.1.1 Codes */
+ GTRasterTypeGeoKey = 1025, /* Section 6.3.1.2 Codes */
+ GTCitationGeoKey = 1026, /* documentation */
+
+ GeographicTypeGeoKey = 2048, /* Section 6.3.2.1 Codes
*/
+ GeogCitationGeoKey = 2049, /* documentation
*/
+ GeogGeodeticDatumGeoKey = 2050, /* Section 6.3.2.2 Codes
*/
+ GeogPrimeMeridianGeoKey = 2051, /* Section 6.3.2.4 codes
*/
+ GeogLinearUnitsGeoKey = 2052, /* Section 6.3.1.3 Codes
*/
+ GeogLinearUnitSizeGeoKey = 2053, /* meters
*/
+ GeogAngularUnitsGeoKey = 2054, /* Section 6.3.1.4 Codes
*/
+
+ GeogAngularUnitSizeGeoKey = 2055, /* radians
*/
+ GeogEllipsoidGeoKey = 2056, /* Section 6.3.2.3 Codes
*/
+ GeogSemiMajorAxisGeoKey = 2057, /* GeogLinearUnits
*/
+ GeogSemiMinorAxisGeoKey = 2058, /* GeogLinearUnits
*/
+ GeogInvFlatteningGeoKey = 2059, /* ratio
*/
+ GeogAzimuthUnitsGeoKey = 2060, /* Section 6.3.1.4 Codes
*/
+ GeogPrimeMeridianLongGeoKey = 2061, /* GeogAngularUnit
*/
+
+ ProjectedCSTypeGeoKey = 3072, /* Section 6.3.3.1 codes
*/
+ PCSCitationGeoKey = 3073, /* documentation
*/
+ ProjectionGeoKey = 3074, /* Section 6.3.3.2 codes
*/
+ ProjCoordTransGeoKey = 3075, /* Section 6.3.3.3 codes
*/
+ ProjLinearUnitsGeoKey = 3076, /* Section 6.3.1.3 codes
*/
+ ProjLinearUnitSizeGeoKey = 3077, /* meters
*/
+ ProjStdParallelGeoKey = 3078, /* GeogAngularUnit */
+ ProjStdParallel2GeoKey = 3079, /* GeogAngularUnit */
+ ProjOriginLongGeoKey = 3080, /* GeogAngularUnit */
+ ProjOriginLatGeoKey = 3081, /* GeogAngularUnit */
+ ProjFalseEastingGeoKey = 3082, /* ProjLinearUnits */
+ ProjFalseNorthingGeoKey = 3083, /* ProjLinearUnits */
+ ProjFalseOriginLongGeoKey = 3084, /* GeogAngularUnit */
+ ProjFalseOriginLatGeoKey = 3085, /* GeogAngularUnit */
+ ProjFalseOriginEastingGeoKey = 3086, /* ProjLinearUnits */
+ ProjFalseOriginNorthingGeoKey = 3087, /* ProjLinearUnits */
+ ProjCenterLongGeoKey = 3088, /* GeogAngularUnit */
+ ProjCenterLatGeoKey = 3089, /* GeogAngularUnit */
+ ProjCenterEastingGeoKey = 3090, /* ProjLinearUnits */
+ ProjCenterNorthingGeoKey = 3091, /* ProjLinearUnits */
+ ProjScaleAtOriginGeoKey = 3092, /* ratio */
+ ProjScaleAtCenterGeoKey = 3093, /* ratio */
+ ProjAzimuthAngleGeoKey = 3094, /* GeogAzimuthUnit */
+ ProjStraightVertPoleLongGeoKey = 3095, /* GeogAngularUnit */
+
+ VerticalCSTypeGeoKey = 4096, /* Section 6.3.4.1 codes
*/
+ VerticalCitationGeoKey = 4097, /* documentation */
+ VerticalDatumGeoKey = 4098, /* Section 6.3.4.2 codes
*/
+ VerticalUnitsGeoKey = 4099; /* Section 6.3.1.3 codes
*/
+
}
Modified: core/trunk/src/org/openjump/core/rasterimage/TiffTags.java
===================================================================
--- core/trunk/src/org/openjump/core/rasterimage/TiffTags.java 2016-09-10
09:49:59 UTC (rev 5011)
+++ core/trunk/src/org/openjump/core/rasterimage/TiffTags.java 2016-09-10
09:54:12 UTC (rev 5012)
@@ -3,8 +3,8 @@
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
+import java.text.Normalizer;
import java.util.List;
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.formats.tiff.TiffField;
@@ -12,10 +12,11 @@
import org.apache.commons.imaging.formats.tiff.TiffImageParser;
import org.apache.commons.imaging.formats.tiff.fieldtypes.FieldType;
import org.libtiff.jai.codec.XTIFF;
+import org.openjump.core.ccordsys.utils.SRSInfo;
public class TiffTags {
- public static TiffMetadata readMetadata(File tiffFile) throws
FileNotFoundException, IOException, TiffReadingException, ImageReadException {
+ public static TiffMetadata readMetadata(File tiffFile) throws IOException,
TiffReadingException, ImageReadException {
Integer colCount = null;
Integer rowCount = null;
@@ -24,10 +25,14 @@
Coordinate tiePoint = null;
Resolution pixelScale = null;
Envelope envelope = null;
+ SRSInfo srsInfo = new SRSInfo().setSource(tiffFile.getPath());
TiffImageParser parser = new TiffImageParser();
TiffImageMetadata metadata = (TiffImageMetadata)
parser.getMetadata(tiffFile);
List<TiffField> tiffFields = metadata.getAllFields();
+ int[] geoKeyDirectoryTag = null;
+ double[] geoDoubleParams = null;
+ String geoAsciiParams = null;
for(TiffField tiffField : tiffFields) {
switch(tiffField.getTag()) {
@@ -62,6 +67,17 @@
pixelScale = new
Resolution(pixelSCaleValues[0],pixelSCaleValues[1],pixelSCaleValues[2]);
}
break;
+ case GeoTiffConstants.GeoKeyDirectoryTag:
+ geoKeyDirectoryTag = tiffField.getIntArrayValue();
+ break;
+ case GeoTiffConstants.GeoDoubleParamsTag:
+ geoDoubleParams = tiffField.getDoubleArrayValue();
+ break;
+ case GeoTiffConstants.GeoAsciiParamsTag:
+ geoAsciiParams = tiffField.getStringValue();
+ geoAsciiParams = geoAsciiParams.replaceAll("[\\s\\|_;]+",
" ");
+ srsInfo.setDescription(geoAsciiParams);
+ System.out.println(geoAsciiParams);
}
}
@@ -80,12 +96,99 @@
envelope = new Envelope(upperLeft, lowerRight);
}
+
+ if (geoKeyDirectoryTag != null && geoKeyDirectoryTag.length >= 4) {
+ readGeoKeys(geoKeyDirectoryTag, geoDoubleParams, geoAsciiParams,
srsInfo);
+ }
+ srsInfo.complete();
- return new TiffTags().new TiffMetadata(colCount, rowCount, pixelScale,
noData, envelope);
+ return new TiffTags().new TiffMetadata(colCount, rowCount, pixelScale,
noData, envelope, srsInfo);
}
+
+
+ private static void readGeoKeys(int[] geoKeys, double[] geoDoubleParams,
String geoAsciiParams, SRSInfo srsInfo) {
+ int numberOfKeys = geoKeys[3];
+ for (int i = 1 ; i <= numberOfKeys ; i++) {
+ int keyID = geoKeys[i*4];
+ int location = geoKeys[i*4+1];
+ int count = geoKeys[i*4+2];
+ int offset = geoKeys[i*4+3];
+ Object value;
+ System.out.println(" GeoKey " + keyID + " " + location + " " +
count + " " + offset);
+ switch(keyID) {
+ case GeoTiffConstants.GTModelTypeGeoKey:
+ int coordSystemType = offset;
+ // default unit for geographic CRS
+ if (coordSystemType ==
GeoTiffConstants.ModelTypeGeographic)
+ srsInfo.setUnit(SRSInfo.Unit.DEGREE);
+ // default unit for projected CRS
+ else if (coordSystemType ==
GeoTiffConstants.ModelTypeProjected)
+ srsInfo.setUnit(SRSInfo.Unit.METER);
+ break;
+ //case GeoTiffConstants.GTRasterTypeGeoKey:
+ // srsInfo.rasterType = offset;
+ // break;
+ case GeoTiffConstants.GTCitationGeoKey:
+ break;
+ case GeoTiffConstants.GeographicTypeGeoKey:
+ case GeoTiffConstants.ProjectedCSTypeGeoKey:
+ value = getGeoValue(location, count, offset,
geoDoubleParams, geoAsciiParams);
+ if (value instanceof String)
+ srsInfo.setDescription((String)value);
+ else if (value instanceof Integer) {
+ if ((Integer)value < 32767) {
+
srsInfo.setRegistry(SRSInfo.Registry.EPSG).setCode(value.toString());
+ } else if ((Integer)value == 32767) {
+
srsInfo.setRegistry(SRSInfo.Registry.SRID).setCode(SRSInfo.UNDEFINED);
+ }
+ }
+ break;
+ case GeoTiffConstants.GeogCitationGeoKey:
+ break;
+ case GeoTiffConstants.PCSCitationGeoKey:
+ break;
+ case GeoTiffConstants.VerticalCSTypeGeoKey:
+ break;
+ case GeoTiffConstants.GeogLinearUnitsGeoKey:
+ case GeoTiffConstants.GeogAngularUnitsGeoKey:
+ if (offset == GeoTiffConstants.Angular_Degree)
srsInfo.setUnit(SRSInfo.Unit.DEGREE);
+ if (offset == GeoTiffConstants.Angular_Radian)
srsInfo.setUnit(SRSInfo.Unit.RADIAN);
+ if (offset == GeoTiffConstants.Angular_Grad)
srsInfo.setUnit(SRSInfo.Unit.GRADE);
+ if (offset == GeoTiffConstants.Angular_DMS)
srsInfo.setUnit(SRSInfo.Unit.DMS);
+ if (offset == GeoTiffConstants.Angular_DMS_Hemisphere)
srsInfo.setUnit(SRSInfo.Unit.DMSH);
+ case GeoTiffConstants.ProjLinearUnitsGeoKey:
+ if (offset == GeoTiffConstants.Linear_Meter)
srsInfo.setUnit(SRSInfo.Unit.METER);
+ if (offset == GeoTiffConstants.Linear_Foot)
srsInfo.setUnit(SRSInfo.Unit.FOOT);
+ if (offset == GeoTiffConstants.Linear_Foot_Clarke)
srsInfo.setUnit(SRSInfo.Unit.FOOT);
+ if (offset == GeoTiffConstants.Linear_Foot_Indian)
srsInfo.setUnit(SRSInfo.Unit.FOOT);
+ if (offset == GeoTiffConstants.Linear_Foot_US_Survey)
srsInfo.setUnit(SRSInfo.Unit.FOOT);
+ if (offset ==
GeoTiffConstants.Linear_Foot_Modified_American)
srsInfo.setUnit(SRSInfo.Unit.FOOT);
+ if (offset == GeoTiffConstants.Linear_Yard_Indian)
srsInfo.setUnit(SRSInfo.Unit.YARD);
+ if (offset == GeoTiffConstants.Linear_Yard_Sears)
srsInfo.setUnit(SRSInfo.Unit.YARD);
+ if (offset ==
GeoTiffConstants.Linear_Mile_International_Nautical)
srsInfo.setUnit(SRSInfo.Unit.MILE);
+ }
+ }
+ }
+
+ private static Object getGeoValue(int location, int count, int offset,
+ double[] geoDoubleParams, String
geoAsciiParams) {
+ if (location == 0) return offset;
+ else if (location == GeoTiffConstants.GeoDoubleParamsTag) {
+ if (count == 0) return new double[0];
+ double[] dd = new double[count];
+ System.arraycopy(geoDoubleParams, offset, dd, 0, count);
+ return dd;
+ }
+ else if (location == GeoTiffConstants.GeoAsciiParamsTag) {
+ if (geoAsciiParams == null || geoAsciiParams.length() == 0) return
"";
+ String substring = geoAsciiParams.substring(offset, offset +
count);
+ return substring.endsWith("|") ? substring.substring(0,
substring.length()-1) : substring;
+ }
+ else return "";
+ }
- public static TiffField readField(File tiffFile, int tagCode) throws
ImageReadException, IOException {
+ static TiffField readField(File tiffFile, int tagCode) throws
ImageReadException, IOException {
TiffImageParser parser = new TiffImageParser();
TiffImageMetadata metadata = (TiffImageMetadata)
parser.getMetadata(tiffFile);
@@ -129,12 +232,14 @@
public class TiffMetadata {
- public TiffMetadata(Integer colsCount, Integer rowsCount, Resolution
resolution, Double noData, Envelope envelope) {
+ public TiffMetadata(Integer colsCount, Integer rowsCount, Resolution
resolution, Double noData,
+ Envelope envelope, SRSInfo srsInfo) {
this.colsCount = colsCount;
this.rowsCount = rowsCount;
this.resolution = resolution;
this.noData = noData;
this.envelope = envelope;
+ this.srsInfo = srsInfo;
}
public Integer getColsCount() {
@@ -156,12 +261,17 @@
public Envelope getEnvelope() {
return envelope;
}
+
+ public SRSInfo getSRSInfo() {
+ return srsInfo;
+ }
private Integer colsCount;
private Integer rowsCount;
private Resolution resolution;
private Double noData;
private Envelope envelope;
+ private SRSInfo srsInfo;
}
------------------------------------------------------------------------------
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel