GDAL库 坐标转换问题

beanflower 2018-07-17 09:22:14
利用gdal库,读取修改shp文件中的图形,需要对Geometry进行坐标转换。

调用setpoint函数后,做是变化修改了。

但是,重新读取打开图形,坐标还是没有变化?需要如何操作?

public void ConvertCoor(string source)
{

DataSource sourceSource = Ogr.Open(source, 0);
OSGeo.OGR.Driver shpDriver = Ogr.GetDriverByName("ESRI Shapefile"); //MapInfo File、ESRI Shapefile
int layerCount = sourceSource.GetLayerCount();

for (int i = 0; i < layerCount; i++)
{
Layer layer = sourceSource.GetLayerByIndex(i);
int featureCount = layer.GetFeatureCount(0);

for (int j = 0; j < featureCount; j++)
{
Feature feature = layer.GetFeature(j);

if (feature != null)
{
try
{
//
Geometry geo = feature.GetGeometryRef();
int count = geo.GetPointCount();
for (int k = 0; k < count; k++) {
double x2 = 0, y2 = 0,b=0,l=0;
double x1 = geo.GetY(k);
double y1 = geo.GetX(k);
x2 = x1+2000;
y2 = y1+3000;
geo.SetPoint_2D(k, y2, x2);
x1 = geo.GetY(k);
y1 = geo.GetX(k);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
continue;
}

layer.ResetReading();
layer.CommitTransaction();
}
}
layer.Dispose();
}


sourceSource.Dispose();
shpDriver.Dispose();
}
...全文
139 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧