private void btnDrive_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; try { IObjectFactory objFactory = m_application as IObjectFactory; //Use reflection to get ClsID of ShapefileWorkspaceFactory Type shpWkspFactType = typeof(ShapefileWorkspaceFactoryClass); string typeClsID = shpWkspFactType.GUID.ToString("B"); string shapeFile = System.IO.Path.GetFileNameWithoutExtension(txtShapeFilePath.Text); string fileFolder = System.IO.Path.GetDirectoryName(txtShapeFilePath.Text); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)objFactory.Create(typeClsID); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(fileFolder, 0); //(@"C:\data\test", 0); //Create the layer IFeatureLayer featureLayer = (IFeatureLayer)objFactory.Create("esriCarto.FeatureLayer"); featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass(shapeFile); // ("worldgrid"); featureLayer.Name = featureLayer.FeatureClass.AliasName; //Add the layer to document IBasicDocument document = (IBasicDocument)m_application.Document; document.AddLayer(featureLayer); document.UpdateContents(); } catch { } //Or make sure it is a valid shp file first this.Cursor = Cursors.Default; }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { IComPropertySheet myPropertySheet = new ComPropertySheetClass(); myPropertySheet.Title = "Simplified Layer Properties (C#)"; myPropertySheet.HideHelpButton = true; //Add by component category - all pages registered in the layer property page //UID layerPropertyID = new UIDClass(); //layerPropertyID.Value = m_layerCategoryID; //myPropertySheet.AddCategoryID(layerPropertyID); //Or add page by page - but have to call Applies yourself myPropertySheet.ClearCategoryIDs(); myPropertySheet.AddCategoryID(new UIDClass()); //a dummy empty UID myPropertySheet.AddPage(new LayerVisibilityPage()); //my custom page myPropertySheet.AddPage(new ESRI.ArcGIS.CartoUI.LayerDrawingPropertyPageClass()); //feature layer symbology //Pass in layer, active view and the application ISet propertyObjects = new SetClass(); IBasicDocument basicDocument = m_application.Document as IBasicDocument; propertyObjects.Add(basicDocument.ActiveView); propertyObjects.Add(basicDocument.SelectedLayer); //or check ContextItem is a layer? propertyObjects.Add(m_application); //optional? //Show the property sheet if (myPropertySheet.CanEdit(propertyObjects)) { myPropertySheet.EditProperties(propertyObjects, m_application.hWnd); } }
internal static void OpenProfilesSetIn3D(ArcSceneArguments layers) { OpenArcScene(); try { IObjectFactory objFactory = m_application as IObjectFactory; Type rasterLayerType = typeof(RasterLayerClass); string typeRasterLayerID = rasterLayerType.GUID.ToString("B"); IRasterLayer elevationRasterLayer = (IRasterLayer)objFactory.Create(typeRasterLayerID); elevationRasterLayer.CreateFromFilePath(layers.DemLayer); ILayer layer = (ILayer)elevationRasterLayer; var line3DLayer = CreateLayer(layers.Line3DLayer, objFactory); var point3DLayer = CreateLayer(layers.Point3DLayer, objFactory); var polygon3DLayer = CreateLayer(layers.Polygon3DLayer, objFactory); var polygonLayerEffects = (ILayerEffects)polygon3DLayer; polygonLayerEffects.Transparency = 50; IBasicDocument document = (IBasicDocument)m_application.Document; document.AddLayer(layer); document.AddLayer(line3DLayer); document.AddLayer(point3DLayer); document.AddLayer(polygon3DLayer); document.UpdateContents(); } catch (Exception ex) { } }
private static void AddDraperyLayer(string draperyLayerName, IObjectFactory objFactory, IFunctionalSurface baseSurface, IBasicDocument document) { var rasterLayer = CreateRasterLayer(objFactory, draperyLayerName); if (rasterLayer != null) { SetVisibilitySessionRaster3DProperties(rasterLayer, objFactory, baseSurface, true); } document.AddLayer(rasterLayer); }
private static void AddVisibilityLayers(IEnumerable <VisibilityResultInfo> info, IObjectFactory objFactory, IBasicDocument document, IFunctionalSurface baseSurface) { Dictionary <ILayer, LayerTypeEnum> layers = new Dictionary <ILayer, LayerTypeEnum>(); foreach (var resultInfo in info) { var layer = GetVisibilityLayer(resultInfo, objFactory, baseSurface); if (layer.Key != null) { layers.Add(layer.Key, layer.Value); try { document.AddLayer(layer.Key); } catch (Exception ex) { logger.ErrorEx(ex.Message); } } } _viewCalcLayers.AddRange(layers.Keys); if (layers.ContainsValue(LayerTypeEnum.PointFeature)) { document.UpdateContents(); foreach (var layer in layers) { if (layer.Value == LayerTypeEnum.PointFeature && _layersWithDefaultRenderer.Contains(layer.Key.Name)) { document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, PointsRender((IFeatureLayer)layer.Key, new RgbColor() { Red = 24, Blue = 255, Green = 163 }, objFactory), document.ActiveView.Extent); } } } }
private static void SetSceneView(IBasicDocument document, IRasterLayer surface) { IEnvelope unionEnvelope = new EnvelopeClass(); foreach (var layer in _viewCalcLayers) { IEnvelope envelope = null; try { envelope = EsriTools.GetLayerExtent(layer, document.ActiveView); } catch (Exception ex) { logger.WarnEx($"Cannot to get envelope from {layer.Name} layer"); } if (envelope != null) { unionEnvelope.Union(envelope); } } var pSxDoc = document as ISxDocument; var camera = pSxDoc.Scene.SceneGraph.ActiveViewer.Camera; var centerPoint = EsriTools.GetCenterPoint(unionEnvelope); centerPoint.AddZCoordinate(surface.Raster); camera.Target = centerPoint; var observerPoint = unionEnvelope.LowerRight.Clone(); observerPoint.AddZCoordinate(surface.Raster); observerPoint.Z += 1000; camera.Observer = observerPoint; camera.Zoom(-2); camera.RecalcUp(); pSxDoc.Scene.SceneGraph.RefreshViewers(); }
private static void AddExtraLayers(Dictionary <ILayer, double> additionalLayers, IObjectFactory objFactory, IBasicDocument document, IFunctionalSurface surface) { foreach (var extraLayer in additionalLayers) { var featureLayer = CreateLayerCopy((IFeatureLayer)extraLayer.Key, objFactory); SetFeatures3DProperties(featureLayer, objFactory, surface, extraLayer.Value); try { document.AddLayer(featureLayer); } catch (Exception ex) { logger.ErrorEx(ex.Message); } } document.UpdateContents(); }
private static IFunctionalSurface AddBaseLayers(ArcSceneArguments layers, IObjectFactory objFactory, IBasicDocument document) { var preparedLayers = GetLayers(layers, objFactory); var surface = (IRasterSurface)objFactory.Create("esrianalyst3d.RasterSurface"); var rasterLayer = (IRasterLayer)preparedLayers[LayerTypeEnum.Raster]; SetFromMapRendererToRasterLayer(rasterLayer, objFactory, rasterLayer.Name); surface.PutRaster(rasterLayer.Raster, 0); var functionalSurface = (IFunctionalSurface)surface; _demLayerName = rasterLayer.Name; SetSurface3DProperties(preparedLayers[LayerTypeEnum.Raster], objFactory, functionalSurface); if (preparedLayers.Count > 1) { SetFeatures3DProperties((IFeatureLayer)preparedLayers[LayerTypeEnum.LineFeature], objFactory, functionalSurface); SetHightFeatures3DProperties((IFeatureLayer)preparedLayers[LayerTypeEnum.PointFeature], objFactory); SetHightFeatures3DProperties((IFeatureLayer)preparedLayers[LayerTypeEnum.PolygonFeature], objFactory); _viewCalcLayers.Add(preparedLayers[LayerTypeEnum.LineFeature]); _layersWithDefaultRenderer.AddRange(preparedLayers.Values.Select(layer => layer.Name)); } foreach (var layer in preparedLayers) { try { document.AddLayer(layer.Value); } catch (Exception ex) { logger.ErrorEx(ex.Message); } } document.UpdateContents(); if (preparedLayers.Count > 1) { document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, VisibilityColorsRender((IFeatureLayer)preparedLayers[LayerTypeEnum.LineFeature], objFactory), document.ActiveView.Extent); document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, PointsRender((IFeatureLayer)preparedLayers[LayerTypeEnum.PointFeature], new RgbColor() { Red = 255, Blue = 24, Green = 198 }, objFactory), document.ActiveView.Extent); document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, VisibilityColorsRender((IFeatureLayer)preparedLayers[LayerTypeEnum.PolygonFeature], objFactory), document.ActiveView.Extent); } return(functionalSurface); }
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { int X = arg.X; int Y = arg.Y; IMxApplication pMxApp = null; IMxDocument pMxDoc = null; pMxApp = (IMxApplication)ArcMap.Application; pMxDoc = (IMxDocument)ArcMap.Application.Document; // calculate tolerance rectangle to identify features inside it int Tolerance = 0; Tolerance = pMxDoc.SearchTolerancePixels; IDisplayTransformation pDispTrans = null; pDispTrans = pMxApp.Display.DisplayTransformation; tagRECT pToleranceRect = new tagRECT(); pToleranceRect.left = X - Tolerance; pToleranceRect.right = X + Tolerance; pToleranceRect.top = Y - Tolerance; pToleranceRect.bottom = Y + Tolerance; IEnvelope pSearchEnvelope = null; pSearchEnvelope = new EnvelopeClass(); pDispTrans.TransformRect(pSearchEnvelope, ref pToleranceRect, (int)(esriDisplayTransformationEnum.esriTransformPosition | esriDisplayTransformationEnum.esriTransformToMap)); // identify feature points of measurement IBasicDocument pBasicDoc = null; pBasicDoc = (IBasicDocument)ArcMap.Application.Document; pSearchEnvelope.SpatialReference = pMxDoc.ActiveView.FocusMap.SpatialReference; IIdentify pIdentify = null; pIdentify = (IIdentify)pMxDoc.FocusMap.get_Layer(0); if (pIdentify == null) { MessageBox.Show("No layer"); return; } IArray pIDArray = null; pIDArray = pIdentify.Identify(pSearchEnvelope); // get object from feature point IIdentifyObj pIDObj = null; if (pIDArray != null) { pIDObj = (IIdentifyObj)pIDArray.get_Element(0); } if (pIDObj == null) { MessageBox.Show("No feature was identified"); return; } // get the name of the layer containing feature points ILayer pLayer = null; pLayer = pMxDoc.FocusMap.get_Layer(0); string layerName = null; layerName = pLayer.Name; // get primary display field for measurement values and set names of a date/time field and gage ID field IFeatureLayer pFeatLayer = null; pFeatLayer = (IFeatureLayer)pLayer; string dataFldName = null; string timefldName = null; string gageIDFldName = null; dataFldName = "TSValue"; timefldName = "TSDateTime"; // substitute data/time field name for different dataset gageIDFldName = "Name"; // substitute gage ID field name for different dataset // get display table from layer ITable pTable = null; IDisplayTable pDisplayTable = null; pDisplayTable = (IDisplayTable)pLayer; if (pDisplayTable != null) { pTable = pDisplayTable.DisplayTable; if (pTable == null) { goto THEEND; } } // get fields from display table IFields pFields = null; pFields = pTable.Fields; long fldCount = 0; fldCount = pFields.FieldCount; // create WHERE clause from identified objects of measurement points int gageIDFldIdx = 0; gageIDFldIdx = pFields.FindField(gageIDFldName); IRowIdentifyObject pRowIDObj = null; pRowIDObj = (IRowIdentifyObject)pIDObj; string gageID = null; gageID = (string)pRowIDObj.Row.get_Value(gageIDFldIdx); IFeatureLayerDefinition pFeatureLayerDef = null; pFeatureLayerDef = (IFeatureLayerDefinition)pLayer; string definitionExpression = null; definitionExpression = pFeatureLayerDef.DefinitionExpression; string whereClause = null; if (definitionExpression == "") { whereClause = "[" + gageIDFldName + "] = '" + gageID + "'"; } else { whereClause = "[" + gageIDFldName + "] = '" + gageID + "' AND " + definitionExpression; } //find color for the identified object from feature layer's renderer IGeoFeatureLayer pGeoFeatureLayer = null; pGeoFeatureLayer = (IGeoFeatureLayer)pLayer; ILookupSymbol pLookupSymbol = null; pLookupSymbol = (ILookupSymbol)pGeoFeatureLayer.Renderer; IFeature pFeature = null; pFeature = (IFeature)pRowIDObj.Row; IMarkerSymbol pSymbol = null; pSymbol = (IMarkerSymbol)pLookupSymbol.LookupSymbol(false, pFeature); // Find an opened GraphWindow IDataGraphBase pDataGraphBase = null; IDataGraphT pDataGraphT = null; IDataGraphWindow2 pDGWin = null; IDataGraphCollection pDataGraphs = null; pDataGraphs = (IDataGraphCollection)pMxDoc; int grfCount = 0; grfCount = pDataGraphs.DataGraphCount; for (int i = 0; i < grfCount; i++) { pDataGraphBase = pDataGraphs.get_DataGraph(i); pDGWin = FindGraphWindow(ref pDataGraphBase); if (pDGWin != null) { break; } } // if there is not an opened graph window - create a new graph for if (pDGWin == null) { // create graph pDataGraphT = new DataGraphTClass(); pDataGraphBase = (IDataGraphBase)pDataGraphT; // load template from <ARCGISHOME>\GraphTemplates\ string strPath = null; strPath = Environment.GetEnvironmentVariable("ARCGISHOME"); try { pDataGraphT.LoadTemplate(strPath + @"GraphTemplates\timeseries.tee"); } catch { } // graph, axis and legend titles. Substitute them for different input layer pDataGraphT.GeneralProperties.Title = "Daily Streamflow for Guadalupe Basin in 1999"; pDataGraphT.LegendProperties.Title = "Monitoring Point"; pDataGraphT.get_AxisProperties(0).Title = "Streamflow (cfs)"; pDataGraphT.get_AxisProperties(0).Logarithmic = true; pDataGraphT.get_AxisProperties(2).Title = "Date"; pDataGraphBase.Name = layerName; } else // get graph from the opened window { pDataGraphT = (IDataGraphT)pDataGraphBase; } // create vertical line series for all measurements for the identified gage ISeriesProperties pSP = null; pSP = pDataGraphT.AddSeries("line:vertical"); pSP.ColorType = esriGraphColorType.esriGraphColorCustomAll; pSP.CustomColor = pSymbol.Color.RGB; pSP.WhereClause = whereClause; pSP.InLegend = true; pSP.Name = gageID; pSP.SourceData = pLayer; pSP.SetField(0, timefldName); pSP.SetField(1, dataFldName); IDataSortSeriesProperties pSortFlds = null; pSortFlds = (IDataSortSeriesProperties)pSP; int idx = 0; pSortFlds.AddSortingField(timefldName, true, ref idx); pDataGraphBase.UseSelectedSet = true; ITrackCancel pCancelTracker = null; pCancelTracker = new CancelTracker(); pDataGraphT.Update(pCancelTracker); // create data graph window if there is not any opened one if (pDGWin == null) { pDGWin = new DataGraphWindowClass(); pDGWin.DataGraphBase = pDataGraphBase; pDGWin.Application = ArcMap.Application; pDGWin.Show(true); pDataGraphs.AddDataGraph(pDataGraphBase); } THEEND: return; //base.OnMouseDown(arg); }