Esempio n. 1
0
        public Hashtable GetDataSummary(string layerName, string summaryFields, string dissolveField, bool selectedOnly = false)
        {
            Hashtable result = new Hashtable();
            ILayer layer = this._getLayerByName(layerName);
            if (layer != null && layer is IFeatureLayer)
            {
                ITable inputTable = (ITable)layer;
                IWorkspaceName wsName =  ((IDataset)(this._tempWorkspace)).FullName as IWorkspaceName;

                /*
                ShapefileWorkspaceFactoryClass tempWSFactory = new ShapefileWorkspaceFactoryClass();
                IWorkspace tempWS = tempWSFactory.OpenFromFile(System.IO.Path.GetTempPath(), 0);
                IWorkspaceName wsName = ((IDataset)(tempWS)).FullName as IWorkspaceName;
                */
                TableNameClass outputName = new TableNameClass();
                outputName.Name = layerName + "_summary_" + DateTime.Now.ToString("MM_dd_yy_H_mm_ss");
                outputName.WorkspaceName = wsName;

                if (inputTable.FindField(dissolveField) > 0)
                {
                    BasicGeoprocessorClass basicGeopro = new BasicGeoprocessorClass();
                    ITable resultTable = basicGeopro.Dissolve(inputTable, selectedOnly, dissolveField, summaryFields, outputName);
                    
                    result.Add("workspace", this._tempWorkspace.PathName);
                    result.Add("table", outputName.Name);

                    // Create a data graph.
                    IDataGraphT dataGraphT = new DataGraphTClass();
                    // Add the graph series.
                    ISeriesProperties seriesProps = dataGraphT.AddSeries("bar:vertical");
                    seriesProps.SourceData = resultTable;

                    seriesProps.SetField(0, resultTable.Fields.get_Field(1).Name);
                    seriesProps.SetField(1, resultTable.Fields.get_Field(2).Name);
                    seriesProps.LabelField = resultTable.Fields.get_Field(1).Name;

                    // Set titles.
                    dataGraphT.GeneralProperties.Title = "Bar Chart";
                    dataGraphT.AxisProperties[1].Title = dissolveField;
                    
                    // Update the data graph.
                    dataGraphT.Update(null);
                    // Export the graph to file (the format depends on the file extension).
                    string tempDir = System.IO.Path.GetTempPath();
                    string outImageFile = System.IO.Path.Combine(tempDir, outputName.Name + ".bmp");

                    if (System.IO.File.Exists(outImageFile))
                    {
                        System.IO.File.Delete(outImageFile);
                    }

                    dataGraphT.ExportToFile(outImageFile);

                    result.Add("graph", outImageFile);

                }
                
                
            }
            return result;
        }
Esempio n. 2
0
        public Hashtable GetFieldStatistics(string layerName, string fieldName, bool selectedOnly=false)
        {
            Hashtable result = new Hashtable();
            ILayer layer = this._getLayerByName(layerName);
            if (layer != null && layer is IFeatureLayer)
            {
                ICursor cursor;
                if (selectedOnly == true)
                {
                    ((IFeatureSelection)layer).SelectionSet.Search(null, false, out cursor);
                }
                else
                {
                    IFeatureLayer featureLayer = layer as IFeatureLayer;
                    cursor = (ICursor)featureLayer.FeatureClass.Search(null, false);
                }

                result.Add("layer_name", layerName);
                result.Add("field_name", fieldName);

                IDataStatistics dataStatistics = new DataStatisticsClass();
                dataStatistics.Cursor = cursor;
                dataStatistics.Field = fieldName;
                IStatisticsResults statResults = dataStatistics.Statistics;
                Hashtable stats = new Hashtable();
                stats.Add("count", statResults.Count);
                stats.Add("sum", statResults.Sum);
                stats.Add("mean", statResults.Mean);
                stats.Add("std", statResults.StandardDeviation);
                stats.Add("minimum", statResults.Minimum);
                stats.Add("maximum", statResults.Maximum);
                result.Add("statistics", stats);

                // Create a data graph.
                IDataGraphT dataGraphT = new DataGraphTClass();
                // Add the histogram series.
                ISeriesProperties seriesProps = dataGraphT.AddSeries("bar:histogram");
                seriesProps.SourceData = (IFeatureLayer)layer; //((IAttributeTable)layer).AttributeTable;
                seriesProps.SetField(0, fieldName);
                
                // Set the histogram properties.
                IHistogramSeriesProperties histogramSeriesProps = (IHistogramSeriesProperties)seriesProps;
                histogramSeriesProps.BinCount = 20;

                if (selectedOnly == true)
                {
                    dataGraphT.UseSelectedSet = true;
                    dataGraphT.HighlightSelection = false;
                    //seriesProps.SourceData = ((IFeatureSelection)layer).SelectionSet;
                }
                else
                {
                    dataGraphT.UseSelectedSet = true;
                    dataGraphT.HighlightSelection = true;
                    //seriesProps.SourceData = ((IFeatureLayer)layer).FeatureClass;
                }
                // Set titles.
                dataGraphT.GeneralProperties.Title = "Histogram of " + fieldName;
                dataGraphT.AxisProperties[1].Title = "COUNT";
                // Update the data graph.
                dataGraphT.Update(null);
                // Export the graph to file (the format depends on the file extension).
                string tempDir = System.IO.Path.GetTempPath();
                string outImageFile = System.IO.Path.Combine(tempDir, layerName+ "_" + fieldName + DateTime.Now.ToString("_MM_dd_yy_H_mm_ss_") + "_histogram.bmp");

                if (System.IO.File.Exists(outImageFile))
                {
                    System.IO.File.Delete(outImageFile);
                }

                dataGraphT.ExportToFile(outImageFile);

                result.Add("histogram", outImageFile);
            }
            return result;
        }