diff --git a/.gitignore b/.gitignore index 1b22170..9616d92 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ ./vs/ ./bin/ ./obj/ -./Properties/launchSettings.json +./Properties/ *.sln.iml *.DotSettings *.dotCover diff --git a/client/tool/ArcGisPro.cs b/client/tool/ArcGisPro.cs index 8e2ce0a..4ae7166 100644 --- a/client/tool/ArcGisPro.cs +++ b/client/tool/ArcGisPro.cs @@ -137,8 +137,8 @@ public class ArcGisPro return result; } - [McpServerTool, Description("获取要素类的属性表内容,可以查看属性表中的至多前20条记录的内容")] - public static async Task GetFeatureDatasetAttributeTable(string datasetPath, string dataName, string rowsLimit) + [McpServerTool, Description("获取要素类的属性表内容,可以查看属性表中的至多前20条记录的内容,传入Where子句筛选特定数据,例如“OBJECTID > 10”")] + public static async Task GetFeatureDatasetAttributeTable(string datasetPath, string dataName, string whereClause) { JsonRpcResultEntity result = new JsonRpcResultEntity(); await QueuedTask.Run(async () => @@ -147,7 +147,7 @@ public class ArcGisPro { using Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(datasetPath))); FeatureClass featureClass = gdb.OpenDataset(dataName); - List> attributeTable = await GetAttributeTableAsync(featureClass,Convert.ToInt32(rowsLimit)); + List> attributeTable = await GetAttributeTableAsync(featureClass,whereClause); result = new JsonRpcSuccessEntity() { Id = 1, @@ -170,15 +170,15 @@ public class ArcGisPro return result; } - private static async Task>> GetAttributeTableAsync(FeatureClass featureClass,int limit = 5) + private static async Task>> GetAttributeTableAsync(FeatureClass featureClass,String whereClause) { - if (limit > 20) - limit = 20; + int limit = 20; return await QueuedTask.Run(() => { var result = new List>(); - - using (var cursor = featureClass.Search()) + QueryFilter queryFilter = new QueryFilter(); + queryFilter.WhereClause = whereClause; + using (var cursor = featureClass.Search(queryFilter)) { int i = 0; while (cursor.MoveNext()) @@ -198,7 +198,10 @@ public class ArcGisPro // 处理 DBNull 值 if (value is DBNull) - value = null; + value = ""; + + if (value == null) + value = ""; record[field.Name] = value.ToString(); }