More

How to change the raster format using QGIS translate?

How to change the raster format using QGIS translate?


I tried to change a raster format from .tiff to .asc using Qgis's 'translate'.

As a result, I get 3 files: a PRJ, XML and a file without extension just a plain file…

What could it be happening? I used the same tool for a bunch of raster previously and it worked…


Seems ok for me.

In the QGIS input form, you have given a file name for the asc file. In most cases, the default file extension will be added, but this dialogue does not do it. I suggest to enter the extension always manually in this input box.

The prj file contains the projection information (same as for shapefiles), while the xml contains other metadata that was stored in the tif, but can not be written in asc format.


Feature to Raster

Any feature class (geodatabase, shapefile, or coverage) containing point, line, or polygon features can be converted to a raster dataset.

The input field type determines the type of output raster. If the field is integer, the output raster will be integer if it is floating point, the output will be floating point.

This tool always uses the cell center to decide the value of a raster pixel. If more control over how different types of input feature geometries are to be converted, refer to the respective specific conversion tools: Point to Raster , Polyline to Raster , and Polygon to Raster .

This tool is a complement to the Raster to Point , Raster to Polyline , and Raster to Polygon tools, which convert a raster to different types of feature dataset geometries.

When selecting the input feature data, the default field will be the first valid field available. If no other valid fields exist, the ObjectID field (for example, OID or FID ) will be the default.

Certain Raster storage environments may apply to this tool.

For the Pyramid environment settings, only the Build pyramids setting is honored. The remaining Pyramid environment settings are ignored. More control over the nature of the pyramids can be obtained in a subsequent step by using the Build Pyramids tool.

For the Compression environment settings, only the type of compression may be honored. This is only for raster formats other than Esri Grid.


1 Answer 1

The raster package has excellent facilities for reading and writing gridded data in many different formats, and for performing a huge variety of manipulations on such data.

Using it, the basic workflow in your case (for a single file) might be something like this:

The package is well documented. I'd suggest starting with ?"raster-package" and vignette(Raster) (plus all of the help files listed in help(package="raster") ), and then coming back here if you run into serious roadblocks.


3.9.2 Working with raster data

To open an existing raster file in GDAL, you would use the Open(. ) function defined in the gdal module. The raster file we will use in the following examples contains world-wide bioclimatic data and will be used again in the lesson’s walkthrough. Download the raster file here.

We now have a GDAL raster dataset in variable raster. Raster datasets are organized into bands. The following command shows that our raster only has a single band:

To access one of the bands, we can use the GetRasterBand(. ) method of a raster dataset and provide the number of the band as a parameter (counting from 1, not from 0!):

If your raster has multiple bands and you want to perform the same operations for each band, you would typically use a for-loop to go through the bands:

There are a number of methods to read different properties of a band in addition to GetMetadata() used in the previous example, such as GetNoDataValue(), GetMinimum(), GetMaximum(), andGetScale().

GDAL provides a number of operations that can be employed to create new files from bands. For instance, the gdal.Polygonize(. ) function can be used to create a vector dataset from a raster band by forming polygons from adjacent cells that have the same value. To apply the function, we first create a new vector dataset and layer in it. Then we add a new field ‘DN’ to the layer for storing the raster values for each of the polygons created:

Once the shapefile is prepared, we call Polygonize(. ) and provide the band and the output layer as parameters plus a few additional parameters needed:

With the None for the second parameter we say that we don’t want to provide a mask for the operation. The 0 for the fourth parameter is the index of the field to which the raster values shall be written, so the index of the newly added ‘DN’ field in this case. The last parameter allows for passing additional options to the function but we do not make use of this, so we provide an empty list. The second line "outfile = None" is for closing the new shapefile and making sure that all data has been written to it. The result produced in the new shapefile rasterPolygonized.shp should look similar to the image below when looked at in a GIS and using a classified symbology based on the values in the ‘DN’ field.

Polygonize(. ) is an example of a GDAL function that operates on an individual band. GDAL also provides functions for manipulating raster files directly, such as gdal.Translate(. ) for converting a raster file into a new raster file. Translate(. ) is very powerful with many parameters and can be used to clip, resample, and rescale the raster as well as convert the raster into a different file format. You will see an example of Translate(. ) being applied in the lesson’s walkthrough. gdal.Warp(. ) is another powerful function that can be used for reprojecting and mosaicking raster files.

While the functions mentioned above and similar functions available in GDAL cover many of the standard manipulation and conversion operations commonly used with raster data, there are cases where one directly wants to work with the values in the raster, e.g. by applying raster algebra operations. The approach to do this with GDAL is to first read the data of a band into a GDAL multi-dimensional array object with the ReadAsArray() method, then manipulate the values in the array, and finally write the new values back to the band with the WriteArray() method.

If you look at the output of this code, you will see that the array in variable data essentially contains the values of the raster cells organized into rows. We can now apply a simple mathematical expression to each of the cells, like this:

The meaning of this expression is to create a new array by multiplying each cell value with 0.1. You should notice the change in the output from +308 to +307. The following expression can be used to change all values that are smaller than 0 to 0:

data.min() in the previous example is used to get the minimum value over all cells and show how this changes to 0 after executing the second line. Similarly to what you saw with pandas data frames in Section 3.8.6, an expression like data < 0 results in a Boolean array with True for only those cells for which the condition <0 is true. Then this Boolean array is used to select only specific cells from the array with data[. ] and only these will be changed to 0. Now, to finally write the modified values back to a raster band, we can use the WriteArray(. ) method. The following code shows how one can first create a copy of a raster with the same properties as the original raster file and then use the modified data to overwrite the band in this new copy:

This approach will not change the original raster file on disk. Instead of writing the updated array to a band of a new file on disk, we can also work with an in-memory copy instead, e.g. to then use this modified band in other GDAL operations such as Polygonize(. ) . An example of this approach will be shown in the walkthrough of this lesson. Here is how you would create the in-memory copy combining the driver creation and raster copying into a single line:

The approach of using raster algebra operations shown above can be used to perform many operations such as reclassification and normalization of a raster. More complex operations like neighborhood/zonal based operators can be implemented by looping through the array and adapting cell values based on the values of adjacent cells. In the lesson’s walkthrough you will get to see an example of how a simple reclassification can be realized using expressions similar to what you saw in this section.

While the GDAL Python package allows for realizing the most common vector and raster operations, it is probably fair to say that it is not the most easy-to-use software API. While the GDAL Python cookbook contains many application examples, it can sometimes take a lot of search on the web to figure out some of the details of how to apply a method or function correctly. Of course, GDAL has the main advantage of being completely free, available for pretty much all main operating systems and programming languages, and not tied to any other GIS or web platform. In contrast, the Esri ArcGIS API for Python discussed in the next section may be more modern, directly developed specifically for Python, and have more to offer in terms of visualization and high-level geoprocessing and analysis functions, but it is tied to Esri’s web platforms and some of the features require an organizational account to be used. These are aspects that need to be considered when making a choice on which API to use for a particular project. In addition, the functionality provided by both APIs only overlaps partially and, as a result, there are also merits in combining the APIs as we will do later on in the lesson’s walkthrough.


Your Answer


StackExchange.ready(function() <
var channelOptions = <
tags: "".split(" "),
id: "79"
>
initTagRenderer("".split(" "), "".split(" "), channelOptions)

StackExchange.using("externalEditor", function() <
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) <
StackExchange.using("snippets", function() <
createEditor()
>)
>
else <
createEditor()
>
>)

function createEditor() <
StackExchange.prepareEditor( <
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: <
brandingHtml: "Powered by u003ca href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
>,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
>)

Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Pyramids

If images have more than about 2,000 rows and columns, it is advantageous to create pyramids. Pyramids are reduced-resolution versions of the imagery that enable faster access at a smaller scale.

Pyramids can be internal to the files or external in the form of .ovr files or .rrd files. The creation of external overviews has the advantage that the original files are not modified, and if necessary, they can be easily removed to reduce space.

The simplest method to create pyramids in ArcGIS on existing data is to use the Build Pyramids And Statistics tool. This creates pyramids for all rasters within a given workspace.

Pyramids are stored in a single file that generally resides next to the source rasters. They will be given the same name as the source, with an *.ovr extension. Internally, these are actually TIFF files created with multiple 2:1 downsampled resolutions. ArcGIS also supports TIFF files with internal pyramids and older .rrd pyramids.

In most cases, pyramids can be compressed even if the original data sources contain no compressed data, since analysis is typically not performed on the pyramids of files. If the data source and pyramids are not compressed, the pyramids will take one-third additional storage space. If the source is not compressed and the pyramids are compressed, the additional storage can be as small as a few percent of the original size. If the original data is compressed, then even if using the same compression as the source, the overviews may be about 40 percent of the source due to the higher frequency of image content typically in the overviews, which means that compression is less.

When creating pyramids, there are environmental variables that control how they are generated. These include the following:

Compression method (pyramids)

In most cases it is suitable to compress the overviews. For natural color 3-band imagery, JPEG YCBCR is recommended. For panchromatic or other imagery, JPEG is recommended. For elevation or categorical data, LZW is recommended. Typically, the compression factor for JPEG can be set to 80. Note that even if the imagery is 16-bit (such as common satellite imagery), JPEG YCBCR or JPEG (RGB) can be used, since ArcGIS supports a 12-bit version of JPEG that is generally suitable for such imagery.

For optical imagery, it is advisable to use bilinear sampling, since this generally provides better-quality imagery when viewed at smaller scales. However, bilinear sampling can result in artifacts at the edges of images that include black (or white) pixels that may be used to define NoData. ArcGIS will correctly handle such NoData pixels and will not create the artifacts if the NoData pixels are correctly defined in the dataset. Therefore, for imagery that does have NoData values, it is recommended that the NoData values are defined prior to creating the pyramids.

For categorical data, the nearest (or majority) sampling method should be used. For datasets such as elevation, more careful consideration needs to be taken as to what sampling method is used, but in most cases bilinear is still recommended. Note that using nearest sampling with a factor of 2 will result in a half-pixel shift at each overview level due to alignment of the image extents. If nearest neighbor sampling is required, it is generally better to set the sampling factor to 3 to avoid such shifts, although this can affect the performance at smaller scales by about 20 percent.


Intermediate QGIS: Beyond the Basics +

(ONLINE CLASS) By completing this workshop, students will learn to use some advanced tools and recently added features in QGIS to analyze spatial data and create cool maps. The workshop will include interactive activities to guide you through QGIS skills. It will also include time to analyze data of your choice, and create visuals to communicate your results.

This workshop is designed for students with some prior QGIS experience. If you're looking to start with QGIS from the beginning, check out the QGIS Quick Start workshop above.

  • Early Registration: $180
  • Full/Late Registration: $198
  • BayGeo Member: $158.40
  • Three dates: TBD

Exporting GRASS maps to GMT

(Supplied by the GRASS Users Group of Davis, California)

Currently there are several *.out.GMT permutations on the Add-ons page, in several different languages (bash, python, etc.), and each of which with relative pros/cons. An effort to unify these approaches would save much of the current difficulties in moving complex raster+vector data into a GMT-friendly format. A simple road map toward this goal is outlined below.

  • v.out.gmt - Vector export for GMT (rewrite to use new OGR r/w support?)
  • r.out.gmt - Raster export for GMT
  • r.out.gmt2 - Raster export for GMT (updated version of the previous one)


To aid custom scripting, g.region in GRASS 6.5+ supports the -t flag to output the current region in GMT's W/E/S/N region format. Both GMT and GRASS support the D:M:Sh notation for latitude and longitude.

Vector

There is currently an effort (with some funding!), see some of the chatter on the GRASS and GMT mailing lists: GRASS-list GMT-help

  • OGR now supports GMT vector (multiline) output, so it is easy to convert data to GMT format for plotting. Use the v.out.ogr module.
  • If outputting areas be sure to explicitly request them, otherwise data attributes may not be transfered. The -c flag limits the export to areas with a centroid (i.e. so holes don't get filled)

Examples

Export and plot areas

Export area vectors from a non-geographic (projected) location. Uses the "trn_sites" map from the Spearfish sample dataset.

If exporting lat/lon data you might skip the rounding outwards hack shown above and change the psxy options as follows:

See GMT's psxy, psbasemap, and gmtdefaults man pages for further details.

Export a vector containing lines:

GMT commands are same as above, but add the -K flag the first time you run psxy to keep the PostScript file open, then the second time you run psxy you can simplify the options a bit and give it the -O flag to tell it that this layer will be an overlay, not a new map. Then append (>> instead of >) to the end of the existing PostScript file.

The above sets the border as follows:

Raster

A combination of r.out.bin | xyz2grd can accomplish this. Several attempts at generalizing this procedure have been proposed: r.out.gmt.py, r.out.gmt (Hamish and Dylan), r.out.gmt2 (Huidae's upgraded version of r.out.gmt), r.out.gmt.sh (Dylan, based Hamish's work).

For multiband imagery data, the following commands will export the different colour bands:

They can then be plotted with:

Examples

Export a raster and overlay lines

This example uses the Spearfish dataset (UTM projection). For the grdimage command the =bs after the .grd filename instructs GMT to expect a classic-GMT format integer grid file (for a CELL map) change it to =bf for a FCELL or r.out.gmt-exported DCELL map. (see the grdreformat man page for a list of two-letter codes).

Coloring

David Finlayson's r.out.gmt.py does a nice job of this. Once we decide on an optimal language to implement the routines in this may need translation.

Symbology

  • GMT has its own symbol symbol format, specified here.
  • To use GMT's .def symbols in GRASS probably it is easier to render them with d.graph or hack into a simple postscript file and plot the .eps with ps.map.
  • Automatic conversion of symbology data stored in a gis.m or QGIS saved state to GMT options

Development plans

Since GMT relies on a sequence of specialized programs to "build-up" a postscript file, some thought must be put into how the conversion should take place. As usual, form should follow function- maximum flexibility, robustness, and accuracy being primary objectives. However, a simple means of creating high quality 2D maps would be a tremendous (I think) addition to the GRASS toolset. Especially since this is something frequently cited by critics. --DylanBeaudette 02:47, 10 December 2006 (CET)


Convert Shapefile SHP to DXF

  • Go to IGIS Map Tool login with registered email id and password or register if you are new user.
  • After that you will directed to the dashboard of tool. Tap on Switch To button on the right hand side of the screen and select the Converter from the drop down list.

  • In the next screen Upload your shapefile using three options first is drag & drop or browse from the system, 2nd is upload from google drive and third option is drop from Dropbox.

**If you are GIS student and looking for GIS data then Download Shapefile free.

  • After upload next step is of selecting the desired output and you alter the CRS (Coordinate Refernce System). After selecting all fields tap on Convert File.

You can style your map using IGIS Map Tool it supports following formats

  • Vector File: Shapefile (with shp, shx, dbf, prj etc), KML, KMZ, GeoJSON, Topojson, GML, GPX, GPS, GPKG, MAPINFO, SQLITE, DXF, MID, MIF, CSV, XLSX
  • Raster File: Geotiff (.geotiff, .tiff, .tif), Netcdf, HDF5, HDF, GRIB2

If you are facing any problem in conversion or login then please let us know by mailing at [email protected] or drop comment.


Knowledge Base

We recommend using the Geospatial Data Abstraction Library (GDAL) to convert GeoTIFF files into a different format. If you want to reproject to lat/lon as well, then we recommend reprojecting before converting to NetCDF (see the FAQ "How do I reproject a GeoTIFF to from polar steroegraphic to geographic lat/lon?"). Here, we outline command line and python options for using GDAL to convert GeoTIFF files into NetCDF format.

GDAL in the command line

  1. You will need to have GDAL already installed. If you need to install it, then further details can be found at https://gdal.org.
  2. Open a terminal/command prompt and navigate to the folder where the file that you want to convert is.
  3. Run the following command in the command line:

gdal_translate -of NetCDF <input filename> <output filename>

For example, if you wanted to convert 'Greenland_vel_moasic_250_vy_v1.tif to a netCDF file:

gdal_translate -of NetCDF Greenland_vel_mosaic_250_vy_v1.tif Greenland_vel_mosaic_250_vy_v1.nc


Watch the video: How to convert Lat Long to UTM Easting,Northing. by QGIS Software English