ww可以根据DLG图批量生成假三维模型,这对于小区等特征相似的建筑物模型的构建是非常有用的。下面来看如何一步步实现假三维模型的加载:

1、Shp文件的制作

首先在arcmap下数字化几个建筑物,并新建height字段存储建筑物的高度。

2、代码实现

  1. /**
  2. *
  3. * @方法名称: init3DModel ;
  4. * @方法描述: 导入简易三维模型 ;
  5. * @参数 :@param filePath :shp文件路径
  6. * @返回类型: void ;
  7. * @创建人:bluce;
  8. * @创建时间:2015年2月3日 下午6:10:22;
  9. * @throws
  10. */
  11. private void init3DModel(String filePath)
  12. {
  13. Shapefile shapefile = new Shapefile(filePath);
  14. RenderableLayer layer = new RenderableLayer();
  15. layer.setName("简易三维模型");
  16. layer.setPickEnabled(true);
  17. try
  18. {
  19. while (shapefile.hasNext())
  20. {
  21. ShapefileRecord record = shapefile.nextRecord();
  22. layer.addRenderable(makeShape(record));
  23. }
  24. wwPanel.getWorldWindowGLCanvas().getModel().getLayers()
  25. .add(layer);
  26. }
  27. finally
  28. {
  29. shapefile.close();
  30. }
  31. }
  32. /**
  33. *
  34. * @方法名称: makeShape ;
  35. * @方法描述:  根据shp文件每条记录创建模型 ;
  36. * @参数 :@param record
  37. * @参数 :@return
  38. * @返回类型: ExtrudedPolygon ;
  39. * @创建人:bluce;
  40. * @创建时间:2015年2月3日 下午6:11:08;
  41. * @throws
  42. */
  43. private ExtrudedPolygon makeShape(ShapefileRecord record)
  44. {
  45. String IMAGE_PATH = "F:\\data\\wwj\\build123sm.jpg";
  46. Double height = null;
  47. String[] heightKeys = new String[]
  48. { "height", "Height", "HEIGHT" };
  49. for (String key : heightKeys)
  50. {
  51. Object o = record.getAttributes().getValue(key);
  52. if (o != null)
  53. {
  54. height = Double.parseDouble(o.toString());
  55. }
  56. }
  57. // 顶部属性
  58. ShapeAttributes capAttrs = new BasicShapeAttributes();
  59. capAttrs.setOutlineMaterial(Material.GRAY);
  60. capAttrs.setInteriorMaterial(Material.CYAN);
  61. // 边属性
  62. ShapeAttributes sideAttributes = new BasicShapeAttributes();
  63. sideAttributes.setInteriorMaterial(Material.LIGHT_GRAY);
  64. sideAttributes.setOutlineMaterial(Material.DARK_GRAY);
  65. sideAttributes.setImageSource(IMAGE_PATH);
  66. // 创建拉伸多边形
  67. VecBuffer vb = record.getPointBuffer(0);
  68. Polygon pgonAirspace = new Polygon(vb.getLocations()); // 根据点串构建多边形
  69. //纹理
  70. ArrayList<String> textures = new ArrayList<String>();
  71. for (int i = 0; i < pgonAirspace.getLocations().size(); i++)
  72. {
  73. textures.add(IMAGE_PATH);
  74. }
  75. ExtrudedPolygon polygon = new ExtrudedPolygon(
  76. pgonAirspace.getLocations(), height, textures);
  77. polygon.setCapAttributes(capAttrs);
  78. polygon.setSideAttributes(sideAttributes);
  79. polygon.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
  80. return polygon;
  81. }

效果如下图所示:

3、问题

发现模型加载不了纹理啊,查了几遍不知道问题出在哪里,希望懂的朋友看到留言给指点下啊,不胜感激。
----------------------------------------------2015年7月26日----------------------------------------------
感谢Q_H_Wang提供的解决方案: 加载不上纹理的是因为 pgonAirspace.getLocations().获取的坐标集合第一个元素与最后一个一样造成的,除掉最后一个元素即可加载。所以只需在添加纹理的地方加个减一即可:
  1. ArrayList<String> textures = new ArrayList<String>();
  2. for (int i = 0; i < pgonAirspace.getLocations().size() - 1; i++)
  3. {
  4. textures.add(IMAGE_PATH);
  5. }

最新文章

  1. H5 canvas的 width、height 与style中宽高的区别
  2. APUE 习题3-2 实现dup2,要求不使用fcntl函数。
  3. git版本控制管理实践-2
  4. Runtime详解
  5. 线上mongodb数据库mLab使用总结
  6. vc-complex-type.2.3: Element &#39;filter-mapping&#39; cannot have character [children], because the type&#39;s content type is element-only.
  7. 数据源和JNDI的关系:
  8. ARM Linux 3.x的设备树(Device Tree)
  9. AutoCompleteTextView控件的使用
  10. uboot的mkconfig分析
  11. bzoj 1927 [Sdoi2010]星际竞速(最小费用最大流)
  12. 视图中的Layout使用(转)
  13. 创建 OVS vlan100 netwrok - 每天5分钟玩转 OpenStack(137)
  14. HDU 3605 Escape (网络流,最大流,位运算压缩)
  15. ad 层次绘图遇到的元件堆积问题
  16. iOS 常用小功能 总结
  17. 关于解决sql2012编辑器对象名无效问题
  18. Centos 5.6安装Mysql(步骤,疑问)
  19. [Linux] Ubuntu修改时区
  20. [ python ] 变量及基础的数据类型

热门文章

  1. Educational Codeforces Round 52D(ARRAY,模拟最短路)
  2. PAT L2-006【二叉树中序后序构造树】
  3. (PHP)redis Hash(哈希)操作
  4. bzoj 2827: 千山鸟飞绝
  5. Git 通过https向码云推送项目
  6. Python爬取天气预报
  7. java 使用 spirng 监控 cpu 使用 状态。。。。
  8. Codeforces Round #363 (Div. 2) C
  9. 1088 Rational Arithmetic(20 分)
  10. 忘记mysql数据库密码时进行修改方法