Esempio n. 1
0
        private void ExtrusionPropertyPage_Load(object sender, EventArgs e)
        {
            ILayerExtensions extensions = this.ilayer_0 as ILayerExtensions;

            this.cboExtrusionType.SelectedIndex = 0;
            for (int i = 0; i <= (extensions.ExtensionCount - 1); i++)
            {
                if (extensions.get_Extension(i) is I3DProperties)
                {
                    I3DProperties properties = extensions.get_Extension(i) as I3DProperties;
                    this.i3DProperties_0 = properties;
                    if (this.i3DProperties_0.ExtrusionType == esriExtrusionType.esriExtrusionNone)
                    {
                        this.chkExtrusion.Checked     = false;
                        this.cboExtrusionType.Enabled = false;
                    }
                    else
                    {
                        this.chkExtrusion.Checked           = true;
                        this.cboExtrusionType.SelectedIndex = ((int)this.i3DProperties_0.ExtrusionType) - 1;
                    }
                    this.txtExtrusionValue.Text = this.i3DProperties_0.ExtrusionExpressionString;
                    break;
                }
            }
            this.bool_0 = true;
        }
Esempio n. 2
0
        private void Btn_ApplyRasterBaseSurface_Click(object sender, EventArgs e)
        {
            ILayer                pBaseLayer                = m_pTarScene.Layer[CbBoxBaseLayer.SelectedIndex];
            ILayer                pDisplayLayer             = m_pTarLayer;
            IRasterSurface        pBaseSurfaceRaster        = new RasterSurface();
            IRasterLayer          pBaseRasterLayer          = pBaseLayer as IRasterLayer;
            IRaster               pBaseRaster               = (IRaster)pBaseRasterLayer.Raster;
            IRasterBandCollection pBaseRasterBandCollection = pBaseRaster as IRasterBandCollection;
            IRasterBand           pBaseRasterBand           = pBaseRasterBandCollection.Item(0);

            pBaseSurfaceRaster.RasterBand = pBaseRasterBand;
            ISurface         pBaseSurface     = pBaseSurfaceRaster as ISurface;
            ILayerExtensions pLayerExtensions = pDisplayLayer as ILayerExtensions;
            I3DProperties    p3DProperties    = null;

            for (int i = 0; i < pLayerExtensions.ExtensionCount; i++)
            {
                object pCurExtension = pLayerExtensions.get_Extension(i);
                if (pCurExtension != null)
                {
                    p3DProperties = (I3DProperties)pCurExtension;
                    break;
                }
            }

            p3DProperties.BaseOption  = esriBaseOption.esriBaseSurface;
            p3DProperties.BaseSurface = pBaseSurface;
            p3DProperties.Apply3DProperties(pDisplayLayer);
            p3DProperties.ZFactor = 1;

            m_pTarScene.SceneGraph.RefreshViewers();
        }
Esempio n. 3
0
        private static void SetVisibilitySessionRaster3DProperties(IRasterLayer rasterLayer,
                                                                   IObjectFactory objFactory,
                                                                   IFunctionalSurface surface,
                                                                   bool isDrapperyLayer = false)
        {
            var properties3D = (I3DProperties3)objFactory.Create("esrianalyst3d.Raster3DProperties");

            properties3D.BaseOption  = esriBaseOption.esriBaseSurface;
            properties3D.BaseSurface = surface;

            if (!isDrapperyLayer)
            {
                properties3D.OffsetExpressionString = "2";
                properties3D.DepthPriorityValue     = 1;
            }
            else
            {
                properties3D.DepthPriorityValue = 9;
            }

            properties3D.ZFactor                   = _zFactor;
            properties3D.RenderVisibility          = esriRenderVisibility.esriRenderAlways;
            properties3D.RenderMode                = esriRenderMode.esriRenderCache;
            properties3D.TextureDownsamplingFactor = 0.7;
            properties3D.AlphaThreshold            = 0.1;
            properties3D.RenderRefreshRate         = 0.75;
            properties3D.Illuminate                = true;

            ILayerExtensions layerExtensions = (ILayerExtensions)rasterLayer;

            layerExtensions.AddExtension(properties3D);
            properties3D.Apply3DProperties(rasterLayer);
        }
Esempio n. 4
0
        private void 影像叠加ToolStripMenuItem_Click(object sender, System.EventArgs e)
        {
            ISceneGraph pSceneGraph = this.axSceneControl1.SceneGraph;
            IScene      pScene      = pSceneGraph.Scene;
            ILayer      layer       = pScene.get_Layer(0);
            ITinLayer   tinLayer    = layer as ITinLayer;

            layer = pScene.get_Layer(1);
            IRasterLayer rasterLayer = layer as IRasterLayer;
            ITinAdvanced tinAdvanced;
            ISurface     surface;

            tinAdvanced = tinLayer.Dataset as ITinAdvanced;
            surface     = tinAdvanced.Surface;

            ILayerExtensions layerExtensions = (ILayerExtensions)rasterLayer;
            I3DProperties    i3dProperties   = null;

            for (int i = 0; i < layerExtensions.ExtensionCount; i++)
            {
                if (layerExtensions.get_Extension(i) is I3DProperties)
                {
                    i3dProperties = (I3DProperties)layerExtensions.get_Extension(i);
                }
            }//get 3d properties from extension

            i3dProperties.BaseOption  = esriBaseOption.esriBaseSurface;
            i3dProperties.BaseSurface = surface;
            i3dProperties.Apply3DProperties(rasterLayer);
            pSceneGraph.RefreshViewers();
        }
Esempio n. 5
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < this.tabControl1.Controls.Count; i++)
     {
         if (
             !((this.tabControl1.Controls[i] as TabPage).Controls[0] as ILayerAndStandaloneTablePropertyPage)
             .Apply())
         {
             return;
         }
     }
     if (this.ibasicMap_0 is IScene)
     {
         ILayerExtensions extensions = this.object_0 as ILayerExtensions;
         for (int j = 0; j <= (extensions.ExtensionCount - 1); j++)
         {
             if (extensions.get_Extension(j) is I3DProperties)
             {
                 (extensions.get_Extension(j) as I3DProperties).Apply3DProperties(this.object_0);
                 break;
             }
         }
     }
     base.DialogResult = DialogResult.OK;
 }
Esempio n. 6
0
        private static void SetFeatures3DProperties(IFeatureLayer layer, IObjectFactory objFactory)
        {
            var properties3D = (I3DProperties)objFactory.Create("esrianalyst3d.Feature3DProperties");

            properties3D.ZFactor = 7;
            properties3D.OffsetExpressionString = "200";

            ILayerExtensions layerExtensions = (ILayerExtensions)layer;

            layerExtensions.AddExtension(properties3D);
            properties3D.Apply3DProperties(layer);
        }
Esempio n. 7
0
        public static void DisableLighting(IGraphicsContainer3D graphicsContainer3D)
        {
            I3DProperties properties3D = new Basic3DPropertiesClass();

            properties3D.Illuminate = false;

            ILayerExtensions layerExtensions = graphicsContainer3D as ILayerExtensions;

            layerExtensions.AddExtension(properties3D);

            properties3D.Apply3DProperties(graphicsContainer3D);
        }
Esempio n. 8
0
        private static void SetHightFeatures3DProperties(IFeatureLayer layer, IObjectFactory objFactory)
        {
            var properties3D = (I3DProperties)objFactory.Create("esrianalyst3d.Feature3DProperties");

            properties3D.BaseOption             = esriBaseOption.esriBaseShape;
            properties3D.ZFactor                = _zFactor;
            properties3D.OffsetExpressionString = "3";

            ILayerExtensions layerExtensions = (ILayerExtensions)layer;

            layerExtensions.AddExtension(properties3D);
            properties3D.Apply3DProperties(layer);
        }
Esempio n. 9
0
        private static void SetSurface3DProperties(ILayer layer, IObjectFactory objFactory, IFunctionalSurface surface)
        {
            var properties3D = (I3DProperties)objFactory.Create("esrianalyst3d.Raster3DProperties");

            properties3D.BaseOption  = esriBaseOption.esriBaseSurface;
            properties3D.BaseSurface = surface;
            properties3D.ZFactor     = 7;

            ILayerExtensions layerExtensions = (ILayerExtensions)layer;

            layerExtensions.AddExtension(properties3D);
            properties3D.Apply3DProperties(layer);
        }
Esempio n. 10
0
        private static void SetLine3DProperties(IFeatureLayer layer, IObjectFactory objFactory, IFunctionalSurface surface)
        {
            var properties3D = (I3DProperties)objFactory.Create("esrianalyst3d.Feature3DProperties");

            properties3D.BaseOption             = esriBaseOption.esriBaseSurface;
            properties3D.BaseSurface            = surface;
            properties3D.ZFactor                = 7;
            properties3D.OffsetExpressionString = "200";

            ILayerExtensions layerExtensions = (ILayerExtensions)layer;

            layerExtensions.AddExtension(properties3D);
            properties3D.Apply3DProperties(layer);
        }
Esempio n. 11
0
        private I3DProperties get3DProps(ITinLayer tinLayer)
        {
            I3DProperties    _3DProps = null;
            ILayerExtensions lyrExt   = tinLayer as ILayerExtensions;

            for (int i = 0; i < lyrExt.ExtensionCount; i++)
            {
                if (lyrExt.get_Extension(i) is I3DProperties)
                {
                    _3DProps = lyrExt.get_Extension(i) as I3DProperties;
                }
            }
            return(_3DProps);
        }
Esempio n. 12
0
        private static void SetFeatures3DProperties(IFeatureLayer layer, IObjectFactory objFactory,
                                                    IFunctionalSurface surface, double height = double.NaN)
        {
            var properties3D = (I3DProperties)objFactory.Create("esrianalyst3d.Feature3DProperties");

            properties3D.BaseOption             = esriBaseOption.esriBaseSurface;
            properties3D.BaseSurface            = surface;
            properties3D.ZFactor                = _zFactor;
            properties3D.OffsetExpressionString = (height == double.NaN) ? "3" : height.ToString();

            ILayerExtensions layerExtensions = (ILayerExtensions)layer;

            layerExtensions.AddExtension(properties3D);
            properties3D.Apply3DProperties(layer);
        }
Esempio n. 13
0
        public I3DProperties Get3DPropsFromLayer(ILayer pLyr)
        {
            ILayerExtensions pLyrExts = (ILayerExtensions)pLyr;
            I3DProperties    p3DProp  = null;

            for (int i = 0; i < pLyrExts.ExtensionCount; i++)
            {
                if (pLyrExts.get_Extension(i) is I3DProperties)
                {
                    p3DProp = (I3DProperties)pLyrExts.get_Extension(i);
                }
            }//get 3d properties from extension

            return(p3DProp);
        }
Esempio n. 14
0
        private bool method_1(ILayer ilayer_0)
        {
            ILayerExtensions extensions = ilayer_0 as ILayerExtensions;

            if (extensions != null)
            {
                for (int i = 0; i < extensions.ExtensionCount; i++)
                {
                    if (extensions.get_Extension(i) is I3DProperties)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 15
0
        private void FrmSceneLayerOffest_Load(object sender, EventArgs e)
        {
            // 读取偏移高程
            if (m_pSceneCtrl != null)
            {
                IScene           pScene          = m_pSceneCtrl.Scene;
                ILayerExtensions layerextensions = pLayer as ILayerExtensions;
                //I3DProperties properties = null;
                if (pLayer is IRasterLayer)
                {
                    properties = new Raster3DPropertiesClass();
                }
                if (pLayer is IFeatureLayer)
                {
                    properties = new Feature3DPropertiesClass();
                }
                if (pLayer is ITinLayer)
                {
                    properties = new Tin3DPropertiesClass();
                }
                object p3d;
                for (int j = 0; j < layerextensions.ExtensionCount; j++)
                {
                    p3d = layerextensions.get_Extension(j);
                    if (p3d != null)
                    {
                        properties = p3d as I3DProperties;
                        if (properties != null)
                        {
                            break;
                        }
                    }
                }
                try
                {
                    numericUpDownOffset.Value = Convert.ToDecimal(properties.OffsetExpressionString);
                }
                catch
                {
                }
                // properties.OffsetExpressionString = doubleInputOffset.Value.ToString();

                //IActiveView iv = m_pSceneCtrl.Scene as IActiveView;
                //iv.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null);
            }
        }
Esempio n. 16
0
        public void AddDrapeLayerToGlobeElevationSurface(IGlobeDisplay globeDisplay, ILayer layer, System.String elevationRasterFilePath)
        {
            ChangeProp(layer);

            IGlobeDisplayLayers globeDisplayLayers = (IGlobeDisplayLayers)globeDisplay; // Explicit cast

            IFeatureLayer pFeatureLayer = (IFeatureLayer)layer;

            pFeatureLayer.Cached = true;

            // Create elevation raster layer
            IRasterLayer elevationRasterLayer = new RasterLayer();

            elevationRasterLayer.CreateFromFilePath(elevationRasterFilePath);

            // Create and add the GlobeLayerProperties extension with the Type set to ElevationData
            IGlobeLayerProperties globeLayerProperties = new GlobeLayerProperties();

            globeLayerProperties.Type = esriGlobeDataType.esriGlobeDataElevation;
            ILayerExtensions layerExtension = (ILayerExtensions)elevationRasterLayer; // Explicit cast

            layerExtension.AddExtension(globeLayerProperties);

            // Set the base option for layer to be esriGlobeLayerBaseLayer and its base layer to be ElevationLayer
            IGlobeLayerProperties  drapeLayerGlobeLayerProperties  = globeDisplayLayers.FindGlobeProperties(layer);
            IGlobeHeightProperties drapeLayerGlobeHeightProperties = drapeLayerGlobeLayerProperties.HeightProperties;

            //
            drapeLayerGlobeHeightProperties.BaseLayer  = elevationRasterLayer;
            drapeLayerGlobeHeightProperties.BaseOption = esriGlobeLayerBaseOption.esriGlobeLayerBaseLayer;
            drapeLayerGlobeHeightProperties.ElevationExpressionString = "[Elevation] * 1000";
            // drapeLayerGlobeHeightProperties.ExtrusionType =  ESRI.ArcGIS.Analyst3D.esriExtrusionType.esriExtrusionBase;
            //drapeLayerGlobeHeightProperties.ExtrusionExpressionString = "Elevation * 1000";
            // Apply the height properties of the layer
            globeDisplayLayers.ApplyHeightProperties(layer);
            drapeLayerGlobeHeightProperties.Apply(m_Globe, layer);
            // globeDisplay.RefreshViewers();

            globeDisplayLayers.RefreshLayer(layer);
            IActiveView pacv = (IActiveView)m_Globe;

            pacv.PartialRefresh(esriViewDrawPhase.esriViewGeography, pFeatureLayer, null);
        }
Esempio n. 17
0
        public static ISurface GetBaseSurface(ILayer ilayer_0)
        {
            ISurface         result          = null;
            ILayerExtensions layerExtensions = ilayer_0 as ILayerExtensions;

            for (int i = 0; i <= layerExtensions.ExtensionCount - 1; i++)
            {
                if (layerExtensions.get_Extension(i) is I3DProperties)
                {
                    I3DProperties i3DProperties = layerExtensions.get_Extension(i) as I3DProperties;
                    if (i3DProperties.BaseOption == esriBaseOption.esriBaseSurface && i3DProperties.BaseSurface != null)
                    {
                        result = (i3DProperties.BaseSurface as ISurface);
                    }
                    return(result);
                }
            }
            return(result);
        }
Esempio n. 18
0
        /// <summary>
        /// Removes the umbriel property set (propertyset with a name/value of LayerExtension/umbriel
        /// </summary>
        /// <param name="layerExtensions">ILayerExtensions</param>
        internal static void RemovePropertySet(ILayerExtensions layerExtensions)
        {
            if (UmbrielPropertySetExists(layerExtensions))
            {
                for (int i = 0; i < layerExtensions.ExtensionCount; i++)
                {
                    object layerExtension = layerExtensions.get_Extension(i);

                    if (layerExtension is IPropertySet)
                    {
                        IPropertySet propertySet = (IPropertySet)layerExtension;
                        string       val         = propertySet.GetProperty("LayerExtension").ToString();
                        if (val.Equals("umbriel", StringComparison.CurrentCultureIgnoreCase))
                        {
                            layerExtensions.RemoveExtension(i);
                        }
                    }
                }
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Searches ILayer's layerextensions for any PropertySets that contain name/value combo
        /// </summary>
        /// <param name="layer">The ILayer</param>
        /// <param name="propertysetname">The propertyset name.</param>
        /// <param name="propertysetvalue">The propertyset value.</param>
        /// <param name="comparison">The string comparison method</param>
        /// <returns>List of IPropertySet</returns>
        public static List <IPropertySet> FindExtensionPropertySet(this ILayer layer, string propertysetname, string propertysetvalue, StringComparison comparison)
        {
            List <IPropertySet> propertySets = new List <IPropertySet>();

            ILayerExtensions layerExtensions = (ILayerExtensions)layer;

            try
            {
                if (layerExtensions.ExtensionCount > 0)
                {
                    for (int i = 0; i < layerExtensions.ExtensionCount; i++)
                    {
                        object layerExtension = layerExtensions.get_Extension(i);

                        if (layerExtension is IPropertySet)
                        {
                            IPropertySet propertySet = (IPropertySet)layerExtension;

                            try
                            {
                                if (propertySet.GetProperty(propertysetname).ToString().Equals(propertysetvalue, comparison))
                                {
                                    propertySets.Add(propertySet);
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                }

                return(propertySets);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.StackTrace);
                throw;
            }
        }
Esempio n. 20
0
        private void SceneRenderPropertyPage_Load(object sender, EventArgs e)
        {
            ILayerExtensions extensions = this.ilayer_0 as ILayerExtensions;

            for (int i = 0; i <= (extensions.ExtensionCount - 1); i++)
            {
                if (extensions.get_Extension(i) is I3DProperties)
                {
                    I3DProperties properties = extensions.get_Extension(i) as I3DProperties;
                    this.i3DProperties_0 = properties;
                    if (this.i3DProperties_0.RenderMode == esriRenderMode.esriRenderCache)
                    {
                        this.rdordoRenderCache.Checked = true;
                    }
                    else if (this.i3DProperties_0.RenderMode == esriRenderMode.esriRenderImmediate)
                    {
                        this.rdoRenderImmediate.Checked = true;
                    }
                    if (this.i3DProperties_0.RenderVisibility == esriRenderVisibility.esriRenderAlways)
                    {
                        this.rdoRenderAlways.Checked = true;
                    }
                    else if (this.i3DProperties_0.RenderVisibility == esriRenderVisibility.esriRenderWhenNavigating)
                    {
                        this.rdoRenderWhenNavigating.Checked = true;
                    }
                    else if (this.i3DProperties_0.RenderVisibility == esriRenderVisibility.esriRenderWhenStopped)
                    {
                        this.rdoRenderWhenStopped.Checked = true;
                    }
                    this.txtRenderRefreshRate.Value          = (decimal)this.i3DProperties_0.RenderRefreshRate;
                    this.chkIlluminate.Checked               = this.i3DProperties_0.Illuminate;
                    this.chkSmoothShading.Checked            = this.i3DProperties_0.SmoothShading;
                    this.cboDepthPriorityValue.SelectedIndex = this.i3DProperties_0.DepthPriorityValue - 1;
                    break;
                }
            }
            this.bool_1 = true;
        }
Esempio n. 21
0
        /// <summary>
        /// Determines if the Umbriel property set exists in the layer extensions
        /// </summary>
        /// <param name="layerExtensions">The layer extensions.</param>
        /// <returns>true if exists, false if it doont</returns>
        internal static bool UmbrielPropertySetExists(ILayerExtensions layerExtensions)
        {
            try
            {
                bool exists = false;

                if (layerExtensions.ExtensionCount > 0)
                {
                    for (int i = 0; i < layerExtensions.ExtensionCount; i++)
                    {
                        object layerExtension = layerExtensions.get_Extension(i);

                        if (layerExtension is IPropertySet)
                        {
                            IPropertySet propertySet = (IPropertySet)layerExtension;
                            try
                            {
                                string val = propertySet.GetProperty("LayerExtension").ToString();
                                if (val.Equals("umbriel", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    exists = true;
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                }

                return(exists);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.StackTrace);
                throw;
            }
        }
Esempio n. 22
0
        public static I3DProperties Get3DPropsFromLayer(ILayer ilayer_0)
        {
            I3DProperties result;

            try
            {
                ILayerExtensions layerExtensions = ilayer_0 as ILayerExtensions;
                for (int i = 0; i <= layerExtensions.ExtensionCount - 1; i++)
                {
                    I3DProperties i3DProperties = layerExtensions.get_Extension(i) as I3DProperties;
                    if (i3DProperties != null)
                    {
                        result = i3DProperties;
                        return(result);
                    }
                }
            }
            catch
            {
            }
            result = null;
            return(result);
        }
Esempio n. 23
0
        public void Execute(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager envMgr, ESRI.ArcGIS.Geodatabase.IGPMessages message)
        {
            try
            {
                IGPUtilities3 gpUtilities3 = new GPUtilitiesClass();

                if (TrackCancel == null)
                {
                    TrackCancel = new CancelTrackerClass();
                }

                IGPParameter inputSourceLayerParameter = paramvalues.get_Element(in_sourcelayerNumber) as IGPParameter;
                IGPValue     inputSourceLayerGPValue   = gpUtilities3.UnpackGPValue(inputSourceLayerParameter) as IGPValue;

                IGPParameter inputTargetLayerParameter = paramvalues.get_Element(in_targetlayerNumber) as IGPParameter;
                IGPValue     inputTargetLayerGPValue   = gpUtilities3.UnpackGPValue(inputTargetLayerParameter) as IGPValue;

                ILayer sourceLayer = gpUtilities3.DecodeLayer(inputSourceLayerGPValue);
                ILayer targetLayer = gpUtilities3.DecodeLayer(inputTargetLayerGPValue);

                ILayerExtensions sourceLayerExtensions = sourceLayer as ILayerExtensions;

                if (sourceLayerExtensions == null)
                {
                    message.AddWarning(resourceManager.GetString("GPTools_GPCopyLayerExtension_source_noext_support"));
                    return;
                }

                ILayerExtensions targetLayerExtensions = targetLayer as ILayerExtensions;

                if (targetLayerExtensions == null)
                {
                    message.AddWarning(resourceManager.GetString("GPTools_GPCopyLayerExtension_target_noext_support"));
                    return;
                }

                // test if the feature classes already exists,
                // if they do and the environments settings are such that an overwrite is not allowed we need to abort at this point
                IGeoProcessorSettings gpSettings = (IGeoProcessorSettings)envMgr;
                if (gpSettings.OverwriteOutput == true)
                {
                }

                else
                {
                    if (gpUtilities3.Exists(inputTargetLayerGPValue) == true)
                    {
                        message.AddError(120003, String.Format(resourceManager.GetString("GPTools_GPCopyLayerExtension_targetlayeralreadyexists"), inputTargetLayerGPValue.GetAsText()));
                        return;
                    }
                }

                for (int targetExtensionIndex = 0; targetExtensionIndex < targetLayerExtensions.ExtensionCount; targetExtensionIndex++)
                {
                    targetLayerExtensions.RemoveExtension(targetExtensionIndex);
                }


                for (int sourceExtensionIndex = 0; sourceExtensionIndex < sourceLayerExtensions.ExtensionCount; sourceExtensionIndex++)
                {
                    targetLayerExtensions.AddExtension(sourceLayerExtensions.get_Extension(sourceExtensionIndex));
                }
            }
            catch (Exception ex)
            {
                message.AddError(120004, ex.Message);
            }
        }
Esempio n. 24
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            //高程底面
            ILayer   pBaseLayer = null;
            ISurface pSurface   = null;

            if (m_pSceneCtrl != null)
            {
                try
                {
                    // m_pSceneCtrl.LoadSxFile(ClsGDBDataCommon.GetParentPathofExe() +@"Resource\DefaultData\Default.sxd");
                }
                catch
                {
                }
                //IScene pScene = new SceneClass();
                //pScene.Name = "Scene";
                //m_pSceneCtrl.Scene = pScene;

                IScene pScene = m_pSceneCtrl.Scene;
                pScene.Name = "Scene";
                //ILayer pglayer = new GraphicsLayer3DClass();
                //pScene.AddLayer(pglayer);
                //pScene.ActiveGraphicsLayer = new CompositeGraphicsLayerClass();

                pScene.ExaggerationFactor = Convert.ToDouble(doubleInputExaFactor.Value.ToString());
                while (pScene.LayerCount > 0)
                {
                    pScene.DeleteLayer(pScene.get_Layer(0));
                }
                // pScene.ClearLayers();
                pScene.AddLayer(pScene.ActiveGraphicsLayer);
                GC.Collect();
                for (int i = 0; i < m_pMapCtrl.Map.LayerCount; i++)
                {
                    ILayer pMapLayer = m_pMapCtrl.Map.get_Layer(i);
                    ILayer pLayer    = pMapLayer;

                    if (comboBoxExBaseHeightLayer.Items.Count > 0)
                    {
                        if (pLayer.Name == comboBoxExBaseHeightLayer.SelectedItem.ToString())
                        {
                            pBaseLayer = pLayer;
                        }
                    }
                }

                if (pBaseLayer is IRasterLayer)
                {
                    IRaster        pRaster  = ((IRasterLayer)pBaseLayer).Raster;
                    IRasterBand    pBand    = ((IRasterBandCollection)pRaster).Item(0);
                    IRasterSurface rsurface = new RasterSurface();
                    rsurface.RasterBand = pBand;
                    //将dem的数据指定为surface
                    pSurface = rsurface as ISurface;
                }
                if (pBaseLayer is ITinLayer)
                {
                    ITin        pTin        = ((ITinLayer)pBaseLayer).Dataset;
                    ITinSurface pTinSurface = pTin as ITinSurface;
                    pSurface = pTinSurface as ISurface;
                }


                for (int i = 0; i < m_pMapCtrl.Map.LayerCount; i++)
                {
                    ILayer pMapLayer = m_pMapCtrl.Map.get_Layer(i);

                    ILayer pLayer     = pMapLayer;
                    string filepath   = "";
                    string filename   = "";
                    string sourcepath = GetDataLayerPath(pMapLayer as IDataLayer, ref filepath, ref filename);

                    //if (pMapLayer is IRasterLayer)
                    //{
                    //    IRasterLayer prl = new RasterLayerClass();
                    //     prl.CreateFromRaster(((IRasterLayer)pMapLayer).Raster);
                    //     pLayer = prl as ILayer;
                    //}
                    if (pMapLayer is IFeatureLayer)
                    {
                        // if (((IFeatureLayer)pMapLayer).FeatureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultiPatch)
                        //  {

                        IFeatureLayer pfl = new FeatureLayerClass();
                        IFeatureClass pFc = ((IFeatureLayer)pMapLayer).FeatureClass;
                        if (pFc != null)
                        {
                            pfl.FeatureClass = ((IFeatureLayer)pMapLayer).FeatureClass;
                            pLayer           = pfl as ILayer;
                            pLayer.Name      = pMapLayer.Name;

                            /////////////////////////////////////////////////////////////////////
                            //后期添加,用于带进涂层渲染
                            /////////////////////////////////////////////////////////////////////
                            IGeoFeatureLayer pGeoFLayer  = pfl as IGeoFeatureLayer;
                            IGeoFeatureLayer pGFMapLayer = pMapLayer as IGeoFeatureLayer;
                            if (pGFMapLayer != null)  //注记图层为空
                            {
                                pGeoFLayer.Renderer = pGFMapLayer.Renderer;
                                ILegendInfo pLegend3D = (ILegendInfo)pGeoFLayer;
                                for (int k = 0; k < pLegend3D.LegendGroupCount; k++)
                                {
                                    ILegendGroup pLgroup = pLegend3D.LegendGroup[k];
                                    for (int p = 0; p < pLgroup.ClassCount; p++)
                                    {
                                        ILegendClass pLClass = pLgroup.Class[p];
                                        if (pLClass.Symbol is IMarkerSymbol)
                                        {
                                            IMarkerSymbol pSMSymbol = pLClass.Symbol as IMarkerSymbol;
                                            pSMSymbol.Size /= 20;
                                        }
                                    }
                                }
                                if (pFc.ShapeType == esriGeometryType.esriGeometryMultipoint || pFc.ShapeType == esriGeometryType.esriGeometryPoint)
                                {
                                    if (pGFMapLayer.Renderer is IUniqueValueRenderer)
                                    {
                                    }
                                }
                            }
                        }
                        //  }
                    }

                    #region 这段代码家的有点重复,如果不加有时候会弹出设置数据源的对话框
                    if (pLayer is IRasterLayer)
                    {
                        I3DProperties properties = null;

                        properties = new Raster3DPropertiesClass();
                        ILayerExtensions layerextensions = pLayer as ILayerExtensions;

                        object p3d;
                        for (int j = 0; j < layerextensions.ExtensionCount; j++)
                        {
                            p3d = layerextensions.get_Extension(j);
                            if (p3d != null)
                            {
                                properties = p3d as I3DProperties;
                                if (properties != null)
                                {
                                    break;
                                }
                            }
                        }
                        properties.BaseOption  = esriBaseOption.esriBaseSurface;
                        properties.BaseSurface = pSurface;
                        //I、更改分辨率后,如何让分辨率设置发挥作用。主要是刷新的问题(使用IActiveView刷新、而不能使用Iscene及IScenegraph刷新)
                        //II、分辨率数值在( 262144-268435456)范围之内,越大越清晰。使用3DProperties.MaxTextureMemory 方法
                        properties.MaxTextureMemory = 268435456;
                    }
                    #endregion
                    pScene.AddLayer(pLayer);
                    //if (((CheckBoxItem)itemPanelSetVisible.Items[i]).Checked == false)
                    //{
                    //    pLayer.Visible = false;
                    //}
                    //else
                    //{
                    //    pLayer.Visible = true;
                    //}
                    if (comboBoxExBaseHeightLayer.Items.Count > 0)
                    {
                        if (pLayer.Name == comboBoxExBaseHeightLayer.SelectedItem.ToString())
                        {
                            pBaseLayer = pLayer;
                        }
                    }
                }
            }

            if (pSurface != null)
            {
                for (int i = 0; i < m_pSceneCtrl.Scene.LayerCount; i++)
                {
                    ILayer pLayer = m_pSceneCtrl.Scene.get_Layer(i);

                    ILayerExtensions layerextensions = m_pSceneCtrl.Scene.get_Layer(i) as ILayerExtensions;
                    I3DProperties    properties      = null;
                    if (pLayer is IRasterLayer)
                    {
                        properties = new Raster3DPropertiesClass();
                    }
                    if (pLayer is IFeatureLayer)
                    {
                        properties = new Feature3DPropertiesClass();
                    }
                    if (pLayer is ITinLayer)
                    {
                        properties = new Tin3DPropertiesClass();
                    }
                    object p3d;
                    for (int j = 0; j < layerextensions.ExtensionCount; j++)
                    {
                        p3d = layerextensions.get_Extension(j);
                        if (p3d != null)
                        {
                            properties = p3d as I3DProperties;
                            if (properties != null)
                            {
                                break;
                            }
                        }
                    }
                    if (!(pLayer is IFeatureLayer))
                    {
                        properties.BaseOption  = esriBaseOption.esriBaseSurface;
                        properties.BaseSurface = pSurface;
                        //I、更改分辨率后,如何让分辨率设置发挥作用。主要是刷新的问题(使用IActiveView刷新、而不能使用Iscene及IScenegraph刷新)
                        //II、分辨率数值在( 262144-268435456)范围之内,越大越清晰。使用3DProperties.MaxTextureMemory 方法
                        properties.MaxTextureMemory = 268435456;
                    }
                    else
                    {
                        IFeatureLayer pFlayer = pLayer as IFeatureLayer;
                        //multipatch的本身有高度信息
                        if (pFlayer.FeatureClass != null && pFlayer.FeatureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultiPatch)
                        {
                            bool needConstantHeight = false;

                            /*
                             * try
                             * {
                             *  //把导航点转向角,视场角等信息都设置成不贴在表面而需要根据生产该信息的文件设置高度
                             *  IFeatureClass fc = pFlayer.FeatureClass;
                             *  IFeatureCursor pFcursor = fc.Search(null, false);
                             *  int OriginalFeatureidx = fc.FindField("OriginalFeatureClass");
                             *  int OriginalFeatureOIDidx = fc.FindField("OID");
                             *  IFeature pF = pFcursor.NextFeature();
                             *  IFeatureLayer pOFeatureLayer = null;
                             *  if (OriginalFeatureidx == -1|| OriginalFeatureOIDidx == -1)
                             *  {
                             *      pF = null;
                             *  }
                             *  else
                             *  {
                             *      if (pF != null)
                             *      {
                             *          //获取路径点图层名称
                             *          string orignalname = pF.get_Value(OriginalFeatureidx).ToString();
                             *          IMap pMap = m_pMapCtrl.Map;
                             *          for (int k = 0; k < pMap.LayerCount; k++)
                             *          {
                             *              if (pMap.get_Layer(k).Name.Equals(orignalname))
                             *              {
                             *                  pOFeatureLayer = pMap.get_Layer(k) as IFeatureLayer;
                             *                  break;
                             *              }
                             *          }
                             *          if (pOFeatureLayer == null)
                             *          {
                             *              pF = null;
                             *          }
                             *      }
                             *  }
                             *
                             *  while (pF != null)
                             *  {
                             *      //IFeatureClass pFClass = pOFeatureLayer.FeatureClass;
                             *      //pFClass.FindField(OriginalFeatureOIDidx);
                             *
                             *
                             *      pF = pFcursor.NextFeature();
                             *  }
                             * }
                             * catch
                             * {
                             *  ;
                             * }
                             */
                            if (needConstantHeight == false)
                            {
                                properties.BaseOption = esriBaseOption.esriBaseSurface;
                                //I3DProperties2 pr = properties as I3DProperties2;
                                //if (pr != null)
                                //{
                                //    pr.OffsetExpressionString = "0.005";
                                //}
                                //  properties.BaseOption = esriBaseOption.esriBaseExpression;
                                properties.BaseSurface = pSurface;
                                //I、更改分辨率后,如何让分辨率设置发挥作用。主要是刷新的问题(使用IActiveView刷新、而不能使用Iscene及IScenegraph刷新)
                                //II、分辨率数值在( 262144-268435456)范围之内,越大越清晰。使用3DProperties.MaxTextureMemory 方法
                                properties.MaxTextureMemory = 268435456;
                            }
                        }
                    }
                    //  properties.Apply3DProperties(domlayer);
                    // ps.SceneGraph.RefreshViewers();

                    IActiveView iv = m_pSceneCtrl.Scene as IActiveView;
                    iv.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null);
                }
            }
        }
Esempio n. 25
0
        private void BaseHeightPropertyPage_Load(object sender, EventArgs e)
        {
            int num;

            for (num = 0; num < this.ibasicMap_0.LayerCount; num++)
            {
                ILayer   layer   = this.ibasicMap_0.get_Layer(num);
                ISurface surface = this.method_0(layer);
                if (surface != null)
                {
                    this.cboSufer.Items.Add(new SuferWrap(surface));
                }
            }
            ILayerExtensions extensions = this.ilayer_0 as ILayerExtensions;

            for (int i = 0; i <= (extensions.ExtensionCount - 1); i++)
            {
                if (extensions.get_Extension(i) is I3DProperties)
                {
                    I3DProperties properties = extensions.get_Extension(i) as I3DProperties;
                    this.i3DProperties_0 = properties;
                    if (properties.BaseOption != esriBaseOption.esriBaseSurface)
                    {
                        if (properties.BaseOption == esriBaseOption.esriBaseExpression)
                        {
                            this.rdoBaseExpression.Checked = true;
                            this.txtBaseExpression.Text    = properties.BaseExpressionString;
                        }
                        else
                        {
                            this.rdoBaseShape.Checked = true;
                        }
                    }
                    else if (properties.BaseSurface != null)
                    {
                        this.rdoBaseSurface.Checked = true;
                        ISurface baseSurface = properties.BaseSurface as ISurface;
                        bool     flag        = true;
                        for (num = 0; num < this.cboSufer.Items.Count; num++)
                        {
                            if ((this.cboSufer.Items[num] as SuferWrap).Surface == baseSurface)
                            {
                                this.cboSufer.SelectedIndex = num;
                                flag = false;
                                break;
                            }
                        }
                        if (flag)
                        {
                            this.cboSufer.Items.Add(new SuferWrap(baseSurface));
                            this.cboSufer.SelectedIndex = this.cboSufer.Items.Count - 1;
                        }
                    }
                    this.txtOffset.Text  = properties.OffsetExpressionString;
                    this.txtZFeator.Text = properties.ZFactor.ToString();
                    break;
                }
            }
            if (this.ilayer_0 is IFeatureLayer)
            {
                IFeatureClass featureClass = (this.ilayer_0 as IFeatureLayer).FeatureClass;
                if (featureClass != null)
                {
                    int index = featureClass.Fields.FindField(featureClass.ShapeFieldName);
                    if (!featureClass.Fields.get_Field(index).GeometryDef.HasZ)
                    {
                        this.rdoBaseShape.Enabled = false;
                    }
                    else
                    {
                        this.rdoBaseShape.Enabled = true;
                        if (this.rdoBaseShape.Checked)
                        {
                            this.rdoBaseExpression.Checked = true;
                        }
                    }
                }
            }
            else
            {
                this.rdoBaseShape.Enabled = false;
                if (this.rdoBaseShape.Checked)
                {
                    this.rdoBaseExpression.Checked = true;
                }
            }
            if (this.cboSufer.Items.Count == 0)
            {
                this.rdoBaseSurface.Enabled = false;
                this.cboSufer.Enabled       = false;
                if (this.rdoBaseSurface.Checked)
                {
                    this.rdoBaseExpression.Checked = true;
                }
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            if (m_hookHelper != null)
            {
                try
                {
                    IApplication appArcMap = (IApplication)m_hookHelper.Hook;
                    IMxDocument  doc       = (IMxDocument)appArcMap.Document;

                    if (doc.SelectedLayer != null)
                    {
                        ILayer       layer       = doc.SelectedLayer;
                        IPropertySet propertySet = null;

                        bool newPropertySet = false;

                        ILayerExtensions layerExtensions = (ILayerExtensions)layer;

                        Trace.WriteLine(layerExtensions.ExtensionCount.ToString());

                        List <IPropertySet> psets = layer.FindExtensionPropertySet("layerextension", "umbriel");



                        if (!LayerExtHelper.UmbrielPropertySetExists(layerExtensions))
                        {
                            propertySet    = LayerExtHelper.CreateUmbrielPropertySet();
                            newPropertySet = true;
                        }
                        else
                        {
                            propertySet = LayerExtHelper.GetUmbrielPropertySet(layerExtensions);
                        }

                        if (propertySet != null)
                        {
                            if (this.propertySetForm == null)
                            {
                                this.propertySetForm = new CustomLayerPropertiesForm(propertySet);
                            }

                            DialogResult res = this.propertySetForm.ShowDialog();

                            if (res == DialogResult.OK)
                            {
                                if (this.propertySetForm.PropertySet != null)
                                {
                                    LayerExtHelper.RemovePropertySet(layerExtensions);
                                    layerExtensions.AddExtension(this.propertySetForm.PropertySet);
                                }
                            }

                            this.propertySetForm.Dispose();
                            this.propertySetForm = null;
                        }
                    }
                    else
                    {
                        MessageBox.Show("No layer highlighted in the table of contents.", "Ooops.", MessageBoxButtons.OK);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "Umbriel Custom Layer Properties Error", System.Windows.Forms.MessageBoxButtons.OK);
                }
            }
            else if (m_sceneHookHelper != null)
            {
                throw new NotImplementedException();
            }
            else if (m_globeHookHelper != null)
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 27
0
        /// <summary>
        /// The add XY event layer.
        /// </summary>
        /// <param name="table">
        /// The table.
        /// </param>
        /// <param name="query">
        /// The query.
        /// </param>
        /// <param name="tweetShow">
        /// The tweet show.
        /// </param>
        public static void AddXyEventLayer(ITable table, string query, bool tweetShow = true)
        {
            var mxdoc = ArcMap.Application.Document as IMxDocument;

            if (mxdoc != null)
            {
                var map = mxdoc.FocusMap;

                // Get the table named XYSample.txt
                var stTableCollection = map as IStandaloneTableCollection;

                // Get the table name object
                var dataset   = table as IDataset;
                var tableName = dataset.FullName;

                // Specify the X and Y fields
                var xyEvent2FieldsProperties = new XYEvent2FieldsProperties() as IXYEvent2FieldsProperties;
                if (xyEvent2FieldsProperties != null)
                {
                    xyEvent2FieldsProperties.XFieldName = "x";
                    xyEvent2FieldsProperties.YFieldName = "y";
                    xyEvent2FieldsProperties.ZFieldName = string.Empty;

                    // Specify the projection
                    var spatialReferenceFactory   = new SpatialReferenceEnvironment() as ISpatialReferenceFactory;
                    var projectedCoordinateSystem =
                        spatialReferenceFactory.CreateGeographicCoordinateSystem(
                            (int)esriSRGeoCSType.esriSRGeoCS_WGS1984);

                    // Create the XY name object as set it's properties
                    var xyEventSourceName = new XYEventSourceName() as IXYEventSourceName;
                    xyEventSourceName.EventProperties  = xyEvent2FieldsProperties;
                    xyEventSourceName.SpatialReference = projectedCoordinateSystem;
                    xyEventSourceName.EventTableName   = tableName;

                    IName          xyName        = xyEventSourceName as IName;
                    IXYEventSource xyEventSource = xyName.Open() as IXYEventSource;

                    // Create a new Map Layer
                    IFeatureLayer featureLayer = new FeatureLayer() as IFeatureLayer;
                    featureLayer.FeatureClass = xyEventSource as IFeatureClass;
                    featureLayer.Name         = query;

                    // Add the layer extension (this is done so that when you edit
                    // the layer's Source properties and click the Set Data Source
                    // button, the Add XY Events Dialog appears)
                    ILayerExtensions          layerExtensions  = featureLayer as ILayerExtensions;
                    XYDataSourcePageExtension resPageExtension = new XYDataSourcePageExtension();
                    layerExtensions.AddExtension(resPageExtension);

                    IGeoFeatureLayer geoLayer       = (IGeoFeatureLayer)featureLayer;
                    ISimpleRenderer  simpleRenderer = (ISimpleRenderer)geoLayer.Renderer;

                    var randomNumber = NumberRandom.Next(0, Colors.Count - 1);
                    var color        = Colors[randomNumber];

                    IRgbColor rgbColor = new RgbColorClass();
                    rgbColor.Blue  = color.B;
                    rgbColor.Red   = color.R;
                    rgbColor.Green = color.G;

                    IMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass();
                    markerSymbol.Color    = rgbColor;
                    markerSymbol.Size     = 5;
                    simpleRenderer.Symbol = (ISymbol)markerSymbol;

                    try
                    {
                        map.AddLayer(featureLayer);
                    }
                    catch (Exception error)
                    {
                        Console.WriteLine(error.Message);
                    }
                }
            }
        }
Esempio n. 28
0
        /// <summary>
        /// this function takes a table and creates a shapefile (XY events) layer
        /// that is then added to the map
        /// </summary>
        /// <param name="pMxDoc">the map doc</param>
        /// <param name="sWorkspacePath">where to put the shapefile that is generated from the xy events / and where the dbf lives</param>
        /// <param name="sTableName">the name of the dbf to open</param>
        /// <param name="pSpatRef">the spatial ref for the prj file for the shapefile</param>\ 
        /// <changelog>
        ///
        ///         comments created.
        ///
        /// </changelog>
        public void addXYEvents(IMxDocument pMxDoc, string sWorkspacePath, string sTableName, ISpatialReference pSpatRef, string xField, string yField, string zField)
        {
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWSF.OpenFromFile(sWorkspacePath, 0);
            ITable            pTable            = (ITable)pFeatureWorkspace.OpenTable(sTableName);

            if (pTable == null)
            {
                MessageBox.Show("The table was not found");
                return;
            }

            // Create a new standalone table and add it
            // to the collection of the focus map
            IStandaloneTable pStTab = new StandaloneTableClass();

            pStTab.Table = (ITable)pTable;

            //sortTable(ref pTable);

            // Get the table name object
            IDataset pDataSet   = (IDataset)pStTab;
            IName    pTableName = pDataSet.FullName;

            // Specify the X and Y fields
            IXYEvent2FieldsProperties pXYEvent2FieldsProperties = new XYEvent2FieldsPropertiesClass();

            pXYEvent2FieldsProperties.XFieldName = xField;
            pXYEvent2FieldsProperties.YFieldName = yField;
            pXYEvent2FieldsProperties.ZFieldName = zField;

            // Create the XY name object and set it's properties
            IXYEventSourceName pXYEventSourceName = new XYEventSourceNameClass();

            pXYEventSourceName.EventProperties = pXYEvent2FieldsProperties;
            if (pSpatRef != null)
            {
                pXYEventSourceName.SpatialReference = pSpatRef;
            }
            pXYEventSourceName.EventTableName = pTableName;
            IName          pXYName        = (IName)pXYEventSourceName;
            IXYEventSource pXYEventSource = (IXYEventSource)pXYName.Open();

            // Create a new Map Layer
            IFeatureLayer pFLayer = new FeatureLayerClass();

            pFLayer.FeatureClass = (IFeatureClass)pXYEventSource;
            pFLayer.Name         = sTableName;

            //Add the layer extension (this is done so that when you edit
            //the layer's Source properties and click the Set Data Source
            //button, the Add XY Events Dialog appears)
            XYDataSourcePageExtension pRESPageExt = new XYDataSourcePageExtension();
            ILayerExtensions          pLayerExt   = (ILayerExtensions)pFLayer;

            pLayerExt.AddExtension(pRESPageExt);

            //Get the FcName from the featureclass
            IFeatureClass pFc = pFLayer.FeatureClass;

            pDataSet = (IDataset)pFc;
            IFeatureClassName pINFeatureClassName = (IFeatureClassName)pDataSet.FullName;
            IDatasetName      pInDsName           = (IDatasetName)pINFeatureClassName;

            //Get the selection set
            IFeatureSelection pFSel   = (IFeatureSelection)pFLayer;
            ISelectionSet     pSelSet = (ISelectionSet)pFSel.SelectionSet;

            //Define the output feature class name
            IFeatureClassName pFeatureClassName = new FeatureClassNameClass();
            IDatasetName      pOutDatasetName   = (IDatasetName)pFeatureClassName;
            //string sDSName = ensureDataName(pDataSet.Name, sWorkspacePath);

            string sDSName = pDataSet.Name; // +DateTime.UtcNow.DayOfYear + DateTime.UtcNow.Hour + DateTime.UtcNow.Minute + DateTime.UtcNow.Second;

            pOutDatasetName.Name = sDSName;

            IWorkspaceName pWorkspaceName = new WorkspaceNameClass();

            pWorkspaceName.PathName = sWorkspacePath;
            pWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapeFileWorkspaceFactory";

            pOutDatasetName.WorkspaceName    = pWorkspaceName;
            pFeatureClassName.FeatureType    = esriFeatureType.esriFTSimple;
            pFeatureClassName.ShapeType      = esriGeometryType.esriGeometryPoint;
            pFeatureClassName.ShapeFieldName = "Shape";

            //Export
            IExportOperation pExportOp = new ExportOperationClass();

            pExportOp.ExportFeatureClass(pInDsName, null, null, null, pOutDatasetName as IFeatureClassName, 0);

            IFeatureClass pClass = (IFeatureClass)pFeatureWorkspace.OpenFeatureClass(sDSName);
            IFeatureLayer pLayer = new FeatureLayerClass();

            pLayer.FeatureClass = pClass;
            pLayer.Name         = sDSName;//pClass.AliasName;

            pMxDoc.AddLayer(pLayer);
            pMxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null);
        }
Esempio n. 29
0
        /// <summary>
        /// Builds the index file with layers
        /// </summary>
        /// <param name="searchPaths">The search paths.</param>
        public void BuildIndex(List <string> searchPaths)
        {
            if (!File.Exists(this.IndexPath))
            {
                CreateNewIndexFile(this.IndexPath);
            }

            List <string> layerFiles = new List <string>();

            int i = 0;


            foreach (string searchPath in searchPaths)
            {
                i++;

                LayerfileIndexer indexer = new LayerfileIndexer(searchPath);
                indexer.Search();
                layerFiles.AddRange(indexer.LayerFiles);

                OnProgressUpdate(i, searchPaths.Count, "Scanning Search Path " + searchPath);
            }

            List <string> insertSQLStatements = new List <string>();

            i = 0;
            foreach (string filePath in layerFiles)
            {
                i++;

                FileInfo fileInfo = new FileInfo(filePath);


                ILayerFile layerFile = new LayerFileClass();
                layerFile.Open(filePath);
                ILayer layer = layerFile.Layer;

                ILayerGeneralProperties layerProps = (ILayerGeneralProperties)layer;
                ILayerExtensions        layerExt   = (ILayerExtensions)layer;

                string lyrGUID  = "00000000-0000-0000-0000-000000000000";
                string revision = "0";

                if (Layer.Util.LayerExtHelper.UmbrielPropertySetExists(layerExt))
                {
                    IPropertySet propertySet = Util.LayerExtHelper.GetUmbrielPropertySet(layerExt);
                    if (propertySet != null && Util.LayerExtHelper.PropertyExists(propertySet, "GUID"))
                    {
                        lyrGUID = propertySet.GetProperty("GUID").ToString();
                    }

                    if (propertySet != null && Util.LayerExtHelper.PropertyExists(propertySet, "revision"))
                    {
                        revision = propertySet.GetProperty("revision").ToString();
                    }
                }

                StringBuilder sql = new StringBuilder();
                sql.AppendLine("INSERT INTO layerfile ");
                sql.AppendLine("(lyrgid,lyrName,lyrDescription,lyrFileName,lyrFullPath,lyrParentDir,lyrRevision,DateRecCreated,DateRecModified)");
                sql.AppendLine(" VALUES (");

                sql.AppendLine("'" + lyrGUID + "'");
                sql.AppendLine(",'" + layer.Name.Replace("'", "''") + "'");
                sql.AppendLine(",'" + layerProps.LayerDescription.Replace("'", "''") + "'");
                sql.AppendLine(",'" + Path.GetFileName(filePath) + "'");
                sql.AppendLine(",\"" + filePath + "\"");
                sql.AppendLine(",'" + Path.GetDirectoryName(filePath) + "'");
                sql.AppendLine("," + revision + "");

                sql.AppendLine(",'" + SqliteDateString(DateTime.Now) + "'");
                sql.AppendLine(",'" + SqliteDateString(DateTime.Now) + "'");

                sql.AppendLine(")");

                Debug.WriteLine(sql.ToString());
                insertSQLStatements.Add(sql.ToString());

                OnProgressUpdate(i, layerFiles.Count, "Building layer data file: ");

                if (layer != null)
                {
                    // System.Runtime.InteropServices.Marshal.FinalReleaseComObject(layerFile);
                }
            }

            i = 0;

            // build insert sql statement
            using (SQLiteConnection cnn = new SQLiteConnection(this.GetDBConnectionString()))
            {
                cnn.Open();

                using (DbTransaction transaction = cnn.BeginTransaction())
                {
                    using (DbCommand cmd = cnn.CreateCommand())
                    {
                        foreach (string sql in insertSQLStatements)
                        {
                            i++;

                            cmd.CommandText = sql;
                            cmd.ExecuteNonQuery();

                            OnProgressUpdate(i, insertSQLStatements.Count, "Inserting data: ");
                        }
                    }
                    transaction.Commit();
                }

                OnProgressUpdate(i, insertSQLStatements.Count, "Insert Complete!");

                cnn.Close();
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                if (m_application == null)
                {
                    return;
                }
                IDocument   document   = m_application.Document;
                ISxDocument sxDocument = (ISxDocument)(document);
                if (sxDocument != null)
                {
                    m_scene = sxDocument.Scene;
                }
                if (m_scene == null)
                {
                    return;
                }
                activeView = m_scene as IActiveView;

                //有图层选图层
                if (m_scene.LayerCount == 0)
                {
                    return;
                }

                //选择基准面
                if (Common.SelectLayer(m_scene.Layers, out SelectedLyrIndex, true, "选择自定义表面") == false)
                {
                    return;
                }

                //QI
                IRasterLayer baseRasterLayer = m_scene.Layer[SelectedLyrIndex[0]] as IRasterLayer;  //不管选多少个只选第一个
                if (baseRasterLayer == null)
                {
                    throw new ArgumentNullException("自定义表面RasterLayer转换失败,为空。");
                }
                IRaster raster = baseRasterLayer.Raster;
                if (raster == null)
                {
                    throw new ArgumentNullException("自定义表面Raster转换失败,为空。");
                }
                IRasterSurface rasterSurface = new RasterSurfaceClass();
                rasterSurface.PutRaster(raster, 0);
                ISurface surface = rasterSurface as ISurface;

                //选择图层
                if (Common.SelectLayer(m_scene.Layers, out SelectedLyrIndex, false, "选择要进行偏移的图层") == false)
                {
                    return;
                }

                //选择倍数
                NumSelect MultiNS = new NumSelect("输入夸大倍数", true);
                if (MultiNS.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                double Multiplier = MultiNS.Result;

                //选择偏移量
                NumSelect NS = new NumSelect();
                if (NS.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                double Offset       = NS.Result;
                bool   DisableCache = NS.DisableCache;

                //Create a CancelTracker.
                ITrackCancel pTrackCancel = new CancelTrackerClass();

                //Create the ProgressDialog. This automatically displays the dialog
                IProgressDialogFactory pProgDlgFactory = new ProgressDialogFactoryClass();
                IProgressDialog2       pProDlg         = pProgDlgFactory.Create(pTrackCancel, m_application.hWnd) as IProgressDialog2;
                pProDlg.CancelEnabled = true;
                pProDlg.Title         = "正在进行自定义表面设置及偏移调整";
                pProDlg.Description   = "设置中,请稍候...";

                pProDlg.Animation = esriProgressAnimationTypes.esriProgressSpiral;

                IStepProgressor pStepPro = pProDlg as IStepProgressor;
                pStepPro.MinRange  = 0;
                pStepPro.MaxRange  = SelectedLyrIndex.Count;
                pStepPro.StepValue = 1;
                pStepPro.Message   = "初始化中...";

                bool bCont = true;

                //对每一个选中的图层进行操作
                for (int i = 0; i < SelectedLyrIndex.Count; i++)
                {
                    //m_application.StatusBar.set_Message(0, i.ToString());
                    pStepPro.Message = "已完成(" + i.ToString() + "/" + SelectedLyrIndex.Count.ToString() + ")";
                    bCont            = pTrackCancel.Continue();
                    if (!bCont)
                    {
                        break;
                    }

                    //选中一个栅格图层
                    IRasterLayer rasterLayer = m_scene.Layer[SelectedLyrIndex[i]] as IRasterLayer;
                    if (rasterLayer == null)
                    {
                        pStepPro.Message = "选中的图层非栅格图层...";
                        continue;
                    }

                    I3DProperties    p3DProperties   = null;
                    ILayerExtensions layerExtensions = rasterLayer as ILayerExtensions;

                    //遍历LayerExtensions找到I3DProperties
                    for (int j = 0; j < layerExtensions.ExtensionCount; j++)
                    {
                        if (layerExtensions.get_Extension(j) is I3DProperties)
                        {
                            p3DProperties = layerExtensions.get_Extension(j) as I3DProperties;
                        }
                    }

                    //设置I3DProperties
                    p3DProperties.ZFactor                = Multiplier;                     //系数
                    p3DProperties.BaseOption             = esriBaseOption.esriBaseSurface; //基准面浮动
                    p3DProperties.BaseSurface            = surface;                        //基准面
                    p3DProperties.OffsetExpressionString = Offset.ToString();              //偏移常量
                    if (DisableCache)
                    {
                        p3DProperties.RenderMode       = esriRenderMode.esriRenderImmediate;         //直接从文件渲染
                        p3DProperties.RenderVisibility = esriRenderVisibility.esriRenderWhenStopped; //停止导航时渲染
                    }
                    p3DProperties.Apply3DProperties(rasterLayer);
                }
                pProDlg.HideDialog();

                //==========================================
                //刷新,不起作用
                if (activeView == null)
                {
                    throw new Exception("活动视图为空! ");
                }
                if (m_sceneHookHelper.ActiveViewer == null)
                {
                    throw new Exception("无活动视图!");
                }
                activeView.Refresh();
                m_sceneHookHelper.ActiveViewer.Redraw(true);
                //==========================================
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
        }