* Lists various information about a GDAL supported vector dataset. * * This is the equivalent of the ogrinfo * utility. * * GDALVectorInfoOptions* must be allocated and freed with * GDALVectorInfoOptionsNew() and GDALVectorInfoOptionsFree() respectively. * * @param hDataset the dataset handle. * @param psOptions the options structure returned by GDALVe
| 1924 | * @since GDAL 3.7 |
| 1925 | */ |
| 1926 | char *GDALVectorInfo(GDALDatasetH hDataset, |
| 1927 | const GDALVectorInfoOptions *psOptions) |
| 1928 | { |
| 1929 | auto poDS = GDALDataset::FromHandle(hDataset); |
| 1930 | if (poDS == nullptr) |
| 1931 | return nullptr; |
| 1932 | |
| 1933 | const GDALVectorInfoOptions sDefaultOptions; |
| 1934 | if (!psOptions) |
| 1935 | psOptions = &sDefaultOptions; |
| 1936 | |
| 1937 | GDALDriver *poDriver = poDS->GetDriver(); |
| 1938 | |
| 1939 | CPLString osRet; |
| 1940 | CPLJSONObject oRoot; |
| 1941 | const std::string osFilename(poDS->GetDescription()); |
| 1942 | |
| 1943 | const bool bExportOgrSchema = psOptions->bExportOgrSchema; |
| 1944 | const bool bJson = psOptions->eFormat == FORMAT_JSON; |
| 1945 | const bool bIsSummaryCli = |
| 1946 | (psOptions->bIsCli && psOptions->bSummaryUserRequested); |
| 1947 | |
| 1948 | CPLJSONArray oLayerArray; |
| 1949 | if (bJson) |
| 1950 | { |
| 1951 | if (!bExportOgrSchema) |
| 1952 | { |
| 1953 | oRoot.Set("description", poDS->GetDescription()); |
| 1954 | if (poDriver) |
| 1955 | { |
| 1956 | oRoot.Set("driverShortName", poDriver->GetDescription()); |
| 1957 | oRoot.Set("driverLongName", |
| 1958 | poDriver->GetMetadataItem(GDAL_DMD_LONGNAME)); |
| 1959 | } |
| 1960 | } |
| 1961 | oRoot.Add("layers", oLayerArray); |
| 1962 | } |
| 1963 | |
| 1964 | /* -------------------------------------------------------------------- */ |
| 1965 | /* Some information messages. */ |
| 1966 | /* -------------------------------------------------------------------- */ |
| 1967 | if (!bJson && psOptions->bVerbose) |
| 1968 | { |
| 1969 | Concat(osRet, psOptions->bStdoutOutput, |
| 1970 | "INFO: Open of `%s'\n" |
| 1971 | " using driver `%s' successful.\n", |
| 1972 | osFilename.c_str(), |
| 1973 | poDriver ? poDriver->GetDescription() : "(null)"); |
| 1974 | } |
| 1975 | |
| 1976 | if (!bJson && psOptions->bVerbose && |
| 1977 | !EQUAL(osFilename.c_str(), poDS->GetDescription())) |
| 1978 | { |
| 1979 | Concat(osRet, psOptions->bStdoutOutput, |
| 1980 | "INFO: Internal data source name `%s'\n" |
| 1981 | " different from user name `%s'.\n", |
| 1982 | poDS->GetDescription(), osFilename.c_str()); |
| 1983 | } |
no test coverage detected