2016-07-29 20 views
5

Gần đây tôi đã bắt đầu chương trình đầu tiên với GeoTools, trong đó tôi cũng đang sử dụng JAI-Java Advanced Imaging 1_1_2_01 với JDK 1_7. Nó hoạt động tốt cho đến khi tôi thêm GeoTiff Jars. Tôi tìm thấy lỗi saujava.lang.NoClassDefFoundError: Không thể khởi tạo lớp javax.media.jai.JAI

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class javax.media.jai.JAI at org.geotools.gce.geotiff.GeoTiffReader.read(GeoTiffReader.java:607) at com.rgb.PixelExtractor.extract(PixelExtractor.java:55) at com.rgb.RGBSpliter.main(RGBSpliter.java:136)

Bộ luật như sau

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 }); 
// The line that throws error 
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()}; 

} 

} 

JDK Chum

JDK images jar

Chum khác

Part1

part2

Tôi cũng đã thêm biến classpath cho GeoTools lọ

classpath

Edit:

jai của tôi là làm việc mà không GeoTools tích hợp, nhưng khi tôi thêm gt-geotiff-14.4.jar nó cố gắng thêm JAI-core-1.1.3.jar xung đột với jai-core.jar trong JDK 1.7 của tôi. Vì vậy, tôi loại bỏ JAI-core-1.1.3.jar và lọ liên quan nhưng nó vẫn mang lại cho tôi lỗi tương tự.

+0

Bạn có thể thêm stacktrace hoàn chỉnh không? – Jens

+0

nó được sao chép ở trên khi bắt đầu câu hỏi. Nhưng tôi thấy câu trả lời là những cái lọ mâu thuẫn. Vì vậy, không cần thêm câu trả lời. –

Trả lời

3

Cuối cùng nó làm việc khi tôi loại bỏ GeoTIFF jai-core-1.1.3.jar, jai-codec-1.1.3.jarjai-imageio-1.1.jar tập tin và thêm lớp mới cho các tệp lớp học gt-utility của jai-ext. Tôi chỉ cần sao chép từ github và thêm vào src của dự án của tôi. gt-utility là hình bị thiếu. Các lọ cũng mâu thuẫn nhau.

2

Bạn phải thêm jai-core.jar vào classpath của bạn

+0

Nó được thêm vào là –

+0

@ParthTrivedi nơi bạn đã thêm, Hiển thị cách bạn bắt đầu chương trình – Jens

+0

Tôi đang sử dụng nhật thực trong đó JDK 1.7 được thêm vào, JAI được cài đặt snapshot hiển thị jai jars không có giới hạn truy cập và tùy chọn bộ nhớ i cũng vậy '- Xms512m -Xmx512m -XX: MaxPermSize = 512m 'Bây giờ nó cho tôi lỗi này. –

0

Hãy làm theo các GeoTools setup instructions mà nói cho JAI :

Java Advanced Imaging Java Advanced Imaging is an image processing library allowing you to form chains of operations to process rasters in a manner similar to functional programming.

References:

http://java.net/projects/jai-core Download this Version of JAI

Java Advanced Imaging API 1.1.3 At the time of writing Oracle is migrating java projects around - try the following:

http://download.java.net/media/jai/builds/release/1_1_3/ http://download.java.net/media/jai/builds/release/1_1_3/INSTALL.html Download JAI for your JDK by clicking on the link for your platform:

Example: jai-1_1_3-lib-windows-i586-jdk.exe

Use the one click installer to install JAI into your JDK

Download JAI for your JRE by clicking on the link for your platform:

Example: jai-1_1_3-lib-windows-i586-jre.exe

Use the one click installer to install JAI into your JRE

(If you are working on linux you will of course need to choose the appropriate download)

+0

jai-1_1_2-lib-windows-i586-jre.exe và jai-1_1_2-lib-windows-i586-jdk.exe, tôi cài đặt lại và chúng được xuất hiện chính xác trong nhật thực của tôi khi các jars đang hiển thị cũng là lỗi để hạn chế truy cập cũng được giải quyết, bây giờ chỉ có lỗi này đang đến để khởi tạo lớp JAI. –

+0

Tất cả các bước được theo sau từ trang đó, cũng cho phép toàn bộ thư mục JDK cũng như thư mục JRE vẫn có lỗi. –

+0

GeoTools 14.x cũng dành cho JDK1.7 và jai-1_1_2-lib cũng dành cho JDK 1.7. –

Các vấn đề liên quan