修复查属性表工具,增加条件查询功能

This commit is contained in:
PeterZhong 2025-07-28 23:36:26 +08:00
parent 468d13b9d1
commit 93f185dc3b
2 changed files with 13 additions and 10 deletions

2
.gitignore vendored
View File

@ -7,7 +7,7 @@
./vs/ ./vs/
./bin/ ./bin/
./obj/ ./obj/
./Properties/launchSettings.json ./Properties/
*.sln.iml *.sln.iml
*.DotSettings *.DotSettings
*.dotCover *.dotCover

View File

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