public static int ContourGenerate(Band srcBand, double contourInterval, double contourBase, int fixedLevelCount, double[] fixedLevels, int useNoData, double noDataValue, OSGeo.OGR.Layer dstLayer, int idField, int elevField, Gdal.GDALProgressFuncDelegate callback, string callback_data) { int ret = GdalPINVOKE.ContourGenerate(Band.getCPtr(srcBand), contourInterval, contourBase, fixedLevelCount, fixedLevels, useNoData, noDataValue, OSGeo.OGR.Layer.getCPtr(dstLayer), idField, elevField, callback, callback_data); if (GdalPINVOKE.SWIGPendingException.Pending) throw GdalPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public string GetSpatialReferenceFromPath(string filepath) { string spatialref = null; Dataset ds = Gdal.Open(filepath, Access.GA_ReadOnly); if (ds == null) { Console.WriteLine(" [-] Could not create dataset from file."); return(spatialref); } spatialref = ds.GetProjectionRef(); ds.Dispose(); return(spatialref); }
static GdalConfiguration() { MessageBox.Show("开始"); var executingAssemblyFile = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath; var executingDirectory = Path.GetDirectoryName(executingAssemblyFile); if (string.IsNullOrEmpty(executingDirectory)) { throw new InvalidOperationException("cannot get executing directory"); } var gdalPath = Path.Combine(executingDirectory, "gdal"); var nativePath = Path.Combine(gdalPath, GetPlatform()); // Prepend native path to environment path, to ensure the // right libs are being used. var path = Environment.GetEnvironmentVariable("PATH"); path = nativePath + ";" + Path.Combine(nativePath, "plugins") + ";" + path; Console.WriteLine(path); Environment.SetEnvironmentVariable("PATH", path); // Set the additional GDAL environment variables. var gdalData = Path.Combine(gdalPath, "data"); Environment.SetEnvironmentVariable("GDAL_DATA", gdalData); Gdal.SetConfigOption("GDAL_DATA", gdalData); var driverPath = Path.Combine(nativePath, "plugins"); Environment.SetEnvironmentVariable("GDAL_DRIVER_PATH", driverPath); Gdal.SetConfigOption("GDAL_DRIVER_PATH", driverPath); Environment.SetEnvironmentVariable("GEOTIFF_CSV", gdalData); Gdal.SetConfigOption("GEOTIFF_CSV", gdalData); var projSharePath = Path.Combine(gdalPath, "share"); Environment.SetEnvironmentVariable("PROJ_LIB", projSharePath); Gdal.SetConfigOption("PROJ_LIB", projSharePath); MessageBox.Show("初始化完毕!"); }
public static extern int SieveFilter(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3, int jarg4, int jarg5, IntPtr[] jarg6, Gdal.GDALProgressFuncDelegate jarg7, string jarg8);
public static extern int Polygonize(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3, int jarg4, IntPtr[] jarg5, Gdal.GDALProgressFuncDelegate jarg6, string jarg7);
public static extern int ComputeProximity(HandleRef jarg1, HandleRef jarg2, IntPtr[] jarg3, Gdal.GDALProgressFuncDelegate jarg4, string jarg5);
public static extern int DitherRGB2PCT(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3, HandleRef jarg4, HandleRef jarg5, Gdal.GDALProgressFuncDelegate jarg6, string jarg7);
public static extern int Band_GetDefaultHistogram(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3, HandleRef jarg4, HandleRef jarg5, int jarg6, Gdal.GDALProgressFuncDelegate jarg7, string jarg8);
public static extern int Band_ComputeStatistics(HandleRef jarg1, bool jarg2, out double jarg3, out double jarg4, out double jarg5, out double jarg6, Gdal.GDALProgressFuncDelegate jarg7, string jarg8);
public static extern IntPtr Driver_CreateCopy(HandleRef jarg1, string jarg2, HandleRef jarg3, int jarg4, IntPtr[] jarg5, Gdal.GDALProgressFuncDelegate jarg6, string jarg7);
public static CPLErr ReprojectImage(Dataset src_ds, Dataset dst_ds, string src_wkt, string dst_wkt, ResampleAlg eResampleAlg, double WarpMemoryLimit, double maxerror, Gdal.GDALProgressFuncDelegate callback, string callback_data) { CPLErr ret = (CPLErr)GdalPINVOKE.ReprojectImage(Dataset.getCPtr(src_ds), Dataset.getCPtr(dst_ds), src_wkt, dst_wkt, (int)eResampleAlg, WarpMemoryLimit, maxerror, callback, callback_data); if (GdalPINVOKE.SWIGPendingException.Pending) throw GdalPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static int RegenerateOverviews(Band srcBand, int overviewBandCount, SWIGTYPE_p_p_GDALRasterBandShadow overviewBands, string resampling, Gdal.GDALProgressFuncDelegate callback, string callback_data) { int ret = GdalPINVOKE.RegenerateOverviews(Band.getCPtr(srcBand), overviewBandCount, SWIGTYPE_p_p_GDALRasterBandShadow.getCPtr(overviewBands), resampling, callback, callback_data); if (GdalPINVOKE.SWIGPendingException.Pending) throw GdalPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static int RegenerateOverview(Band srcBand, Band overviewBand, string resampling, Gdal.GDALProgressFuncDelegate callback, string callback_data) { int ret = GdalPINVOKE.RegenerateOverview(Band.getCPtr(srcBand), Band.getCPtr(overviewBand), resampling, callback, callback_data); if (GdalPINVOKE.SWIGPendingException.Pending) throw GdalPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static int RasterizeLayer(Dataset dataset, int bands, int[] band_list, OSGeo.OGR.Layer layer, IntPtr pfnTransformer, IntPtr pTransformArg, int burn_values, double[] burn_values_list, string[] options, Gdal.GDALProgressFuncDelegate callback, string callback_data) { int ret = GdalPINVOKE.RasterizeLayer(Dataset.getCPtr(dataset), bands, band_list, OSGeo.OGR.Layer.getCPtr(layer), pfnTransformer, pTransformArg, burn_values, burn_values_list, (options != null)? new GdalPINVOKE.StringListMarshal(options)._ar : null, callback, callback_data); if (GdalPINVOKE.SWIGPendingException.Pending) throw GdalPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static void PushErrorHandler(Gdal.GDALErrorHandlerDelegate arg0) { GdalPINVOKE.PushErrorHandler__SWIG_1(arg0); if (GdalPINVOKE.SWIGPendingException.Pending) throw GdalPINVOKE.SWIGPendingException.Retrieve(); }
public static extern int ContourGenerate(HandleRef jarg1, double jarg2, double jarg3, int jarg4, HandleRef jarg5, int jarg6, double jarg7, HandleRef jarg8, int jarg9, int jarg10, Gdal.GDALProgressFuncDelegate jarg11, string jarg12);
public void FindNoDataXYCoords(string filepath, string outputdir) { //returns coordinates of points below a certain value, but only if N adjacent //nodes also fall below that value. the goal is to only identify anomalous clusters //of near-0 points ('data voids') Dataset ds = Gdal.Open(filepath, Access.GA_ReadOnly); //Read raster if (ds == null) { Console.WriteLine(" [-] Could not create raster dataset from file."); Environment.Exit(1); } if (ds.RasterCount < 3) { Console.WriteLine(" [-] Need at least a three band raster image."); Environment.Exit(1); ds.Dispose(); Environment.Exit(1); } List <string> OutputCSV = new List <string>(); double[] gt = new double[6]; ds.GetGeoTransform(gt); //Read geo transform info into array int Rows = ds.RasterYSize; int Cols = ds.RasterXSize; Band redband = ds.GetRasterBand(1); Band greenband = ds.GetRasterBand(2); Band blueband = ds.GetRasterBand(3); double startX = gt[0]; //Upper left lon double startY = gt[3]; //Upper left lat double interval = gt[1]; //Cell size double x, y; //Current lon and lat string filename = Path.GetFileNameWithoutExtension(filepath); int adjacencycount = 0; int adjacencythreshold = 25; bool previousrow = false; bool isinvalid = false; int pointsoverflow = 0; for (int k = 0; k < Rows; k++) //read one line { adjacencycount = 0; y = startY - k * interval; //current lat int[][] buf = new int[3][]; buf[0] = new int[Cols]; buf[1] = new int[Cols]; buf[2] = new int[Cols]; int[] previouspixel = new int[3]; //ReadRaster parameters are StartCol, StartRow, ColumnsToRead, RowsToRead, BufferToStoreInto, BufferColumns, BufferRows, 0, 0 try { redband.ReadRaster(0, k, Cols, 1, buf[0], Cols, 1, 0, 0); greenband.ReadRaster(0, k, Cols, 1, buf[1], Cols, 1, 0, 0); blueband.ReadRaster(0, k, Cols, 1, buf[2], Cols, 1, 0, 0); } catch { if (isinvalid == false) { Console.WriteLine("Invalid compression result. Please rerun ImageChecker"); isinvalid = true; } continue; } List <List <double> > pixlists = new List <List <double> >(); bool previous = false; bool hasblackpx = false; bool existingsequence = false; int firstinrow = 1; int sequencenumber = 0; //iterate each item in one line for (int r = 0; r < Cols; r++) { bool isidentical = false; bool isdarkpixel = false; if (buf[0][r] == previouspixel[0] && buf[1][r] == previouspixel[1] && buf[2][r] == previouspixel[2]) { isidentical = true; } if (buf[0][r] <= 15 && buf[1][r] <= 15 && buf[2][r] <= 15) { isdarkpixel = true; } //if we have reached this point then no additional coordinates will be found, so might as well avoid array accesses if (r >= (Cols - adjacencythreshold) && adjacencycount < adjacencythreshold) { break; } if ((isdarkpixel || isidentical) && previous == true) { //only add pixels if they're directly adjacent //this way, you avoid all the errant little shadows that aren't actual data voids //needs reworking x = startX + r * interval; //current lon List <double> potentialresult = new List <double>(); double ydistance = Convert.ToDouble(k); double xdistance = Convert.ToDouble(r); if (previousrow == true) { potentialresult.Add(x); potentialresult.Add(y); potentialresult.Add(ydistance); potentialresult.Add(xdistance); pixlists.Add(potentialresult); } ++adjacencycount; } else { existingsequence = false; adjacencycount = 0; previous = false; if (isdarkpixel || isidentical) { previous = true; } pixlists.Clear(); } if (adjacencycount == 0) { existingsequence = false; pixlists.Clear(); } if (adjacencycount == adjacencythreshold) { hasblackpx = true; if (previousrow == true) //cuts down the # of false positives while preserving "actual" voids { List <double> firstresult = pixlists.First(); List <double> lastresult = pixlists.Last(); double firstx = firstresult[0]; double firsty = firstresult[1]; double firstrow = firstresult[2]; double firstcolumn = firstresult[3]; double lastx = lastresult[0]; double lasty = lastresult[1]; double lastrow = lastresult[2]; double lastcolumn = lastresult[3]; if (existingsequence == true) //save array space by only preserving first/last points in a contiguous sequence { //wish C# had something like pop_back()... OutputCSV.RemoveAt(OutputCSV.Count - 1); } //just in case, don't want to hit OOM if (OutputCSV.Count > 500000) { Console.WriteLine("[-] Found a lot of valid BlackPx. Please consider using -m to mask out shoreline tiles"); string overflowfile = outputdir + "\\" + filename + "_" + pointsoverflow.ToString() + ".csv"; WritePointData(overflowfile, OutputCSV); ResultCoords.csvfiles.Add(overflowfile); pointsoverflow += 1; OutputCSV.Clear(); } //edge case if (sequencenumber == Int32.MaxValue) { Console.WriteLine("[-] Found too many unique patterns. Please consider using -m to mask out shoreline tiles"); Console.WriteLine(" Reducing results size, may skew results"); ReduceXYList(OutputCSV); } if (existingsequence == false) //another optimization { sequencenumber += 1; string firstline = string.Format("{0},{1},{2},{3},{4},{5},{6}{7}", firstx, firsty, firstrow, firstcolumn, sequencenumber, firstinrow, filename, Environment.NewLine); OutputCSV.Add(firstline); } if (existingsequence == false && firstinrow == 1) { firstinrow = 0; } string lastline = string.Format("{0},{1},{2},{3},{4},{5},{6}{7}", lastx, lasty, lastrow, lastcolumn, sequencenumber, firstinrow, filename, Environment.NewLine); OutputCSV.Add(lastline); } pixlists.Clear(); adjacencycount = 0; existingsequence = true; } previouspixel[0] = buf[0][r]; previouspixel[1] = buf[1][r]; previouspixel[2] = buf[2][r]; } if (hasblackpx == true) { previousrow = true; } else { previousrow = false; } } if (OutputCSV.Any()) { string outputfile = outputdir + "\\" + filename + ".csv"; WritePointData(outputfile, OutputCSV); ResultCoords.csvfiles.Add(outputfile); } ds.Dispose(); }
public static int SieveFilter(Band srcBand, Band maskBand, Band dstBand, int threshold, int connectedness, string[] options, Gdal.GDALProgressFuncDelegate callback, string callback_data) { int ret = GdalPINVOKE.SieveFilter(Band.getCPtr(srcBand), Band.getCPtr(maskBand), Band.getCPtr(dstBand), threshold, connectedness, (options != null)? new GdalPINVOKE.StringListMarshal(options)._ar : null, callback, callback_data); if (GdalPINVOKE.SWIGPendingException.Pending) throw GdalPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static extern int Dataset_BuildOverviews(HandleRef jarg1, string jarg2, int jarg3, IntPtr jarg4, Gdal.GDALProgressFuncDelegate jarg5, string jarg6);
public CPLErr GetDefaultHistogram(SWIGTYPE_p_double min_ret, SWIGTYPE_p_double max_ret, SWIGTYPE_p_int buckets_ret, SWIGTYPE_p_p_int ppanHistogram, int force, Gdal.GDALProgressFuncDelegate callback, string callback_data) { CPLErr ret = (CPLErr)GdalPINVOKE.Band_GetDefaultHistogram(swigCPtr, SWIGTYPE_p_double.getCPtr(min_ret), SWIGTYPE_p_double.getCPtr(max_ret), SWIGTYPE_p_int.getCPtr(buckets_ret), SWIGTYPE_p_p_int.getCPtr(ppanHistogram), force, callback, callback_data); if (GdalPINVOKE.SWIGPendingException.Pending) throw GdalPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static extern int Band_GetHistogram(HandleRef jarg1, double jarg2, double jarg3, int jarg4, int[] jarg5, int jarg6, int jarg7, Gdal.GDALProgressFuncDelegate jarg8, string jarg9);
public CPLErr ComputeStatistics(bool approx_ok, out double min, out double max, out double mean, out double stddev, Gdal.GDALProgressFuncDelegate callback, string callback_data) { CPLErr ret = (CPLErr)GdalPINVOKE.Band_ComputeStatistics(swigCPtr, approx_ok, out min, out max, out mean, out stddev, callback, callback_data); if (GdalPINVOKE.SWIGPendingException.Pending) throw GdalPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static extern int ComputeMedianCutPCT(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3, int jarg4, HandleRef jarg5, Gdal.GDALProgressFuncDelegate jarg6, string jarg7);
public CPLErr GetDefaultHistogram(out double min_ret, out double max_ret, out int buckets_ret, out int[] ppanHistogram, int force, Gdal.GDALProgressFuncDelegate callback, string callback_data) { CPLErr ret = (CPLErr)GdalPINVOKE.Band_GetDefaultHistogram(swigCPtr, out min_ret, out max_ret, out buckets_ret, out ppanHistogram, force, callback, callback_data); if (GdalPINVOKE.SWIGPendingException.Pending) throw GdalPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static extern int ReprojectImage(HandleRef jarg1, HandleRef jarg2, string jarg3, string jarg4, int jarg5, double jarg6, double jarg7, Gdal.GDALProgressFuncDelegate jarg8, string jarg9);
public CPLErr GetHistogram(double min, double max, int buckets, int[] panHistogram, int include_out_of_range, int approx_ok, Gdal.GDALProgressFuncDelegate callback, string callback_data) { CPLErr ret = (CPLErr)GdalPINVOKE.Band_GetHistogram(swigCPtr, min, max, buckets, panHistogram, include_out_of_range, approx_ok, callback, callback_data); if (GdalPINVOKE.SWIGPendingException.Pending) throw GdalPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static extern int RasterizeLayer(HandleRef jarg1, int jarg2, HandleRef jarg3, HandleRef jarg4, HandleRef jarg5, HandleRef jarg6, int jarg7, HandleRef jarg8, IntPtr[] jarg9, Gdal.GDALProgressFuncDelegate jarg10, string jarg11);
/*@SWIG@*/ public int BuildOverviews( string resampling, int[] overviewlist, Gdal.GDALProgressFuncDelegate callback, string callback_data) { int retval; if (overviewlist.Length <= 0) throw new ArgumentException("overviewlist size is small (BuildOverviews)"); IntPtr ptr = Marshal.AllocHGlobal(overviewlist.Length * Marshal.SizeOf(overviewlist[0])); try { Marshal.Copy(overviewlist, 0, ptr, overviewlist.Length); retval = BuildOverviews(resampling, overviewlist.Length, ptr, callback, callback_data); } finally { Marshal.FreeHGlobal(ptr); } GC.KeepAlive(this); return retval; }
public static extern int FillNodata(HandleRef jarg1, HandleRef jarg2, double jarg3, int jarg4, IntPtr[] jarg5, Gdal.GDALProgressFuncDelegate jarg6, string jarg7);
public int BuildOverviews(string resampling, int overviewlist, IntPtr pOverviews, Gdal.GDALProgressFuncDelegate callback, string callback_data) { int ret = GdalPINVOKE.Dataset_BuildOverviews(swigCPtr, resampling, overviewlist, pOverviews, callback, callback_data); if (GdalPINVOKE.SWIGPendingException.Pending) throw GdalPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static extern int RegenerateOverview(HandleRef jarg1, HandleRef jarg2, string jarg3, Gdal.GDALProgressFuncDelegate jarg4, string jarg5);
public void StartToProcess() { GdalConfiguration.ConfigureGdal(); /* -------------------------------------------------------------------- */ /* Register driver(s). */ /* -------------------------------------------------------------------- */ Gdal.AllRegister(); /* -------------------------------------------------------------------- */ /* Open dataset. */ /* -------------------------------------------------------------------- */ List <string> tiffFiles = GetGeoTiffFiles(); foreach (string servertiffFile in tiffFiles) { string localTiffFile = GetLocalTiffFileName(Path.GetFileNameWithoutExtension(servertiffFile)); string localPngFile = GetLocalPngFileName(Path.GetFileNameWithoutExtension(servertiffFile)); string serverPngFile = servertiffFile.Replace(".tif", ".png"); DownloadGeoTiffFile(servertiffFile, localTiffFile); Dataset ds = Gdal.Open(localTiffFile, Access.GA_Update); if (ds == null) { Console.WriteLine("Can't open " + localTiffFile); throw new Exception(); } Console.WriteLine("Raster dataset parameters:"); Console.WriteLine(" Projection: " + ds.GetProjectionRef()); Console.WriteLine(" RasterCount: " + ds.RasterCount); Console.WriteLine(" RasterSize (" + ds.RasterXSize + "," + ds.RasterYSize + ")"); /* -------------------------------------------------------------------- */ /* Get driver */ /* -------------------------------------------------------------------- */ Driver drv = ds.GetDriver(); if (drv == null) { Console.WriteLine("Can't get driver."); System.Environment.Exit(-1); } Console.WriteLine("Using driver " + drv.LongName); /* -------------------------------------------------------------------- */ /* Get raster band */ /* -------------------------------------------------------------------- */ for (int iBand = 1; iBand <= ds.RasterCount; iBand++) { Band band = ds.GetRasterBand(iBand); Console.WriteLine("Band " + iBand + " :"); Console.WriteLine(" DataType: " + band.DataType); Console.WriteLine(" Size (" + band.XSize + "," + band.YSize + ")"); Console.WriteLine(" PaletteInterp: " + band.GetRasterColorInterpretation().ToString()); for (int iOver = 0; iOver < band.GetOverviewCount(); iOver++) { Band over = band.GetOverview(iOver); Console.WriteLine(" OverView " + iOver + " :"); Console.WriteLine(" DataType: " + over.DataType); Console.WriteLine(" Size (" + over.XSize + "," + over.YSize + ")"); Console.WriteLine(" PaletteInterp: " + over.GetRasterColorInterpretation().ToString()); } } /* -------------------------------------------------------------------- */ /* Processing the raster */ /* -------------------------------------------------------------------- */ //SaveBitmapBuffered(ds, localPngFile, -1); SaveBitmapGrayBuffered(ds, localPngFile, -1); UploadKmzFile(localPngFile, serverPngFile); } //string fileName = "cspp-viirs-flood-globally_20180815_080000.p153435116453720"; //string geoTiffFileName = string.Format(@"D:\Repos\GmuGeo-bak\Resources\VIIRS_floodmap_Aug15_2018\{0}.tif", fileName); //string pngFileName = string.Format(@"D:\Repos\GmuGeo\Examples\png\{0}.png", fileName); }
public int TransformGeolocations(Band xBand, Band yBand, Band zBand, Gdal.GDALProgressFuncDelegate callback, string callback_data, string[] options) { int ret = GdalPINVOKE.Transformer_TransformGeolocations(swigCPtr, Band.getCPtr(xBand), Band.getCPtr(yBand), Band.getCPtr(zBand), callback, callback_data, (options != null)? new GdalPINVOKE.StringListMarshal(options)._ar : null); if (GdalPINVOKE.SWIGPendingException.Pending) throw GdalPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static extern void PushErrorHandler__SWIG_1(Gdal.GDALErrorHandlerDelegate jarg1);