加载中…
个人资料
沙痕
沙痕
  • 博客等级:
  • 博客积分:0
  • 博客访问:194,588
  • 关注人气:306
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
公告

此博文纯为个人学习之记录,虽力求精细、准确,以与志同道合者分享交流,如文中涉及版权、错误、误导之处,希来信告知,即可改正,无需在此留下不愉快,对此深表歉意。

Email:80941918@qq.com

QQ: 80941918

搜博主文章
新浪微博
我去过的地方
国内 (0篇)
国外 (0篇)
博文



阅读  ┆ 评论  ┆ 转载 ┆ 收藏 




阅读  ┆ 评论  ┆ 转载 ┆ 收藏 
参考:
https://geonet.esri.com/thread/185176-convert-raster-dem-to-stl-for-3d-printing
http://gis.ess.washington.edu/data/vrml/vrml2stl.py

修改后,支持arcgis10.2,代码如下:

#! /usr/bin/env python
# Translates simple vrml to stl
# There is no support for textures.
# This has been tested on a large vrml file (representing topography) created
# by the tinvrml command in ARC/INFO 8.1, and running with 
# python 2.2.1 under solaris8 unix.
# The one argument is the root name of a .wrl file.
# The output is root.stl
# Version 1.1 does not stop at the first separator.
# Copyleft Harvey Greenberg, University of Washington, hgreen@u.washington.edu
import string
import sys

root = sys.argv[1]
print 'Converting ',root+'.wrl to ',root+'.stl'
f=open(root+'.wrl')
while 1:      # skip through initial stuff
  linney=string.split(f.readline())
# print linney
  if len(linney) == 4:
    if linney[0] == 'translation':
      transx = float(linney[1])
      transy = float(linney[2])
      transz = float(linney[3])
#     print 'xyz',transx,transy,transz # I don't use these values.
  #print linney
  #raw_input()
  if linney == ['point']:
    break
#print 'Reading vertex coordinates.'
skipline=f.readline()
verts = [] # The first triplet is index zero in the wrl file.
while 1:
  xyz = f.readline()
  linney=string.split(xyz)
  i = string.find(xyz,' ')
  if linney==[']']:    # end of vertex coordinates
    break
  else:
    verts.append(linney) # building a list of xyz strings
print 'We have',len(verts)-1,'vertices.'
while 1:     # skip to triplets of vertex numbers
  linney=string.split(f.readline())  # linney was a list, now it's a string
  if linney[0] == '[':
    break 
g=open(root+'.stl','w') # open stl file for writing.
g.write('solid %s\n' % root)
print 'Reading triangles.'
linney=f.readline()
#print linney
linney=linney.split('-1')
for row in linney:
  abc=string.split(row)
  if len(abc)<3:
  break
  else:
    #print abc[0]
    #print int(abc[0])
    xyz = verts[int(abc[0])] # look up a vertex in the list
    #print xyz
    #raw_input()
    x1 = float(xyz[0]) 
    y1 = float(xyz[1])
    z1 = float(xyz[2])
    xyz = verts[int(abc[1])]
    x2 = float(xyz[0])
    y2 = float(xyz[1])
    z2 = float(xyz[2])
    xyz = verts[int(abc[2])]
    x3 = float(xyz[0])
    y3 = float(xyz[1])
    z3 = float(xyz[2])

    dx1 = x1-x3
    dy1 = y1-y3
    dz1 = z1-z3
    dx2 = x2-x3
    dy2 = y2-y3
    dz2 = z2-z3
# print 'dx1=',dx1,'\ndy1=',dy1,'\ndz1=',dz1,'\ndx2=',dx2,'\ndy2=',dy2,'\ndz2=',dz2,'\n'
    vx = dy1*dz2 - dz1*dy2  # take the cross product of two edges
    vy = dz1*dx2 - dx1*dz2
    vz = dx1*dy2 - dy1*dx2
    templength = (vx*vx + vy*vy + vz*vz)**.5
    xn = vx/templength     # normalize the normal vector
    yn = vy/templength
    zn = vz/templength
# print 'Normal  %f,%f,%f\n' % (xn,yn,zn)

    g.write(' facet normal %f %f %f\n  outer loop\n' % (xn,yn,zn))
    g.write('   vertex %d %d %.2f\n' % (x1,y1,z1))
    g.write('   vertex %d %d %.2f\n' % (x2,y2,z2))
    g.write('   vertex %d %d %.2f\n' % (x3,y3,z3))
    g.write('  endloop\n endfacet\n')
g.write('endsolid %s\n' % root)
print 'Thank you.'



阅读  ┆ 评论  ┆ 转载 ┆ 收藏 

【2016-7-13更新】

大多数水利环境业务系统集成专业模型时,用户的需求是这样表达的:某真实案例,客户说,我们要开发一个B/S系统,里面想嵌入已经构建好的模型(比如说MIKE模型,但不限于MIKE模型),希望通过前台可以改变一些输入或者参数(比如说改变方案计算时间、边界条件时间序列、实时加一个溃口等),然后前台有个类似于开始运行的按钮,按了之后模型就开始运算了,不用让用户跳出模型本身的界面再进行操作。基于这样一种需求,SYP平台其实已经在架构设计里包含了这种需求,完全SOA的架构,业务模型逻辑层->WCF服务层->客户端调用服务的API层(C#C++JAVA->客户端界面层(WebWPFWinformQt等)。我们特别写了两个demo工程,示例说明了这种模式。实现线下模型模版的一键管理,修改计算参数、边界条件、实时动态加载溃口,启动计算,实时获取结果,整个流程。

 

示例工程前端是以控制台作为输出载体,后面我们会逐步改到直接在osg三维gis上做实时渲染。以下给出了示例工程代码的下载地址,demo工程代码下载地址: svnhttps://shywater.com/svn/SYAPP/branches/4Guest_Mike21RealtimeSimulation 用户名:guest;密码:guest

 

已编译好的可执行程序下载地址: https://shywater.com/svn/SYAPP/branches/4Guest_Mike21RealtimeSimulation/实时计算MikeFlood模型.zip 

以下为在我们三维osg平台上的运行效果:





 以下是C#C++调用的示例代码: 

 

C#

Code Snippet

  1. private static void InterfaceTest1()
  2. {
  3. //1.指定本地模型包
  4. modelConfigfile = @"../../bin/Data/FloodplainDemonstration.zip";
  5.  
  6. if (File.Exists(modelConfigfile))
  7. {
  8. //2.上传模型包(指定本地模版模型)
  9. var handle = new FlowModelBaseHandle();
  10. handle.OutputMsgCallback += handle_OutputMsgCallback;
  11. modelId = handle.GenerateMikeFloodModel(modelConfigfile);
  12.  
  13. //3.设置计算参数
  14. SY.Models.Scenario.ScenarionTime st = new SY.Models.Scenario.ScenarionTime();
  15. SY.Models.ModelBase.ModelTime mt = new SY.Models.ModelBase.ModelTime();
  16. mt.StartTime = DateTime.Parse("2002/05/23 0:00:00");
  17. mt.EndTime = DateTime.Parse("2002/05/24 10:30:00");
  18. mt.OutputStep = 60;
  19. st.ModelTimePara = mt;
  20. handle.CalculateParaSet(modelId, SY.Models.Scenario.enumModelDomainType.一二维耦合,
  21. SY.Models.Scenario.enumModelName.MIKEFLOOD, SY.Models.Scenario.enumScenarioFeild.防洪,
  22. st);
  23.  
  24. //4.设置边界条件
  25. //SY.Models.Scenario.ScenarioInput si = new SY.Models.Scenario.ScenarioInput();
  26. //SY.Models.ModelBase.Boundary bd = new SY.Models.ModelBase.Boundary();
  27. //bd.BDIndex = 0;
  28. //bd.HDType = SY.Models.ModelBase.enumHDBoundaryType.水位;
  29. //bd.Value = new List() { };
  30. //si.ModelBoundary.Add(bd);
  31.  
  32. //handle.GeneralSectionBoundaryConditionSet(modelId, SY.Models.Scenario.enumModelDomainType.一二维耦合,
  33. //SY.Models.Scenario.enumModelName.MIKEFLOOD, SY.Models.Scenario.enumScenarioFeild.防洪,
  34. //si.ModelBoundary);
  35.  
  36. //5.设置溃口条件
  37. SY.Models.ModelBase.DykeBreakStructure db = new SY.Models.ModelBase.DykeBreakStructure();
  38. //5.1基本信息
  39. db.GeneralInfo.breakLevel = 0.5f;
  40. db.GeneralInfo.breakTime = DateTime.Parse("2002/5/23 4:30:00");
  41. db.GeneralInfo.elevation = 0.5f;
  42. db.GeneralInfo.name = "kuikou_1";
  43. db.GeneralInfo.width = 50;
  44. db.GeneralInfo.x = 372810; //地图点选的溃口发生的位置x坐标
  45. db.GeneralInfo.y = 8127330;//地图点选的溃口发生的位置y坐标
  46. db.GeneralInfo.XLink = new List<</SPAN>double> { 372780, 372764 };
  47. db.GeneralInfo.YLink = new List<</SPAN>double> { 8127313, 8127350 };
  48. //5.2溃口信息
  49. db.BreakPara = new ListDykeBreakingGeometryStruct>()
  50. {
  51. new SY.Models.ModelBase.DykeBreakingGeometryStruct(){
  52. level=0.5f, time=0,width=0,slope=1
  53. },
  54. new SY.Models.ModelBase.DykeBreakingGeometryStruct(){
  55. level=0.4f, time=300,width=10,slope=0.6f
  56. },
  57. new SY.Models.ModelBase.DykeBreakingGeometryStruct(){
  58. level=0.3f, time=600,width=40,slope=0.6f
  59. },
  60. new SY.Models.ModelBase.DykeBreakingGeometryStruct(){
  61. level=0.2f, time=900,width=80,slope=0.6f
  62. },
  63. new SY.Models.ModelBase.DykeBreakingGeometryStruct(){
  64. level=0.1f, time=6000000,width=150,slope=0.6f
  65. }
  66. };
  67.  
  68. handle.DykeSet(modelId, SY.Models.Scenario.enumModelDomainType.一二维耦合,
  69. SY.Models.Scenario.enumModelName.MIKEFLOOD, SY.Models.Scenario.enumScenarioFeild.防洪,
  70. db);
  71.  
  72. //6.启动计算
  73. handle.RealTimeSimulateModel(modelId, SY.Models.Scenario.enumModelName.MIKEFLOOD);
  74. }
  75. }

 

C++

Code Snippet

  1. int _tmain(int argc, _TCHAR* argv[])
  2. {
  3. //1.指定本地模型包
  4. std::string modelZipfile = "../bin/Data/FloodplainDemonstration.zip";
  5.  
  6. //2.上传模型包(指定本地模版模型)
  7. modelId = GenerateMikeFloodModel(modelZipfile, &RecievedMsg);
  8.  
  9. //3.设置计算参数
  10. CalculateParaStruct para;
  11. para.calModelType = CalculateModelType::MODEL_12D;
  12. para.calModelName = CalculateModelName::MIKEFLOOD;
  13. para.calProjectType = CalculateProjectType::FLOODPROTECTION;
  14. para.modelId = modelId;
  15. para.startTime = "2002/05/23 0:00:00";
  16. para.endTime = "2002/05/24 10:30:00";
  17. para.outputStep = 600;
  18. para.timeValueStep = 34;
  19. CalculateParaSet(para, &RecievedMsg);
  20.  
  21. //4.设置边界条件
  22. //std::vector sectionBoundary;
  23.  
  24. //GeneralSectionStruct spara;
  25. //spara.boundaryType = BoundaryType::WaterLevel;
  26. //spara.boundaryID = 0;
  27.  
  28. //std::vector listTime;
  29. //listTime.push_back("2002/05/23 0:00:00");
  30. //listTime.push_back("2002/05/24 10:30:00");
  31.  
  32. //std::vector listData;
  33. //listData.push_back(0.1f);
  34. //listData.push_back(0.2f);
  35.  
  36. //spara.time = listTime;
  37. //spara.value = listData;
  38.  
  39. //sectionBoundary.push_back(spara);
  40.  
  41. ////2
  42. //spara.boundaryType = BoundaryType::WaterLevel;
  43. //spara.boundaryID = 1;
  44.  
  45. //listTime.clear();
  46. //listData.clear();
  47.  
  48. //listTime.push_back("2002/05/23 0:00:00");
  49. //listTime.push_back("2002/05/24 10:30:00");
  50.  
  51. //listData.push_back(0.1f);
  52. //listData.push_back(0.2f);
  53.  
  54. //spara.time = listTime;
  55. //spara.value = listData;
  56.  
  57. //sectionBoundary.push_back(spara);
  58.  
  59. //GeneralSectionBoundaryConditionSet(modelId,sectionBoundary, &RecievedMsg);
  60.  
  61. //5.设置溃口条件
  62. DykeGeneralInfoStruct para1;
  63. std::vector<</SPAN>DykeBreakingGeometryStruct> para2;
  64. para1.breakLevel = 0.5f;
  65. para1.breakTime = "2002/5/23 4:30:00";
  66. para1.elevation = 0.5f;
  67. para1.name = "kuikou01";
  68. para1.width = 50;
  69. para1.x = 372810;
  70. para1.y = 8127330;
  71. para1.Xlink.push_back(372780);
  72. para1.Xlink.push_back(372764);
  73. para1.Ylink.push_back(8127313);
  74. para1.Ylink.push_back(8127350);
  75.  
  76. DykeBreakingGeometryStruct para3;
  77. para3.relativeTime = 0;
  78. para3.level = 0.5f;
  79. para3.width = 0;
  80. para3.slope = 1;
  81. para2.push_back(para3);
  82. para3.relativeTime = 300;
  83. para3.level = 0.4f;
  84. para3.width = 10;
  85. para3.slope = 0.6f;
  86. para2.push_back(para3);
  87. para3.relativeTime = 600;
  88. para3.level = 0.3f;
  89. para3.width = 40;
  90. para3.slope = 0.6f;
  91. para2.push_back(para3);
  92. para3.relativeTime = 900;
  93. para3.level = 0.2f;
  94. para3.width = 80;
  95. para3.slope = 0.6f;
  96. para2.push_back(para3);
  97. para3.relativeTime = 6000000;
  98. para3.level = 0.1f;
  99. para3.width = 150;
  100. para3.slope = 0.6f;
  101. para2.push_back(para3);
  102.  
  103. DykeSet(modelId, BreakMode::Time, para1, para2, &RecievedMsg);
  104.  
  105. //6.启动模型计算
  106. RealTimeSimulateMikeFloodModel(modelId, &RecievedMsg);
  107.  
  108. getchar();
  109. return 0;
  110. }

 

阅读  ┆ 评论  ┆ 转载 ┆ 收藏 
去年针对洪水风险图项目,就如何在Arcgis中快速成图MIKE21模型的计算结果,写过一篇blog(http://blog.sina.com.cn/s/blog_5e778a9d0102v8tm.html),本次针对城市水系规划项目,如何在Arcgis中快速出图MIKE11模型的计算结果(水位、流量、流速、流向),提出一种解决方案。

问题由来:水系设计规划项目中,往往涉及很多方案的计算,而且方案不断变更,如何应对这种任务而不至于过于疲惫,又能保证标准化出图?那么我这里想到的就是在Arcgis里做一个数据模型,配置好出图样式,那么不同方案情况下,我们只需要替换掉图层的数据源就可以了,具体步骤如下。

解决方案:

1.准备好河网文件和结果文件,注意,在河网文件里生成计算点(View ->Tabular view ->Grid points ->Generate Grid Points)&#8203;与结果文件存储的计算点个数一致。

2.打开SYP,选择【MIKE11模型结果转换】&#8203;APP,按界面要求将计算结果转换为流量、水位、流速的矢量文件。

3.Arcgis中图层加载,水位、流速图层的加载及标准化出图比较简单,按正常样式配置。&#8203;这里特别说明的是基于流量图层生成流向图层。这里就需要构建一系列的GIS数据模型,主要思路就是获取河段矢量走向,再根据流量的正负来获得流向的角度,这里涉及一些了字段添加、计算等操作,可以根据自身出图需要定义相应的模型过程。如下我自己的数据模型即为一次性出具日流量及流向的数据模型。

&#8203;Arcgis数据模型



Arcmap标准化出图模版


阅读  ┆ 评论  ┆ 转载 ┆ 收藏 
  

新浪BLOG意见反馈留言板 电话:4006900000 提示音后按1键(按当地市话标准计费) 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

新浪公司 版权所有