Exemple #1
0
void SmallpatchSieveFilter::SieveFilter(const char* Src_path, const char* Dst_Path, int SizeThresthod, int Connectedness)
{
	GDALAllRegister();
	CPLSetConfigOption("GDAL_FILENAME_IS_UTF8","NO");
	GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTIFF");
	if (poDriver == NULL)
	{
		cout << "不能创建指定类型的文件:" << endl;
	}
	GDALDataset* poSrc = (GDALDataset*)GDALOpen(Src_path,GA_ReadOnly);
	int NewBandXsize = poSrc->GetRasterXSize();
	int NewBandYsize = poSrc->GetRasterYSize();
	GDALDataType Type = poSrc->GetRasterBand(1)->GetRasterDataType();
	
	GDALDataset* poDstDS = poDriver->Create(Dst_Path, NewBandXsize, NewBandYsize, 1, Type, NULL);
	double GeoTrans[6] = { 0 };
	poSrc->GetGeoTransform(GeoTrans);
	poDstDS->SetGeoTransform(GeoTrans);
	poDstDS->SetProjection(poSrc->GetProjectionRef());
	GDALRasterBandH HImgBand = (GDALRasterBandH)poSrc->GetRasterBand(1);
	GDALRasterBandH HPDstDSBand = (GDALRasterBandH)poDstDS->GetRasterBand(1);
	GDALSetRasterColorTable(HPDstDSBand, GDALGetRasterColorTable(HImgBand));

	GDALSieveFilter(HImgBand, NULL, HPDstDSBand, SizeThresthod, Connectedness, NULL, NULL, NULL);

	GDALClose((GDALDatasetH)poDstDS);
};
void SourcePostProcess(PLCContext *plContext)

{
    /* -------------------------------------------------------------------- */
    /*      Check configuration.                                            */
    /* -------------------------------------------------------------------- */
    if( plContext->sourceTraceDS == NULL )
    {
        CPLError( CE_Fatal, CPLE_AppDefined,
                  "source_sieve_threshold set without source trace enabled.");
        exit(1);
    }

    if( plContext->averageBestRatio > 0.0 )
    {
        CPLError( CE_Fatal, CPLE_AppDefined,
                  "source_sieve_threshold and average_best_ratio set, "
                  "they are mutually exclusive.");
        exit(1);
    }

    /* -------------------------------------------------------------------- */
    /*      Do the sieve filtering.                                         */
    /* -------------------------------------------------------------------- */
    GDALRasterBand *poSourceMapBand =
        plContext->sourceTraceDS->GetRasterBand(1);

    CPLErr eErr = GDALSieveFilter(
                      (GDALRasterBandH) poSourceMapBand,
                      NULL,
                      (GDALRasterBandH) poSourceMapBand,
                      plContext->sourceSieveThreshold,
                      4,
                      NULL,
                      NULL,
                      NULL);

    if( eErr != CE_None )
        exit(1);

    /* -------------------------------------------------------------------- */
    /*      Rebuild the output result image.                                */
    /* -------------------------------------------------------------------- */
    RebuildOutputFromSourceMap(plContext);
}