Reading and writing raster data using GDAL

Here are some commands for reading and writing raster data with GDAL:

In: !gdalinfo --formats

This command lists all supported file formats in GDAL. For a summary including the CRS, use !gdalinfo without any prefixes:

In: !gdalinfo "C:datagdalNE50m_rasterNE1_50M_SR_W
NE1_50M_SR_W.tif"

Out: Driver: GTiff/GeoTIFF
Files: C:datagdalNE50m_rasterNE1_50M_SR_WNE1_50M_SR_W.tif Size is 10800, 5400 Coordinate System is: GEOGCS["WGS 84", DATUM["WGS_1984", ...

You can convert a GeoTIFF to a JPEG file as follows:

In: !gdal_translate -of JPEG 
"C:datagdalNE50m_rasterNE1_50M_SR_WNE1_50M_SR_W.tif"
NE1_50M_SR_W.jpg

Out: Input file size is 10800, 5400 0...10...20...30...40...50...60...70...80...90...100 - done.

The output, NE1_50M_SR_W.jpg, will look like this:

Now, let's open a GeoPackage using GDAL. GeoPackages can be either vector or raster-based, but in this case, we'll open a raster-based one, which becomes clear from the following output. For reading and writing GeoPackages, we need GDAL version 2.2.2, so the following example won't work for lower version numbers. Download the following GeoPackage file (http://www.geopackage.org/data/gdal_sample_v1.2_no_extensions.gpkg) and reference it as follows:

In: !gdalinfo                                                             
"C:UsersUserNameDownloadsgdal_sample_v1.2_no_extensions.gpkg"

Out: Driver: GPKG/GeoPackageFiles:
C:UsersUserNameDownloadsgdal_sample_v1.2_no_extensions.gpkg
Size is 512, 512
Coordinate System is''
...

 

The GDAL Web Map Service (WMS) driver allows for interacting with online web mapping services. You can use it to download various geospatial datasets, subsets, or information about available datasets directly from a command prompt (or in this case, a Jupyter Notebook) without using a browser to navigate to a website and download data manually. There are many different options, so refer to the online documentation for more information. The following example requires GDAL version 2.0 or higher. The following command uses the URL of a REpresentational State Transfer (REST) definition for an ArcGIS MapServer and returns the information about the requested image service, such as the amount of bands, band names, CRS, corner coordinates, and more:

In: !gdalinfo http://server.arcgisonline.com/ArcGIS/rest/services/
World_Imagery/MapServer?f=json&pretty=true

Note that you added some information to the URL of the image service, in this case, f=json&pretty=true. This means the requested file format by the user is pretty json, which is a nicely formatted json that is easier to read for humans.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset