修复查属性表工具,增加条件查询功能
This commit is contained in:
parent
468d13b9d1
commit
93f185dc3b
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,7 +7,7 @@
|
||||
./vs/
|
||||
./bin/
|
||||
./obj/
|
||||
./Properties/launchSettings.json
|
||||
./Properties/
|
||||
*.sln.iml
|
||||
*.DotSettings
|
||||
*.dotCover
|
||||
|
||||
@ -137,8 +137,8 @@ public class ArcGisPro
|
||||
return result;
|
||||
}
|
||||
|
||||
[McpServerTool, Description("获取要素类的属性表内容,可以查看属性表中的至多前20条记录的内容")]
|
||||
public static async Task<JsonRpcResultEntity> GetFeatureDatasetAttributeTable(string datasetPath, string dataName, string rowsLimit)
|
||||
[McpServerTool, Description("获取要素类的属性表内容,可以查看属性表中的至多前20条记录的内容,传入Where子句筛选特定数据,例如“OBJECTID > 10”")]
|
||||
public static async Task<JsonRpcResultEntity> 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<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()
|
||||
{
|
||||
Id = 1,
|
||||
@ -170,15 +170,15 @@ public class ArcGisPro
|
||||
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)
|
||||
limit = 20;
|
||||
int limit = 20;
|
||||
return await QueuedTask.Run(() =>
|
||||
{
|
||||
var result = new List<Dictionary<string, string>>();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user