/// <summary> /// Build a contour vector layer /// </summary> /// <param name="InputRaster"></param> /// <param name="OutputShp">output shapefile</param> /// <param name="ContoutInterval">increment balue (from CotourBase) to create contour</param> /// <param name="ContourBase">initial value to compute contour</param> public static void Contour(string InputRaster, string OutputShp, double ContourInterval, double ContourBase) { // https://gis.stackexchange.com/questions/210500/calling-gdal-contour-from-python-ipython using (var dsc = Gdal.Open(InputRaster, Access.GA_ReadOnly)) { var band = dsc.GetRasterBand(1); // Generate layer to save Contourlines in using (var ogr_ds = Ogr.GetDriverByName("ESRI Shapefile").CreateDataSource(OutputShp, new string[] { "srs", dsc.GetProjection() })) { var srs = new OSGeo.OSR.SpatialReference(dsc.GetProjection()); var contour_shp = ogr_ds.CreateLayer("contour", srs, wkbGeometryType.wkbLineString, null); contour_shp.CreateField(new FieldDefn("ID", FieldType.OFTInteger), 1); contour_shp.CreateField(new FieldDefn("ELEVATION", FieldType.OFTReal), 2); //Generate Contour lines Gdal.ContourGenerate(band, ContourInterval, ContourBase, 0, null, 0, -9999.9, contour_shp, contour_shp.FindFieldIndex("ID", 0), contour_shp.FindFieldIndex("ELEVATION", 0), GDalProgress, string.Empty); } } }