Hot answers tagged

11

Honestly it's easier to do this by using gdalbuildvrt in a subprocess or os.system. Should you wish to do this through Python it can be done. Using the standard dataset creation methods within GDAL Python we can easily create the base dataset VRT. from osgeo import gdal drv = gdal.GetDriverByName("VRT") vrt = drv.Create("test.vrt", x_size, y_size, 0) ...


11

I love processing with vrt's. you can make lots of interim changes. Evaluate them quickly in QGIS and if you like any of them just translate back to a selfcontained raster format (tif, png etc). saves lots of time. U2ros,your uses of vrt's makes perfect sense, to me at least :) mosaicking and then clipping is what I originally started using vrts for: ...


11

The answer of @rcoup only worked for me, if modify it as follows: from osgeo import gdal vrt_options = gdal.BuildVRTOptions(resampleAlg='cubic', addAlpha=True) my_vrt = gdal.BuildVRT('my.vrt', ['one.tif', 'two.tif'], options=vrt_options) my_vrt = None Otherwise, the file is not written to disk.


9

Since GDAL 2.1 the CLI tools are available as library functions, and in fact that's what the CLI tools now call internally. For example: gdalbuildvrt -r cubic -addalpha my.vrt one.tif two.tif Is the equivalent of: from osgeo import gdal vrt_options = gdal.BuildVRTOptions(resampleAlg='cubic', addAlpha=True) gdal.BuildVRT('my.vrt', ['one.tif', 'two.tif'], ...


8

It depends mostly on which is the minimun scale to show your image layer. Creating overviews for individual rasters is more flexible when you update your layer partially. Just delete old image and put a new image with overviews in place. If you have build overviews for the .vrt you must create it again after update. However, individual overviews do not work ...


7

You don't have to use a .vrt any more. ogr2ogr supports reading csv files with geometry directly since version 2.1. The ogr2ogr command: ogr2ogr -f "PostgreSQL" PG:"host=000.000.000.000 port=0000 dbname=myDB user=me password=youtellme" -s_srs EPSG:4326 -t_srs EPSG:3857 -progress -nln output -lco OVERWRITE=YES -lco GEOMETRY_NAME=shape -oo X_POSSIBLE_NAMES=...


6

First of all, I don't think that gdalbuildvrt will do exactly what you want with the "-separate" option : the stacked file will be a layer of N bands containing each individual image in one of those bands. Concerning your syntax, I would write : gdalbuildvrt -separate -input_file_list inputlist.txt stack.vrt In python, I usually call gdal directly ...


6

You can solve with two chained VRT files and a bit of OGR SQL. The first VRT (e.g. remapped_csv.vrt) is: <OGRVRTDataSource> <OGRVRTLayer name="remapped_csv"> <SrcDataSource>test.csv</SrcDataSource> <SrcSQL>SELECT *, SUBSTR(latlon,2,5) AS lat, SUBSTR(latlon,9,12) AS lon FROM test</SrcSQL> </...


6

Depending on where you create the VRT, it will either become a relative path, or an absolute path. You can manually set this, by modifying the relativeToVRT="1"to a 0, and then write a complete path in the instead of just the image filename. See the example below of a full path VRT. <VRTRasterBand dataType="Byte" band="1"> <ColorInterp>...


6

The best solution for you would be the VSIMEM filesystem which lets you save outputs of gdal utilities into a filesystem stored in memory. gdal.Warp('/vsimem/reprojected.tif', ds, srsSRS=in_proj, dstSRS=out_proj) You could also make a vrt: gdal.Warp('/vsimem/reprojected.vrt', ds, srsSRS=in_proj, dstSRS=out_proj) Once stored in the vsimem filesystem, the ...


6

It is better that you consult the Soilgrids FAQ mainly the section How can I download Soilgrids the webdav download describes what are the vrt and ovr files. vrt is a virtual XML file that points to tiles creating a mosaic that behaves like a single file, therefore if you copy only the vrt to your computer you will not get anything, ovr are overviews of ...


5

No, this does not make sense. VRT is Virtual Raster Type, not a real raster. There is no data in a VRT, the data is just referenced in an XML file. You have to keep the original data. <SourceFilename relativeToVRT="1">utm.tif</SourceFilename> See here for documentation. VRT's make sense for e.g. mosaicing, merging, cutting, converting files ...


4

Have you tried it sucessfully with a handfull of files? For me, it worked with 300 files. At first, I had to build individual vrts for each image to expand the colour information to rgba: for %%N in (D:\Karten\gdal\gdal2tiles\NL25\*.tif) DO gdal_translate -of vrt -expand rgba %%N D:\Karten\gdal\gdal2tiles\NL25\%%~nN.vrt Second run, I merged all those vrts ...


4

Not sure if it helps you, but this was my workflow to tile 2GB of 300 Dutch Topo maps to OSM compatible zoomlevel 15 and 16: Create vrts for each tif and expand indexed colours to RGBA: for %%N in (D:\Karten\gdal\gdal2tiles\NL25*.tif) DO gdal_translate -of vrt -expand rgba %%N D:\Karten\gdal\gdal2tiles\NL25\%%~nN.vrt Create an index vrt for all files: ...


4

Convert the file to WGS84 gdalwarp in_test.vrt out_test.vrt -t_srs "+proj=longlat +ellps=WGS84" Calcualte the bbox with GDAL in Python import gdal ds = gdal.Open('out_test.vrt') cols = ds.RasterXSize rows = ds.RasterYSize geotransform = ds.GetGeoTransform() bb1 = originX = geotransform[0] bb4 = originY = geotransform[3] pixelWidth = geotransform[1] ...


4

I'm afraid it is a typo in the first line. Try: <OGRVRTDataSource> <OGRVRTLayer name="grid"> <SrcDataSource>grid.csv</SrcDataSource> <GeometryType>wkbPoint25D</GeometryType> <LayerSRS>WGS84</LayerSRS> <GeometryField encoding="PointFromColumns" x="x" y="y" z="z"/> &...


4

If you want to work with GDAL on command line, you have to change your input file to comma delimiters: X,Y -5.48,42.81 -4.78,42.52 -5.06,42.02 The appropriate vrt file for it is: <OGRVRTDataSource> <OGRVRTLayer name="test"> <SrcDataSource>test.csv</SrcDataSource> <GeometryType>wkbPoint</GeometryType> ...


4

More info about gdal.Grid() and gdal.GridOptions() are available in the GDAL/OGR Python API. Instead, here's the available options of the interpolation algorithms. About the linear approach, this line (and more in detail the algorithm options 'linear:radius=0'): output = gdal.Grid('outcome.tif','newpoints.vrt', algorithm = 'linear:radius=0') returns always ...


4

Sounds like you'd want to use the image mosaic plugin: http://docs.geoserver.org/stable/en/user/data/raster/imagemosaic/index.html The configuration of the mosaic can be scary, but if all you want is to merge all the images together visually, then put them in a directory and just point the GeoServer image mosaic at it with no other setups, it should self-...


4

You are probably looking at estimated values. Check under layer properties, Symbology tab if Actual Accuracy is selected: Virtual raster is basically just list of rasters, when creating it original data does not get altered, just referenced.


3

VRT can be used cross platform (if you are using relative paths and you place in the same directory as the images, otherwise the path names are not the same) and read it with ArcGIS. It is also easy to read what you have in it. It is great for processing large collections of coherent non overlapping images (lazy computation at its best) RMD has a set of ...


3

From the CSV driver documentation: Starting with GDAL 1.8.0, for files structured as CSV, but not ending with .CSV extension, the 'CSV:' prefix can be added before the filename to force loading by the CSV driver. Either rename DGM5_BE.txt to DGM5_BE.csv or change the <SrcDataSource> element to: <SrcDataSource>CSV:DGM5_BE.txt</...


3

I suggest that you build you vrt at the first stage, so that you only process what you need. See this post about lazy computation. You could also get some inspiration from this post aboutPython function for pixels. But my last recommendation is to use Orfeo Toolbox (an open source software). You can do both steps with the Band math filter application (a ...


3

No, you can't use VRT as an output format for gdal_calc.py. gdal_calc.py reads raster data into numpy arrays, performs the requested calculation and writes the resulting numpy array out to a raster file on disk. In future, you should be be able to create a VRT with the calculation required to derive it using python code embedded in the VRT. See this GDAL-...


3

To perform the conversion to GeoTIFF: gdal_translate in.vrt out.tif See the gdal_translate help and the GeoTIFF driver documentation for various other arguments and config options to control the conversion, such as whether to compress the output. For stacking, look at gdalbuildvrt. Something like: gdalbuildvrt -separate stacked.vrt [in vrts or rasters] ...


3

I think the most likely reason for the different behavior is related to when and how the data is accessed. In the case of the TIF, there is essentially a TIF-access pointer that is being shared between processes/threads. The reading of information from thread A interferes with thread B that is also trying to read data using the same in-memory interface. ...


3

If you find a way to create GeoTIFF files which cover the whole VRT area with pixel sizes matching the overview levels 128, 256, and 512 you can point the VRT file to use them as overviews https://gdal.org/drivers/raster/vrt.html Overview: This optional element describes one overview level for the band. It should have a child SourceFilename and ...


3

BuildVRT can take a list of files as it's 2nd (source) parameter so you need to find all the files that match your date (using a full path) and pass that list to the function. So something like: for day in dates: f = [file for file in rasters if rasters.contains(day)] my_vrt = gdal.BuildVRT(out_vrt+name, f)


3

Read the documentation of VRT https://gdal.org/drivers/raster/vrt.html and add color table. Step by step example: Create test image with gdal_create https://gdal.org/programs/gdal_create.html#gdal-create. Utility is included in GDAL version 3.2 and higher. gdal_create -of GTiff -outsize 10 10 -bands 1 -burn 2 -ot Float32 float_gray.tif Create a VRT from ...


2

Andre Joost had the correct answer in his last statement. Its a character limit. If you use the wildcard it runs fine. I just tried on 28000 tiffs and it ran no problem.


Only top voted, non community-wiki answers of a minimum length are eligible