Private Sub LoadImageForSelectedFeat() Dim pMxDoc As IMxDocument Dim pMap As IMap Dim pFeatureLayer As IFeatureLayer Dim pFeatureSelection As IFeatureSelection Dim pFeatureCursor As IFeatureCursor Dim pSelectedFeature As IFeature Dim pSelectionSet As ISelectionSet Set pMxDoc = ThisDocument Set pMap = pMxDoc.FocusMap Set pFeatureLayer = pMap.Layer(0) ' Layer index of the shape file Set pFeatureSelection = pFeatureLayer Set pSelectionSet = pFeatureSelection.SelectionSet pSelectionSet.Search Nothing, False, pFeatureCursor Set pSelectedFeature = pFeatureCursor.NextFeature 'I assume that you have single feature selected If Not pSelectedFeature Is Nothing Then Dim strFullPath As String strFullPath = pSelectedFeature.Value(pSelectedFeature.Fields.FindField("LOCATION")) ' You can specify the field name from where you accessing the path Dim strPath As String Dim strFilename As String Dim strArray() As String Dim intI As Integer strArray = Split(strFullPath, "\") strFilename = strArray(UBound(strArray)) strPath = Mid(strFullPath, 1, Len(strFullPath) - Len(strFilename)) Dim pWorkspaceFactory As IWorkspaceFactory Set pWorkspaceFactory = New RasterWorkspaceFactory Dim pRasterWorkspace As IRasterWorkspace Set pRasterWorkspace = pWorkspaceFactory.OpenFromFile(strPath, 0) Dim pRasterDataset As IRasterDataset Set pRasterDataset = pRasterWorkspace.OpenRasterDataset(strFilename) Dim pRasterLayer As IRasterLayer Set pRasterLayer = New RasterLayer pRasterLayer.CreateFromDataset pRasterDataset pMap.AddLayer pRasterLayer pMxDoc.UpdateContents pMxDoc.ActiveView.Refresh End If End Sub
I tested it today and it works really good, but there is one more wish I have. The rasters are very big and they need pyramids because of their size. In most cases they don't have pyramids. Is it possible to add some code to the script which build pyramids, when the selected raster don't have any?Thanks for your help!
Hi community,I need some help... I have a VBA script that can load raster data with the path in the attribute table. It looks like:The problem is that I'm new to scripting and I need some additional functionality: - This script is only able to load one selected raster layer at the time. It will be much better for me to load several layers at the same time. - The feature layer with the path has to be the first layer in the layer index. But if I load a raster, this is the first layer in the layer index, so I have to put my layer back on the top of the layer index.I hope you can understand the problems. Maybe someone will find a solution to this. Thanks in AdvanceJann
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.