ArcEngine加载图层的五个步骤Word格式文档下载.docx
《ArcEngine加载图层的五个步骤Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《ArcEngine加载图层的五个步骤Word格式文档下载.docx(11页珍藏版)》请在冰豆网上搜索。
//Addthefollowingreferencestotheproject:
//ESRI.ArcGIS.DataSourcesRaster
//ESRI.ArcGIS.Geodatabase
//ESRI.ArcGIS.System
//IntendedArcGISProductsforthissnippet:
//ArcGISDesktop(ArcEditor,ArcInfo,ArcView)
//ArcGISEngine
//ArcGISServer
//ApplicableArcGISProductVersions:
//9.2
//9.3
//RequiredArcGISExtensions:
//ArcGISSpatialAnalyst
//Notes:
//ThissnippetisintendedtobeinsertedatthebaselevelofaClass.
//ItisnotintendedtobenestedwithinanexistingMethod.
///<
summary>
///OpenaRasterfileondiskbyit'
/summary>
paramname="
path"
>
ASystem.Stringthatisthedirectorylocationoftherasterfile.Example:
"
C:
\raster_data"
<
/param>
name"
ASystem.Stringthatisthenameoftherasterfileinthedirectory.Example:
landuse"
or"
watershed"
returns>
AnIGeoDatasetinterface.<
/returns>
remarks>
///IRasterWorkspaceisusedtoaccessarasterstoredinafilesysteminanysupportedrasterformat.
///RasterWorkspaceFactorymustbeusedtocreatearasterworkspace.
///Toaccessrasterfromgeodatabase,useIRasterWorkspaceExinterface.
///
///FormoreinformationonworkingwiththeArcGISSpatialAnaylstobjectssee:
/remarks>
publicESRI.ArcGIS.Geodatabase.IGeoDatasetOpenRasterFileAsGeoDatset(System.Stringpath,System.Stringname)
{
try
{
ESRI.ArcGIS.Geodatabase.IWorkspaceFactoryworkspaceFactory=newESRI.ArcGIS.DataSourcesRaster.RasterWorkspaceFactoryClass();
ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspacerasterWorkspace=(ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace)(workspaceFactory.OpenFromFile(path,0));
ESRI.ArcGIS.Geodatabase.IRasterDatasetrasterDataset=rasterWorkspace.OpenRasterDataset(name);
ESRI.ArcGIS.Geodatabase.IGeoDatasetgeoDataset=(ESRI.ArcGIS.Geodatabase.IGeoDataset)rasterDataset;
//ExplicitCast
returngeoDataset;
}
catch(Exceptionex)
//System.Diagnostics.Debug.WriteLine(ex.Message)
returnnull;
}
#endregion[VisualBasic.NET]
#Region"
'
ArcGISSnippetTitle:
OpenRasterFileAsGeoDatset
LongDescription:
OpenaRasterfileondiskbyit'
Addthefollowingreferencestotheproject:
ESRI.ArcGIS.DataSourcesRaster
ESRI.ArcGIS.Geodatabase
ESRI.ArcGIS.System
IntendedArcGISProductsforthissnippet:
ArcGISDesktop(ArcEditor,ArcInfo,ArcView)
ArcGISEngine
ArcGISServer
ApplicableArcGISProductVersions:
9.2
9.3
RequiredArcGISExtensions:
ArcGISSpatialAnalyst
Notes:
ThissnippetisintendedtobeinsertedatthebaselevelofaClass.
ItisnotintendedtobenestedwithinanexistingFunctionorSub.
<
IRasterWorkspaceisusedtoaccessarasterstoredinafilesysteminanysupportedrasterformat.
RasterWorkspaceFactorymustbeusedtocreatearasterworkspace.
Toaccessrasterfromgeodatabase,useIRasterWorkspaceExinterface.
FormoreinformationonworkingwiththeArcGISSpatialAnaylstobjectssee:
PublicFunctionOpenRasterFileAsGeoDatset(ByValpathAsSystem.String,ByValnameAsSystem.String)AsESRI.ArcGIS.Geodatabase.IGeoDataset
Try
DimworkspaceFactoryAsESRI.ArcGIS.Geodatabase.IWorkspaceFactory=NewESRI.ArcGIS.DataSourcesRaster.RasterWorkspaceFactoryClass()
DimrasterWorkspaceAsESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace=CType(workspaceFactory.OpenFromFile(path,0),ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace)
DimrasterDatasetAsESRI.ArcGIS.Geodatabase.IRasterDataset=rasterWorkspace.OpenRasterDataset(name)
DimgeoDatasetAsESRI.ArcGIS.Geodatabase.IGeoDataset=CType(rasterDataset,ESRI.ArcGIS.Geodatabase.IGeoDataset)'
ExplicitCast
ReturngeoDataset
CatchexAsException
'
System.Diagnostics.Debug.WriteLine(ex.Message)
ReturnNothing
EndTry
EndFunction
#EndRegion
2.添加shapefile
AddShapefileUsingOpenFileDialog"
//AddShapefileUsingOpenFileDialog
//AddashapefiletotheActiveViewusingtheWindows.Forms.OpenFileDialogcontrol.
//ESRI.ArcGIS.Carto
//ESRI.ArcGIS.DataSourcesFile
//ESRI.ArcGIS.Display
//ESRI.ArcGIS.Geometry
//System.Windows.Forms
//(NONE)
///<
AddashapefiletotheActiveViewusingtheWindows.Forms.OpenFileDialogcontrol.<
///
activeView"
AnIActiveViewinterface<
publicvoidAddShapefileUsingOpenFileDialog(ESRI.ArcGIS.Carto.IActiveViewactiveView)
//parametercheck
if(activeView==null)
return;
//UsetheOpenFileDialogClasstochoosewhichshapefiletoload.
System.Windows.Forms.OpenFileDialogopenFileDialog=newSystem.Windows.Forms.OpenFileDialog();
openFileDialog.InitialDirectory="
c:
\\"
;
openFileDialog.Filter="
Shapefiles(*.shp)|*.shp"
openFileDialog.FilterIndex=2;
openFileDialog.RestoreDirectory=true;
openFileDialog.Multiselect=false;
if(openFileDialog.ShowDialog()==System.Windows.Forms.DialogResult.OK)
//Theuserchoseaparticularshapefile.
//Thereturnedstringwillbethefullpath,filenameandfile-extensionforthechosenshapefile.Example:
\test\cities.shp"
stringshapefileLocation=openFileDialog.FileName;
if(shapefileLocation!
="
"
)
//Ensuretheuserchoosesashapefile
//CreateanewShapefileWorkspaceFactoryCoClasstocreateanewworkspace
ESRI.ArcGIS.Geodatabase.IWorkspaceFactoryworkspaceFactory=newESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
//System.IO.Path.GetDirectoryName(shapefileLocation)returnsthedirectorypartofthestring.Example:
\test\"
ESRI.ArcGIS.Geodatabase.IFeatureWorkspacefeatureWorkspace=(ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(shapefileLocation),0);
//System.IO.Path.GetFileNameWithoutExtension(shapefileLocation)returnsthebasefilename(withoutextension).Example:
cities"
ESRI.ArcGIS.Geodatabase.IFeatureClassfeatureClass=featureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(shapefileLocation));
ESRI.ArcGIS.Carto.IFeatureLayerfeatureLayer=newESRI.ArcGIS.Carto.FeatureLayerClass();
featureLayer.FeatureClass=featureClass;
featureLayer.Name=featureClass.AliasName;
featureLayer.Visible=true;
activeView.FocusMap.AddLayer(featureLayer);
//Zoomthedisplaytothefullextentofalllayersinthemap
activeView.Extent=activeView.FullExtent;
activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography,null,null);
else
//Theuserdidnotchooseashapefile.
//Dowhateverremedialactionsasnecessary
//System.Windows.Forms.MessageBox.Show("
Noshapefilechosen"
"
NoChoice#1"
//System.Windows.Forms.MessageBoxButtons.OK,
//System.Windows.Forms.MessageBoxIcon.Exclamation);
//Theuserdidnotchooseashapefile.TheyclickedCancelorclosedthedialogbythe"
X"
button.
//Dowhateverremedialactionsasnecessary.
NoChoice#2"
#endregion
[VisualBasic.NET]
AddShapefileUsingOpenFileDialog
AddashapefiletotheActiveViewusingtheWindows.Forms.OpenFileDialogcontrol.
ESRI.ArcGIS.Carto
ESRI.ArcGIS.DataSourcesFile
ESRI.ArcGIS.Display
ESRI.ArcGIS.Geometry
System.Windows.Forms
(NONE)