|
阅读:1389回复:5
请总统帮我看看这段代码,加载Shape文件的
<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> |
|
|
1楼#
发布于:2006-08-18 09:32
总统急呀 ~~~~~~帮下忙
这个我弄了好久了还是不能实现想要的功能 总统要尽快帮忙呀 |
|
|
2楼#
发布于:2006-08-18 10:23
<P>把你所选择的所有文件的文件名放到一个数组里,然后循环数组,取出每个文件名再调用你的方法不就得了。。。</P>
|
|
|
|
3楼#
发布于:2006-08-18 11:17
<P>本人是初学的 可以具体点不 最好是能够写代码出来 这样会更加容易理解</P>
|
|
|
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> |
|
|
5楼#
发布于:2006-08-18 13:35
非常感谢~~~~~
谢谢这位高手,以后请多多指教!!!~!~~~~ |
|