Null Pinter Exception只是意味着它是因为值变为null。但是如果使用像GeoTiff这样的APis,找出使用中的错误会很烦人。
我的代码如下:
System.out.println("vectorization starts");
GridCoverage2D srcCoverage = new GeoTiffReader(new File("E:/output/ll_processed.TIFF")).read(new GeneralParameterValue[]{policy, gridsize, useJaiRead});
SimpleFeatureCollection fc = RasterToVectorProcess.process(srcCoverage, 3, cov.getEnvelope(), Collections.singletonList(0.0d), true, null);
System.out.println("process ends");
System.out.println("vectorization ends");
//MapContext map = new DefaultMapContext();
//map.setTitle("raster to vector conversion");
Style style = SLD.createPolygonStyle(Color.BLUE, Color.CYAN, 1.0f);
//map.addLayer(fc, style);
//map.getLayerBounds();
//JMapFrame.showMap(map);
MapContent mapContent= new MapContent();
mapContent.setTitle("Illegal Mining");
Layer layer = new FeatureLayer(fc, style,"VectorLayer");
//int boundary = 10;
// ReferencedEnvelope env2 = new ReferencedEnvelope(srcCoverage.getEnvelope().getMinimum(0) - boundary, srcCoverage.getEnvelope().getMaximum(0) + boundary,
//srcCoverage.getEnvelope().getMinimum(1) - boundary, srcCoverage.getEnvelope().getMaximum(1) + boundary, srcCoverage.getCoordinateReferenceSystem());
//mapContent.getViewport().setBounds(fc.getBounds());
Line 199 : if(layer.getBounds()!=null) // here the error is coming also tried with if(layer != null && layer.getBounds()!=null)
{
mapContent.addLayer(layer);
}else{
System.out.println("Layer bounds are null");
}
mapContent.getViewport().setCoordinateReferenceSystem(
DefaultGeographicCRS.WGS84);
错误
at org.geotools.map.FeatureLayer.getBounds(FeatureLayer.java:199)
我正在尝试将Tiff转换为Vector图像然后我想将其存储在磁盘上。
答案 0 :(得分:0)
最有可能的是,您的featureSource
为空,因为geotools FeatureLayer
class方法getBounds()
使用featureSource
来检索边界,但在构造函数FeatureLayer
中没有检查featureSource
是否为null
。
featureSource
是FeatureLayer
构造函数的第一个参数。在您的情况下,这是变量SimpleFeatureCollection fc
。
最有可能的是,方法process.process
返回null
,因此fc
为空。
RasterToVectorProcess.java中的次要更改
//features.add(builder.buildFeature(null));
//System.out.println("ignored");
//add
System.out.println("adding...");
SimpleFeature feature = builder.buildFeature(null);
((Collection<SimpleFeature>) features).add(feature);