public static int CalculateSpeceficValuesCount(string requireColumnName, string fieldValue, ShapeFileFeatureLayer featureLayer) { int count = 0; if (!String.IsNullOrEmpty(requireColumnName)) { featureLayer.SafeProcess(() => { string dbfPath = Path.ChangeExtension(featureLayer.ShapePathFilename, ".dbf"); if (File.Exists(dbfPath)) { using (GeoDbf dbf = new GeoDbf(dbfPath)) { dbf.Open(); string orignalColumnName = requireColumnName; for (int i = 1; i <= dbf.RecordCount; i++) { var currentFieldValue = dbf.ReadFieldAsString(i, orignalColumnName); if (currentFieldValue.Equals(fieldValue, StringComparison.Ordinal)) { count++; } } dbf.Close(); } } }); } return(count); }
public static IEnumerable <IGrouping <string, string> > GroupColumnValues(string requireColumnName , ShapeFileFeatureLayer featureLayer) { Collection <string> fieldValues = new Collection <string>(); if (!String.IsNullOrEmpty(requireColumnName)) { featureLayer.SafeProcess(() => { string dbfPath = Path.ChangeExtension(featureLayer.ShapePathFilename, ".dbf"); if (File.Exists(dbfPath)) { string orignalColumnName = requireColumnName; using (GeoDbf dbf = new GeoDbf(dbfPath)) { dbf.Open(); for (int i = 1; i <= dbf.RecordCount; i++) { fieldValues.Add(dbf.ReadFieldAsString(i, orignalColumnName)); } dbf.Close(); } } }); } return(fieldValues.GroupBy(fieldValue => fieldValue)); }
/// <summary> /// Points to Draw Elapsed MS /// 10000 605 /// 20000 998 /// 50000 2658 /// 100000 4980 /// </summary> private static double GetRecommendPointToValueRatio(FeatureLayer layer, string columnName) { int pointsToDraw = 0; // better performance. if (layer is ShapeFileFeatureLayer) { var shpLayer = (ShapeFileFeatureLayer)layer; var shpFName = shpLayer.ShapePathFilename; var dbfFName = Path.ChangeExtension(shpFName, ".dbf"); if (File.Exists(dbfFName)) { using (GeoDbf geoDbf = new GeoDbf(dbfFName, GeoFileReadWriteMode.Read)) { geoDbf.Open(); for (int i = 1; i <= geoDbf.RecordCount; i++) { string fieldValue = geoDbf.ReadFieldAsString(i, columnName); try { pointsToDraw += (int)Convert.ToDouble(fieldValue); } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); } } geoDbf.Close(); } } } else { IEnumerable <Feature> features = null; layer.SafeProcess(() => { features = layer.QueryTools.GetAllFeatures(new string[] { columnName }); }); pointsToDraw = features.Sum(tmpFeature => { try { return((int)Convert.ToDouble(tmpFeature.ColumnValues[columnName])); } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); return(0); } }); } double pointToValueRatio = 1d; if (maxDotsToDraw < pointsToDraw) { pointToValueRatio = (double)maxDotsToDraw / (double)pointsToDraw; } return(pointToValueRatio); }