Как использовать gdal C ++ для пространственного анализа? - PullRequest
0 голосов
/ 28 января 2020

Я пытаюсь реализовать пересечение векторных данных с gdal, но после выполнения моего тестового кода никакие функции не генерируются, и таблица атрибутов пуста. Кто-нибудь знает, почему? вот мой тестовый код:

#include "gdal_priv.h"
#include "ogrsf_frmts.h"
#include <iostream>

bool VectorIntersection(const char *pszSrcShp, const char *pszMethodShp, const char *pszDstShp, const char* pszFormat);

int main()
{
    const char *pszSrcFile = "D:\\MyThesis\\TestData\\MethodLayer.shp"; 
    const char *pszMethodFile = "D:\\MyThesis\\TestData\\SiChuan\\SrcLayer.shp"; 
    const char *pszOutFile = "D:\\MyThesis\\intersection.shp"; 
    VectorIntersection(pszSrcFile, pszMethodFile, pszOutFile, "ESRI Shapefile");
    return 0;
}

bool VectorIntersection(const char *pszSrcShp, const char *pszMethodShp, const char *pszDstShp, const char* pszFormat)
{
    GDALAllRegister();
    OGRRegisterAll();
    GDALDataset *poSrcDS;
    poSrcDS = (GDALDataset*)GDALOpenEx(pszSrcShp, GDAL_OF_VECTOR, NULL, NULL, NULL);
    GDALDataset *poMethodDS;
    poMethodDS = (GDALDataset*)GDALOpenEx(pszMethodShp, GDAL_OF_VECTOR, NULL, NULL, NULL);
    GDALDriver *poDriver;
    poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);
    GDALDataset* poDstDS = poDriver->Create(pszDstShp, 0, 0, 0, GDT_Unknown, NULL);
    OGRLayer *poSrcLayer = poSrcDS->GetLayer(0);
    OGRLayer *poMethodLayer = poMethodDS->GetLayer(0);
    OGRLayer *poDstLayer;
    OGRSpatialReference *pSRS = poSrcLayer->GetSpatialRef();
    poDstLayer = poDstDS->CreateLayer("NewLayer", pSRS, wkbPoint, NULL);

    poSrcLayer->Intersection(poMethodLayer, poDstLayer, NULL, NULL, NULL);
    poDstLayer->SyncToDisk();

    GDALClose(poSrcDS); 
    GDALClose(poMethodDS);
    GDALClose(poDstDS);

    return true;
}```
...