引起:org.opengis.referencing.NoSuchAuthorityCodeException:对于“EngineeringCRS”类型的对象,找不到来自权限“EPSG”的代码“EPSG:4326”

时间:2016-07-28 11:41:34

标签: java jai geotools

我正在尝试在我的一个程序中使用GeoTiff和JAI,但是我遇到了以下错误。

  

引起:org.opengis.referencing.NoSuchAuthorityCodeException:对于“EngineeringCRS”类型的对象,没有为权限“EPSG”找到代码“EPSG:4326”。

代码如下:

     PixelExtractor ext = new PixelExtractor();
     ext.extract(new File("E:/ll.TIF"), "ESPG:4326", "28/07/2016");

PixelExtractor类是

import com.spatial4j.core.io.GeohashUtils;
import java.awt.geom.Rectangle2D;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.GridEnvelope2D;
import org.geotools.coverage.grid.GridGeometry2D;
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.coverage.grid.io.OverviewPolicy;
import org.geotools.gce.geotiff.GeoTiffReader;
import org.geotools.geometry.Envelope2D;
import org.opengis.parameter.GeneralParameterValue;
import org.opengis.parameter.ParameterValue;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.cs.CoordinateSystem;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.Serializable;


public class PixelExtractor implements Serializable {



/**
* returns a pixel as a string with teh following format String outString =
* geoHash + "@" + name + "@" + date + "@" + originalBands
*
* @param f the geotif file
* @param name the name of the file
* @param date the date of information (when the image was captured)
* @param collector
* @throws Exception
*/
 public void extract(File f, String name, String date) throws Exception {
ParameterValue<OverviewPolicy> policy = AbstractGridFormat.OVERVIEW_POLICY
        .createValue();
policy.setValue(OverviewPolicy.IGNORE);

// this will basically read 4 tiles worth of data at once from the disk...
ParameterValue<String> gridsize = AbstractGridFormat.SUGGESTED_TILE_SIZE.createValue();
//gridsize.setValue(512 * 4 + "," + 512);

// Setting read type: use JAI ImageRead (true) or ImageReaders read methods (false)
ParameterValue<Boolean> useJaiRead = AbstractGridFormat.USE_JAI_IMAGEREAD.createValue();
useJaiRead.setValue(true);

//reader.read(new GeneralParameterValue[] { policy, gridsize, useJaiRead });
 GridCoverage2D image
        = new GeoTiffReader(f).read(new GeneralParameterValue[]{policy, gridsize, useJaiRead});
Rectangle2D bounds2D = image.getEnvelope2D().getBounds2D();
bounds2D.getCenterX();
// calculate zoom level for the image
GridGeometry2D geometry = image.getGridGeometry();



BufferedImage img = ImageIO.read(f);
// ColorModel colorModel = img.getColorModel(      
WritableRaster raster = img.getRaster();

int numBands = raster.getNumBands();

int w = img.getWidth();
int h = img.getHeight();
outer:
for (int i = 0; i < w; i++) {//width...

  for (int j = 0; j < h; j++) {

    double[] latlon = geo(geometry, i, j);
    double lat = latlon[0];
    double lon = latlon[1];

    Double s = 0d;

    String originalBands = "";
    for (int k = 0; k < numBands; k++) {
       double d = raster.getSampleDouble(i, j, k);
      originalBands += d + ",";
      s += d;
    }

    originalBands = originalBands.substring(0, originalBands.length() - 1);
    if (s.compareTo(0d) == 0) {
      continue;
    }
    String geoHash = GeohashUtils.encodeLatLon(lat, lon);
    //here do something with the bands, lat, long, geohash, etc....

  }

 }

 }

  private static double[] geo(GridGeometry2D geometry, int x, int y) throws Exception {

//int zoomlevel = 1;
Envelope2D pixelEnvelop = geometry.gridToWorld(new GridEnvelope2D(x, y, 1, 1));

// pixelEnvelop.getCoordinateReferenceSystem().getName().getCodeSpace();
return new double[]{pixelEnvelop.getCenterY(), pixelEnvelop.getCenterX()};

}

}

在阅读GeoTools espg插件后,我添加了gt-epsg-hsql.jar和包含所有epsg条目的属性文件并将错误更改为

  

java.lang.NoClassDefFoundError:无法初始化类javax.media.jai.JAI

0 个答案:

没有答案