| 
					
				 | 
			
			
				@@ -0,0 +1,138 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package com.onemap.analyse.service.impl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.onemap.analyse.service.IImageService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.coverage.grid.GridCoverage2D; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.data.DataStoreFinder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.data.FeatureSource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.data.simple.SimpleFeatureCollection; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.data.simple.SimpleFeatureSource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.opengis.feature.simple.SimpleFeature; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.feature.simple.SimpleFeatureBuilder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.feature.simple.SimpleFeatureTypeBuilder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.geometry.jts.ReferencedEnvelope; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.map.FeatureLayer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.map.GridReaderLayer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.map.Layer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.map.MapContent; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.referencing.crs.DefaultGeographicCRS; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.renderer.lite.StreamingRenderer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.renderer.style.Style; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.styling.SLD; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.geotools.util.factory.Hints; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.locationtech.jts.geom.Geometry; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.locationtech.jts.io.ParseException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.locationtech.jts.io.WKTReader; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.opengis.feature.simple.SimpleFeatureType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.opengis.feature.type.FeatureType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import javax.imageio.ImageIO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.awt.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.awt.image.BufferedImage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.File; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * 生成图片服务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class ImageServiceImpl implements IImageService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 获取遥感图像 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param geomWkt 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public String getSensingImage(String geomWkt) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //     try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         SimpleFeatureSource geometrySource = DataStoreFinder.getDataStore(postgisParams).getFeatureSource("your_geometry_table"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         // 加载影像数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         AbstractGridCoverage2DReader rasterReader = (AbstractGridCoverage2DReader) DataStoreFinder.getDataStore(postgisParams).getFeatureSource("your_raster_table").getGridCoverageReader(new Hints()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         // 创建样式 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         Style geometryStyle = (Style) SLD.createSimpleStyle(geometrySource.getSchema()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         GridCoverage2D coverage = (GridCoverage2D) rasterReader.read(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         Style rasterStyle = SLD.wrapGridCoverage(coverage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         // 创建地图内容 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         MapContent map = new MapContent(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         map.setTitle("PostGIS Raster and Geometry Screenshot"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         // 添加几何图层 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         Layer geometryLayer = new FeatureLayer(geometrySource, geometryStyle); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         map.addLayer(geometryLayer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         // 添加影像图层 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         Layer rasterLayer = new GridReaderLayer(rasterReader, rasterStyle); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         map.addLayer(rasterLayer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         // 创建渲染器 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         StreamingRenderer renderer = new StreamingRenderer(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         renderer.setMapContent(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         // 创建BufferedImage 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         int imageWidth = 800; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         int imageHeight = 600; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         Graphics2D graphics = image.createGraphics(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         // 设置背景颜色 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         graphics.setPaint(Color.WHITE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         graphics.fillRect(0, 0, imageWidth, imageHeight); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         // 设置视图 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         ReferencedEnvelope mapBounds = map.getMaxBounds(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         renderer.paint(graphics, new java.awt.Rectangle(imageWidth, imageHeight), mapBounds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         // 保存截图 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         File outputfile = new File("screenshot.png"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         ImageIO.write(image, "png", outputfile); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         System.out.println("截图已保存到: " + outputfile.getAbsolutePath()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //     } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //         e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //     return ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// public FeatureSource getFeatureResource(String geomWkt) throws ParseException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // // 1. 解析WKT数据为Geometry对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // WKTReader reader = new WKTReader(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // Geometry geometry = reader.read(geomWkt); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // // 2. 创建SimpleFeatureType,定义Feature的结构 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // typeBuilder.setName("PolygonFeatureType"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // typeBuilder.setCRS(org.geotools.referencing.crs.DefaultGeographicCRS.WGS84); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // typeBuilder.add("geometry", Geometry.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // SimpleFeatureType featureType = typeBuilder.buildFeatureType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // // 3. 创建SimpleFeature,将Geometry对象放入Feature中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // featureBuilder.add(geometry); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // SimpleFeature feature = featureBuilder.buildFeature(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // // 4. 创建FeatureCollection,将Feature放入其中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // List<SimpleFeature> features = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // features.add(feature); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // SimpleFeatureCollection collection = DataUtilities.collection(features); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // // 5. 创建FeatureSource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // FeatureType ft = collection.getSchema(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // FeatureSource featureSource = DataUtilities.source(collection); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     // return featureSource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//     return ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// } 
			 |