hahaaluo
路人甲
路人甲
  • 注册日期2006-08-05
  • 发帖数146
  • QQ
  • 铜币591枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1389回复:5

请总统帮我看看这段代码,加载Shape文件的

楼主#
更多 发布于:2006-08-17 19:29
<P>private void cmdshape_Click(object sender, System.EventArgs e)<BR>  {<BR>     <BR>   IGxDialog gxDialog = new GxDialogClass();<BR>   IGxObjectFilter gxFilter = new GxFilterFeatureDatasetsAndFeatureClasses();<BR>   <BR>   // set the properties on the GxDialog object<BR>   gxDialog.AllowMultiSelect = true;<BR>   gxDialog.Title = "Add FeatureDatasets and FeatureClasses:";<BR>   gxDialog.ObjectFilter = gxFilter;</P>
<P>   </P>
<P>   IEnumGxObject enumGxObject = null;<BR>   if (gxDialog.DoModalOpen(0, out enumGxObject) == true)<BR>   {<BR>   <BR>    <BR>     AddShapeFile(@"F:\\New Folder\\ArcGIS\\DeveloperKit\\samples\\data\\world",  "Country.shp");<BR>    <BR>    </P>
<P>   }<BR>  }<BR>   <BR> <BR>  public void AddShapeFile (string path,string fileName)<BR>  {<BR>   IWorkspaceFactory  pWorkspaceFactory;<BR>   IFeatureWorkspace  pFeatureWorkspace;<BR>   IFeatureLayer  pFeatureLayer;<BR>   pWorkspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();<BR>   pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(@"F:\\New Folder\\ArcGIS\\DeveloperKit\\samples\\data\\world", 0) as IFeatureWorkspace;<BR>   pFeatureLayer = new ESRI.ArcGIS.Carto.FeatureLayerClass();<BR>   <BR>   pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass("Country");<BR>   <BR>           <BR>   pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;<BR>   this.axMapControl1.AddShapeFile(@"F:\\New Folder\\ArcGIS\\DeveloperKit\\samples\\data\\world",  "Country.shp"); </P>
<P>  }</P>
<P>这段代码只能是固定添加一个shape文件,可是我的想法是要每次点击时就能添加不同的shape文件  应该如何改呢 ??</P>
<P>总统 谢谢了 ~~~~~~</P>
<P>收到的话请尽快帮我解决好吗??</P>
喜欢0 评分0
hahaaluo
路人甲
路人甲
  • 注册日期2006-08-05
  • 发帖数146
  • QQ
  • 铜币591枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2006-08-18 09:32
总统急呀 ~~~~~~帮下忙
这个我弄了好久了还是不能实现想要的功能 总统要尽快帮忙呀
举报 回复(0) 喜欢(0)     评分
hsghxm
路人甲
路人甲
  • 注册日期2004-10-27
  • 发帖数517
  • QQ4604052
  • 铜币1枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2006-08-18 10:23
<P>把你所选择的所有文件的文件名放到一个数组里,然后循环数组,取出每个文件名再调用你的方法不就得了。。。</P>
MSN:hsghxm@163.com QQ:4604052 (很少用,最好别加) Email:hsghxm@163.com 我的BOLG:http://www.gisempire.com/blog/user1/864/index.htm
举报 回复(0) 喜欢(0)     评分
hahaaluo
路人甲
路人甲
  • 注册日期2006-08-05
  • 发帖数146
  • QQ
  • 铜币591枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2006-08-18 11:17
<P>本人是初学的 可以具体点不  最好是能够写代码出来  这样会更加容易理解</P>
举报 回复(0) 喜欢(0)     评分
gisleonzhouly
路人甲
路人甲
  • 注册日期2006-07-24
  • 发帖数15
  • QQ
  • 铜币157枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2006-08-18 12:52
<P>'按下加载shp文件按钮<BR>'===================================================<BR>Private Sub btnLoadSHP_Click()<BR>        Dim sFilePath As String<BR>        Dim pWorkspaceFactory As IWorkspaceFactory<BR>        Dim pFeatureWorkspace As IFeatureWorkspace<BR>        Dim pFeatureLayer As IFeatureLayer<BR>            CommonDialog1.DialogTitle = "Browse Map Document"<BR>            CommonDialog1.Filter = "Map Documents (*.shp)|*.shp"<BR>            CommonDialog1.CancelError = True<BR>        On Error GoTo error<BR>            CommonDialog1.ShowOpen<BR>            If Len(CommonDialog1.FileName) = 0 Then Exit Sub<BR>error:<BR>            sFilePath = CommonDialog1.FileName<BR>            If sFilePath = "" Then Exit Sub<BR>                fname = Left(CommonDialog1.FileTitle, Len(CommonDialog1.FileTitle) - 4)<BR>            Set pWorkspaceFactory = New ShapefileWorkspaceFactory<BR>            Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(CurDir, 0)<BR>            Set pFeatureLayer = New FeatureLayer<BR>            Set pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(fname)<BR>            pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName<BR>            Set pMap = MapCon.Map<BR>            pMap.AddLayer pFeatureLayer<BR>                 </P>

<P>这段代码可以直接用的</P>
举报 回复(0) 喜欢(0)     评分
hahaaluo
路人甲
路人甲
  • 注册日期2006-08-05
  • 发帖数146
  • QQ
  • 铜币591枚
  • 威望0点
  • 贡献值0点
  • 银元0个
5楼#
发布于:2006-08-18 13:35
非常感谢~~~~~
谢谢这位高手,以后请多多指教!!!~!~~~~
举报 回复(0) 喜欢(0)     评分
游客

返回顶部