栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++ GDAL/OGR 图层求交集Intersection

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++ GDAL/OGR 图层求交集Intersection

上两期文章,说明了如何创建点类型的图层和多边形类型的图层,创建好这两个图层之后,将两个图层求交得到TestResult.shp,此shp文件包含了求交后的结果。

int TestIntersection() {
    GDALAllRegister();
    GDALDriver* shpDriver = GetGDALDriverManager()->GetDriverByName("ESRI Shapefile");
    if (shpDriver == NULL) {
        printf("%sn", "ESRI Shapefile驱动创建失败!");
        return -1;
    }
    GDALDataset* shipDataSet = (GDALDataset*)GDALOpenEx("..\shp\TestPoint.shp", GDAL_OF_VECTOR, NULL, NULL, NULL);
    GDALDataset* regDataSet = (GDALDataset*)GDALOpenEx("..\shp\TestPolygon.shp", GDAL_OF_VECTOR, NULL, NULL, NULL);

    OGRSpatialReference osr;
    //osr.SetWellKnownGeogCS("WGS84");
    if (osr.importFromEPSG(4326) != OGRERR_NONE) {
        printf("%sn", "坐标系创建失败!");
        return -1;
    }

    OGRLayer* shipLayer = shipDataSet->GetLayerByName("TestPoint");
    OGRLayer* regLayer = regDataSet->GetLayerByName("TestPolygon");
    GDALDataset* resultDataSet = shpDriver->Create("..//shp//TestResult.shp", 0, 0, 0, GDT_Unknown, NULL);
    char** papszOptions = NULL;
    papszOptions = CSLSetNameValue(papszOptions, "ENCODING", "UTF-8");
    OGRLayer* resultLayer = resultDataSet->CreateLayer("resultLyr", &osr, wkbPoint, papszOptions);
    regLayer->Intersection(shipLayer, resultLayer, NULL, GDALTermProgress, NULL);
    GDALClose(shipDataSet);
    GDALClose(regDataSet);
}

TestPoint.shp的图层有三个点,与TestPolygon.shp的图层求交集以后得到TestResult.shp。它们求交集之后会自动合并字段。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1012554.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号