[JAVA][Geotools][添加图层相关的问题

【环境】
   java1.5
   geotools 2.3 

   【描述】
   已经实现读取本地shp文件,以及多个shp叠加,进行地图浏览  
   现打算在指定的经纬度,添加基站或者车辆图标

   【方案】
    有2个思路:
    一是利用经纬度 使用 类似 MaptoWindow的  函数获得图标在窗口的相对显示位置,然后使用canvas绘制上去
    二是Geotools文档中提到的gridCoverage层,实现imageReader来提取相应的coverage图象

   【问题】
    请问大家在gis显示中添加图标的一般做法是什么?
    在gis规范里有使用图标的标准吗?

    第一个思路我在delphi+其他的gis中间件上实现了。在java+Geotools上还没做过。我已经看过了Feature以及FeatureType的说明,JTS文档也浏览了一遍,不知道这2个思路是否能够顺利实现,在网上寻找很久了,由于gis的知识有限,希望有做过朋友可以指点一二,如果能给个demo例子学习不甚感谢。
    
    新人没分,抱着学习态度提问,请不吝指点。

 

—————————————————————————————————————————————————————————–

使用第一种方法已经解决。但总觉得不会是标准的解决方案。

把自己的方法和大家共享一下。

主要的方法是获得gis到客户区域的坐标
/**
  * gisToClient
  * 通过gis坐标获得界面坐标
  * @param ClientEvent
  * @return
  */
private Coordinate gisToClient(Coordinate gisEvent){
// 初始化返回值
Coordinate coord =null;
//获取当前map的边界
     Rectangle rec = map.getComponent().getBounds();            
     Envelope env = map.getRenderingStrategy().getMapArea();
     if (env!=null && rec!=null){
     GeometryFactory geofact = new GeometryFactory();
     coord = toGisCoord(gisEvent.x,gisEvent.y,env.getWidth(), env.getHeight(), rec,env);
     Point point = geofact.createPoint(coord);

         CoordinateReferenceSystem targetCRS = map.getRenderingStrategy().getContext

().getCoordinateReferenceSystem();
         CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84;
         
         try{
             MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
             Geometry targetGeometry = JTS.transform( point, transform);
             coord = targetGeometry.getCoordinate();
            
         }catch(Exception e){
         System.out.println(“CRS transformSource to target ERROR”);
         } 
         
     }
return coord;
}
然后重写jFrame的paint方法
/**
  * 重载JFrame的paint实现图标绘画
  */

public void paint(Graphics g)
{
super.paint(g);
Image srcImage=null;
try {
srcImage = ImageIO.read(new File(“图标的绝对路径”));
} catch (IOException e) {
System.out.println(“image error”);
e.printStackTrace();
}
Coordinate x= gisToClient(new Coordinate(0,0));
g.drawImage(srcImage,(int)x.x, (int)x.y, 32, 32, null);
}

虽然可以做,但是觉得并不完善,暂时还不结贴,

不知道有没有标准gis实现这种图标显示的图层或者方法。

望指教。

转载自:https://blog.csdn.net/sxausgyy/article/details/8113047

You may also like...

退出移动版