private void sqlToolStripMenuItem_Click(object sender, EventArgs e)
{
Selection objSelect = map.FindSelection(true)[0];
Recordset objSelectRd = objSelect.ToRecordset();
objSelectRd.MoveFirst();
string getName = objSelectRd.GetString(0);
int id = Convert.ToInt32(getName);
Datasources datasources = workspace1.Datasources;
Datasource datasource = datasources[0];
Datasets datasets = datasource.Datasets;
for (int i = 0; i < datasets.Count; i++)
{
if (datasets[i].Name == "bufferriver")
{
datasets.Delete("bufferriver");
MessageBox.Show("Delete Dataset Succes");
break;
}
}
if (map.Layers.Contains("bufferriver@SDBSystem"))
{
map.Layers.RemoveByDataset(datasets["bufferriver"]);
MessageBox.Show("删除成功");
}
string riverName = objSelectRd.GetFieldValue("name").ToString();
int distance = getvalue();
bool isSuccess = datasource.ExecuteSQL($"create table Bufferriver as select ST_Buffer(shape, {distance}, 'endcap=round join=round') from waterways where fid = {id};");
if (isSuccess)
{
datasource.Refresh();
Layer bufferLayer = map.Layers.Add(datasets["bufferriver"], true);
LayerSettingVector bufferSetting = (LayerSettingVector)bufferLayer.AdditionalSetting;
GeoStyle geoStyle = new GeoStyle();
geoStyle.FillForeColor = Color.Orange;
geoStyle.FillOpaqueRate = 50;
bufferSetting.Style = geoStyle;
}
else
{
MessageBox.Show("创建失败");
}
}
由于实验需要,要在Objects .net中使用SQL进行缓冲区的创建,但第一次创建可以成功,之后再创建就会报错如下,除此之外,有时在添加map.Refresh()刷新地图时,也会报这个错。我感觉是因为Layer对象和map没有释放,但我写Dispose释放说连点对象不能显示释放。求大佬支招。