Tif Image Insert Problem in ArcMap

1852
1
10-24-2013 09:27 AM
IvanHuilca
New Contributor
Hello everyone.
I have developed a tool with Visual Studio 2010, which inserts an image. Tif to give the user click in the area of view of ArcMap, the image is inserted into the TOC but no picture in the area of view, but to move your mouse to pan tool, you can view the picture but remains visible in the area of view.
I attached the script.
regards
Ivan

++++++ script
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            IMxDocument mxdoc = ArcMap.Document;

            ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = mxdoc.ActiveView.ScreenDisplay;
            punto = screenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);
          
           
            string dir = @"\\Miserver\imagenes\";
            ESRI.ArcGIS.Carto.IActiveView activeView = mxdoc.ActivatedView;
                  
          
            screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)
                ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit cast.
            ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol = new
                ESRI.ArcGIS.Display.SimpleMarkerSymbolClass();

            ESRI.ArcGIS.Display.ISymbol symbol = simpleMarkerSymbol as
                ESRI.ArcGIS.Display.ISymbol; // Dynamic cast.
            screenDisplay.SetSymbol(symbol);
            ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation =
                screenDisplay.DisplayTransformation;

           

            IWorkspace espacio = VersionedArcSdeWorkspace("MiserverGis", "sde:sqlserver:MiserverGis", "MiBaseGis", "dbo.DEFAULT");
         
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)espacio;
            IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("MiBaseGis.dbo.Grilaimg");
          
          
            IGeometry queryGeometry = punto;           
            // Create the spatial filter. "highwayFeatureClass" is the feature class containing
            // the highway data. Set the SubFields property to "FULL_NAME", as only that field is
            // going to be displayed.
            ISpatialFilter spatialFilter = new SpatialFilterClass();
            spatialFilter.Geometry = queryGeometry;
            spatialFilter.GeometryField = featureClass.ShapeFieldName;
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;          
            spatialFilter.SubFields = "NH";
            // Find the position of the "FULL_NAME" field in the highway feature class.
          
            int nameNH = featureClass.FindField("NH");
            // Execute the query and iterate through the cursor's results.
           
            IFeatureCursor highwayCursor = featureClass.Search(spatialFilter, false);
            IFeature highwayFeature = null;
           
            string varNh = string.Empty;
            string hoja = string.Empty;
            if ((highwayFeature = highwayCursor.NextFeature()) != null)
            {
                varNh = highwayFeature.get_Value(nameNH).ToString();  
               
               
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
                IWorkspaceFactory wsFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                IRasterWorkspace2 rasterWS = (IRasterWorkspace2)wsFactory.OpenFromFile(dir,0);
                IRasterDataset rds = rasterWS.OpenRasterDataset("h"+varNh + ".tif");
                IRasterLayer rasterLayer = new RasterLayerClass();
                rasterLayer.CreateFromDataset(rds);
              

                IMap mapa = activeView.FocusMap;
                mapa.AddLayer(rasterLayer);
               
                activeView.Refresh();

              
            }
            else MessageBox.Show("image not found.");
        }
0 Kudos
1 Reply
seria
by Esri Contributor
Esri Contributor

I created a new ArcMap Add-in based on your code and it worked just fine - the code was able to add a raster to the ActiveView in ArcMap. See below:

protected override void OnClick()

{
     string dir = @"C:\Temp\RasterFolder\"; // The path to to directory containing the Tiff file
     string varNh = @"Clipped_DEM_Israel.tif"; // Name of the Tiff File 

     Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
     IWorkspaceFactory wsFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
     IRasterWorkspace2 rasterWS = (IRasterWorkspace2)wsFactory.OpenFromFile(dir, 0);
     IRasterDataset rds = rasterWS.OpenRasterDataset(varNh);
     IRasterLayer rasterLayer = new RasterLayerClass();
          rasterLayer.CreateFromDataset(rds);
     IMap mapa = ArcMap.Document.FocusMap;
          mapa.AddLayer(rasterLayer);
     IActiveView activeView = mapa as IActiveView;
          activeView.Refresh();
}

Raster_ArcMap.png

I performed the test using ArcGIS 10.3.What version of ArcGIS were you using?