public void LayerRender() { try { //IFeatureLayer pFeatureLayer = featLayer; IGeoFeatureLayer pGeoFeatureLayer = featLayer as IGeoFeatureLayer; IFeatureClass pFeatureClass = featLayer.FeatureClass; //获取图层上的featureClass IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false); IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); //唯一值渲染器 //设置渲染字段对象 pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, fieldName); ISimpleFillSymbol pSimFillSymbol = new SimpleFillSymbolClass(); //创建填充符号 pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSimFillSymbol; pUniqueValueRenderer.UseDefaultSymbol = false; int n = pFeatureClass.FeatureCount(null); for (int i = 0; i < n; i++) { IFeature pFeature = pFeatureCursor.NextFeature(); IClone pSourceClone = pSimFillSymbol as IClone; ISimpleFillSymbol pSimpleFillSymbol = pSourceClone.Clone() as ISimpleFillSymbol; string pFeatureValue = pFeature.get_Value(pFeature.Fields.FindField(fieldName)).ToString(); pUniqueValueRenderer.AddValue(pFeatureValue, "", (ISymbol)pSimpleFillSymbol); } //为每个符号设置颜色 for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++) { string xv = pUniqueValueRenderer.get_Value(i); if (xv != "") { ISimpleFillSymbol pNextSymbol = (ISimpleFillSymbol)pUniqueValueRenderer.get_Symbol(xv); pNextSymbol.Color = colorRamp.get_Color(i * (colorRamp.Size / pUniqueValueRenderer.ValueCount)); pUniqueValueRenderer.set_Symbol(xv, (ISymbol)pNextSymbol); if (xv.Contains(".")) { pUniqueValueRenderer.set_Label(xv, xv.Substring(0, xv.IndexOf(".") + 4)); } else { pUniqueValueRenderer.set_Label(xv, xv); } } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); axtoccontrol.Update(); } catch (Exception e) { MessageBox.Show(e.Message); } }
private void styleGipodLyr(IGeoFeatureLayer geolayer) { IUniqueValueRenderer renderer = new UniqueValueRendererClass(); renderer.FieldCount = 1; renderer.set_Field(0, "hinder"); renderer.set_FieldType(0, false); //renderer.UseDefaultSymbol = true; renderer.DefaultLabel = "other"; ISimpleMarkerSymbol trueMarkerSymbol = new SimpleMarkerSymbolClass(); trueMarkerSymbol.Color = new RgbColorClass() { Red = 255, Blue = 0, Green = 255 }; trueMarkerSymbol.Outline = true; trueMarkerSymbol.OutlineColor = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 };; trueMarkerSymbol.Size = 5; trueMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; ISimpleMarkerSymbol falseMarkerSymbol = new SimpleMarkerSymbolClass(); falseMarkerSymbol.Color = new RgbColorClass() { Red = 255, Blue = 0, Green = 0 }; falseMarkerSymbol.Outline = true; falseMarkerSymbol.OutlineColor = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 };; falseMarkerSymbol.Size = 5; falseMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; renderer.AddValue("0", "", falseMarkerSymbol as ISymbol); renderer.set_Label("0", "Geen hinder"); renderer.AddValue("1", "", trueMarkerSymbol as ISymbol); renderer.set_Label("1", "Veel hinder"); geolayer.Renderer = renderer as IFeatureRenderer; IMxDocument mxDoc = ArcMap.Document; mxDoc.CurrentContentsView.Refresh(null); }
public IFeatureRenderer UniqueValueRenderer(IFeatureWorkspace workspace, IFeatureClass fc) { try { string tablename = ((IDataset)fc).BrowseName; ITable ipTable = workspace.OpenTable(tablename); IFeatureCursor featureCursor = fc.Search(null, false); IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Cursor = featureCursor as ICursor; dataStatistics.Field = "gridcode"; System.Collections.IEnumerator enumerator = dataStatistics.UniqueValues; enumerator.Reset(); while (enumerator.MoveNext()) { object myObject = enumerator.Current; } int uniqueValues = dataStatistics.UniqueValueCount; //Create colors for each unique value. IRandomColorRamp colorRamp = new RandomColorRampClass(); colorRamp.Size = uniqueValues; colorRamp.Seed = 100; bool createColorRamp; colorRamp.CreateRamp(out createColorRamp); if (createColorRamp == false) { return(null); } IUniqueValueRenderer uvRenderer = new UniqueValueRendererClass(); IFeatureRenderer featRenderer = (IFeatureRenderer)uvRenderer; uvRenderer.FieldCount = 1; ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); ISimpleFillSymbol fillSymbol2 = new SimpleFillSymbolClass(); ISimpleLineSymbol outlineSymbol = new SimpleLineSymbolClass(); outlineSymbol.Color = new RgbColorClass() { NullColor = true } as IColor; outlineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; if (ShowNonVisibleData == true) { fillSymbol.Color = new RgbColorClass() { Red = 255 } as IColor; fillSymbol.Outline = outlineSymbol; uvRenderer.AddValue("0", "", fillSymbol as ISymbol); uvRenderer.set_Label("0", "Non-Visible"); } fillSymbol2.Color = new RgbColorClass() { Green = 255 } as IColor; fillSymbol2.Outline = outlineSymbol; uvRenderer.AddValue("1", "", fillSymbol2 as ISymbol); uvRenderer.set_Label("1", "Visible by 1 Observer"); int field = ipTable.FindField("gridcode"); uvRenderer.set_Field(0, "gridcode"); for (int i = 2; i < uniqueValues; i++) { ISimpleFillSymbol newFillSymbol = new SimpleFillSymbolClass(); newFillSymbol.Color = colorRamp.get_Color(i); newFillSymbol.Outline = outlineSymbol; uvRenderer.AddValue(i.ToString(), "", newFillSymbol as ISymbol); string label = "Visible by " + i.ToString() + " Observers"; uvRenderer.set_Label(i.ToString(), label); } return(featRenderer); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return(null); } }
public static void DefineUniqueValueRenderer(IGeoFeatureLayer geoFealyr,string fieldName) { // Create color ramp for the symbol in rendere IRandomColorRamp randomColorRamp = new RandomColorRampClass(); randomColorRamp.MinSaturation = 20; randomColorRamp.MaxSaturation = 40; randomColorRamp.MinValue = 85; randomColorRamp.MaxValue = 100; randomColorRamp.StartHue = 76; randomColorRamp.EndHue = 188; randomColorRamp.UseSeed = true; randomColorRamp.Seed = 43; // Create a symbol ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; simpleFillSymbol.Outline.Width = 0.4; // Create the renderer IUniqueValueRenderer uniqueValueRender = new UniqueValueRendererClass(); uniqueValueRender.FieldCount = 1; uniqueValueRender.set_Field(0, fieldName); uniqueValueRender.DefaultSymbol = simpleFillSymbol as ISymbol; uniqueValueRender.UseDefaultSymbol = true; IDisplayTable displayTable = geoFealyr as IDisplayTable; IFeatureCursor feacursor = displayTable.SearchDisplayTable(null, false) as IFeatureCursor; IFeature fea = feacursor.NextFeature(); bool valfound; int fieldIndex; IFields fields = feacursor.Fields; fieldIndex = fields.FindField(fieldName); while(fea!=null) { ISimpleFillSymbol classSymbol = new SimpleFillSymbolClass(); classSymbol.Style = esriSimpleFillStyle.esriSFSSolid; classSymbol.Outline.Width = 0.4; string classValue; classValue = fea.get_Value(fieldIndex) as string; valfound = false; for(int i=0;i<=uniqueValueRender.ValueCount-1;i++) { if(uniqueValueRender.get_Value(i)==classValue) { valfound = true; break; } } if(valfound==false) { uniqueValueRender.AddValue(classValue, fieldName, classSymbol as ISymbol); uniqueValueRender.set_Label(classValue, classValue); uniqueValueRender.set_Symbol(classValue, classSymbol as ISymbol); } fea = feacursor.NextFeature(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(feacursor); randomColorRamp.Size = uniqueValueRender.ValueCount; bool bOK; randomColorRamp.CreateRamp(out bOK); IEnumColors enumColors = randomColorRamp.Colors; enumColors.Reset(); for(int j=0;j<=uniqueValueRender.ValueCount-1;j++) { string xv; xv = uniqueValueRender.get_Value(j); if(xv!="") { ISimpleFillSymbol simplefs = uniqueValueRender.get_Symbol(xv) as ISimpleFillSymbol; simplefs.Color = enumColors.Next(); uniqueValueRender.set_Symbol(xv, simplefs as ISymbol); } } uniqueValueRender.ColorScheme = "Custome"; ITable tbl = displayTable as ITable; bool isString = tbl.Fields.get_Field(fieldIndex).Type == esriFieldType.esriFieldTypeString; uniqueValueRender.set_FieldType(0, isString); geoFealyr.Renderer = uniqueValueRender as IFeatureRenderer; IUID uid = new UIDClass(); uid.Value = "{25AE5C2F-0B57-41C6-A492-31352BAD3A37}"; geoFealyr.RendererPropertyPageClassID = uid as UIDClass; }
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(); }
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 strSigLv = nudSigLv.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.cluster(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, global.sig = " + strSigLv + ", method = '" + strLSig + "', type.row.stand = '" + strRowStd + "', alternative = 'two', diag.zero = " + strNonZero + ")"); string[] strGlobal = pEngine.Evaluate("as.character(sample.result[[1]]$sig.global)").AsCharacter().ToArray(); string[] strFDR = pEngine.Evaluate("as.character(sample.result[[1]]$sig.FDR)").AsCharacter().ToArray(); string[] strSpBonf = pEngine.Evaluate("as.character(sample.result[[1]]$sig.spBonf)").AsCharacter().ToArray(); string[] strBonf = pEngine.Evaluate("as.character(sample.result[[1]]$sig.genBonf)").AsCharacter().ToArray(); string[] strQuad = pEngine.Evaluate("as.character(sample.result[[1]]$final.quad)").AsCharacter().ToArray(); string[] strSigLevels = pEngine.Evaluate("as.character(round(sample.result[[2]],6))").AsCharacter().ToArray(); //Save Output on SHP //Add Target fields to store results in the shapefile for (int j = 0; j < 5; 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); //MessageBox.Show("Same field name exists.", "Same field name", MessageBoxButtons.OK, MessageBoxIcon.Warning); //pfrmProgress.Close(); //return; } } //Update Field pFCursor = pFClass.Update(null, false); pFeature = pFCursor.NextFeature(); string strFinalQuadFldName = lvFields.Items[4].SubItems[1].Text; int intGlobalFldIdx = pFClass.FindField(lvFields.Items[0].SubItems[1].Text); int intFDRFldIdx = pFClass.FindField(lvFields.Items[1].SubItems[1].Text); int intSpatialBonfFldIdx = pFClass.FindField(lvFields.Items[2].SubItems[1].Text); int intGenBonfFldIdx = pFClass.FindField(lvFields.Items[3].SubItems[1].Text); int intFinalQuadFldIdx = pFClass.FindField(strFinalQuadFldName); int featureIdx = 0; while (pFeature != null) { pFeature.set_Value(intGlobalFldIdx, strGlobal[featureIdx]); pFeature.set_Value(intFDRFldIdx, strFDR[featureIdx]); pFeature.set_Value(intSpatialBonfFldIdx, strSpBonf[featureIdx]); pFeature.set_Value(intGenBonfFldIdx, strBonf[featureIdx]); pFeature.set_Value(intFinalQuadFldIdx, strQuad[featureIdx]); pFCursor.UpdateFeature(pFeature); pFeature = pFCursor.NextFeature(); featureIdx++; } pFCursor.Flush(); if (chkMap.Checked) { double[,] adblMinMaxForLabel = new double[2, 4]; ITable pTable = (ITable)pFClass; IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, strFinalQuadFldName); ISimpleFillSymbol pSymbol; IQueryFilter pQFilter = new QueryFilterClass(); int intTotalCount = 0; string strHeading = null; int intSigIdx = 0; for (int j = 0; j < 16; j++) { pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(m_pClusterSymbols[j].R, m_pClusterSymbols[j].G, m_pClusterSymbols[j].B); if (j % 4 == 0) { intTotalCount = 0; for (int k = 0; k < 4; k++) { pQFilter.WhereClause = strFinalQuadFldName + " = '" + m_pClusterSymbols[j + k].Value + "'"; int intCnt = pTable.RowCount(pQFilter); intTotalCount += intCnt; } intSigIdx = 3; strHeading = m_pClusterSymbols[j].Heading + " (" + intTotalCount.ToString() + ")"; pUniqueValueRenderer.AddValue(m_pClusterSymbols[j].Value, strHeading, (ISymbol)pSymbol); pUniqueValueRenderer.set_Label(m_pClusterSymbols[j].Value, m_pClusterSymbols[j].Label + "(" + strSigLevels[intSigIdx] + ")"); } else { intSigIdx--; pUniqueValueRenderer.AddValue(m_pClusterSymbols[j].Value, strHeading, (ISymbol)pSymbol); pUniqueValueRenderer.set_Label(m_pClusterSymbols[j].Value, m_pClusterSymbols[j].Label + "(" + strSigLevels[intSigIdx] + ")"); } } string strNotSig = "not sig."; pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(255, 255, 255); pQFilter.WhereClause = strFinalQuadFldName + " = '" + strNotSig + "'"; intTotalCount = pTable.RowCount(pQFilter); pUniqueValueRenderer.AddValue(strNotSig, null, (ISymbol)pSymbol); pUniqueValueRenderer.set_Label(strNotSig, "Not significant (" + intTotalCount.ToString() + ")"); pUniqueValueRenderer.UseDefaultSymbol = false; IFeatureLayer pNewFLayer = new FeatureLayerClass(); pNewFLayer.FeatureClass = pFClass; pNewFLayer.Name = "Bivariate Spatial Clusters"; 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"); } }
private IFeatureRenderer method_6(ITopology itopology_0, esriTopologyRenderer esriTopologyRenderer_0) { IUniqueValueRenderer renderer = null; IList list; IFillSymbol symbol; ILineSymbol symbol2; bool flag; IEnumColors colors; IFillSymbol symbol3; int num; ITopologyRule rule; int topologyRuleType; ILineSymbol symbol4; ISimpleMarkerSymbol symbol5; ISimpleMarkerSymbol symbol6; IRandomColorRamp ramp = new RandomColorRampClass { StartHue = 40, EndHue = 120, MinValue = 65, MaxValue = 90, MinSaturation = 25, MaxSaturation = 45, Size = 5, Seed = 23 }; switch (esriTopologyRenderer_0) { case esriTopologyRenderer.esriTRAreaErrors: renderer = new UniqueValueRendererClass(); list = this.method_4(itopology_0); symbol = new SimpleFillSymbolClass { Color = ColorManage.CreatColor(255, 128, 128) }; symbol2 = new SimpleLineSymbolClass { Width = 2.5, Color = ColorManage.CreatColor(255, 0, 0) }; symbol.Outline = symbol2; renderer.DefaultSymbol = (symbol as IClone).Clone() as ISymbol; ramp.Size = list.Count + 2; ramp.CreateRamp(out flag); colors = ramp.Colors; colors.Reset(); symbol3 = (symbol as IClone).Clone() as IFillSymbol; symbol3.Color = colors.Next(); renderer.AddValue("0", "必须大于集束容限值", symbol3 as ISymbol); renderer.set_Label("0", "必须大于集束容限值"); for (num = 0; num < list.Count; num++) { rule = list[num] as ITopologyRule; symbol3 = (symbol as IClone).Clone() as IFillSymbol; symbol3.Color = colors.Next(); topologyRuleType = (int)rule.TopologyRuleType; renderer.AddValue(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType), symbol3 as ISymbol); renderer.set_Label(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType)); } break; case esriTopologyRenderer.esriTRLineErrors: renderer = new UniqueValueRendererClass(); list = this.method_3(itopology_0); symbol2 = new SimpleLineSymbolClass { Width = 2.5, Color = ColorManage.CreatColor(255, 128, 128) }; renderer.DefaultSymbol = (symbol2 as IClone).Clone() as ISymbol; ramp.Size = list.Count + 2; ramp.CreateRamp(out flag); colors = ramp.Colors; colors.Reset(); symbol4 = (symbol2 as IClone).Clone() as ILineSymbol; symbol4.Color = colors.Next(); renderer.AddValue("0", "必须大于集束容限值", symbol4 as ISymbol); renderer.set_Label("0", "必须大于集束容限值"); for (num = 0; num < list.Count; num++) { rule = list[num] as ITopologyRule; symbol4 = (symbol2 as IClone).Clone() as ILineSymbol; symbol4.Color = colors.Next(); topologyRuleType = (int)rule.TopologyRuleType; renderer.AddValue(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType), symbol4 as ISymbol); renderer.set_Label(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType)); } break; case esriTopologyRenderer.esriTRPointErrors: renderer = new UniqueValueRendererClass(); list = this.method_2(itopology_0); symbol5 = new SimpleMarkerSymbolClass { Size = 6.0, Style = esriSimpleMarkerStyle.esriSMSSquare, Color = ColorManage.CreatColor(255, 128, 128) }; renderer.DefaultSymbol = (symbol5 as IClone).Clone() as ISymbol; if (list.Count > 0) { ramp.Size = list.Count + 1; ramp.CreateRamp(out flag); colors = ramp.Colors; colors.Reset(); symbol6 = null; for (num = 0; num < list.Count; num++) { rule = list[num] as ITopologyRule; symbol6 = (symbol5 as IClone).Clone() as ISimpleMarkerSymbol; symbol6.Color = colors.Next(); topologyRuleType = (int)rule.TopologyRuleType; renderer.AddValue(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType), symbol6 as ISymbol); renderer.set_Label(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType)); } } break; case esriTopologyRenderer.esriTRAreaExceptions: renderer = new UniqueValueRendererClass(); list = this.method_4(itopology_0); symbol = new SimpleFillSymbolClass { Color = ColorManage.CreatColor(255, 255, 255) }; symbol2 = new SimpleLineSymbolClass { Width = 1.0, Color = ColorManage.CreatColor(128, 255, 128) }; symbol.Outline = symbol2; renderer.DefaultSymbol = (symbol as IClone).Clone() as ISymbol; ramp.Size = list.Count + 2; ramp.CreateRamp(out flag); colors = ramp.Colors; colors.Reset(); symbol3 = (symbol as IClone).Clone() as IFillSymbol; symbol3.Color = colors.Next(); renderer.AddValue("0", "必须大于集束容限值", symbol3 as ISymbol); renderer.set_Label("0", "必须大于集束容限值"); for (num = 0; num < list.Count; num++) { rule = list[num] as ITopologyRule; symbol3 = (symbol as IClone).Clone() as IFillSymbol; symbol3.Color = colors.Next(); topologyRuleType = (int)rule.TopologyRuleType; renderer.AddValue(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType), symbol3 as ISymbol); renderer.set_Label(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType)); } break; case esriTopologyRenderer.esriTRLineExceptions: renderer = new UniqueValueRendererClass(); list = this.method_3(itopology_0); symbol2 = new SimpleLineSymbolClass { Width = 1.0, Color = ColorManage.CreatColor(128, 255, 128) }; renderer.DefaultSymbol = (symbol2 as IClone).Clone() as ISymbol; ramp.Size = list.Count + 2; ramp.CreateRamp(out flag); colors = ramp.Colors; colors.Reset(); symbol4 = (symbol2 as IClone).Clone() as ILineSymbol; symbol4.Color = colors.Next(); renderer.AddValue("0", "必须大于集束容限值", symbol4 as ISymbol); renderer.set_Label("0", "必须大于集束容限值"); for (num = 0; num < list.Count; num++) { rule = list[num] as ITopologyRule; symbol4 = (symbol2 as IClone).Clone() as ILineSymbol; symbol4.Color = colors.Next(); topologyRuleType = (int)rule.TopologyRuleType; renderer.AddValue(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType), symbol4 as ISymbol); renderer.set_Label(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType)); } break; case esriTopologyRenderer.esriTRPointExceptions: renderer = new UniqueValueRendererClass(); list = this.method_2(itopology_0); symbol5 = new SimpleMarkerSymbolClass { Size = 5.0, Style = esriSimpleMarkerStyle.esriSMSSquare, Color = ColorManage.CreatColor(128, 255, 128) }; renderer.DefaultSymbol = (symbol5 as IClone).Clone() as ISymbol; if (list.Count > 0) { ramp.Size = list.Count + 1; ramp.CreateRamp(out flag); colors = ramp.Colors; colors.Reset(); symbol6 = null; for (num = 0; num < list.Count; num++) { rule = list[num] as ITopologyRule; symbol6 = (symbol5 as IClone).Clone() as ISimpleMarkerSymbol; symbol6.Color = colors.Next(); topologyRuleType = (int)rule.TopologyRuleType; renderer.AddValue(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType), symbol6 as ISymbol); renderer.set_Label(topologyRuleType.ToString(), this.method_5(rule.TopologyRuleType)); } } break; } return(renderer as IFeatureRenderer); }
//added by chulili //函数功能:根据xml配置文件为图层设置符号(xml配置文件暂时采用指定全路径) //输入参数:图层 日志文件 输出参数:无 public static void SetRenderByXML(ILayer pLayer, LogFile Log) { string serverstylename; //符号库名称 XmlDocument xmldoc = new XmlDocument(); string strCurFile = Application.StartupPath + "\\..\\Template\\Render.xml"; //查找配置文件中关于该图层信息 string strSearchExp = "//GisLayer [@ItemName='" + pLayer.Name + "']"; XmlNode xmlRenderNode; if (File.Exists(strCurFile) == false) { if (Log != null) { Log.Writelog("符号配置文件不存在"); } return; } if (Log != null) { Log.Writelog("加载符号配置文件"); } //读取xml配置文件 xmldoc.Load(strCurFile); xmlRenderNode = xmldoc.SelectSingleNode(strSearchExp); if (xmlRenderNode == null) { if (Log != null) { Log.Writelog("符号配置文件中不存在图层节点"); } return; } if (Log != null) { Log.Writelog("读取符号配置文件信息"); } XmlElement xmlElent = (XmlElement)xmlRenderNode; string strStyle, ColName, defaultname, defaultLab; //读取图层节点属性值 strStyle = xmlElent.GetAttribute("sTyle"); ColName = xmlElent.GetAttribute("ColName"); //符号化依据的字段名称 defaultname = xmlElent.GetAttribute("DefaultSymbol"); //默认符号 defaultLab = xmlElent.GetAttribute("DefaultLabel"); //默认符号的标签 IFeatureLayer pFLayer = pLayer as IFeatureLayer; IFeatureClass fcls = pFLayer.FeatureClass; IUniqueValueRenderer ptmpRender; ptmpRender = new UniqueValueRendererClass(); //固定按照一个字段进行符号化,设置符号化字段 ptmpRender.FieldCount = 1; ptmpRender.set_Field(0, ColName); ptmpRender.RemoveAllValues(); //读取符号库(暂时使用固定的符号库,以后应该可配置) string stylefileFullname = Application.StartupPath + @"\..\Styles\testStyle.ServerStyle"; string colvalue, symbolname, labelname; if (Log != null) { Log.Writelog("读取符号库,为图层设置符号"); } foreach (XmlNode xmlchild in xmlRenderNode.ChildNodes)//根据xml构造每个symbol { if (xmlchild.NodeType.ToString().Equals("Element")) { //读取符号节点的属性 xmlElent = (XmlElement)xmlchild; colvalue = xmlElent.GetAttribute("ColValue"); //字段值 symbolname = xmlElent.GetAttribute("Symbol"); //符号名 labelname = xmlElent.GetAttribute("Label"); //符号标签 //根据符号库全路径,符号类别,符号名获取符号 ISymbol pSymbol = GetSymbol(stylefileFullname, strStyle, symbolname); //添加符号 ptmpRender.AddValue(colvalue, "", pSymbol); //设置符号标签 ptmpRender.set_Label(colvalue, labelname); } } //设置默认符号(即地物的字段值不满足其他渲染条件的情况下,地物采用的符号) ISymbol pDefaultSym = GetSymbol(stylefileFullname, strStyle, defaultname); ptmpRender.DefaultSymbol = pDefaultSym; ptmpRender.DefaultLabel = defaultLab; if (ptmpRender.DefaultSymbol != null) { ptmpRender.UseDefaultSymbol = true; } (pFLayer as IGeoFeatureLayer).Renderer = ptmpRender as IFeatureRenderer; if (Log != null) { Log.Writelog("图层符号配置完成"); } }
private void btnRun_Click(object sender, EventArgs e) { try { //Checking if (cboFieldName.Text == "") { MessageBox.Show("Please select target field"); return; } frmProgress pfrmProgress = new frmProgress(); pfrmProgress.lblStatus.Text = "Processing:"; pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee; pfrmProgress.Show(); int nFeature = m_pFClass.FeatureCount(null); IFeatureCursor pFCursor = m_pFLayer.Search(null, true); IFeature pFeature = pFCursor.NextFeature(); //Get index for independent and dependent variables //Get variable index string strVarNM = (string)cboFieldName.SelectedItem; int intVarIdx = m_pFClass.FindField(strVarNM); //Store Variable at Array double[] arrVar = new double[nFeature]; int i = 0; while (pFeature != null) { arrVar[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx)); i++; pFeature = pFCursor.NextFeature(); } //Plot command for R StringBuilder plotCommmand = new StringBuilder(); if (!m_blnCreateSWM) { //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 if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPolygon) { m_pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')"); } else if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPoint) { m_pEngine.Evaluate("sample.shp <- readShapePoints('" + strNameR + "')"); } else { MessageBox.Show("This geometry type is not supported"); pfrmProgress.Close(); this.Close(); } int intSuccess = m_pSnippet.CreateSpatialWeightMatrix(m_pEngine, m_pFClass, txtSWM.Text, pfrmProgress); if (intSuccess == 0) { return; } } NumericVector vecVar = m_pEngine.CreateNumericVector(arrVar); m_pEngine.SetSymbol(strVarNM, vecVar); if (cboSAM.Text == "Local Moran") { #region Local Moran plotCommmand.Append("localmoran(" + strVarNM + ", sample.listw, alternative = 'two.sided', "); //select multiple correction method (only Bonferroni.. 100915 HK) if (cboAdjustment.Text == "None") { plotCommmand.Append(", zero.policy=TRUE)"); } else if (cboAdjustment.Text == "Bonferroni correction") { plotCommmand.Append("p.adjust.method='bonferroni', zero.policy=TRUE)"); } NumericMatrix nmResults = m_pEngine.Evaluate(plotCommmand.ToString()).AsNumericMatrix(); string strFlgFldNam = lvFields.Items[3].SubItems[1].Text; //Save Output on SHP //Add Target fields to store results in the shapefile for (int j = 0; j < 4; j++) { IField newField = new FieldClass(); IFieldEdit fieldEdit = (IFieldEdit)newField; fieldEdit.Name_2 = lvFields.Items[j].SubItems[1].Text; if (j == 3) { fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; } else { fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; } m_pFClass.AddField(newField); } //Update Field pFCursor = m_pFClass.Update(null, false); pFeature = pFCursor.NextFeature(); int intStatFldIdx = m_pFClass.FindField(lvFields.Items[0].SubItems[1].Text); int intZFldIdx = m_pFClass.FindField(lvFields.Items[1].SubItems[1].Text); int intPrFldIdx = m_pFClass.FindField(lvFields.Items[2].SubItems[1].Text); int intFlgFldIdx = m_pFClass.FindField(strFlgFldNam); double dblValue = 0, dblPvalue = 0, dblZvalue = 0; double dblValueMean = arrVar.Average(); double dblPrCri = Convert.ToDouble(nudConfLevel.Value); int featureIdx = 0; while (pFeature != null) { dblValue = arrVar[featureIdx] - dblValueMean; dblZvalue = nmResults[featureIdx, 3]; dblPvalue = nmResults[featureIdx, 4]; pFeature.set_Value(intStatFldIdx, (object)nmResults[featureIdx, 0]); pFeature.set_Value(intZFldIdx, dblZvalue); pFeature.set_Value(intPrFldIdx, dblPvalue); if (dblPvalue < dblPrCri) { if (dblZvalue > 0) { if (dblValue > 0) { pFeature.set_Value(intFlgFldIdx, "HH"); } else { pFeature.set_Value(intFlgFldIdx, "LL"); } } else { if (dblValue > 0) { pFeature.set_Value(intFlgFldIdx, "HL"); } else { pFeature.set_Value(intFlgFldIdx, "LH"); } } } //else // pFeature.set_Value(intFlgFldIdx, ""); pFCursor.UpdateFeature(pFeature); pFeature = pFCursor.NextFeature(); featureIdx++; } pfrmProgress.Close(); if (chkMap.Checked) { double[,] adblMinMaxForLabel = new double[2, 4]; ITable pTable = (ITable)m_pFClass; IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, strFlgFldNam); IDataStatistics pDataStat; IStatisticsResults pStatResults; ICursor pCursor; if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPolygon) { ISimpleFillSymbol pSymbol; IQueryFilter pQFilter = new QueryFilterClass(); pQFilter.WhereClause = strFlgFldNam + " = 'HH'"; int intCnt = pTable.RowCount(pQFilter); pCursor = pTable.Search(pQFilter, true); pDataStat = new DataStatisticsClass(); pDataStat.Field = lvFields.Items[1].SubItems[1].Text; pDataStat.Cursor = pCursor; pStatResults = pDataStat.Statistics; adblMinMaxForLabel[0, 0] = pStatResults.Minimum; adblMinMaxForLabel[1, 0] = pStatResults.Maximum; pCursor.Flush(); pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(255, 80, 80); pUniqueValueRenderer.AddValue("HH", null, (ISymbol)pSymbol); if (intCnt == 1) { pUniqueValueRenderer.set_Label("HH", "HH (" + adblMinMaxForLabel[0, 0].ToString("N1") + ")"); } else if (intCnt == 0) { pUniqueValueRenderer.set_Label("HH", "HH (no obs)"); } else { pUniqueValueRenderer.set_Label("HH", "HH (" + adblMinMaxForLabel[0, 0].ToString("N1") + "-" + adblMinMaxForLabel[1, 0].ToString("N1") + ")"); } pQFilter.WhereClause = strFlgFldNam + " = 'LL'"; intCnt = pTable.RowCount(pQFilter); pCursor = pTable.Search(pQFilter, true); pDataStat = new DataStatisticsClass(); pDataStat.Field = lvFields.Items[1].SubItems[1].Text; pDataStat.Cursor = pCursor; pStatResults = pDataStat.Statistics; adblMinMaxForLabel[0, 1] = pStatResults.Minimum; adblMinMaxForLabel[1, 1] = pStatResults.Maximum; pCursor.Flush(); pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(50, 157, 194); pUniqueValueRenderer.AddValue("LL", null, (ISymbol)pSymbol); if (intCnt == 1) { pUniqueValueRenderer.set_Label("LL", "LL (" + adblMinMaxForLabel[0, 1].ToString("N1") + ")"); } else if (intCnt == 0) { pUniqueValueRenderer.set_Label("LL", "LL (no obs)"); } else { pUniqueValueRenderer.set_Label("LL", "LL (" + adblMinMaxForLabel[0, 1].ToString("N1") + "-" + adblMinMaxForLabel[1, 1].ToString("N1") + ")"); } pQFilter.WhereClause = strFlgFldNam + " = 'HL'"; intCnt = pTable.RowCount(pQFilter); pCursor = pTable.Search(pQFilter, true); pDataStat = new DataStatisticsClass(); pDataStat.Field = lvFields.Items[1].SubItems[1].Text; pDataStat.Cursor = pCursor; pStatResults = pDataStat.Statistics; adblMinMaxForLabel[0, 2] = pStatResults.Minimum; adblMinMaxForLabel[1, 2] = pStatResults.Maximum; pCursor.Flush(); pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(244, 199, 0); pUniqueValueRenderer.AddValue("HL", null, (ISymbol)pSymbol); if (intCnt == 1) { pUniqueValueRenderer.set_Label("HL", "HL (" + adblMinMaxForLabel[0, 2].ToString("N1") + ")"); } else if (intCnt == 0) { pUniqueValueRenderer.set_Label("HL", "HL (no obs)"); } else { pUniqueValueRenderer.set_Label("HL", "HL (" + adblMinMaxForLabel[0, 2].ToString("N1") + "-" + adblMinMaxForLabel[1, 2].ToString("N1") + ")"); } pQFilter.WhereClause = strFlgFldNam + " = 'LH'"; intCnt = pTable.RowCount(pQFilter); pCursor = pTable.Search(pQFilter, true); pDataStat = new DataStatisticsClass(); pDataStat.Field = lvFields.Items[1].SubItems[1].Text; pDataStat.Cursor = pCursor; pStatResults = pDataStat.Statistics; adblMinMaxForLabel[0, 3] = pStatResults.Minimum; adblMinMaxForLabel[1, 3] = pStatResults.Maximum; pCursor.Flush(); pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(173, 255, 179); pUniqueValueRenderer.AddValue("LH", null, (ISymbol)pSymbol); if (intCnt == 1) { pUniqueValueRenderer.set_Label("LH", "LH (" + adblMinMaxForLabel[0, 3].ToString("N1") + ")"); } else if (intCnt == 0) { pUniqueValueRenderer.set_Label("LH", "LH (no obs)"); } else { pUniqueValueRenderer.set_Label("LH", "LH (" + adblMinMaxForLabel[0, 3].ToString("N1") + "-" + adblMinMaxForLabel[1, 3].ToString("N1") + ")"); } pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(200, 200, 200); //pUniqueValueRenderer.AddValue("", strFlgFldNam, (ISymbol)pSymbol); //pUniqueValueRenderer.set_Label("", "Not significant"); pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSymbol; pUniqueValueRenderer.DefaultLabel = "Not significant"; pUniqueValueRenderer.UseDefaultSymbol = true; } else if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPoint) { ISimpleMarkerSymbol pSymbol; IQueryFilter pQFilter = new QueryFilterClass(); pQFilter.WhereClause = strFlgFldNam + " = 'HH'"; int intCnt = pTable.RowCount(pQFilter); pCursor = pTable.Search(pQFilter, true); pDataStat = new DataStatisticsClass(); pDataStat.Field = lvFields.Items[1].SubItems[1].Text; pDataStat.Cursor = pCursor; pStatResults = pDataStat.Statistics; adblMinMaxForLabel[0, 0] = pStatResults.Minimum; adblMinMaxForLabel[1, 0] = pStatResults.Maximum; pCursor.Flush(); pSymbol = new SimpleMarkerSymbolClass(); pSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pSymbol.Color = m_pSnippet.getRGB(255, 80, 80); pUniqueValueRenderer.AddValue("HH", null, (ISymbol)pSymbol); if (intCnt == 1) { pUniqueValueRenderer.set_Label("HH", "HH (" + adblMinMaxForLabel[0, 0].ToString("N1") + ")"); } else if (intCnt == 0) { pUniqueValueRenderer.set_Label("HH", "HH (no obs)"); } else { pUniqueValueRenderer.set_Label("HH", "HH (" + adblMinMaxForLabel[0, 0].ToString("N1") + "-" + adblMinMaxForLabel[1, 0].ToString("N1") + ")"); } pQFilter.WhereClause = strFlgFldNam + " = 'LL'"; intCnt = pTable.RowCount(pQFilter); pCursor = pTable.Search(pQFilter, true); pDataStat = new DataStatisticsClass(); pDataStat.Field = lvFields.Items[1].SubItems[1].Text; pDataStat.Cursor = pCursor; pStatResults = pDataStat.Statistics; adblMinMaxForLabel[0, 1] = pStatResults.Minimum; adblMinMaxForLabel[1, 1] = pStatResults.Maximum; pCursor.Flush(); pSymbol = new SimpleMarkerSymbolClass(); pSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pSymbol.Color = m_pSnippet.getRGB(50, 157, 194); pUniqueValueRenderer.AddValue("LL", null, (ISymbol)pSymbol); if (intCnt == 1) { pUniqueValueRenderer.set_Label("LL", "LL (" + adblMinMaxForLabel[0, 1].ToString("N1") + ")"); } else if (intCnt == 0) { pUniqueValueRenderer.set_Label("LL", "LL (no obs)"); } else { pUniqueValueRenderer.set_Label("LL", "LL (" + adblMinMaxForLabel[0, 1].ToString("N1") + "-" + adblMinMaxForLabel[1, 1].ToString("N1") + ")"); } pQFilter.WhereClause = strFlgFldNam + " = 'HL'"; intCnt = pTable.RowCount(pQFilter); pCursor = pTable.Search(pQFilter, true); pDataStat = new DataStatisticsClass(); pDataStat.Field = lvFields.Items[1].SubItems[1].Text; pDataStat.Cursor = pCursor; pStatResults = pDataStat.Statistics; adblMinMaxForLabel[0, 2] = pStatResults.Minimum; adblMinMaxForLabel[1, 2] = pStatResults.Maximum; pCursor.Flush(); pSymbol = new SimpleMarkerSymbolClass(); pSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pSymbol.Color = m_pSnippet.getRGB(244, 199, 0); pUniqueValueRenderer.AddValue("HL", null, (ISymbol)pSymbol); if (intCnt == 1) { pUniqueValueRenderer.set_Label("HL", "HL (" + adblMinMaxForLabel[0, 2].ToString("N1") + ")"); } else if (intCnt == 0) { pUniqueValueRenderer.set_Label("HL", "HL (no obs)"); } else { pUniqueValueRenderer.set_Label("HL", "HL (" + adblMinMaxForLabel[0, 2].ToString("N1") + "-" + adblMinMaxForLabel[1, 2].ToString("N1") + ")"); } pQFilter.WhereClause = strFlgFldNam + " = 'LH'"; intCnt = pTable.RowCount(pQFilter); pCursor = pTable.Search(pQFilter, true); pDataStat = new DataStatisticsClass(); pDataStat.Field = lvFields.Items[1].SubItems[1].Text; pDataStat.Cursor = pCursor; pStatResults = pDataStat.Statistics; adblMinMaxForLabel[0, 3] = pStatResults.Minimum; adblMinMaxForLabel[1, 3] = pStatResults.Maximum; pCursor.Flush(); pSymbol = new SimpleMarkerSymbolClass(); pSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pSymbol.Color = m_pSnippet.getRGB(173, 255, 179); pUniqueValueRenderer.AddValue("LH", null, (ISymbol)pSymbol); if (intCnt == 1) { pUniqueValueRenderer.set_Label("LH", "LH (" + adblMinMaxForLabel[0, 3].ToString("N1") + ")"); } else if (intCnt == 0) { pUniqueValueRenderer.set_Label("LH", "LH (no obs)"); } else { pUniqueValueRenderer.set_Label("LH", "LH (" + adblMinMaxForLabel[0, 3].ToString("N1") + "-" + adblMinMaxForLabel[1, 3].ToString("N1") + ")"); } pSymbol = new SimpleMarkerSymbolClass(); pSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pSymbol.Color = m_pSnippet.getRGB(200, 200, 200); //pUniqueValueRenderer.AddValue("", strFlgFldNam, (ISymbol)pSymbol); //pUniqueValueRenderer.set_Label("", "Not significant"); pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSymbol; pUniqueValueRenderer.DefaultLabel = "Not significant"; pUniqueValueRenderer.UseDefaultSymbol = true; } IFeatureLayer pNewFLayer = new FeatureLayerClass(); pNewFLayer.FeatureClass = m_pFClass; pNewFLayer.Name = cboSAM.Text + " of " + m_pFLayer.Name; IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer; pGFLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; m_pActiveView.FocusMap.AddLayer(pGFLayer); m_pActiveView.Refresh(); m_pForm.axTOCControl1.Update(); } else { MessageBox.Show("Complete. The results are stored in the shape file"); } #endregion } else if (cboSAM.Text == "Gi*") { #region Gi* m_pEngine.Evaluate("sample.lg <- localG(" + strVarNM + ", sample.listw, zero.policy=TRUE)"); m_pEngine.Evaluate("sample.p <- 2*pnorm(-abs(sample.lg))"); if (cboAdjustment.Text == "Bonferroni correction") { m_pEngine.Evaluate("sample.p <- p.adjust(sample.p, method = 'bonferroni', n = length(sample.p))"); } double[] dblGValues = m_pEngine.Evaluate("sample.lg").AsNumeric().ToArray(); double[] dblPvalues = m_pEngine.Evaluate("sample.p").AsNumeric().ToArray(); //Save Output on SHP //Add Target fields to store results in the shapefile for (int j = 0; j < 2; j++) { IField newField = new FieldClass(); IFieldEdit fieldEdit = (IFieldEdit)newField; fieldEdit.Name_2 = lvFields.Items[j].SubItems[1].Text; fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; m_pFClass.AddField(newField); } //Update Field pFCursor = m_pFClass.Update(null, false); pFeature = pFCursor.NextFeature(); int intStatFldIdx = m_pFClass.FindField(lvFields.Items[0].SubItems[1].Text); int intPrFldIdx = m_pFClass.FindField(lvFields.Items[1].SubItems[1].Text); int featureIdx = 0; while (pFeature != null) { pFeature.set_Value(intStatFldIdx, dblGValues[featureIdx]); pFeature.set_Value(intPrFldIdx, dblPvalues[featureIdx]); pFCursor.UpdateFeature(pFeature); pFeature = pFCursor.NextFeature(); featureIdx++; } pFCursor.Flush(); pfrmProgress.Close(); if (chkMap.Checked) { string strStaticFldName = lvFields.Items[0].SubItems[1].Text; m_pEngine.Evaluate("p.vals <- c(0.1, 0.05, 0.01)"); if (cboAdjustment.Text == "Bonferroni correction") { m_pEngine.Evaluate("sample.n <- length(sample.p)"); m_pEngine.Evaluate("p.vals <- p.vals/sample.n"); } m_pEngine.Evaluate("zc <- qnorm(1 - (p.vals/2))"); double[] dblZBrks = m_pEngine.Evaluate("sort(cbind(zc, -zc))").AsNumeric().ToArray(); pFCursor = m_pFClass.Search(null, false); IDataStatistics pDataStat = new DataStatisticsClass(); pDataStat.Field = strStaticFldName; pDataStat.Cursor = (ICursor)pFCursor; IStatisticsResults pStatResults = pDataStat.Statistics; double dblMax = pStatResults.Maximum; double dblMin = pStatResults.Minimum; int intBreaksCount = dblZBrks.Length + 2; double[] cb = new double[intBreaksCount]; //Assign Min and Max values for class breaks if (dblMin < dblZBrks[0]) { cb[0] = dblMin; } else { cb[0] = dblZBrks[0] - 1; //Manually Assigned minimum value } if (dblMax > dblZBrks[dblZBrks.Length - 1]) { cb[intBreaksCount - 1] = dblMax; } else { cb[intBreaksCount - 1] = dblZBrks[dblZBrks.Length - 1] + 1;//Manually Assigned minimum value } for (int k = 0; k < intBreaksCount - 2; k++) { cb[k + 1] = dblZBrks[k]; } IClassBreaksRenderer pCBRenderer = new ClassBreaksRenderer(); pCBRenderer.Field = strStaticFldName; pCBRenderer.BreakCount = intBreaksCount - 1; pCBRenderer.MinimumBreak = cb[0]; //' use this interface to set dialog properties IClassBreaksUIProperties pUIProperties = (IClassBreaksUIProperties)pCBRenderer; pUIProperties.ColorRamp = "Custom"; if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPolygon) { ISimpleFillSymbol pSimpleFillSym; int[,] arrColors = CreateColorRamp(); //Add Probability Value Manually string[] strsProbLabels = new string[] { "(0.01)", "(0.05)", "(0.1)", "(0.1)", "(0.05)", "(0.01)" }; //' be careful, indices are different for the diff lists for (int j = 0; j < intBreaksCount - 1; j++) { pCBRenderer.Break[j] = cb[j + 1]; if (j == 0) { pCBRenderer.Label[j] = " <= " + Math.Round(cb[j + 1], 2).ToString() + strsProbLabels[j]; } else if (j == intBreaksCount - 2) { pCBRenderer.Label[j] = " > " + Math.Round(cb[j], 2).ToString() + strsProbLabels[j - 1]; } else { pCBRenderer.Label[j] = Math.Round(cb[j], 2).ToString() + strsProbLabels[j - 1] + " ~ " + Math.Round(cb[j + 1], 2).ToString() + strsProbLabels[j]; } pUIProperties.LowBreak[j] = cb[j]; pSimpleFillSym = new SimpleFillSymbolClass(); IRgbColor pRGBColor = m_pSnippet.getRGB(arrColors[j, 0], arrColors[j, 1], arrColors[j, 2]); pSimpleFillSym.Color = (IColor)pRGBColor; pCBRenderer.Symbol[j] = (ISymbol)pSimpleFillSym; } } else if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPoint) { ISimpleMarkerSymbol pSimpleMarkerSym; int[,] arrColors = CreateColorRamp(); //Add Probability Value Manually string[] strsProbLabels = new string[] { "(0.01)", "(0.05)", "(0.1)", "(0.1)", "(0.05)", "(0.01)" }; //' be careful, indices are different for the diff lists for (int j = 0; j < intBreaksCount - 1; j++) { pCBRenderer.Break[j] = cb[j + 1]; if (j == 0) { pCBRenderer.Label[j] = " <= " + Math.Round(cb[j + 1], 2).ToString() + strsProbLabels[j]; } else if (j == intBreaksCount - 2) { pCBRenderer.Label[j] = " > " + Math.Round(cb[j], 2).ToString() + strsProbLabels[j - 1]; } else { pCBRenderer.Label[j] = Math.Round(cb[j], 2).ToString() + strsProbLabels[j - 1] + " ~ " + Math.Round(cb[j + 1], 2).ToString() + strsProbLabels[j]; } pUIProperties.LowBreak[j] = cb[j]; pSimpleMarkerSym = new SimpleMarkerSymbolClass(); IRgbColor pRGBColor = m_pSnippet.getRGB(arrColors[j, 0], arrColors[j, 1], arrColors[j, 2]); pSimpleMarkerSym.Color = (IColor)pRGBColor; pCBRenderer.Symbol[j] = (ISymbol)pSimpleMarkerSym; } } IFeatureLayer pNewFLayer = new FeatureLayerClass(); pNewFLayer.FeatureClass = m_pFClass; pNewFLayer.Name = cboSAM.Text + " of " + m_pFLayer.Name; IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer; pGFLayer.Renderer = (IFeatureRenderer)pCBRenderer; m_pActiveView.FocusMap.AddLayer(pGFLayer); m_pActiveView.Refresh(); m_pForm.axTOCControl1.Update(); } else { MessageBox.Show("Complete. The results are stored in the shape file"); } #endregion } this.Close(); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
/// <summary> /// 按聚类号对凸包进行渲染 /// </summary> /// <param name="pGeoFeatureLayer"></param> /// <param name="fieldName"></param> public void DefinePolygonUniqueValueRenderer(IGeoFeatureLayer pGeoFeatureLayer, string fieldName) { IRandomColorRamp pRandomColorRamp = new RandomColorRampClass(); //Create the color ramp for the symbols in the renderer. pRandomColorRamp.MinSaturation = 20; pRandomColorRamp.MaxSaturation = 40; pRandomColorRamp.MinValue = 85; pRandomColorRamp.MaxValue = 100; pRandomColorRamp.StartHue = 76; pRandomColorRamp.EndHue = 188; pRandomColorRamp.UseSeed = true; pRandomColorRamp.Seed = 43; //Create the renderer. IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleFillSymbol.Outline.Width = 0.4; /* ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); * pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; * pSimpleMarkerSymbol.Size = 5; * pSimpleMarkerSymbol.Outline = true; * IRgbColor pLineRgbColor = new RgbColorClass(); * pLineRgbColor.Red = 0; * pLineRgbColor.Green = 0; * pLineRgbColor.Blue = 0; * pSimpleMarkerSymbol.OutlineColor = pLineRgbColor as IColor; */ //These properties should be set prior to adding values. pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, fieldName); pUniqueValueRenderer.DefaultSymbol = pSimpleFillSymbol as ISymbol; pUniqueValueRenderer.UseDefaultSymbol = true; IDisplayTable pDisplayTable = pGeoFeatureLayer as IDisplayTable; IFeatureCursor pFeatureCursor = pDisplayTable.SearchDisplayTable(null, false) as IFeatureCursor; IFeature pFeature = pFeatureCursor.NextFeature(); bool ValFound; int fieldIndex; IFields pFields = pFeatureCursor.Fields; fieldIndex = pFields.FindField(fieldName); while (pFeature != null) { ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass(); pClassSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassSymbol.Outline.Width = 0.4; /* ISimpleMarkerSymbol pClassSymbol = new SimpleMarkerSymbolClass(); * pClassSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; * pClassSymbol.Size = 5; * pClassSymbol.Outline = true; * pClassSymbol.OutlineColor = pLineRgbColor as IColor; */ string classValue; classValue = pFeature.get_Value(fieldIndex).ToString(); //Test to see if this value was added to the renderer. If not, add it. ValFound = false; for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++) { if (pUniqueValueRenderer.get_Value(i) == classValue) { ValFound = true; break; //Exit the loop if the value was found. } } //If the value was not found, it's new and will be added. if (ValFound == false) { pUniqueValueRenderer.AddValue(classValue, fieldName, pClassSymbol as ISymbol); pUniqueValueRenderer.set_Label(classValue, classValue); pUniqueValueRenderer.set_Symbol(classValue, pClassSymbol as ISymbol); } pFeature = pFeatureCursor.NextFeature(); } //Since the number of unique values is known, the color ramp can be sized and the colors assigned. pRandomColorRamp.Size = pUniqueValueRenderer.ValueCount; bool bOK; pRandomColorRamp.CreateRamp(out bOK); IEnumColors pEnumColors = pRandomColorRamp.Colors; pEnumColors.Reset(); for (int j = 0; j <= pUniqueValueRenderer.ValueCount - 1; j++) { string xv; xv = pUniqueValueRenderer.get_Value(j); if (xv != "") { ISimpleFillSymbol pSimpleFillColor = pUniqueValueRenderer.get_Symbol(xv) as ISimpleFillSymbol; pSimpleFillColor.Color = pEnumColors.Next(); pUniqueValueRenderer.set_Symbol(xv, pSimpleFillColor as ISymbol); } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; pGeoFeatureLayer.DisplayField = fieldName; }
/// <summary> /// Returns Simple Renderer if no values can be found /// </summary> /// <param name="renderContainer"></param> /// <returns></returns> public static IFeatureRenderer NewUniqueValueRenderer(RendererContainer renderContainer) { BiPolarRendererContainer biPolarRendererContainer = renderContainer.BiPolarRendererContainer; IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass(); ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; simpleFillSymbol.Outline.Width = 0.4; var fieldName = biPolarRendererContainer.Field.Name; uniqueValueRenderer.FieldCount = 1; uniqueValueRenderer.Field[0] = fieldName; int fieldIndex; ISet <double> setOfFeatures = new HashSet <double>(); var containsDbNullValue = false; using (var comReleaser = new ComReleaser()) { var featureCursor = renderContainer.Field.Feature.FeatureClass.Search(null, true); comReleaser.ManageLifetime(featureCursor); fieldIndex = featureCursor.Fields.FindField(fieldName); IFeature currentFeature; while ((currentFeature = featureCursor.NextFeature()) != null) { var value = currentFeature.Value[fieldIndex]; if (Convert.IsDBNull(value)) { containsDbNullValue = true; continue; } //TODO datetime is possible??? setOfFeatures.Add(Convert.ToDouble(value)); } } if (containsDbNullValue && setOfFeatures.Count == 0) { return(NewAllMissingValuesRenderer()); } if (setOfFeatures.Count == 0) { return(NewSimpleRenderer()); } IEnumerable <double> orderedSet = setOfFeatures.OrderBy(d => d); foreach (var currentClassValue in orderedSet) { ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass(); pClassSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassSymbol.Outline.Width = 0.4; // the format is important, because the normal to string will represent the power as E-05 or something like that // the result are mismatches between the renderer value and the column value //string classValue = currentClassValue.ToString("N20"); does not really work var dirtyTrick = (decimal)currentClassValue; var classValue = dirtyTrick.ToString(); uniqueValueRenderer.AddValue(classValue, fieldName, (ISymbol)pClassSymbol); uniqueValueRenderer.set_Label(classValue, classValue); uniqueValueRenderer.set_Symbol(classValue, (ISymbol)pClassSymbol); } //figure out how many colors belong to which side from the neutral color var size = uniqueValueRenderer.ValueCount; var left = (int)(size * biPolarRendererContainer.NeutralColorPosition); var right = size - left; // for the case one or both are zero -> create color ramp crashes, the magic value seems to be 2 if (left < 2) { left = 2; } if (right < 2) { right = 2; } IAlgorithmicColorRamp firstColorRamp = new AlgorithmicColorRampClass(); firstColorRamp.FromColor = ToColor(biPolarRendererContainer.NegativColor); firstColorRamp.ToColor = ToColor(biPolarRendererContainer.NeutralColor); firstColorRamp.Size = left; bool bOk; IAlgorithmicColorRamp secondColorRamp = new AlgorithmicColorRampClass(); secondColorRamp.FromColor = ToColor(biPolarRendererContainer.NeutralColor); secondColorRamp.ToColor = ToColor(biPolarRendererContainer.PositivColor); secondColorRamp.Size = right; firstColorRamp.CreateRamp(out bOk); secondColorRamp.CreateRamp(out bOk); var firstEnumColors = firstColorRamp.Colors; var secondEnumColors = secondColorRamp.Colors; firstEnumColors.Reset(); secondEnumColors.Reset(); for (var j = 0; j <= uniqueValueRenderer.ValueCount - 1; j++) { var label = uniqueValueRenderer.Value[j]; var pSimpleFillColor = (ISimpleFillSymbol)uniqueValueRenderer.Symbol[label]; var color = firstEnumColors.Next(); //in case the first half colors is "empty" change to the second if (color == null) { firstEnumColors = secondEnumColors; color = firstEnumColors.Next(); } pSimpleFillColor.Color = color; uniqueValueRenderer.set_Symbol(label, (ISymbol)pSimpleFillColor); } //'** If you didn'toolParameter use a predefined color ramp //'** in a style, use "Custom" here. Otherwise, //'** use the name of the color ramp you selected. uniqueValueRenderer.ColorScheme = "Custom"; ////ITable pTable = pDisplayTable as ITable; bool isString = renderContainer.Field.Feature.FeatureClass.Fields.Field[fieldIndex].Type == esriFieldType.esriFieldTypeString; //uniqueValueRenderer.FieldType[0] = isString; uniqueValueRenderer.set_FieldType(0, isString); //TODO geoFeatureLayer var geoFeatureLayer = renderContainer.Field.Feature.FeatureLayer as IGeoFeatureLayer; geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer; return((IFeatureRenderer)uniqueValueRenderer); }
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"); } }
public static void DefineUniqueValueRenderer(IGeoFeatureLayer pGeoFeatureLayer, string fieldName) { IRandomColorRamp pRandomColorRamp = new RandomColorRampClass(); //Create the color ramp for the symbols in the renderer. pRandomColorRamp.MinSaturation = 20; pRandomColorRamp.MaxSaturation = 40; pRandomColorRamp.MinValue = 85; pRandomColorRamp.MaxValue = 100; pRandomColorRamp.StartHue = 76; pRandomColorRamp.EndHue = 188; pRandomColorRamp.UseSeed = true; pRandomColorRamp.Seed = 43; //Create the renderer. IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleFillSymbol.Outline.Width = 0.4; //These properties should be set prior to adding values. pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, fieldName); pUniqueValueRenderer.DefaultSymbol = pSimpleFillSymbol as ISymbol; pUniqueValueRenderer.UseDefaultSymbol = true; IDisplayTable pDisplayTable = pGeoFeatureLayer as IDisplayTable; IFeatureCursor pFeatureCursor = pDisplayTable.SearchDisplayTable(null, false) as IFeatureCursor; IFeature pFeature = pFeatureCursor.NextFeature(); bool ValFound; int fieldIndex; IFields pFields = pFeatureCursor.Fields; fieldIndex = pFields.FindField(fieldName); while (pFeature != null) { ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass(); pClassSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassSymbol.Outline.Width = 0.4; string classValue; classValue = pFeature.get_Value(fieldIndex) as string; //Test to see if this value was added to the renderer. If not, add it. ValFound = false; for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++) { if (pUniqueValueRenderer.get_Value(i) == classValue) { ValFound = true; break; //Exit the loop if the value was found. } } //If the value was not found, it's new and will be added. if (ValFound == false) { pUniqueValueRenderer.AddValue(classValue, fieldName, pClassSymbol as ISymbol); pUniqueValueRenderer.set_Label(classValue, classValue); pUniqueValueRenderer.set_Symbol(classValue, pClassSymbol as ISymbol); } pFeature = pFeatureCursor.NextFeature(); } //Since the number of unique values is known, the color ramp can be sized and the colors assigned. pRandomColorRamp.Size = pUniqueValueRenderer.ValueCount; bool bOK; pRandomColorRamp.CreateRamp(out bOK); IEnumColors pEnumColors = pRandomColorRamp.Colors; pEnumColors.Reset(); for (int j = 0; j <= pUniqueValueRenderer.ValueCount - 1; j++) { string xv; xv = pUniqueValueRenderer.get_Value(j); if (xv != "") { ISimpleFillSymbol pSimpleFillColor = pUniqueValueRenderer.get_Symbol(xv) as ISimpleFillSymbol; pSimpleFillColor.Color = pEnumColors.Next(); pUniqueValueRenderer.set_Symbol(xv, pSimpleFillColor as ISymbol); } } //'** If you didn't use a predefined color ramp in a style, use "Custom" here. //'** Otherwise, use the name of the color ramp you selected. pUniqueValueRenderer.ColorScheme = pRandomColorRamp.Name;//"Custom"; ITable pTable = pDisplayTable as ITable; bool isString = pTable.Fields.get_Field(fieldIndex).Type == esriFieldType.esriFieldTypeString; pUniqueValueRenderer.set_FieldType(0, isString); pGeoFeatureLayer.Renderer = pUniqueValueRenderer as IFeatureRenderer; //This makes the layer properties symbology tab show the correct interface. IUID pUID = new UIDClass(); pUID.Value = "{683C994E-A17B-11D1-8816-080009EC732A}"; pGeoFeatureLayer.RendererPropertyPageClassID = pUID as UIDClass; }
private void btnRun_Click(object sender, EventArgs e) { try { 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(); } //Plot command for R StringBuilder plotCommmand = new StringBuilder(); string strStartPath = m_pForm.strPath; string pathr = strStartPath.Replace(@"\", @"/"); pEngine.Evaluate("source('" + pathr + "/AllFunctions_LeeL.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 + "')"); if (txtSWM.Text == "Default") { pEngine.Evaluate("sample.nb <- poly2nb(sample.shp)"); } else { int intResult = m_pSnippet.SWMusingGAL(pEngine, pFClass, txtSWM.Text); if (intResult == -1) { return; } } NumericVector vecVar1 = pEngine.CreateNumericVector(arrVar1); pEngine.SetSymbol("sample.v1", vecVar1); NumericVector vecVar2 = pEngine.CreateNumericVector(arrVar2); pEngine.SetSymbol("sample.v2", vecVar2); string strSigLv = nudSigLv.Value.ToString(); string strSigMethod = cboSigMethod.Text; if (cboSAM.Text == "Lee's L") { #region Li pEngine.Evaluate("sample.l <- L.local.test(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, style='W', sig.levels=c(" + strSigLv + "), method='" + strSigMethod + "', alternative='two.sided', diag.zero=FALSE)"); double[] dblLValues = pEngine.Evaluate("sample.l$local.L").AsNumeric().ToArray(); double[] dblPvalues = pEngine.Evaluate("sample.l$pvalue").AsNumeric().ToArray(); string[] strFlgs = pEngine.Evaluate("as.character(sample.l$sig)").AsCharacter().ToArray(); //Save Output on SHP //Add Target fields to store results in the shapefile for (int j = 0; j < 3; j++) { IField newField = new FieldClass(); IFieldEdit fieldEdit = (IFieldEdit)newField; fieldEdit.Name_2 = lvFields.Items[j].SubItems[1].Text; if (j == 2) { fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; } else { fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; } pFClass.AddField(newField); } //Update Field pFCursor = pFClass.Update(null, false); pFeature = pFCursor.NextFeature(); string strFlgFldNam = lvFields.Items[2].SubItems[1].Text; int intStatFldIdx = pFClass.FindField(lvFields.Items[0].SubItems[1].Text); int intPrFldIdx = pFClass.FindField(lvFields.Items[1].SubItems[1].Text); int intFlgFldIdx = pFClass.FindField(strFlgFldNam); int featureIdx = 0; while (pFeature != null) { pFeature.set_Value(intStatFldIdx, dblLValues[featureIdx]); pFeature.set_Value(intPrFldIdx, dblPvalues[featureIdx]); pFeature.set_Value(intFlgFldIdx, strFlgs[featureIdx]); pFCursor.UpdateFeature(pFeature); pFeature = pFCursor.NextFeature(); featureIdx++; } pFCursor.Flush(); pfrmProgress.Close(); if (chkMap.Checked) { double[,] adblMinMaxForLabel = new double[2, 4]; ITable pTable = (ITable)pFClass; IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, strFlgFldNam); IDataStatistics pDataStat; IStatisticsResults pStatResults; ISimpleFillSymbol pSymbol; ICursor pCursor; IQueryFilter pQFilter = new QueryFilterClass(); pQFilter.WhereClause = strFlgFldNam + " = 'HH'"; int intCnt = pTable.RowCount(pQFilter); pCursor = pTable.Search(pQFilter, true); pDataStat = new DataStatisticsClass(); pDataStat.Field = lvFields.Items[1].SubItems[1].Text; pDataStat.Cursor = pCursor; pStatResults = pDataStat.Statistics; adblMinMaxForLabel[0, 0] = pStatResults.Minimum; adblMinMaxForLabel[1, 0] = pStatResults.Maximum; pCursor.Flush(); pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(255, 80, 80); pUniqueValueRenderer.AddValue("HH", null, (ISymbol)pSymbol); if (intCnt == 1) { pUniqueValueRenderer.set_Label("HH", "HH (" + adblMinMaxForLabel[0, 0].ToString("N1") + ")"); } else if (intCnt == 0) { pUniqueValueRenderer.set_Label("HH", "HH (no obs)"); } else { pUniqueValueRenderer.set_Label("HH", "HH (" + adblMinMaxForLabel[0, 0].ToString("N1") + "-" + adblMinMaxForLabel[1, 0].ToString("N1") + ")"); } pQFilter.WhereClause = strFlgFldNam + " = 'LL'"; intCnt = pTable.RowCount(pQFilter); pCursor = pTable.Search(pQFilter, true); pDataStat = new DataStatisticsClass(); pDataStat.Field = lvFields.Items[1].SubItems[1].Text; pDataStat.Cursor = pCursor; pStatResults = pDataStat.Statistics; adblMinMaxForLabel[0, 1] = pStatResults.Minimum; adblMinMaxForLabel[1, 1] = pStatResults.Maximum; pCursor.Flush(); pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(50, 157, 194); pUniqueValueRenderer.AddValue("LL", null, (ISymbol)pSymbol); if (intCnt == 1) { pUniqueValueRenderer.set_Label("LL", "LL (" + adblMinMaxForLabel[0, 1].ToString("N1") + ")"); } else if (intCnt == 0) { pUniqueValueRenderer.set_Label("LL", "LL (no obs)"); } else { pUniqueValueRenderer.set_Label("LL", "LL (" + adblMinMaxForLabel[0, 1].ToString("N1") + "-" + adblMinMaxForLabel[1, 1].ToString("N1") + ")"); } pQFilter.WhereClause = strFlgFldNam + " = 'HL'"; intCnt = pTable.RowCount(pQFilter); pCursor = pTable.Search(pQFilter, true); pDataStat = new DataStatisticsClass(); pDataStat.Field = lvFields.Items[1].SubItems[1].Text; pDataStat.Cursor = pCursor; pStatResults = pDataStat.Statistics; adblMinMaxForLabel[0, 2] = pStatResults.Minimum; adblMinMaxForLabel[1, 2] = pStatResults.Maximum; pCursor.Flush(); pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(244, 199, 0); pUniqueValueRenderer.AddValue("HL", null, (ISymbol)pSymbol); if (intCnt == 1) { pUniqueValueRenderer.set_Label("HL", "HL (" + adblMinMaxForLabel[0, 2].ToString("N1") + ")"); } else if (intCnt == 0) { pUniqueValueRenderer.set_Label("HL", "HL (no obs)"); } else { pUniqueValueRenderer.set_Label("HL", "HL (" + adblMinMaxForLabel[0, 2].ToString("N1") + "-" + adblMinMaxForLabel[1, 2].ToString("N1") + ")"); } pQFilter.WhereClause = strFlgFldNam + " = 'LH'"; intCnt = pTable.RowCount(pQFilter); pCursor = pTable.Search(pQFilter, true); pDataStat = new DataStatisticsClass(); pDataStat.Field = lvFields.Items[1].SubItems[1].Text; pDataStat.Cursor = pCursor; pStatResults = pDataStat.Statistics; adblMinMaxForLabel[0, 3] = pStatResults.Minimum; adblMinMaxForLabel[1, 3] = pStatResults.Maximum; pCursor.Flush(); pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(173, 255, 179); pUniqueValueRenderer.AddValue("LH", null, (ISymbol)pSymbol); if (intCnt == 1) { pUniqueValueRenderer.set_Label("LH", "LH (" + adblMinMaxForLabel[0, 3].ToString("N1") + ")"); } else if (intCnt == 0) { pUniqueValueRenderer.set_Label("LH", "LH (no obs)"); } else { pUniqueValueRenderer.set_Label("LH", "LH (" + adblMinMaxForLabel[0, 3].ToString("N1") + "-" + adblMinMaxForLabel[1, 3].ToString("N1") + ")"); } pSymbol = new SimpleFillSymbolClass(); pSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSymbol.Color = m_pSnippet.getRGB(200, 200, 200); //pUniqueValueRenderer.AddValue("", strFlgFldNam, (ISymbol)pSymbol); //pUniqueValueRenderer.set_Label("", "Not significant"); pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSymbol; pUniqueValueRenderer.DefaultLabel = "Not significant"; pUniqueValueRenderer.UseDefaultSymbol = true; IFeatureLayer pNewFLayer = new FeatureLayerClass(); pNewFLayer.FeatureClass = pFClass; pNewFLayer.Name = cboSAM.Text + " of " + pFLayer.Name; IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer; pGFLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; m_pActiveView.FocusMap.AddLayer(pGFLayer); m_pActiveView.Refresh(); m_pForm.axTOCControl1.Update(); } else { MessageBox.Show("Complete. The results are stored in the shape file"); } #endregion } } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
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(); }
// ********************* // Author: Erika Kamptner // Created Date: 3/10/2017 // Description: This method takes several parameters from the BuildMap method to connect to geodatabase, load layer, // place in appropriate group layer, style, and label. Only Address points, Cadastral, Building, and Centerline layers // have specified labels and symbology. // // ************************** public static void LoadCSCLFeatureClass(bool isCSCL, string strFCName, IGroupLayer pGroupLayer, string strGeodatabase) { //Point to map document IMxDocument pMxDoc; pMxDoc = (IMxDocument)ArcMap.Application.Document; IMap pMap; pMap = pMxDoc.FocusMap; //Set up shapefile Workspace connection IWorkspaceFactory pWorkspaceFactory; pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); //If connecting to SDE, set up SDE workspace connection //IWorkspaceFactory pWorkspaceFactory; //pWorkspaceFactory = new SdeWorkspaceFactoryClass(); IWorkspace pWorkspace; pWorkspace = pWorkspaceFactory.OpenFromFile(strGeodatabase, 0); IFeatureWorkspace pFeatureWorkspace; pFeatureWorkspace = (IFeatureWorkspace)pWorkspace; IFeatureClass pFeatureClass; pFeatureClass = pFeatureWorkspace.OpenFeatureClass(strFCName); IFeatureLayer pFeatureLayer; pFeatureLayer = new FeatureLayer(); pFeatureLayer.FeatureClass = pFeatureClass; pFeatureLayer.Name = pFeatureClass.AliasName; //Add layer to group if CSCL map type. Otherwise, just add layer. if (isCSCL) { pGroupLayer.Add((ILayer)pFeatureLayer); } else { pMap.AddLayer((ILayer)pFeatureLayer); } //Symbolize Address points based if the address has subaddresses if (pFeatureLayer.Name == "AddressPoint") { ILayer pLayer; pLayer = (ILayer)pFeatureLayer; IGeoFeatureLayer pGeoFeatureLayer; pGeoFeatureLayer = (IGeoFeatureLayer)pLayer; pGeoFeatureLayer.DisplayAnnotation = true; //Create unique symbology based on subaddress flag using unique value renderer ISimpleMarkerSymbol pAddressSymbolDefault; pAddressSymbolDefault = new SimpleMarkerSymbolClass(); pAddressSymbolDefault.Color = SetColor(230, 0, 0); pAddressSymbolDefault.Style = esriSimpleMarkerStyle.esriSMSCircle; pAddressSymbolDefault.Size = 4; IUniqueValueRenderer pUniqueValueRenderer; pUniqueValueRenderer = new UniqueValueRendererClass(); pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, "SUBADDRESS"); pUniqueValueRenderer.UseDefaultSymbol = false; //Create unique symbology for different values ISimpleMarkerSymbol pAddressSymbolYES; pAddressSymbolYES = new SimpleMarkerSymbolClass(); pAddressSymbolYES.Color = SetColor(230, 0, 0); pAddressSymbolYES.Style = esriSimpleMarkerStyle.esriSMSCircle; pAddressSymbolYES.Size = 8; pAddressSymbolYES.OutlineSize = 2; pAddressSymbolYES.OutlineColor = SetColor(255, 255, 0); pAddressSymbolYES.Outline = true; ISimpleMarkerSymbol pAddressSymbolNO; pAddressSymbolNO = new SimpleMarkerSymbolClass(); pAddressSymbolNO.Color = SetColor(230, 0, 0); pAddressSymbolNO.Style = esriSimpleMarkerStyle.esriSMSCircle; pAddressSymbolNO.Size = 4; pUniqueValueRenderer.AddValue("YES", "SUBADDRESS", pAddressSymbolYES as ISymbol); pUniqueValueRenderer.set_Label("YES", "YES"); pUniqueValueRenderer.set_Symbol("YES", pAddressSymbolYES as ISymbol); pUniqueValueRenderer.AddValue("NO", "SUBADDRESS", pAddressSymbolNO as ISymbol); pUniqueValueRenderer.set_Label("NO", "NO"); pUniqueValueRenderer.set_Symbol("NO", pAddressSymbolNO as ISymbol); //Create Label LabelFeatures(pGeoFeatureLayer, "\"ADDRESSID: \" + [ADDRESS_ID]"); pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; } else if (pFeatureLayer.Name == "Building") { ILayer pLayer; pLayer = (ILayer)pFeatureLayer; IGeoFeatureLayer pGeoFeatureLayer; pGeoFeatureLayer = (IGeoFeatureLayer)pLayer; pGeoFeatureLayer.DisplayField = "BIN"; pGeoFeatureLayer.DisplayAnnotation = true; //Create ouline element ISimpleLineSymbol pOutline; pOutline = new SimpleLineSymbolClass(); pOutline.Color = SetColor(0, 0, 255); pOutline.Width = 2; //Create polygon with outline element ISimpleFillSymbol pBuildingSymbol; pBuildingSymbol = new SimpleFillSymbolClass(); pBuildingSymbol.Style = esriSimpleFillStyle.esriSFSHollow; pBuildingSymbol.Outline = pOutline; //Create Label LabelFeatures(pGeoFeatureLayer, "\"BIN : \" + [BIN]"); //Render features ISimpleRenderer pSimpleRenderer; pSimpleRenderer = new SimpleRenderer(); pSimpleRenderer.Symbol = (ISymbol)pBuildingSymbol; pGeoFeatureLayer.Renderer = (IFeatureRenderer)pSimpleRenderer; } else if (pFeatureLayer.Name == "StreetCenterline") { ILayer pLayer; pLayer = (ILayer)pFeatureLayer; IGeoFeatureLayer pGeoFeatureLayer; pGeoFeatureLayer = (IGeoFeatureLayer)pLayer; pGeoFeatureLayer.DisplayField = "ST_NAME"; pGeoFeatureLayer.DisplayAnnotation = true; //Create arrow element to place at end of line segment IArrowMarkerSymbol arrowMarkerSymbol = new ArrowMarkerSymbolClass(); arrowMarkerSymbol.Color = SetColor(0, 0, 0); arrowMarkerSymbol.Size = 6; arrowMarkerSymbol.Length = 8; arrowMarkerSymbol.Width = 6; arrowMarkerSymbol.XOffset = 0.8; //Create cartographic line symbol ICartographicLineSymbol pCartographicLineSymbol; pCartographicLineSymbol = new CartographicLineSymbolClass(); pCartographicLineSymbol.Color = SetColor(0, 0, 0); pCartographicLineSymbol.Width = 2; //Place arrow at end of line ISimpleLineDecorationElement pCenterlineDecoration; pCenterlineDecoration = new SimpleLineDecorationElementClass(); pCenterlineDecoration.AddPosition(1); pCenterlineDecoration.MarkerSymbol = arrowMarkerSymbol; pCenterlineDecoration.Rotate = true; //set line decoration ILineDecoration pLineDecoration; pLineDecoration = new LineDecorationClass(); pLineDecoration.AddElement(pCenterlineDecoration); //Set line properties ILineProperties lineProperties = (ILineProperties)pCartographicLineSymbol; lineProperties.LineDecoration = pLineDecoration; lineProperties.Flip = false; //Create Label LabelFeatures(pGeoFeatureLayer, "[L_LOW_HN] + \" - \" + [L_HIGH_HN]+ \" \" +[ST_NAME] + vbCrLf + [PHYSICALID]"); //Render features ISimpleRenderer pSimpleRenderer; pSimpleRenderer = new SimpleRenderer(); pSimpleRenderer.Symbol = (ISymbol)pCartographicLineSymbol; pGeoFeatureLayer.Renderer = (IFeatureRenderer)pSimpleRenderer; } else if (pFeatureLayer.Name == "Cadastral") { ILayer pLayer; pLayer = (ILayer)pFeatureLayer; IGeoFeatureLayer pGeoFeatureLayer; pGeoFeatureLayer = (IGeoFeatureLayer)pLayer; pGeoFeatureLayer.DisplayField = "BBL"; pGeoFeatureLayer.DisplayAnnotation = true; //Create ouline element ISimpleLineSymbol pOutline; pOutline = new SimpleLineSymbolClass(); pOutline.Color = SetColor(76, 230, 0); pOutline.Width = 2; //Create polygon with outline element ISimpleFillSymbol pTaxLotSymbol; pTaxLotSymbol = new SimpleFillSymbolClass(); pTaxLotSymbol.Style = esriSimpleFillStyle.esriSFSHollow; pTaxLotSymbol.Outline = pOutline; //Create label LabelFeatures(pGeoFeatureLayer, "\"BBL: \" + [BBL]"); //Render features ISimpleRenderer pSimpleRenderer; pSimpleRenderer = new SimpleRenderer(); pSimpleRenderer.Symbol = (ISymbol)pTaxLotSymbol; pGeoFeatureLayer.Renderer = (IFeatureRenderer)pSimpleRenderer; } else { pFeatureLayer.Visible = false; } }
/// <summary> /// 按聚类号对凸包进行渲染 /// </summary> /// <param name="pGeoFeatureLayer"></param> /// <param name="fieldName"></param> public void DefinePointUniqueValueRenderer(IGeoFeatureLayer pGeoFeatureLayer, string fieldName) { IRandomColorRamp pRandomColorRamp = new RandomColorRampClass(); //Create the color ramp for the symbols in the renderer. pRandomColorRamp.MinSaturation = 20; pRandomColorRamp.MaxSaturation = 40; pRandomColorRamp.MinValue = 85; pRandomColorRamp.MaxValue = 100; pRandomColorRamp.StartHue = 76; pRandomColorRamp.EndHue = 188; pRandomColorRamp.UseSeed = true; pRandomColorRamp.Seed = 43; //Create the renderer. IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); /* ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleFillSymbol.Outline.Width = 0.4; */ ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pSimpleMarkerSymbol.Size = 5; pSimpleMarkerSymbol.Outline = true; IRgbColor pLineRgbColor = new RgbColorClass(); pLineRgbColor.Red = 0; pLineRgbColor.Green = 0; pLineRgbColor.Blue = 0; pSimpleMarkerSymbol.OutlineColor = pLineRgbColor as IColor; //These properties should be set prior to adding values. pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, fieldName); pUniqueValueRenderer.DefaultSymbol = pSimpleMarkerSymbol as ISymbol; pUniqueValueRenderer.UseDefaultSymbol = true; IDisplayTable pDisplayTable = pGeoFeatureLayer as IDisplayTable; IFeatureCursor pFeatureCursor = pDisplayTable.SearchDisplayTable(null, false) as IFeatureCursor; IFeature pFeature = pFeatureCursor.NextFeature(); bool ValFound; int fieldIndex; IFields pFields = pFeatureCursor.Fields; fieldIndex = pFields.FindField(fieldName); while (pFeature != null) { /* ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass(); pClassSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassSymbol.Outline.Width = 0.4; */ ISimpleMarkerSymbol pClassSymbol = new SimpleMarkerSymbolClass(); pClassSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pClassSymbol.Size = 5; pClassSymbol.Outline = true; pClassSymbol.OutlineColor = pLineRgbColor as IColor; string classValue; classValue = pFeature.get_Value(fieldIndex).ToString(); //Test to see if this value was added to the renderer. If not, add it. ValFound = false; for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++) { if (pUniqueValueRenderer.get_Value(i) == classValue) { ValFound = true; break; //Exit the loop if the value was found. } } //If the value was not found, it's new and will be added. if (ValFound == false) { pUniqueValueRenderer.AddValue(classValue, fieldName, pClassSymbol as ISymbol); pUniqueValueRenderer.set_Label(classValue, classValue); pUniqueValueRenderer.set_Symbol(classValue, pClassSymbol as ISymbol); } pFeature = pFeatureCursor.NextFeature(); } //Since the number of unique values is known, the color ramp can be sized and the colors assigned. pRandomColorRamp.Size = pUniqueValueRenderer.ValueCount; bool bOK; pRandomColorRamp.CreateRamp(out bOK); IEnumColors pEnumColors = pRandomColorRamp.Colors; pEnumColors.Reset(); for (int j = 0; j <= pUniqueValueRenderer.ValueCount - 1; j++) { string xv; xv = pUniqueValueRenderer.get_Value(j); if (xv != "") { ISimpleMarkerSymbol pSimpleMarkerColor = pUniqueValueRenderer.get_Symbol(xv) as ISimpleMarkerSymbol; pSimpleMarkerColor.Color = pEnumColors.Next(); pUniqueValueRenderer.set_Symbol(xv, pSimpleMarkerColor as ISymbol); } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; pGeoFeatureLayer.DisplayField = fieldName; }
private void styleGipodLyr( IGeoFeatureLayer geolayer ) { IUniqueValueRenderer renderer = new UniqueValueRendererClass(); renderer.FieldCount = 1; renderer.set_Field(0, "hinder"); renderer.set_FieldType(0, false); //renderer.UseDefaultSymbol = true; renderer.DefaultLabel = "other"; ISimpleMarkerSymbol trueMarkerSymbol = new SimpleMarkerSymbolClass(); trueMarkerSymbol.Color = new RgbColorClass(){Red= 255, Blue= 0, Green= 255 }; trueMarkerSymbol.Outline = true; trueMarkerSymbol.OutlineColor = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 }; ; trueMarkerSymbol.Size = 5; trueMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; ISimpleMarkerSymbol falseMarkerSymbol = new SimpleMarkerSymbolClass(); falseMarkerSymbol.Color = new RgbColorClass() { Red = 255, Blue = 0, Green = 0 }; falseMarkerSymbol.Outline = true; falseMarkerSymbol.OutlineColor = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 }; ; falseMarkerSymbol.Size = 5; falseMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; renderer.AddValue("0","", falseMarkerSymbol as ISymbol); renderer.set_Label("0", "Geen hinder"); renderer.AddValue("1", "", trueMarkerSymbol as ISymbol); renderer.set_Label("1", "Veel hinder"); geolayer.Renderer = renderer as IFeatureRenderer; IMxDocument mxDoc = ArcMap.Document; mxDoc.CurrentContentsView.Refresh(null); }
public IFeatureRenderer UnqueValueRenderer(IFeatureWorkspace workspace, IFeatureClass fc) { try { string tablename = ((IDataset)fc).BrowseName; ITable ipTable = workspace.OpenTable(tablename); IFeatureCursor featureCursor = fc.Search(null, false); IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Cursor = featureCursor as ICursor; dataStatistics.Field = "gridcode"; System.Collections.IEnumerator enumerator = dataStatistics.UniqueValues; enumerator.Reset(); while (enumerator.MoveNext()) { object myObject = enumerator.Current; } int uniqueValues = dataStatistics.UniqueValueCount; //Create colors for each unique value. IRandomColorRamp colorRamp = new RandomColorRampClass(); colorRamp.Size = uniqueValues; colorRamp.Seed = 100; bool createColorRamp; colorRamp.CreateRamp(out createColorRamp); if (createColorRamp == false) { return null; } IUniqueValueRenderer uvRenderer = new UniqueValueRendererClass(); IFeatureRenderer featRenderer = (IFeatureRenderer)uvRenderer; uvRenderer.FieldCount = 1; ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); ISimpleFillSymbol fillSymbol2 = new SimpleFillSymbolClass(); if (ShowNonVisibleData == true) { fillSymbol.Color = new RgbColorClass() { Red = 255 } as IColor; uvRenderer.AddValue("0", "", fillSymbol as ISymbol); uvRenderer.set_Label("0", "Non-Visible"); } fillSymbol2.Color = new RgbColorClass() { Green = 255 } as IColor; uvRenderer.AddValue("1", "", fillSymbol2 as ISymbol); uvRenderer.set_Label("1", "Visible by 1 Observer"); int field = ipTable.FindField("gridcode"); uvRenderer.set_Field(0, "gridcode"); for (int i = 2; i < uniqueValues; i++) { ISimpleFillSymbol newFillSymbol = new SimpleFillSymbolClass(); newFillSymbol.Color = colorRamp.get_Color(i); uvRenderer.AddValue(i.ToString(), "", newFillSymbol as ISymbol); string label = "Visible by " + i.ToString() + " Observers"; uvRenderer.set_Label(i.ToString(), label); } return featRenderer; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return null; } }