做矢量瓦片时发现项目使用的Tippecanoe不能直接处理shp类型文件,需要将shp转成geojson类型。在网上查找相关资料:
https://blog.csdn.net/weixin_43857611/article/details/120556351
https://www.cnblogs.com/yulijunzj/p/4974369.html
感谢两位的分享,实践可行
void SHPToGEOJson::Shpfile2GeojsonFile(eString inFileName, eString outFileName) { GDALAllRegister(); OGRRegisterAll(); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); CPLSetConfigOption("SHAPE_ENCODING", "CP936"); eUTF8String utf8FilePathin(inFileName); eUTF8String utf8FilePathout(outFileName); GDALDataset *poSrcDS = (GDALDataset *)GDALOpenEx(utf8FilePathin.Cstr(), GDAL_OF_VECTOR, NULL, NULL, NULL); if (poSrcDS == NULL) { return; } GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GeoJSON"); GDALDataset* poDstDS = poDriver->CreateCopy(utf8FilePathout.Cstr(), poSrcDS, FALSE, NULL, NULL, NULL); if (poDstDS != NULL) { GDALClose((GDALDatasetH)poDstDS); } GDALClose((GDALDatasetH)poSrcDS); }
代码中的个别变量类型为项目使用类型,文件名称可用char*类型取代。
转化后的文件为UTF-8编码,中文不乱码。