private void btn_OK_Click(object sender, EventArgs e)
        {
            string FieldName = cbx_Field.SelectedItem.ToString();

            if (FieldName == "None")
            {
                MessageBox.Show("不可用字段,请选择其它图层"); return;
            }
            IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)m_FeatureLayer;

            pGeoFeatureLayer.ScaleSymbols = true;
            ITable  pTable  = (ITable)pGeoFeatureLayer;
            ICursor pCursor = pTable.Search(null, true);

            IDataStatistics pDataStatistics = new DataStatisticsClass();

            pDataStatistics.Cursor = pCursor;
            //Set statistical field
            pDataStatistics.Field = FieldName;
            //Get the result of statistics
            IStatisticsResults pStatisticsResult = pDataStatistics.Statistics;

            if (pStatisticsResult == null)
            {
                MessageBox.Show("Failed to gather stats on the feature class");
                return;
            }

            IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
            // pFillSymbol.Color = m_BackGroundColor;


            IMarkerSymbol pCharaterMarkerS = new CharacterMarkerSymbolClass();

            pCharaterMarkerS       = (IMarkerSymbol)m_StyleGallertItem.Item;
            pCharaterMarkerS.Size  = (int)numericUpDown1.Value;
            pCharaterMarkerS.Color = m_BackGroundColor;

            IProportionalSymbolRenderer pProportionalSymbolR = new ProportionalSymbolRendererClass();

            pProportionalSymbolR.ValueUnit            = esriUnits.esriUnknownUnits;
            pProportionalSymbolR.Field                = FieldName;
            pProportionalSymbolR.FlanneryCompensation = false;
            pProportionalSymbolR.MinDataValue         = pStatisticsResult.Minimum;
            pProportionalSymbolR.MaxDataValue         = pStatisticsResult.Maximum;
            pProportionalSymbolR.BackgroundSymbol     = pFillSymbol;
            pProportionalSymbolR.MinSymbol            = (ISymbol)pCharaterMarkerS;
            pProportionalSymbolR.LegendSymbolCount    = 5;
            pProportionalSymbolR.CreateLegendSymbols();

            IRotationRenderer pRotationRenderer = (IRotationRenderer)pProportionalSymbolR;

            pRotationRenderer.RotationField = FieldName;
            pRotationRenderer.RotationType  = esriSymbolRotationType.esriRotateSymbolGeographic;
            //Set the states layer renderer to the proportional symbol renderer and refresh the display
            pGeoFeatureLayer.Renderer = (IFeatureRenderer)pProportionalSymbolR;

            m_MapControl.ActiveView.ContentsChanged();
            m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
Пример #2
0
        private ICharacterMarkerSymbol GetMarkerSymbol(bool bLocated)
        {
            //Create a new system draw font
            System.Drawing.Font drawFont = new System.Drawing.Font("ESRI Crime Analysis", 21);

            //Create a new CharacterMarkerSymbol and get the ICharacterMarkerSymbol interface
            ICharacterMarkerSymbol charMarker = new CharacterMarkerSymbolClass();

            //Set the marker symbol properties
            charMarker.Font = (stdole.IFontDisp)OLE.GetIFontDispFromFont(drawFont);

            if (bLocated == true)
            {
                charMarker.CharacterIndex = 56;
                charMarker.Color          = GetRGBColor(255, 0, 0);
                charMarker.Size           = 30;
            }
            else
            {
                charMarker.CharacterIndex = 46;
                charMarker.Color          = GetRGBColor(0, 0, 0);
                charMarker.Size           = 30;
            }
            return(charMarker);
        }
Пример #3
0
 //文字符号化
 private void CharacterMarkerSymbolToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         //获得点图层,要求当前地图文档第一个图层为点图层
         IFeatureLayer layer;
         layer = mainMapControl.get_Layer(0) as IFeatureLayer;
         //QI到IGeoFeatureLayer
         IGeoFeatureLayer       geoFeatureLayer        = layer as IGeoFeatureLayer;
         SimpleRenderer         simpleRender           = new SimpleRendererClass();
         ICharacterMarkerSymbol pCharacterMarkerSymbol = new CharacterMarkerSymbolClass();
         IColor pColor = new RgbColorClass();
         pColor.RGB = 2256;
         stdole.IFontDisp font = new stdole.StdFontClass() as stdole.IFontDisp;
         font.Name = "Arial"; font.Size = 30;
         font.Bold = true;
         pCharacterMarkerSymbol.Font           = font;
         pCharacterMarkerSymbol.Color          = pColor;
         pCharacterMarkerSymbol.Size           = 20;
         pCharacterMarkerSymbol.CharacterIndex = 55;
         //ASCII55对应数字7
         simpleRender.Symbol      = pCharacterMarkerSymbol as ISymbol;
         geoFeatureLayer.Renderer = simpleRender as IFeatureRenderer;
         mainMapControl.Refresh();
         axTOCControl1.Update();
     }
     catch
     {
         MessageBox.Show("没有可以实例化的图层");
     }
 }
Пример #4
0
        private ISymbol CreateBikeRouteSymbol()
        {
            IColor color = (IColor)ESRI.ArcGIS.ADF.Connection.Local.Converter.ToRGBColor(Color.FromArgb(0, 90, 250));
            ICharacterMarkerSymbol charMarkerSymbol = new CharacterMarkerSymbolClass();

            charMarkerSymbol.Color          = color;
            charMarkerSymbol.Font           = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToStdFont(new Font("ESRI Default Marker", 17.0f, FontStyle.Bold));
            charMarkerSymbol.CharacterIndex = 189;
            charMarkerSymbol.Size           = 17;

            IMarkerLineSymbol markerLineSymbol = new MarkerLineSymbolClass();

            markerLineSymbol.Color        = color;
            markerLineSymbol.Width        = 17.0;
            markerLineSymbol.MarkerSymbol = (IMarkerSymbol)charMarkerSymbol;

            // Makes a new Cartographic Line symbol and sets its properties
            ICartographicLineSymbol cartographicLineSymbol = markerLineSymbol as ICartographicLineSymbol;

            // In order to set additional properties like offsets and dash patterns we must create an ILineProperties object
            ILineProperties lineProperties = cartographicLineSymbol as ILineProperties;

            lineProperties.Offset = 0;

            // Here's how to do a template for the pattern of marks and gaps
            double[] hpe = new double[4];
            hpe[0] = 0;
            hpe[1] = 39;
            hpe[2] = 1;
            hpe[3] = 0;

            ITemplate template = new TemplateClass();

            template.Interval = 1;
            for (int i = 0; i < hpe.Length; i = i + 2)
            {
                template.AddPatternElement(hpe[i], hpe[i + 1]);
            }
            lineProperties.Template = template;

            // Set the basic and cartographic line properties
            cartographicLineSymbol.Color = color;

            color = (IColor)ESRI.ArcGIS.ADF.Connection.Local.Converter.ToRGBColor(Color.FromArgb(0, 220, 100));

            // create a simple line
            ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();

            simpleLineSymbol.Color = color;
            simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
            simpleLineSymbol.Width = 1.2;

            IMultiLayerLineSymbol multiLayerLineSymbol = new MultiLayerLineSymbolClass();

            multiLayerLineSymbol.AddLayer((ILineSymbol)cartographicLineSymbol);
            multiLayerLineSymbol.AddLayer((ILineSymbol)simpleLineSymbol);

            return(multiLayerLineSymbol as ISymbol);
        }
Пример #5
0
        //ProportionalSymbolRenderer
        private void button4_Click(object sender, EventArgs e)
        {
            IGeoFeatureLayer            geoFeatureLayer;
            IFeatureLayer               featureLayer;
            IProportionalSymbolRenderer proportionalSymbolRenderer;
            ITable             table;
            ICursor            cursor;
            IDataStatistics    dataStatistics;
            IStatisticsResults statisticsResult;

            stdole.IFontDisp fontDisp;

            geoFeatureLayer       = getGeoLayer("Continents");
            featureLayer          = geoFeatureLayer as IFeatureLayer;
            table                 = geoFeatureLayer as ITable;
            cursor                = table.Search(null, true);
            dataStatistics        = new DataStatisticsClass();
            dataStatistics.Cursor = cursor;
            dataStatistics.Field  = "sqmi";
            statisticsResult      = dataStatistics.Statistics;
            if (statisticsResult != null)
            {
                IFillSymbol fillSymbol = new SimpleFillSymbolClass();
                fillSymbol.Color = getRGB(0, 255, 0);
                ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass();
                fontDisp      = new stdole.StdFontClass() as stdole.IFontDisp;
                fontDisp.Name = "arial";
                fontDisp.Size = 20;
                characterMarkerSymbol.Font                      = fontDisp;
                characterMarkerSymbol.CharacterIndex            = 90;
                characterMarkerSymbol.Color                     = getRGB(255, 0, 0);
                characterMarkerSymbol.Size                      = 8;
                proportionalSymbolRenderer                      = new ProportionalSymbolRendererClass();
                proportionalSymbolRenderer.ValueUnit            = esriUnits.esriUnknownUnits;
                proportionalSymbolRenderer.Field                = "sqmi";
                proportionalSymbolRenderer.FlanneryCompensation = false;
                proportionalSymbolRenderer.MinDataValue         = statisticsResult.Minimum;
                proportionalSymbolRenderer.MaxDataValue         = statisticsResult.Maximum;
                proportionalSymbolRenderer.BackgroundSymbol     = fillSymbol;
                proportionalSymbolRenderer.MinSymbol            = characterMarkerSymbol as ISymbol;
                proportionalSymbolRenderer.LegendSymbolCount    = 10;
                proportionalSymbolRenderer.CreateLegendSymbols();
                geoFeatureLayer.Renderer = proportionalSymbolRenderer as IFeatureRenderer;
            }
            this.axMapControl1.Refresh();
        }
Пример #6
0
        public void ProportionalRenderer1(IFeatureLayer featLayer, string fieldName, IColorRamp colorRamp, int size)
        {
            IGeoFeatureLayer            geoFeatureLayer;
            IFeatureLayer               featureLayer;
            IProportionalSymbolRenderer proportionalSymbolRenderer;
            ITable             table;
            ICursor            cursor;
            IDataStatistics    dataStatistics;
            IStatisticsResults statisticsResult;

            stdole.IFontDisp fontDisp;

            geoFeatureLayer       = featLayer as IGeoFeatureLayer;
            featureLayer          = geoFeatureLayer as IFeatureLayer;
            table                 = geoFeatureLayer as ITable;
            cursor                = table.Search(null, true);
            dataStatistics        = new DataStatisticsClass();
            dataStatistics.Cursor = cursor;
            dataStatistics.Field  = fieldName;
            statisticsResult      = dataStatistics.Statistics;
            if (statisticsResult != null)
            {
                IFillSymbol fillSymbol = new SimpleFillSymbolClass();
                fillSymbol.Color = colorRamp.get_Color(0);
                ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass();

                fontDisp      = new stdole.StdFontClass() as stdole.IFontDisp;
                fontDisp.Name = "arial";
                fontDisp.Size = 20;
                characterMarkerSymbol.Font                      = fontDisp;
                characterMarkerSymbol.CharacterIndex            = 90;
                characterMarkerSymbol.Color                     = colorRamp.get_Color(4);
                characterMarkerSymbol.Size                      = size;
                proportionalSymbolRenderer                      = new ProportionalSymbolRendererClass();
                proportionalSymbolRenderer.ValueUnit            = esriUnits.esriUnknownUnits;
                proportionalSymbolRenderer.Field                = fieldName;
                proportionalSymbolRenderer.FlanneryCompensation = false;
                proportionalSymbolRenderer.MinDataValue         = statisticsResult.Minimum;
                proportionalSymbolRenderer.MaxDataValue         = statisticsResult.Maximum;
                proportionalSymbolRenderer.BackgroundSymbol     = fillSymbol;
                proportionalSymbolRenderer.MinSymbol            = characterMarkerSymbol as ISymbol;
                proportionalSymbolRenderer.LegendSymbolCount    = 10;
                proportionalSymbolRenderer.CreateLegendSymbols();
                geoFeatureLayer.Renderer = proportionalSymbolRenderer as IFeatureRenderer;
            }
        }
Пример #7
0
        /// <summary>
        /// create the layer's glyphs used to set the symbol of the dynamic-layer items
        /// </summary>
        /// <param name="pDynamicGlyphFactory"></param>
        private void CreateDynamicSymbols(IDynamicGlyphFactory2 pDynamicGlyphFactory)
        {
            try
            {
                //set the background color
                IColor color = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToRGBColor(Color.FromArgb(255, 255, 255)) as IColor;

                // Create Character Marker Symbols glyph
                // --------------------------------------
                ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass();
                characterMarkerSymbol.Color          = color as IColor;
                characterMarkerSymbol.Font           = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToStdFont(new Font("ESRI Environmental & Icons", 32));
                characterMarkerSymbol.Size           = 40;
                characterMarkerSymbol.Angle          = 0;
                characterMarkerSymbol.CharacterIndex = 36;

                //create the glyph from the marker symbol
                m_markerGlyphs[0] = pDynamicGlyphFactory.CreateDynamicGlyph(characterMarkerSymbol as ISymbol);

                characterMarkerSymbol.Size           = 32;
                characterMarkerSymbol.CharacterIndex = 224;

                //create the glyph from the marker symbol
                m_markerGlyphs[1] = pDynamicGlyphFactory.CreateDynamicGlyph(characterMarkerSymbol as ISymbol);

                // Create the glyph from embedded bitmap
                // -----------------------------------
                // Sets the transparency color
                IColor transparentColor = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToRGBColor(Color.FromArgb(255, 255, 255)) as IColor;

                Bitmap bitmap = new Bitmap(GetType(), "B2.bmp");
                m_markerGlyphs[2] = pDynamicGlyphFactory.CreateDynamicGlyphFromBitmap(esriDynamicGlyphType.esriDGlyphMarker, bitmap.GetHbitmap().ToInt32(), false, transparentColor);

                // Create a glyph for the labels text, use the first 'internal' text glyph
                // ------------------------------------------------------------------------
                m_textGlyph = pDynamicGlyphFactory.get_DynamicGlyph(1, esriDynamicGlyphType.esriDGlyphText, 1);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }
Пример #8
0
        /// <summary>
        /// Symbol Render
        /// </summary>
        /// <param name="currentLayer"></param>
        /// <param name="breakCount"></param>
        /// <author>Shen Yongyuan</author>
        /// <date>20091114</date>
        public static void SymbolRender(ILayer currentLayer, string fieldName)
        {
            IGeoFeatureLayer pGeoFeatureL = currentLayer as IGeoFeatureLayer;

            pGeoFeatureL.ScaleSymbols = true;

            //Use the statistics objects to calculate the max value and the min value
            IFeatureCursor  pCursor         = pGeoFeatureL.DisplayFeatureClass.Search(null, true);
            IDataStatistics pDataStatistics = new DataStatisticsClass();

            pDataStatistics.Cursor = pCursor as ICursor;
            pDataStatistics.Field  = fieldName;
            IStatisticsResults pStatisticsResult = pDataStatistics.Statistics;


            IFillSymbol pFillSymbol = new SimpleFillSymbolClass();

            pFillSymbol.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(239, 228, 190));
            ICharacterMarkerSymbol pCharaterMarkerS = new CharacterMarkerSymbolClass();

            stdole.StdFont pFontDisp = new stdole.StdFontClass();
            pFontDisp.Name                  = "ESRI Default Marker";
            pFontDisp.Size                  = 30;
            pCharaterMarkerS.Font           = (IFontDisp)pFontDisp;
            pCharaterMarkerS.CharacterIndex = 81;
            pCharaterMarkerS.Color          = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(255, 0, 0));
            pCharaterMarkerS.Size           = 30;

            IProportionalSymbolRenderer pProportionalSymbolR = new ProportionalSymbolRendererClass();

            pProportionalSymbolR.ValueUnit            = esriUnits.esriUnknownUnits;
            pProportionalSymbolR.Field                = fieldName;
            pProportionalSymbolR.FlanneryCompensation = false;
            pProportionalSymbolR.MinDataValue         = pStatisticsResult.Minimum;
            pProportionalSymbolR.MaxDataValue         = pStatisticsResult.Maximum;
            pProportionalSymbolR.BackgroundSymbol     = pFillSymbol;
            pProportionalSymbolR.MinSymbol            = (ISymbol)pCharaterMarkerS;
            pProportionalSymbolR.LegendSymbolCount    = 12;
            pProportionalSymbolR.CreateLegendSymbols();

            pGeoFeatureL.Renderer = (IFeatureRenderer)pProportionalSymbolR;
        }
Пример #9
0
        public object ConvertToSupportedObject(esriArcGISVersion docVersion)
        {
            //in case of 8.3, create a character marker element and use a triangle marker...
            ICharacterMarkerSymbol charMarkerSymbol = new CharacterMarkerSymbolClass();

            charMarkerSymbol.Color          = m_fillSymbol.Color;
            charMarkerSymbol.Angle          = m_rotation;
            charMarkerSymbol.Size           = m_size;
            charMarkerSymbol.Font           = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToStdFont(new Font("ESRI Default Marker", (float)m_size, FontStyle.Regular));
            charMarkerSymbol.CharacterIndex = 184;

            IMarkerElement markerElement = new MarkerElementClass();

            markerElement.Symbol = (IMarkerSymbol)charMarkerSymbol;

            IPoint   point   = ((IClone)m_pointGeometry).Clone() as IPoint;
            IElement element = (IElement)markerElement;

            element.Geometry = (IGeometry)point;

            return(element);
        }
Пример #10
0
        private void CharacterpointToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFeatureLayer layer;

            layer = axMapControl1.get_Layer(0) as IFeatureLayer;                       //QI到IGeoFeatureLayer
            IGeoFeatureLayer       geoFeatureLayer        = layer as IGeoFeatureLayer; //新建SimpleRendererClass对象
            SimpleRenderer         simpleRender           = new SimpleRendererClass();
            ICharacterMarkerSymbol pCharacterMarkerSymbol = new CharacterMarkerSymbolClass();
            IColor pColor = new RgbColorClass();

            pColor.RGB = 2256;
            stdole.IFontDisp font = new stdole.StdFontClass() as stdole.IFontDisp;
            font.Name = "Arial"; font.Size = 30;
            font.Bold = true;
            pCharacterMarkerSymbol.Font           = font;
            pCharacterMarkerSymbol.Color          = pColor;
            pCharacterMarkerSymbol.Size           = 20;
            pCharacterMarkerSymbol.CharacterIndex = 55; //ASCII55对应数字7
            simpleRender.Symbol      = pCharacterMarkerSymbol as ISymbol;
            geoFeatureLayer.Renderer = simpleRender as IFeatureRenderer;
            axMapControl1.Refresh();
            axTOCControl1.Update();
        }
    public override void DrawDynamicLayer(esriDynamicDrawPhase DynamicDrawPhase, IDisplay Display, IDynamicDisplay DynamicDisplay)
    {
      if (DynamicDrawPhase != esriDynamicDrawPhase.esriDDPImmediate)
        return;

      if (!m_bValid || !m_visible)
        return;

      IEnvelope visibleExtent = Display.DisplayTransformation.FittedBounds;

      if (m_bOnce)
      {
        IDynamicGlyphFactory dynamicGlyphFactory = DynamicDisplay.DynamicGlyphFactory;
        m_dynamicSymbolProps = DynamicDisplay as IDynamicSymbolProperties2;


        ICharacterMarkerSymbol markerSymbol = new CharacterMarkerSymbolClass();
        markerSymbol.Font = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToStdFont(new Font("ESRI Default Marker", 25.0f, FontStyle.Bold));
        markerSymbol.Size = 25.0;
        // set the symbol color to white
        markerSymbol.Color = (IColor)ESRI.ArcGIS.ADF.Connection.Local.Converter.ToRGBColor(Color.FromArgb(255, 255, 255));
        markerSymbol.CharacterIndex = 92;

        // create the dynamic glyph
        m_myGlyph = dynamicGlyphFactory.CreateDynamicGlyph((ISymbol)markerSymbol);


        Random r = new Random();
        double X = visibleExtent.XMin + r.NextDouble() * visibleExtent.Width;
        double Y = visibleExtent.YMin + r.NextDouble() * visibleExtent.Height;
        m_point = new PointClass();
        m_point.PutCoords(X, Y);

        m_stepX = visibleExtent.Width / 250;
        m_stepY = visibleExtent.Height / 250;

        // start the update timer
        m_updateTimer.Enabled = true;

        m_bOnce = false;
      }

      // draw the marker
      m_dynamicSymbolProps.set_DynamicGlyph(esriDynamicSymbolType.esriDSymbolMarker, m_myGlyph);
      m_dynamicSymbolProps.SetColor(esriDynamicSymbolType.esriDSymbolMarker, 1.0f, 0.0f, 0.0f, 1.0f);
      m_dynamicSymbolProps.SetScale(esriDynamicSymbolType.esriDSymbolMarker, 1.0f, 1.0f);
      DynamicDisplay.DrawMarker(m_point);

      // update the point location for the next draw cycle
      m_point.X += m_stepX;
      m_point.Y += m_stepY;

      // make sure that the point fall within the visible extent
      if (m_point.X > visibleExtent.XMax) m_stepX = -Math.Abs(m_stepX);
      if (m_point.X < visibleExtent.XMin) m_stepX = Math.Abs(m_stepX);
      if (m_point.Y > visibleExtent.YMax) m_stepY = -Math.Abs(m_stepY);
      if (m_point.Y < visibleExtent.YMin) m_stepY = Math.Abs(m_stepY);

      // set the dirty flag to false since drawing is done.
      base.m_bIsImmediateDirty = false;
    }
    private ISymbol CreateBikeRouteSymbol()
    {
        IColor color = (IColor)ESRI.ArcGIS.ADF.Connection.Local.Converter.ToRGBColor(Color.FromArgb(0, 90, 250));
      ICharacterMarkerSymbol charMarkerSymbol = new CharacterMarkerSymbolClass();
      charMarkerSymbol.Color = color;
      charMarkerSymbol.Font = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToStdFont(new Font("ESRI Default Marker", 17.0f, FontStyle.Bold));
      charMarkerSymbol.CharacterIndex = 189;
      charMarkerSymbol.Size = 17;

      IMarkerLineSymbol markerLineSymbol = new MarkerLineSymbolClass();
      markerLineSymbol.Color = color;
      markerLineSymbol.Width = 17.0;
      markerLineSymbol.MarkerSymbol = (IMarkerSymbol)charMarkerSymbol;

      // Makes a new Cartographic Line symbol and sets its properties
      ICartographicLineSymbol cartographicLineSymbol = markerLineSymbol as ICartographicLineSymbol;

      // In order to set additional properties like offsets and dash patterns we must create an ILineProperties object
      ILineProperties lineProperties = cartographicLineSymbol as ILineProperties;
      lineProperties.Offset = 0;

      // Here's how to do a template for the pattern of marks and gaps
      double[] hpe = new double[4];
      hpe[0] = 0;
      hpe[1] = 39;
      hpe[2] = 1;
      hpe[3] = 0;

      ITemplate template = new TemplateClass();
      template.Interval = 1;
      for (int i = 0; i < hpe.Length; i = i + 2)
      {
        template.AddPatternElement(hpe[i], hpe[i + 1]);
      }
      lineProperties.Template = template;

      // Set the basic and cartographic line properties
      cartographicLineSymbol.Color = color;

      color = (IColor)ESRI.ArcGIS.ADF.Connection.Local.Converter.ToRGBColor(Color.FromArgb(0, 220, 100));

      // create a simple line
      ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();
      simpleLineSymbol.Color = color;
      simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
      simpleLineSymbol.Width = 1.2;

      IMultiLayerLineSymbol multiLayerLineSymbol = new MultiLayerLineSymbolClass();
      multiLayerLineSymbol.AddLayer((ILineSymbol)cartographicLineSymbol);
      multiLayerLineSymbol.AddLayer((ILineSymbol)simpleLineSymbol);

      return multiLayerLineSymbol as ISymbol;
    }
		private ICharacterMarkerSymbol GetMarkerSymbol(bool bLocated)
		{
			//Create a new system draw font
			System.Drawing.Font drawFont = new System.Drawing.Font("ESRI Crime Analysis", 21);

			//Create a new CharacterMarkerSymbol and get the ICharacterMarkerSymbol interface
			ICharacterMarkerSymbol charMarker = new CharacterMarkerSymbolClass();
			//Set the marker symbol properties
			charMarker.Font = (stdole.IFontDisp) OLE.GetIFontDispFromFont(drawFont);
			
			if (bLocated == true)
			{
				charMarker.CharacterIndex = 56;
				charMarker.Color = GetRGBColor(255, 0, 0);
				charMarker.Size = 30;
			}
			else
			{
				charMarker.CharacterIndex = 46;
				charMarker.Color = GetRGBColor(0, 0, 0);
				charMarker.Size = 30;
			}
			return charMarker;
		}
Пример #14
0
        /// <summary>
        /// 绘制瓦斯压力点符号
        /// ge绘制瓦斯压力点的数据结构
        /// editlayer指定需要在哪个图层添加该瓦斯压力点
        /// 2013-12-14
        /// lntu_GISer1
        /// </summary>
        /// <param name="ge"></param>
        /// <param name="pfeaLayer"></param>
        public void DrawGasPressureGE(IFeatureLayer editlayer, GasPressureEntity ge)
        {
            IFeature f;
            IPoint   p;
            //定义一个地物类,把要编辑的图层转化为定义的地物类
            IFeatureClass fc = editlayer.FeatureClass;
            //先定义一个编辑的工作空间,然后把转化为数据集,最后转化为编辑工作空间,
            IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit;

            //开始事务操作
            w.StartEditing(false);
            //开始编辑
            w.StartEditOperation();
            //创建一个地物
            f = fc.CreateFeature();
            p = new PointClass();
            //设置点的坐标
            p.PutCoords(Convert.ToDouble(ge.CoordinateX), Convert.ToDouble(ge.CoordinateY));
            try
            {
                //确定图形类型
                f.Shape = p;
                int num3;
                //num3 = editlayer.FeatureClass.Fields.FindField("PRIMARY_KEY");
                //f.set_Value(num3, ge.PrimaryKey);
                num3 = editlayer.FeatureClass.Fields.FindField("COORDINATE_X");
                f.set_Value(num3, ge.CoordinateX);
                num3 = editlayer.FeatureClass.Fields.FindField("COORDINATE_Y");
                f.set_Value(num3, ge.CoordinateY);
                num3 = editlayer.FeatureClass.Fields.FindField("COORDINATE_Z");
                f.set_Value(num3, ge.CoordinateZ);
                num3 = editlayer.FeatureClass.Fields.FindField("DEPTH");
                f.set_Value(num3, ge.Depth);
                num3 = editlayer.FeatureClass.Fields.FindField("GAS_PRESSURE_VALUE");
                f.set_Value(num3, ge.GasPressureValue);
                num3 = editlayer.FeatureClass.Fields.FindField("MEASURE_DATE_TIME");
                f.set_Value(num3, ge.MeasureDateTime);
                //保存地物
                f.Store();
                ICharacterMarkerSymbol pMarkerSymbol;
                pMarkerSymbol = new CharacterMarkerSymbolClass();
                stdole.IFontDisp stdFont = new stdole.StdFontClass() as stdole.IFontDisp;
                stdFont.Name                 = "ESRI Caves 3";
                stdFont.Size                 = 48;
                pMarkerSymbol.Font           = stdFont;
                pMarkerSymbol.CharacterIndex = 107;
                //Symbol颜色
                pMarkerSymbol.Color = getRGB(0, 0, 0);
                //Symbol旋转角度
                pMarkerSymbol.Angle = 0;
                //Symbol大小
                pMarkerSymbol.Size = 48;
                RenderfeatureLayer(editlayer, pMarkerSymbol as ISymbol);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            //结束编辑
            w.StopEditOperation();
            //结束事务操作
            w.StopEditing(true);
        }
Пример #15
0
        /// <summary>
        /// 比例符号法渲染器(ProportionalSymbolRenderer)——用不同大小的符号绘制要素, 其大小对应某一字段值的比例。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 比例符号法渲染ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //声明IGeoFeatureLayer变量, 提供一个要素图层对成员控制地理特征的入口
            IGeoFeatureLayer geoFeatureLayer;
            //声明要素图层
            IFeatureLayer pFtLayer;
            //声明专题图变量
            //在利用该方法进行着色时, 需获得最大和最小标识符号所代表的字段及其各个数值, 还需要确定每个字段数值所匹配的着色符号。
            IProportionalSymbolRenderer proportionalSymbolRenderer;
            //声明表格
            ITable table;
            //声明游标
            ICursor cursor;
            //用于统计变量
            IDataStatistics dataStatistics;
            //用于存放统计结果
            IStatisticsResults statisticsResults;

            //声明一个字体对象
            stdole.IFontDisp fontDisp;
            //获取图层
            geoFeatureLayer = getGeoLayer("北部湾");
            //强转为要素图层
            pFtLayer = geoFeatureLayer as IFeatureLayer;
            //图层类型转换成表
            table = geoFeatureLayer as ITable;
            //获取游标
            cursor = table.Search(null, true);
            //实例化数据统计对象
            dataStatistics = new DataStatisticsClass();
            //赋游标给数据统计对象的游标
            dataStatistics.Cursor = cursor;
            //获取图层要素中进行专题地图制图的字段名称, 此实例中所用的数据中字段名为"年"(2010年GDP增长速率)
            dataStatistics.Field = "年";
            //存放统计结果为统计对象的统计数据
            statisticsResults = dataStatistics.Statistics;
            //如果统计结果不为空
            if (statisticsResults != null)
            {
                //简单填充符号
                IFillSymbol fillSymbol = new SimpleFillSymbolClass();
                //设置颜色
                fillSymbol.Color = getRGB(195, 255, 255);
                //设置简单线型符号
                ISimpleLineSymbol SLS = new SimpleLineSymbolClass();
                SLS.Color          = getRGB(196, 196, 196); //颜色
                SLS.Width          = 1.5;                   //宽度
                fillSymbol.Outline = SLS;                   //外边界线
                //利用ESRI特殊符号调用成员进行填充
                ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass();
                fontDisp = new stdole.StdFontClass() as stdole.IFontDisp;
                //调用指定子库(ESRI Default Marker是子库名称)
                fontDisp.Name = "ESRI Default Marker";

                //对characterMarkerSymbol的font属性
                characterMarkerSymbol.Font = fontDisp;
                //特征标记符号(Character Marker Symbol)的索引值
                //0xB6是C#特殊的16进制表示方法, 换算为十进制值182
                characterMarkerSymbol.CharacterIndex = 0xB6;
                //特征标记符号的颜色
                characterMarkerSymbol.Color = getRGB(253, 191, 110);
                //设计特征标记符号的尺寸
                characterMarkerSymbol.Size = 18;
                //实例化一个比例符号渲染器
                proportionalSymbolRenderer           = new ProportionalSymbolRendererClass();
                proportionalSymbolRenderer.ValueUnit = esriUnits.esriUnknownUnits;
                //获取渲染字段
                proportionalSymbolRenderer.Field = "年";
                //是否启用颜色补偿(默认为否)
                proportionalSymbolRenderer.FlanneryCompensation = false;
                //赋值统计数据(比例符号渲染器)
                //MinDataValue获取数据中最小值
                proportionalSymbolRenderer.MinDataValue = statisticsResults.Minimum;
                //获取数据中最大值
                proportionalSymbolRenderer.MaxDataValue = statisticsResults.Maximum;
                //在多边形特征上绘制比例标记符号时使用的背景填充符号
                proportionalSymbolRenderer.BackgroundSymbol = fillSymbol;
                //用于绘制具有规格化最小数据值的特征的符号。
                proportionalSymbolRenderer.MinSymbol = characterMarkerSymbol as ISymbol;
                //目录和图例中显示的符号数为3
                proportionalSymbolRenderer.LegendSymbolCount = 3;
                //创建图例, 设置完所有属性后调用。
                proportionalSymbolRenderer.CreateLegendSymbols();
                //赋值目标图层的渲染器属性
                geoFeatureLayer.Renderer = proportionalSymbolRenderer as IFeatureRenderer;
            }
            axMapControl1.Refresh(); //刷新axMapControl1
            axTOCControl1.Update();  //更新axTOCControl1
        }
    private IUniqueValueRenderer CreateUniqueValueRenderer(IFeatureClass featureClass, string fieldName)
    {
      IRgbColor color = new RgbColorClass();
      color.Red = 255;
      color.Blue = 0;
      color.Green = 0;

      ICharacterMarkerSymbol charMarkersymbol = new CharacterMarkerSymbolClass();
      charMarkersymbol.Font = Converter.ToStdFont(new Font(new FontFamily("ESRI Default Marker"), 12.0f, FontStyle.Regular));
      charMarkersymbol.CharacterIndex = 96;
      charMarkersymbol.Size = 12.0;
      charMarkersymbol.Color = (IColor)color;


      IRandomColorRamp randomColorRamp = new RandomColorRampClass();
      randomColorRamp.MinSaturation = 20;
      randomColorRamp.MaxSaturation = 40;
      randomColorRamp.MaxValue = 85;
      randomColorRamp.MaxValue = 100;
      randomColorRamp.StartHue = 75;
      randomColorRamp.EndHue = 190;
      randomColorRamp.UseSeed = true;
      randomColorRamp.Seed = 45;

      IUniqueValueRenderer uniqueRenderer = new UniqueValueRendererClass();
      uniqueRenderer.FieldCount = 1;
      uniqueRenderer.set_Field(0, fieldName);
      uniqueRenderer.DefaultSymbol = (ISymbol)charMarkersymbol;
      uniqueRenderer.UseDefaultSymbol = true;



      Random rand = new Random();
      bool bValFound = false;
      IFeatureCursor featureCursor = featureClass.Search(null, true);
      IFeature feature = null;
      string val = string.Empty;
      int fieldID = featureClass.FindField(fieldName);
      if (-1 == fieldID)
        return uniqueRenderer;

      while ((feature = featureCursor.NextFeature()) != null)
      {
        bValFound = false;
        val = Convert.ToString(feature.get_Value(fieldID));
        for (int i = 0; i < uniqueRenderer.ValueCount - 1; i++)
        {
          if (uniqueRenderer.get_Value(i) == val)
            bValFound = true;
        }

        if (!bValFound)//need to add the value to the renderer
        {
          color.Red = rand.Next(255);
          color.Blue = rand.Next(255);
          color.Green = rand.Next(255);

          charMarkersymbol = new CharacterMarkerSymbolClass();
          charMarkersymbol.Font = Converter.ToStdFont(new Font(new FontFamily("ESRI Default Marker"), 10.0f, FontStyle.Regular));
          charMarkersymbol.CharacterIndex = rand.Next(40, 118);
          charMarkersymbol.Size = 20.0;
          charMarkersymbol.Color = (IColor)color;

          //add the value to the renderer
          uniqueRenderer.AddValue(val, "name", (ISymbol)charMarkersymbol);
        }
      }

      //release the featurecursor
      ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor);

      return uniqueRenderer;
    }
Пример #17
0
 //比例图
 private void button4_Click(object sender, EventArgs e)
 {
     IGeoFeatureLayer geoFeatureLayer;
     IFeatureLayer featureLayer;
     IProportionalSymbolRenderer proportionalSymbolRenderer;
     ITable table;
     ICursor cursor;
     IDataStatistics dataStatistics;
     IStatisticsResults statisticsResult;
     stdole.IFontDisp fontDisp;
     geoFeatureLayer = getGeoLayer("东丰县行政区域");
     featureLayer = geoFeatureLayer as IFeatureLayer;
     table = geoFeatureLayer as ITable;
     cursor = table.Search(null, true);
     dataStatistics = new DataStatisticsClass();
     dataStatistics.Cursor = cursor;
     dataStatistics.Field = "SHAPE_Area";
     statisticsResult = dataStatistics.Statistics;
     if (statisticsResult != null)
     {
         IFillSymbol fillSymbol = new SimpleFillSymbolClass();
         fillSymbol.Color = getRGB(0, 255, 0);
         ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass();
         fontDisp = new stdole.StdFontClass() as stdole.IFontDisp;
         fontDisp.Name = "arial";
         fontDisp.Size = 20;
         characterMarkerSymbol.Font = fontDisp;
         characterMarkerSymbol.CharacterIndex = 90;
         characterMarkerSymbol.Color = getRGB(255, 0, 0);
         characterMarkerSymbol.Size = 8;
         proportionalSymbolRenderer = new ProportionalSymbolRendererClass();
         proportionalSymbolRenderer.ValueUnit = esriUnits.esriUnknownUnits;
         proportionalSymbolRenderer.Field = "SHAPE_Area";
         proportionalSymbolRenderer.FlanneryCompensation = false;
         proportionalSymbolRenderer.MinDataValue = statisticsResult.Minimum;
         proportionalSymbolRenderer.MaxDataValue = statisticsResult.Maximum;
         proportionalSymbolRenderer.BackgroundSymbol = fillSymbol;
         proportionalSymbolRenderer.MinSymbol = characterMarkerSymbol as ISymbol;
         proportionalSymbolRenderer.LegendSymbolCount = 10;
         proportionalSymbolRenderer.CreateLegendSymbols();
         geoFeatureLayer.Renderer = proportionalSymbolRenderer as IFeatureRenderer;
     }
     this.axMapControl1.Refresh();
 }
        private void UpdateMapControlWithMarker(IMapControl4 updateMapControl, string action)
        {
            IRgbColor redRgbColor = new RgbColorClass();
            redRgbColor.Red = 255;
            redRgbColor.Green = 0;
            redRgbColor.Blue = 0;

            IRgbColor yellowRgbColor = new RgbColorClass();
            yellowRgbColor.Red = 255;
            yellowRgbColor.Green = 255;
            yellowRgbColor.Blue = 115;

            IRgbColor blackRgbcolor = new RgbColorClass();
            blackRgbcolor.Red = 0;
            blackRgbcolor.Green = 0;
            blackRgbcolor.Blue = 0;

            IRgbColor greenRgbColor = new RgbColorClass();
            greenRgbColor.Red = 0;
            greenRgbColor.Green = 255;
            greenRgbColor.Blue = 0;

            IEnvelope extentEnvelope = updateMapControl.Extent;
            IGraphicsContainer graphicsContainer = updateMapControl.Map.BasicGraphicsLayer as IGraphicsContainer;

            if (action == "DeleteMarker")
            {
                DeleteElement(updateMapControl, action);
            }
            else if (action == "AcceptMarker")
            {
                DeleteElement(updateMapControl, action);
            }

            IMultiLayerMarkerSymbol multiLayerMarkerSymbol = new MultiLayerMarkerSymbolClass();

            stdole.IFontDisp esriDefaultMarkerFont = new stdole.StdFontClass() as stdole.IFontDisp;
            esriDefaultMarkerFont.Name = "ESRI Default Marker";
            esriDefaultMarkerFont.Size = Convert.ToDecimal(48);

            IPoint markerLocation = new PointClass();
            markerLocation.SpatialReference = updateMapControl.SpatialReference;

            markerLocation.X = extentEnvelope.LowerLeft.X + extentEnvelope.Width / 10;
            markerLocation.Y = extentEnvelope.LowerLeft.Y + extentEnvelope.Height / (10 * (extentEnvelope.Height / extentEnvelope.Width));

            IMarkerElement markerElement = new MarkerElementClass();
            ((IElement)markerElement).Geometry = markerLocation;

            ISimpleMarkerSymbol backgroundMarkerSymbol = new SimpleMarkerSymbolClass();
            backgroundMarkerSymbol.Color = (IColor)yellowRgbColor;
            backgroundMarkerSymbol.Size = 45;
            backgroundMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;
            backgroundMarkerSymbol.Outline = true;
            backgroundMarkerSymbol.OutlineColor = blackRgbcolor;
            backgroundMarkerSymbol.OutlineSize = 2;

            multiLayerMarkerSymbol.AddLayer((IMarkerSymbol)backgroundMarkerSymbol);

            if (action == "DeleteMarker")
            {
                ICharacterMarkerSymbol deleteMarkerSymbol = new CharacterMarkerSymbolClass();
                deleteMarkerSymbol.Font = esriDefaultMarkerFont;
                deleteMarkerSymbol.CharacterIndex = 68;
                deleteMarkerSymbol.Color = redRgbColor;
                deleteMarkerSymbol.Size = 48;

                multiLayerMarkerSymbol.AddLayer(deleteMarkerSymbol);

                ((IElementProperties)markerElement).Name = "DeleteMarker";

            }
            else if (action == "AcceptMarker")
            {
                ICharacterMarkerSymbol acceptMarkerSymbol = new CharacterMarkerSymbolClass();

                acceptMarkerSymbol.Font = esriDefaultMarkerFont;
                acceptMarkerSymbol.CharacterIndex = 105;
                acceptMarkerSymbol.Color = greenRgbColor;
                acceptMarkerSymbol.Size = 48;

                multiLayerMarkerSymbol.AddLayer(acceptMarkerSymbol);

                ((IElementProperties)markerElement).Name = "AcceptMarker";
            }

            markerElement.Symbol = (IMarkerSymbol)multiLayerMarkerSymbol;

            graphicsContainer.AddElement((IElement)markerElement, 99);

            updateMapControl.Refresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
    public object ConvertToSupportedObject(esriArcGISVersion docVersion)
    {
      //in case of 8.3, create a character marker element and use a triangle marker...
      ICharacterMarkerSymbol charMarkerSymbol = new CharacterMarkerSymbolClass();
      charMarkerSymbol.Color = m_fillSymbol.Color;
      charMarkerSymbol.Angle = m_rotation;
      charMarkerSymbol.Size = m_size;
      charMarkerSymbol.Font = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToStdFont(new Font("ESRI Default Marker", (float)m_size, FontStyle.Regular));
      charMarkerSymbol.CharacterIndex = 184;

      IMarkerElement markerElement = new MarkerElementClass();
      markerElement.Symbol = (IMarkerSymbol)charMarkerSymbol;

      IPoint point = ((IClone)m_pointGeometry).Clone() as IPoint;
      IElement element = (IElement)markerElement;
      element.Geometry = (IGeometry)point;

      return element;
    }
 /// <summary>
 /// 绘制瓦斯含量点
 /// </summary>
 /// <param name="editlayer"></param>
 /// <param name="ge"></param>
 public void DrawGasContentPointGE(IFeatureLayer editlayer, GasContentEntity ge)
 {
     IFeature f;
        IPoint p;
        //定义一个地物类,把要编辑的图层转化为定义的地物类
        IFeatureClass fc = editlayer.FeatureClass;
        //先定义一个编辑的工作空间,然后把转化为数据集,最后转化为编辑工作空间,
        IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit;
        //开始事务操作
        w.StartEditing(false);
        //开始编辑
        w.StartEditOperation();
        //创建一个地物
        f = fc.CreateFeature();
        p = new PointClass();
        //设置点的坐标
        p.PutCoords(Convert.ToDouble(ge.CoordinateX), Convert.ToDouble(ge.CoordinateY));
        try
        {
        //确定图形类型
        f.Shape = p;
        int num3;
        //num3 = editlayer.FeatureClass.Fields.FindField("PRIMARY_KEY");
        //f.set_Value(num3, ge.PrimaryKey);
        num3 = editlayer.FeatureClass.Fields.FindField("COORDINATE_X");
        f.set_Value(num3, ge.CoordinateX);
        num3 = editlayer.FeatureClass.Fields.FindField("COORDINATE_Y");
        f.set_Value(num3, ge.CoordinateY);
        num3 = editlayer.FeatureClass.Fields.FindField("COORDINATE_Z");
        f.set_Value(num3, ge.CoordinateZ);
        num3 = editlayer.FeatureClass.Fields.FindField("DEPTH");
        f.set_Value(num3, ge.Depth);
        num3 = editlayer.FeatureClass.Fields.FindField("GAS_CONTENT_VALUE");
        f.set_Value(num3, ge.GasContentValue);
        num3 = editlayer.FeatureClass.Fields.FindField("MEASURE_DATE_TIME");
        f.set_Value(num3, ge.MeasureDateTime);
        //保存地物
        f.Store();
        }
        catch (Exception e)
        {
        MessageBox.Show(e.Message);
        }
        ICharacterMarkerSymbol pMarkerSymbol;
        pMarkerSymbol = new CharacterMarkerSymbolClass();
        stdole.IFontDisp stdFont = new stdole.StdFontClass() as stdole.IFontDisp;
        stdFont.Name = "ESRI Hazardous Materials";
        stdFont.Size = 48;
        pMarkerSymbol.Font = stdFont;
        pMarkerSymbol.CharacterIndex = 216;
        //Symbol颜色
        pMarkerSymbol.Color = getRGB(0, 0, 0);
        //Symbol旋转角度
        pMarkerSymbol.Angle = 0;
        //Symbol大小
        pMarkerSymbol.Size = 48;
        RenderfeatureLayer(editlayer, pMarkerSymbol as ISymbol);
        //结束编辑
        w.StopEditOperation();
        //结束事务操作
        w.StopEditing(true);
 }
    /// <summary>
    /// create the layer's glyphs used to set the symbol of the dynamic-layer items
    /// </summary>
    /// <param name="pDynamicGlyphFactory"></param>
    private void CreateDynamicSymbols(IDynamicGlyphFactory2 pDynamicGlyphFactory)
    {
      try
      {
        //set the background color
				IColor color = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToRGBColor (Color.FromArgb (255, 255, 255)) as IColor;

        // Create Character Marker Symbols glyph
        // --------------------------------------
				ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass ();
				characterMarkerSymbol.Color = color as IColor;
                characterMarkerSymbol.Font = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToStdFont(new Font("ESRI Environmental & Icons", 32));
				characterMarkerSymbol.Size = 40;
				characterMarkerSymbol.Angle = 0;
				characterMarkerSymbol.CharacterIndex = 36;

        //create the glyph from the marker symbol
        m_markerGlyphs[0] = pDynamicGlyphFactory.CreateDynamicGlyph(characterMarkerSymbol as ISymbol);

        characterMarkerSymbol.Size = 32;
        characterMarkerSymbol.CharacterIndex = 224;

        //create the glyph from the marker symbol
        m_markerGlyphs[1] = pDynamicGlyphFactory.CreateDynamicGlyph(characterMarkerSymbol as ISymbol);

        // Create the glyph from embedded bitmap
        // -----------------------------------
        // Sets the transparency color
        IColor transparentColor = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToRGBColor(Color.FromArgb(255, 255, 255)) as IColor;

				Bitmap bitmap = new Bitmap (GetType (), "B2.bmp");
				m_markerGlyphs[2] = pDynamicGlyphFactory.CreateDynamicGlyphFromBitmap(esriDynamicGlyphType.esriDGlyphMarker, bitmap.GetHbitmap ().ToInt32 (), false, transparentColor);
     
        // Create a glyph for the labels text, use the first 'internal' text glyph 
        // ------------------------------------------------------------------------
        m_textGlyph = pDynamicGlyphFactory.get_DynamicGlyph(1, esriDynamicGlyphType.esriDGlyphText, 1);

      }
      catch (Exception ex)
      {
        System.Diagnostics.Trace.WriteLine(ex.Message);
      }
    }
Пример #22
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (cboFldnm1.Text == "" || cboFldnm2.Text == "")
            {
                MessageBox.Show("Please select target field");
                return;
            }

            frmProgress pfrmProgress = new frmProgress();

            pfrmProgress.lblStatus.Text    = "Processing:";
            pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee;
            pfrmProgress.Show();

            REngine pEngine = m_pForm.pEngine;
            // Creates the input and output matrices from the shapefile//
            string strLayerName = cboTargetLayer.Text;

            int    intLIndex = m_pSnippet.GetIndexNumberFromLayerName(m_pActiveView, strLayerName);
            ILayer pLayer    = m_pForm.axMapControl1.get_Layer(intLIndex);

            IFeatureLayer pFLayer  = pLayer as IFeatureLayer;
            IFeatureClass pFClass  = pFLayer.FeatureClass;
            int           nFeature = pFClass.FeatureCount(null);

            IFeatureCursor pFCursor = pFLayer.Search(null, true);
            IFeature       pFeature = pFCursor.NextFeature();

            //Get index for independent and dependent variables
            //Get variable index
            string strVarNM1  = (string)cboFldnm1.SelectedItem;
            string strVarNM2  = (string)cboFldnm2.SelectedItem;
            int    intVarIdx1 = pFClass.FindField(strVarNM1);
            int    intVarIdx2 = pFClass.FindField(strVarNM2);

            //Store Variable at Array
            double[] arrVar1 = new double[nFeature];
            double[] arrVar2 = new double[nFeature];

            int i = 0;

            while (pFeature != null)
            {
                arrVar1[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx1));
                arrVar2[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx2));
                i++;
                pFeature = pFCursor.NextFeature();
            }

            pFCursor.Flush();

            //Plot command for R
            StringBuilder plotCommmand = new StringBuilder();

            string strStartPath = m_pForm.strPath;
            string pathr        = strStartPath.Replace(@"\", @"/");

            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_LARRY.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_neighbor.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_SASbi.R')");

            //Get the file path and name to create spatial weight matrix
            string strNameR = m_pSnippet.FilePathinRfromLayer(pFLayer);

            if (strNameR == null)
            {
                return;
            }

            //Create spatial weight matrix in R
            pEngine.Evaluate("library(spdep); library(maptools)");
            pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')");
            pEngine.Evaluate("sample.nb <- poly2nb(sample.shp)");

            NumericVector vecVar1 = pEngine.CreateNumericVector(arrVar1);

            pEngine.SetSymbol("sample.v1", vecVar1);
            NumericVector vecVar2 = pEngine.CreateNumericVector(arrVar2);

            pEngine.SetSymbol("sample.v2", vecVar2);

            string strRSigLv  = nudRsigLv.Value.ToString();
            string strLSigLv  = nudLsigLv.Value.ToString();
            string strLSig    = cboLocalL.Text;
            string strRsig    = cboLocalPearson.Text;
            string strRowStd  = cboRowStandardization.Text;
            string strNonZero = null;

            if (chkDiagZero.Checked)
            {
                strNonZero = "FALSE";
            }
            else
            {
                strNonZero = "TRUE";
            }

            pEngine.Evaluate("sample.result <- LARRY.bivariate.spatial.outlier(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, pearson.sig = " +
                             strRSigLv + ", lee.sig = " + strLSigLv + ", method.pearson = '" + strRsig + "', method.lee = '" +
                             strLSig + "', type.row.stand = '" + strRowStd + "', alternative = 'two', diag.zero = "
                             + strNonZero + ")");

            string[] strSPOutliers = pEngine.Evaluate("as.character(sample.result$sp.outlier)").AsCharacter().ToArray();

            //Save Output on SHP
            //Add Target fields to store results in the shapefile // Keep loop
            for (int j = 0; j < 1; j++)
            {
                string strfldName = lvFields.Items[j].SubItems[1].Text;
                if (pFClass.FindField(strfldName) == -1)
                {
                    IField     newField  = new FieldClass();
                    IFieldEdit fieldEdit = (IFieldEdit)newField;
                    fieldEdit.Name_2 = strfldName;
                    fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                    pFClass.AddField(newField);
                }
            }

            //Update Field
            pFCursor = pFClass.Update(null, false);
            pFeature = pFCursor.NextFeature();

            string strSpOutlierFldName = lvFields.Items[0].SubItems[1].Text;
            int    intSpOutlierFldIdx  = pFClass.FindField(strSpOutlierFldName);

            int featureIdx = 0;

            while (pFeature != null)
            {
                pFeature.set_Value(intSpOutlierFldIdx, strSPOutliers[featureIdx]);

                pFCursor.UpdateFeature(pFeature);

                pFeature = pFCursor.NextFeature();
                featureIdx++;
            }
            pFCursor.Flush();

            if (chkMap.Checked)
            {
                ITable pTable = (ITable)pFClass;

                IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();
                pUniqueValueRenderer.FieldCount = 1;
                pUniqueValueRenderer.set_Field(0, strSpOutlierFldName);
                if (cboMaptype.Text == "choropleth map")
                {
                    ISimpleFillSymbol pSymbol;
                    IQueryFilter      pQFilter = new QueryFilterClass();
                    int    intTotalCount       = 0;
                    string strLabel            = null;

                    for (int j = 0; j < 4; j++)
                    {
                        pSymbol       = new SimpleFillSymbolClass();
                        pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                        pSymbol.Color = m_pSnippet.getRGB(m_pOutlierSymbols[j].R, m_pOutlierSymbols[j].G, m_pOutlierSymbols[j].B);

                        pQFilter.WhereClause = strSpOutlierFldName + " = '" + m_pOutlierSymbols[j].Value + "'";

                        intTotalCount = pTable.RowCount(pQFilter);

                        strLabel = m_pOutlierSymbols[j].Label + " (" + intTotalCount.ToString() + ")";
                        pUniqueValueRenderer.AddValue(m_pOutlierSymbols[j].Value, null, (ISymbol)pSymbol);
                        pUniqueValueRenderer.set_Label(m_pOutlierSymbols[j].Value, strLabel);
                    }
                    pUniqueValueRenderer.UseDefaultSymbol = false;
                }
                else if (cboMaptype.Text == "point map")
                {
                    ICharacterMarkerSymbol pSymbol;
                    stdole.IFontDisp       stdFontCls = ((stdole.IFontDisp)(new stdole.StdFont()));
                    stdFontCls.Name = "ESRI NIMA VMAP1&2 PT";
                    stdFontCls.Size = 10;

                    IQueryFilter pQFilter      = new QueryFilterClass();
                    int          intTotalCount = 0;
                    string       strLabel      = null;

                    for (int j = 0; j < 4; j++)
                    {
                        pSymbol = new CharacterMarkerSymbolClass();
                        pSymbol.CharacterIndex = 248;
                        //pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B);
                        pSymbol.Size = 10;
                        pSymbol.Font = stdFontCls;

                        pSymbol.Angle = m_pOutlierSymbols[j].Angle;

                        pQFilter.WhereClause = strSpOutlierFldName + " = '" + m_pOutlierSymbols[j].Value + "'";

                        intTotalCount = pTable.RowCount(pQFilter);

                        strLabel = m_pOutlierSymbols[j].Label + " (" + intTotalCount.ToString() + ")";
                        pUniqueValueRenderer.AddValue(m_pOutlierSymbols[j].Value, null, (ISymbol)pSymbol);
                        pUniqueValueRenderer.set_Label(m_pOutlierSymbols[j].Value, strLabel);
                    }
                    pUniqueValueRenderer.UseDefaultSymbol = false;
                }
                IFeatureLayer pNewFLayer = new FeatureLayerClass();
                pNewFLayer.FeatureClass = pFClass;
                pNewFLayer.Name         = "Bivariate Spatial Quadrants";
                IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer;
                pGFLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
                m_pActiveView.FocusMap.AddLayer(pGFLayer);
                m_pActiveView.Refresh();
                m_pForm.axTOCControl1.Update();

                pfrmProgress.Close();
            }
            else
            {
                MessageBox.Show("Complete. The results are stored in the shape file");
            }
        }
Пример #23
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (cboFldnm1.Text == "" || cboFldnm2.Text == "")
            {
                MessageBox.Show("Please select target field");
                return;
            }

            frmProgress pfrmProgress = new frmProgress();

            pfrmProgress.lblStatus.Text    = "Processing:";
            pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee;
            pfrmProgress.Show();

            REngine pEngine = m_pForm.pEngine;

            int nFeature = m_pFClass.FeatureCount(null);

            IFeatureCursor pFCursor = m_pFClass.Search(null, true);
            IFeature       pFeature = pFCursor.NextFeature();

            //Get index for independent and dependent variables
            //Get variable index
            string strVarNM1  = (string)cboFldnm1.SelectedItem;
            string strVarNM2  = (string)cboFldnm2.SelectedItem;
            int    intVarIdx1 = m_pFClass.FindField(strVarNM1);
            int    intVarIdx2 = m_pFClass.FindField(strVarNM2);
            int    intFIDIdx  = m_pFClass.FindField(m_pFClass.OIDFieldName);

            //Store Variable at Array
            double[] arrVar1 = new double[nFeature];
            double[] arrVar2 = new double[nFeature];

            int[] arrFID = new int[nFeature];

            int i = 0;

            while (pFeature != null)
            {
                arrVar1[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx1));
                arrVar2[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx2));
                arrFID[i]  = Convert.ToInt32(pFeature.get_Value(intFIDIdx));
                i++;
                pFeature = pFCursor.NextFeature();
            }

            pFCursor.Flush();

            //Plot command for R
            StringBuilder plotCommmand = new StringBuilder();

            string strStartPath = m_pForm.strPath;
            string pathr        = strStartPath.Replace(@"\", @"/");

            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_LARRY.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_neighbor.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_SASbi.R')");

            //Get the file path and name to create spatial weight matrix
            string strNameR = m_pSnippet.FilePathinRfromLayer(m_pFLayer);

            if (strNameR == null)
            {
                return;
            }

            //Create spatial weight matrix in R
            pEngine.Evaluate("library(spdep); library(maptools)");
            pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')");
            //pEngine.Evaluate("sample.nb <- poly2nb(sample.shp, queen=FALSE)");
            pEngine.Evaluate("sample.nb <- poly2nb(sample.shp)");

            NumericVector vecVar1 = pEngine.CreateNumericVector(arrVar1);

            pEngine.SetSymbol("sample.v1", vecVar1);
            NumericVector vecVar2 = pEngine.CreateNumericVector(arrVar2);

            pEngine.SetSymbol("sample.v2", vecVar2);

            string strNonZero = null;

            if (chkDiagZero.Checked)
            {
                strNonZero = "FALSE";
            }
            else
            {
                strNonZero = "TRUE";
            }

            string[] strSPQuadrants = null;

            double[]      adblVar1 = null;
            double[]      adblVar2 = null;
            NumericVector vecCoeff = null;

            if (cboMeasure.Text == "Lee's L")
            {
                pEngine.Evaluate("sample.result <- LARRY.bivariate.quadrant.lee(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, style = 'W', diag.zero = " + strNonZero + ")");
                strSPQuadrants = pEngine.Evaluate("as.character(sample.result$quad)").AsCharacter().ToArray();
                if (chkScatterplot.Checked)
                {
                    adblVar1 = pEngine.Evaluate("as.numeric(sample.result$v.z.x)").AsNumeric().ToArray();
                    adblVar2 = pEngine.Evaluate("as.numeric(sample.result$v.z.y)").AsNumeric().ToArray();
                    vecCoeff = pEngine.Evaluate("lm(sample.result$v.z.y~sample.result$v.z.x)$coefficients").AsNumeric();
                }
            }
            else if (cboMeasure.Text == "Local Pearson")
            {
                pEngine.Evaluate("sample.result <- LARRY.bivariate.quadrant.pearson(sample.v1, sample.v2, 1:length(sample.nb))");
                strSPQuadrants = pEngine.Evaluate("as.character(sample.result$quad)").AsCharacter().ToArray();
                if (chkScatterplot.Checked)
                {
                    adblVar1 = pEngine.Evaluate("as.numeric(sample.result$z.x)").AsNumeric().ToArray();
                    adblVar2 = pEngine.Evaluate("as.numeric(sample.result$z.y)").AsNumeric().ToArray();
                    vecCoeff = pEngine.Evaluate("lm(sample.result$z.y~sample.result$z.x)$coefficients").AsNumeric();
                }
            }

            //Save Output on SHP
            //Add Target fields to store results in the shapefile // Keep loop
            for (int j = 0; j < 1; j++)
            {
                string strfldName = lvFields.Items[j].SubItems[1].Text;
                if (m_pFClass.FindField(strfldName) == -1)
                {
                    IField     newField  = new FieldClass();
                    IFieldEdit fieldEdit = (IFieldEdit)newField;
                    fieldEdit.Name_2 = strfldName;
                    fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                    m_pFClass.AddField(newField);
                }
            }

            //Update Field
            pFCursor = m_pFClass.Update(null, false);
            pFeature = pFCursor.NextFeature();

            string strSpQuadFldName = lvFields.Items[0].SubItems[1].Text;
            int    intSpQuadFldIdx  = m_pFClass.FindField(strSpQuadFldName);

            int featureIdx = 0;

            while (pFeature != null)
            {
                pFeature.set_Value(intSpQuadFldIdx, strSPQuadrants[featureIdx]);

                pFCursor.UpdateFeature(pFeature);

                pFeature = pFCursor.NextFeature();
                featureIdx++;
            }
            pFCursor.Flush();

            if (chkMap.Checked)
            {
                ITable pTable = (ITable)m_pFClass;

                IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();
                pUniqueValueRenderer.FieldCount = 1;
                pUniqueValueRenderer.set_Field(0, strSpQuadFldName);

                if (cboMaptype.Text == "choropleth map")
                {
                    ISimpleFillSymbol pSymbol;
                    IQueryFilter      pQFilter = new QueryFilterClass();
                    int    intTotalCount       = 0;
                    string strLabel            = null;

                    for (int j = 0; j < 4; j++)
                    {
                        pSymbol       = new SimpleFillSymbolClass();
                        pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                        pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B);

                        pQFilter.WhereClause = strSpQuadFldName + " = '" + m_pQuadrantSymbols[j].Value + "'";

                        intTotalCount = pTable.RowCount(pQFilter);

                        strLabel = m_pQuadrantSymbols[j].Label + " (" + intTotalCount.ToString() + ")";
                        pUniqueValueRenderer.AddValue(m_pQuadrantSymbols[j].Value, null, (ISymbol)pSymbol);
                        pUniqueValueRenderer.set_Label(m_pQuadrantSymbols[j].Value, strLabel);
                    }
                    pUniqueValueRenderer.UseDefaultSymbol = false;
                }
                else if (cboMaptype.Text == "point map")
                {
                    ICharacterMarkerSymbol pSymbol;
                    stdole.IFontDisp       stdFontCls = ((stdole.IFontDisp)(new stdole.StdFont()));
                    stdFontCls.Name = "ESRI NIMA VMAP1&2 PT";
                    stdFontCls.Size = 10;

                    IQueryFilter pQFilter      = new QueryFilterClass();
                    int          intTotalCount = 0;
                    string       strLabel      = null;

                    for (int j = 0; j < 4; j++)
                    {
                        pSymbol = new CharacterMarkerSymbolClass();
                        pSymbol.CharacterIndex = 248;
                        //pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B);
                        pSymbol.Size = 10;
                        pSymbol.Font = stdFontCls;

                        pSymbol.Angle = m_pQuadrantSymbols[j].Angle;

                        //Create a Fill Symbol for the Mask
                        ISimpleFillSymbol smpFill = new SimpleFillSymbol();
                        smpFill.Color = m_pSnippet.getRGB(0, 0, 0);
                        smpFill.Style = esriSimpleFillStyle.esriSFSSolid;
                        //Create a MultiLayerMarkerSymbol
                        IMultiLayerMarkerSymbol multiLyrMrk = new MultiLayerMarkerSymbol();
                        //Add the simple marker to the MultiLayer
                        multiLyrMrk.AddLayer(pSymbol);
                        //Create a Mask for the MultiLayerMarkerSymbol
                        IMask mrkMask = (IMask)multiLyrMrk;
                        mrkMask.MaskSymbol = smpFill;
                        mrkMask.MaskStyle  = esriMaskStyle.esriMSHalo;
                        mrkMask.MaskSize   = 0.5;

                        pQFilter.WhereClause = strSpQuadFldName + " = '" + m_pQuadrantSymbols[j].Value + "'";

                        intTotalCount = pTable.RowCount(pQFilter);

                        strLabel = m_pQuadrantSymbols[j].Label + " (" + intTotalCount.ToString() + ")";
                        pUniqueValueRenderer.AddValue(m_pQuadrantSymbols[j].Value, null, (ISymbol)multiLyrMrk);
                        pUniqueValueRenderer.set_Label(m_pQuadrantSymbols[j].Value, strLabel);
                    }
                    pUniqueValueRenderer.UseDefaultSymbol = false;
                }
                IFeatureLayer pNewFLayer = new FeatureLayerClass();
                pNewFLayer.FeatureClass = m_pFClass;
                pNewFLayer.Name         = "Bivariate Spatial Quadrants";
                IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer;
                pGFLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
                m_pActiveView.FocusMap.AddLayer(pGFLayer);
                m_pActiveView.Refresh();
                m_pForm.axTOCControl1.Update();
            }

            if (chkScatterplot.Checked)
            {
                frmMScatterResults pfrmMScatterResult = new frmMScatterResults();
                pfrmMScatterResult.pChart.ChartAreas[0].AxisX.IsStartedFromZero = false;
                pfrmMScatterResult.pChart.ChartAreas[0].AxisX.IsMarginVisible   = true;

                pfrmMScatterResult.pChart.ChartAreas[0].AxisY.IsStartedFromZero = false;

                pfrmMScatterResult.Text = cboMeasure.Text + " Scatter Plot of " + m_pFLayer.Name;
                pfrmMScatterResult.pChart.Series.Clear();
                System.Drawing.Color pMarkerColor = System.Drawing.Color.Blue;
                var seriesPts = new System.Windows.Forms.DataVisualization.Charting.Series
                {
                    Name              = "Points",
                    Color             = pMarkerColor,
                    BorderColor       = pMarkerColor,
                    IsVisibleInLegend = false,
                    IsXValueIndexed   = false,
                    ChartType         = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point,
                    MarkerStyle       = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle
                };

                pfrmMScatterResult.pChart.Series.Add(seriesPts);

                for (int j = 0; j < adblVar1.Length; j++)
                {
                    seriesPts.Points.AddXY(adblVar1[j], adblVar2[j]);
                }

                var VLine = new System.Windows.Forms.DataVisualization.Charting.Series
                {
                    Name            = "VLine",
                    Color           = System.Drawing.Color.Black,
                    BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash,
                    //BorderColor = System.Drawing.Color.Black,
                    IsVisibleInLegend = false,
                    IsXValueIndexed   = false,
                    ChartType         = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line
                };
                pfrmMScatterResult.pChart.Series.Add(VLine);

                VLine.Points.AddXY(adblVar1.Average(), adblVar2.Min());
                VLine.Points.AddXY(adblVar1.Average(), adblVar2.Max());

                var HLine = new System.Windows.Forms.DataVisualization.Charting.Series
                {
                    Name            = "HLine",
                    Color           = System.Drawing.Color.Black,
                    BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash,
                    //BorderColor = System.Drawing.Color.Black,
                    IsVisibleInLegend = false,
                    IsXValueIndexed   = false,
                    ChartType         = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line
                };
                pfrmMScatterResult.pChart.Series.Add(HLine);

                HLine.Points.AddXY(adblVar1.Min(), adblVar2.Average());
                HLine.Points.AddXY(adblVar1.Max(), adblVar2.Average());

                var seriesLine = new System.Windows.Forms.DataVisualization.Charting.Series
                {
                    Name  = "RegLine",
                    Color = System.Drawing.Color.Red,
                    //BorderColor = System.Drawing.Color.Black,
                    IsVisibleInLegend = false,
                    IsXValueIndexed   = false,
                    ChartType         = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line
                };

                pfrmMScatterResult.pChart.Series.Add(seriesLine);

                seriesLine.Points.AddXY(adblVar1.Min(), adblVar1.Min() * vecCoeff[1] + vecCoeff[0]);
                seriesLine.Points.AddXY(adblVar1.Max(), adblVar1.Max() * vecCoeff[1] + vecCoeff[0]);

                if (cboMeasure.Text == "Local Pearson")
                {
                    pfrmMScatterResult.pChart.ChartAreas[0].AxisX.Title = "z-transformed " + cboFldnm1.Text;
                    pfrmMScatterResult.pChart.ChartAreas[0].AxisY.Title = "z-transformed " + cboFldnm2.Text;
                    pfrmMScatterResult.lblRegression.Text = string.Empty;
                }
                else
                {
                    pfrmMScatterResult.pChart.ChartAreas[0].AxisX.Title = "z-transformed SMA of " + cboFldnm1.Text;
                    pfrmMScatterResult.pChart.ChartAreas[0].AxisY.Title = "z-transformed SMA of " + cboFldnm2.Text;
                    pfrmMScatterResult.lblRegression.Text = string.Empty;
                }

                pfrmMScatterResult.m_pForm       = m_pForm;
                pfrmMScatterResult.m_pFLayer     = m_pFLayer;
                pfrmMScatterResult.m_pActiveView = m_pActiveView;
                pfrmMScatterResult.arrVar        = adblVar1;
                pfrmMScatterResult.arrFID        = arrFID;
                pfrmMScatterResult.strFIDNM      = m_pFClass.OIDFieldName;
                //pfrmMScatterResult.arrWeightVar = arrWeightVar;
                pfrmMScatterResult.pMakerColor = pMarkerColor;
                pfrmMScatterResult.strVarNM    = cboFldnm1.Text;

                pfrmMScatterResult.pChart.ChartAreas[0].AxisX.IsLabelAutoFit = false;
                pfrmMScatterResult.pChart.ChartAreas[0].AxisX.CustomLabels.Clear();
                pfrmMScatterResult.pChart.ChartAreas[0].AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None;
                //pfrmMScatterResult.pChart.ChartAreas[0].AxisX.MajorTickMark.Interval = 1;
                //pfrmMScatterResult.pChart.ChartAreas[0].AxisX.MajorTickMark.IntervalOffset = -2;

                int intMin = Convert.ToInt32(Math.Floor(adblVar1.Min()));
                int intMax = Convert.ToInt32(Math.Ceiling(adblVar1.Max()));
                for (int n = intMin; n < intMax; n++)
                {
                    System.Windows.Forms.DataVisualization.Charting.CustomLabel pcutsomLabel = new System.Windows.Forms.DataVisualization.Charting.CustomLabel();
                    pcutsomLabel.FromPosition = n - 0.5;
                    pcutsomLabel.ToPosition   = n + 0.5;
                    pcutsomLabel.Text         = n.ToString();
                    pfrmMScatterResult.pChart.ChartAreas[0].AxisX.CustomLabels.Add(pcutsomLabel);
                }

                pfrmMScatterResult.Show();
            }
            pfrmProgress.Close();
        }
		/// <summary>
		/// Initialize the symbol that would use to highlight selected items
		/// </summary>
    private void InitializeSelectionSymbol()
		{
			//use a character marker symbol:
			ICharacterMarkerSymbol chMrkSym;
			chMrkSym = new CharacterMarkerSymbolClass();
			
      //Set the selection color (yellow)
			IRgbColor color;
			color = new RgbColorClass();
			color.Red = 0;
			color.Green = 255;
			color.Blue = 255;

      //set the font
			stdole.IFont aFont;
			aFont = new stdole.StdFontClass();
			aFont.Name = "ESRI Default Marker";
      aFont.Size = m_symbolSize;
			aFont.Bold = true;			

      //char #41 is just a rectangle
			chMrkSym.CharacterIndex = 41;
			chMrkSym.Color = color as IColor;
			chMrkSym.Font = aFont as stdole.IFontDisp;
      chMrkSym.Size = m_symbolSize;
			
			m_selectionSymbol = chMrkSym as ISymbol;
		}
Пример #25
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (cboFldnm1.Text == "" || cboFldnm2.Text == "")
            {
                MessageBox.Show("Please select target field");
                return;
            }

            frmProgress pfrmProgress = new frmProgress();

            pfrmProgress.lblStatus.Text    = "Processing:";
            pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee;
            pfrmProgress.Show();

            REngine pEngine = m_pForm.pEngine;

            int nFeature = m_pFClass.FeatureCount(null);

            IFeatureCursor pFCursor = m_pFClass.Search(null, true);
            IFeature       pFeature = pFCursor.NextFeature();

            //Get index for independent and dependent variables
            //Get variable index
            string strVarNM1  = (string)cboFldnm1.SelectedItem;
            string strVarNM2  = (string)cboFldnm2.SelectedItem;
            int    intVarIdx1 = m_pFClass.FindField(strVarNM1);
            int    intVarIdx2 = m_pFClass.FindField(strVarNM2);
            int    intFIDIdx  = m_pFClass.FindField(m_pFClass.OIDFieldName);

            //Store Variable at Array
            double[] arrVar1 = new double[nFeature];
            double[] arrVar2 = new double[nFeature];

            int[] arrFID = new int[nFeature];

            int i = 0;

            while (pFeature != null)
            {
                arrVar1[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx1));
                arrVar2[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx2));
                arrFID[i]  = Convert.ToInt32(pFeature.get_Value(intFIDIdx));
                i++;
                pFeature = pFCursor.NextFeature();
            }

            pFCursor.Flush();

            //Plot command for R
            StringBuilder plotCommmand = new StringBuilder();

            string strStartPath = m_pForm.strPath;
            string pathr        = strStartPath.Replace(@"\", @"/");

            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_LARRY.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_neighbor.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_SASbi.R')");

            //Get the file path and name to create spatial weight matrix
            string strNameR = m_pSnippet.FilePathinRfromLayer(m_pFLayer);

            if (strNameR == null)
            {
                return;
            }

            //Create spatial weight matrix in R
            pEngine.Evaluate("library(spdep); library(maptools)");
            pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')");
            //pEngine.Evaluate("sample.nb <- poly2nb(sample.shp, queen=FALSE)");
            pEngine.Evaluate("sample.nb <- poly2nb(sample.shp)");

            NumericVector vecVar1 = pEngine.CreateNumericVector(arrVar1);

            pEngine.SetSymbol("sample.v1", vecVar1);
            NumericVector vecVar2 = pEngine.CreateNumericVector(arrVar2);

            pEngine.SetSymbol("sample.v2", vecVar2);

            string strNonZero = null;

            if (chkDiagZero.Checked)
            {
                strNonZero = "FALSE";
            }
            else
            {
                strNonZero = "TRUE";
            }
            string strSigLv = nudSigLv.Value.ToString();

            string[] strSPQuadrants = null;

            //double[] adblVar1 = null;
            //double[] adblVar2 = null;
            //NumericVector vecCoeff = null;
            if (cboMeasure.Text == "Lee's L")
            {
                pEngine.Evaluate("sample.result <- LARRY.bivariate.sig.quad.lee(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, style = 'W', sig.level=c(" + strSigLv + "), method='" + cboMethod.Text + "', alternative='" + txtAlternative.Text + "', diag.zero = " + strNonZero + ")");

                //pEngine.Evaluate("sample.result <- LARRY.bivariate.sig.quad.lee(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, style = 'W', sig.level=c(" + strSigLv + "), method='total', alternative='two.sided', diag.zero = " + strNonZero + ")");
                strSPQuadrants = pEngine.Evaluate("as.character(sample.result[[6]])").AsCharacter().ToArray();
            }
            else if (cboMeasure.Text == "Local Pearson")
            {
                pEngine.Evaluate("sample.result <- LARRY.bivariate.sig.quad.pearson(sample.v1, sample.v2, 1:length(sample.nb), sig.level=c(" + strSigLv + ", 0.01), method='" + cboMethod.Text + "', alternative='" + txtAlternative.Text + "')");

                //pEngine.Evaluate("sample.result <- LARRY.bivariate.sig.quad.pearson(sample.v1, sample.v2, 1:length(sample.nb), sig.level=c(" + strSigLv + "), method='total', alternative='two.sided')");
                strSPQuadrants = pEngine.Evaluate("as.character(sample.result[[6]])").AsCharacter().ToArray();
            }

            //Save Output on SHP
            //Add Target fields to store results in the shapefile // Keep loop
            for (int j = 0; j < 1; j++)
            {
                string strfldName = lvFields.Items[j].SubItems[1].Text;
                if (m_pFClass.FindField(strfldName) == -1)
                {
                    IField     newField  = new FieldClass();
                    IFieldEdit fieldEdit = (IFieldEdit)newField;
                    fieldEdit.Name_2 = strfldName;
                    fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                    m_pFClass.AddField(newField);
                }
            }

            //Update Field
            pFCursor = m_pFClass.Update(null, false);
            pFeature = pFCursor.NextFeature();

            string strSpQuadFldName = lvFields.Items[0].SubItems[1].Text;
            int    intSpQuadFldIdx  = m_pFClass.FindField(strSpQuadFldName);

            int featureIdx = 0;

            while (pFeature != null)
            {
                pFeature.set_Value(intSpQuadFldIdx, strSPQuadrants[featureIdx]);

                pFCursor.UpdateFeature(pFeature);

                pFeature = pFCursor.NextFeature();
                featureIdx++;
            }
            pFCursor.Flush();

            if (chkMap.Checked)
            {
                ITable pTable = (ITable)m_pFClass;

                IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();
                pUniqueValueRenderer.FieldCount = 1;
                pUniqueValueRenderer.set_Field(0, strSpQuadFldName);

                if (cboMaptype.Text == "choropleth map")
                {
                    ISimpleFillSymbol pSymbol;
                    IQueryFilter      pQFilter = new QueryFilterClass();
                    int    intTotalCount       = 0;
                    string strLabel            = null;

                    for (int j = 0; j < 5; j++)
                    {
                        pSymbol       = new SimpleFillSymbolClass();
                        pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                        pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B);

                        pQFilter.WhereClause = strSpQuadFldName + " = '" + m_pQuadrantSymbols[j].Value + "'";

                        intTotalCount = pTable.RowCount(pQFilter);

                        strLabel = m_pQuadrantSymbols[j].Label + " (" + intTotalCount.ToString() + ")";
                        pUniqueValueRenderer.AddValue(m_pQuadrantSymbols[j].Value, null, (ISymbol)pSymbol);
                        pUniqueValueRenderer.set_Label(m_pQuadrantSymbols[j].Value, strLabel);
                    }
                    pUniqueValueRenderer.UseDefaultSymbol = false;
                }
                else if (cboMaptype.Text == "point map")
                {
                    ICharacterMarkerSymbol pSymbol;
                    stdole.IFontDisp       stdFontCls = ((stdole.IFontDisp)(new stdole.StdFont()));
                    stdFontCls.Name = "ESRI NIMA VMAP1&2 PT";
                    stdFontCls.Size = 10;

                    IQueryFilter pQFilter      = new QueryFilterClass();
                    int          intTotalCount = 0;
                    string       strLabel      = null;

                    for (int j = 0; j < 4; j++)
                    {
                        ////Without hallo
                        //pSymbol = new CharacterMarkerSymbolClass();
                        //pSymbol.CharacterIndex = 248;
                        ////pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B);
                        //pSymbol.Size = 10;
                        //pSymbol.Font = stdFontCls;

                        //pSymbol.Angle = m_pQuadrantSymbols[j].Angle;

                        //With hallo
                        pSymbol = new CharacterMarkerSymbolClass();
                        pSymbol.CharacterIndex = 248;
                        //pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B);
                        pSymbol.Size = 10;
                        pSymbol.Font = stdFontCls;

                        pSymbol.Angle = m_pQuadrantSymbols[j].Angle;

                        //Create a Fill Symbol for the Mask
                        ISimpleFillSymbol smpFill = new SimpleFillSymbol();
                        smpFill.Color = m_pSnippet.getRGB(0, 0, 0);
                        smpFill.Style = esriSimpleFillStyle.esriSFSSolid;
                        //Create a MultiLayerMarkerSymbol
                        IMultiLayerMarkerSymbol multiLyrMrk = new MultiLayerMarkerSymbol();
                        //Add the simple marker to the MultiLayer
                        multiLyrMrk.AddLayer(pSymbol);
                        //Create a Mask for the MultiLayerMarkerSymbol
                        IMask mrkMask = (IMask)multiLyrMrk;
                        mrkMask.MaskSymbol = smpFill;
                        mrkMask.MaskStyle  = esriMaskStyle.esriMSHalo;
                        mrkMask.MaskSize   = 0.5;

///to here
                        pQFilter.WhereClause = strSpQuadFldName + " = '" + m_pQuadrantSymbols[j].Value + "'";

                        intTotalCount = pTable.RowCount(pQFilter);

                        strLabel = m_pQuadrantSymbols[j].Label + " (" + intTotalCount.ToString() + ")";
                        pUniqueValueRenderer.AddValue(m_pQuadrantSymbols[j].Value, null, (ISymbol)pSymbol);
                        pUniqueValueRenderer.set_Label(m_pQuadrantSymbols[j].Value, strLabel);
                    }
                    pUniqueValueRenderer.UseDefaultSymbol = false;
                }
                IFeatureLayer pNewFLayer = new FeatureLayerClass();
                pNewFLayer.FeatureClass = m_pFClass;
                pNewFLayer.Name         = "Bivariate Spatial Significant Quadrant";
                IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer;
                pGFLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
                m_pActiveView.FocusMap.AddLayer(pGFLayer);
                m_pActiveView.Refresh();
                m_pForm.axTOCControl1.Update();
            }
            pfrmProgress.Close();
        }
        private IUniqueValueRenderer CreateUniqueValueRenderer(IFeatureClass featureClass, string fieldName)
        {
            IRgbColor color = new RgbColorClass();

            color.Red   = 255;
            color.Blue  = 0;
            color.Green = 0;

            ICharacterMarkerSymbol charMarkersymbol = new CharacterMarkerSymbolClass();

            charMarkersymbol.Font           = Converter.ToStdFont(new Font(new FontFamily("ESRI Default Marker"), 12.0f, FontStyle.Regular));
            charMarkersymbol.CharacterIndex = 96;
            charMarkersymbol.Size           = 12.0;
            charMarkersymbol.Color          = (IColor)color;


            IRandomColorRamp randomColorRamp = new RandomColorRampClass();

            randomColorRamp.MinSaturation = 20;
            randomColorRamp.MaxSaturation = 40;
            randomColorRamp.MaxValue      = 85;
            randomColorRamp.MaxValue      = 100;
            randomColorRamp.StartHue      = 75;
            randomColorRamp.EndHue        = 190;
            randomColorRamp.UseSeed       = true;
            randomColorRamp.Seed          = 45;

            IUniqueValueRenderer uniqueRenderer = new UniqueValueRendererClass();

            uniqueRenderer.FieldCount = 1;
            uniqueRenderer.set_Field(0, fieldName);
            uniqueRenderer.DefaultSymbol    = (ISymbol)charMarkersymbol;
            uniqueRenderer.UseDefaultSymbol = true;



            Random         rand          = new Random();
            bool           bValFound     = false;
            IFeatureCursor featureCursor = featureClass.Search(null, true);
            IFeature       feature       = null;
            string         val           = string.Empty;
            int            fieldID       = featureClass.FindField(fieldName);

            if (-1 == fieldID)
            {
                return(uniqueRenderer);
            }

            while ((feature = featureCursor.NextFeature()) != null)
            {
                bValFound = false;
                val       = Convert.ToString(feature.get_Value(fieldID));
                for (int i = 0; i < uniqueRenderer.ValueCount - 1; i++)
                {
                    if (uniqueRenderer.get_Value(i) == val)
                    {
                        bValFound = true;
                    }
                }

                if (!bValFound)//need to add the value to the renderer
                {
                    color.Red   = rand.Next(255);
                    color.Blue  = rand.Next(255);
                    color.Green = rand.Next(255);

                    charMarkersymbol                = new CharacterMarkerSymbolClass();
                    charMarkersymbol.Font           = Converter.ToStdFont(new Font(new FontFamily("ESRI Default Marker"), 10.0f, FontStyle.Regular));
                    charMarkersymbol.CharacterIndex = rand.Next(40, 118);
                    charMarkersymbol.Size           = 20.0;
                    charMarkersymbol.Color          = (IColor)color;

                    //add the value to the renderer
                    uniqueRenderer.AddValue(val, "name", (ISymbol)charMarkersymbol);
                }
            }

            //release the featurecursor
            ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor);

            return(uniqueRenderer);
        }
        public override void DrawDynamicLayer(esriDynamicDrawPhase DynamicDrawPhase, IDisplay Display, IDynamicDisplay DynamicDisplay)
        {
            if (DynamicDrawPhase != esriDynamicDrawPhase.esriDDPImmediate)
            {
                return;
            }

            if (!m_bValid || !m_visible)
            {
                return;
            }

            IEnvelope visibleExtent = Display.DisplayTransformation.FittedBounds;

            if (m_bOnce)
            {
                IDynamicGlyphFactory dynamicGlyphFactory = DynamicDisplay.DynamicGlyphFactory;
                m_dynamicSymbolProps = DynamicDisplay as IDynamicSymbolProperties2;


                ICharacterMarkerSymbol markerSymbol = new CharacterMarkerSymbolClass();
                markerSymbol.Font = ESRI.ArcGIS.ADF.Connection.Local.Converter.ToStdFont(new Font("ESRI Default Marker", 25.0f, FontStyle.Bold));
                markerSymbol.Size = 25.0;
                // set the symbol color to white
                markerSymbol.Color          = (IColor)ESRI.ArcGIS.ADF.Connection.Local.Converter.ToRGBColor(Color.FromArgb(255, 255, 255));
                markerSymbol.CharacterIndex = 92;

                // create the dynamic glyph
                m_myGlyph = dynamicGlyphFactory.CreateDynamicGlyph((ISymbol)markerSymbol);


                Random r = new Random();
                double X = visibleExtent.XMin + r.NextDouble() * visibleExtent.Width;
                double Y = visibleExtent.YMin + r.NextDouble() * visibleExtent.Height;
                m_point = new PointClass();
                m_point.PutCoords(X, Y);

                m_stepX = visibleExtent.Width / 250;
                m_stepY = visibleExtent.Height / 250;

                // start the update timer
                m_updateTimer.Enabled = true;

                m_bOnce = false;
            }

            // draw the marker
            m_dynamicSymbolProps.set_DynamicGlyph(esriDynamicSymbolType.esriDSymbolMarker, m_myGlyph);
            m_dynamicSymbolProps.SetColor(esriDynamicSymbolType.esriDSymbolMarker, 1.0f, 0.0f, 0.0f, 1.0f);
            m_dynamicSymbolProps.SetScale(esriDynamicSymbolType.esriDSymbolMarker, 1.0f, 1.0f);
            DynamicDisplay.DrawMarker(m_point);

            // update the point location for the next draw cycle
            m_point.X += m_stepX;
            m_point.Y += m_stepY;

            // make sure that the point fall within the visible extent
            if (m_point.X > visibleExtent.XMax)
            {
                m_stepX = -Math.Abs(m_stepX);
            }
            if (m_point.X < visibleExtent.XMin)
            {
                m_stepX = Math.Abs(m_stepX);
            }
            if (m_point.Y > visibleExtent.YMax)
            {
                m_stepY = -Math.Abs(m_stepY);
            }
            if (m_point.Y < visibleExtent.YMin)
            {
                m_stepY = Math.Abs(m_stepY);
            }

            // set the dirty flag to false since drawing is done.
            base.m_bIsImmediateDirty = false;
        }