zoukankan      html  css  js  c++  java
  • World Wind Java开发之五——读取本地shp文件(转)

    http://blog.csdn.net/giser_whu/article/details/41484433

    World Wind Java 使用IconLayer图层类表现点和多点数据,使用RenderableLayer图层表现线和面数据,一个图层只能对应一组shape文件。World Wind Java首先使用ShapefileLoader类完成对shape文件的读取和加载,再通过createLayerFromSource方法创建RenderableLayer,最后将创建的Layer加在layers上。源码如下:

    [java] view plain copy
     
     print?在CODE上查看代码片派生到我的代码片
    1. /** 
    2.      *  
    3.      * 方法名称: AddShapeData ; 
    4.      * 方法描述:  添加本地shape文件 ; 
    5.      * 参数 :@param filePath :文件路径  
    6.      * 参数 :@param fileName :文件名 
    7.      * 参数 :@param layerTitle :图层名称 
    8.      * 参数 :@param maxActiveAltitude :图层可见最高视点 
    9.      * 参数 :@param minActiveAltitude :图层可见最低视点 
    10.      * 参数 :@return  
    11.      * 返回类型: boolean ; 
    12.      * 创建人:James; 
    13.      * 创建时间:2014-11-25 下午5:19:48; 
    14.      * @throws 
    15.      */  
    16.     public boolean AddShapeData(String filePath, String fileName,  
    17.             String layerTitle, double maxActiveAltitude,  
    18.             double minActiveAltitude)  
    19.     {  
    20.         boolean result = false;  
    21.         try  
    22.         {  
    23.   
    24.             ShapefileLoader pShapefileLoader = new ShapefileLoader();  
    25.             pShapeLayer = pShapefileLoader.createLayerFromSource(filePath  
    26.                     + fileName + ".shp");  
    27.             pShapeLayer.setName(layerTitle);// 设置图层名称  
    28.             pShapeLayer.setMaxActiveAltitude(maxActiveAltitude);  
    29.             pShapeLayer.setMinActiveAltitude(minActiveAltitude);  
    30.               
    31.             worldWindowGLCanvas.getModel().getLayers().add(pShapeLayer);  
    32.             //添加图层树节点  
    33.             pVectorNode.add(new DefaultMutableTreeNode(layerTitle));  
    34.             pLayerTree.updateUI();  
    35.             result = true;  
    36.   
    37.         }  
    38.   
    39.         catch (Exception e)  
    40.         {  
    41.             // TODO: handle exception  
    42.             System.out.println(e.getMessage());  
    43.   
    44.         }  
    45.         return result;  
    46.     }  

    效果图如下图所示:

  • 相关阅读:
    PAT顶级 1024 Currency Exchange Centers (35分)(最小生成树)
    Codeforces 1282B2 K for the Price of One (Hard Version)
    1023 Have Fun with Numbers (20)
    1005 Spell It Right (20)
    1092 To Buy or Not to Buy (20)
    1118 Birds in Forest (25)
    1130 Infix Expression (25)
    1085 Perfect Sequence (25)
    1109 Group Photo (25)
    1073 Scientific Notation (20)
  • 原文地址:https://www.cnblogs.com/telwanggs/p/6774553.html
Copyright © 2011-2022 走看看