io.io_gdal — Geospatial Data Abstraction Library

The io.io_gdal and io.extract_metadata modules provide convenience wrappers to GDAL.

New in version 0.1.0.

class plio.io.io_gdal.GeoDataset(file_name)[source]

Geospatial dataset object that represents.

Parameters

file_name (str) – The name of the input image, including its full path.

base_name

The base name of the input image, extracted from the full path.

Type

str

bounding_box

The bounding box of the image in lat/lon space

Type

object

geotransform

Geotransform reference OGR object as an array of size 6 containing the affine transformation coefficients for transforming from raw sample/line to projected x/y. xproj = geotransform[0] + sample * geotransform[1] + line * geotransform[2] yproj = geotransform[3] + sample * geotransform[4] + line * geotransform[5]

Type

object

geospatial_coordinate_system

Geospatial coordinate system OSR object.

Type

object

latlon_extent

of two tuples containing the latitide/longitude boundaries. This list is in the form [(lowerlat, lowerlon), (upperlat, upperlon)].

Type

list

pixel_width

The width of the image pixels (i.e. displacement in the x-direction). Note: This is the second value geotransform array.

Type

float

pixel_height

The height of the image pixels (i.e. displacement in the y-direction). Note: This is the sixth (last) value geotransform array.

Type

float

spatial_reference

Spatial reference system OSR object.

Type

object

standard_parallels

of the standard parallels used by the map projection found in the metadata using the spatial reference for this GeoDataset.

Type

list

unit_type

Name of the unit used by the raster, e.g. ‘m’ or ‘ft’.

Type

str

x_rotation

The geotransform coefficient that represents the rotation about the x-axis. Note: This is the third value geotransform array.

Type

float

xy_extent

of two tuples containing the sample/line boundaries. The first value is the upper left corner of the upper left pixel and the second value is the lower right corner of the lower right pixel. This list is in the form [(minx, miny), (maxx, maxy)].

Type

list

xy_corners

of tuple corner coordinates in the form: [upper left, lower left, lower right, upper right]

Type

list

y_rotation

The geotransform coefficient that represents the rotation about the y-axis. Note: This is the fifth value geotransform array.

Type

float

coordinate_transformation

The coordinate transformation from the spatial reference system to the geospatial coordinate system.

Type

object

inverse_coordinate_transformation

The coordinate transformation from the geospatial coordinate system to the spatial reference system.

Type

object

scale

The name and value of the linear projection units of the spatial reference system. This tuple is of type string/float of the form (unit name, value). To transform a linear distance to meters, multiply by this value. If no units are available (“Meters”, 1) will be returned.

Type

tuple

spheroid

The spheroid found in the metadata using the spatial reference system. This is of the form (semi-major, semi-minor, inverse flattening).

Type

tuple

raster_size

The dimensions of the raster, i.e. (number of samples, number of lines).

Type

tuple

central_meridian

The central meridian of the map projection from the metadata.

Type

float

no_data_value

Special value used to indicate pixels that are not valid.

Type

float

metadata

A dictionary of available image metadata

Type

dict

footprint

An OGR footprint object

Type

object

property geotransform

Where the array is in the form: [top left x, w-e pixel resolution, x-rotation, top left y, y-rotation, n-s pixel resolution]

latlon_to_pixel(lat, lon)[source]

Convert from lat/lon space to pixel space (i.e. sample/line).

Parameters
  • lat (float) – Latitude to be transformed.

  • lon (float) – Longitude to be transformed.

Returns

x, y – (Sample, line) position corresponding to the given (latitude, longitude).

Return type

tuple

pixel_to_latlon(x, y)[source]

Convert from pixel space (i.e. sample/line) to lat/lon space.

Parameters
  • x (float) – x-coordinate to be transformed.

  • y (float) – y-coordinate to be transformed.

Returns

lat, lon – (Latitude, Longitude) corresponding to the given (x,y).

Return type

tuple

read_array(band=1, pixels=None, dtype=None)[source]

Extract the required data as a NumPy array

Parameters
  • band (int) – The image band number to be extracted as a NumPy array. Default band=1.

  • pixels (list) – [xstart, ystart, xcount, ycount]. Default pixels=None.

  • dtype (str) – The NumPy dtype for the output array. Defaults to the band dtype.

Returns

array – The dataset for the specified band.

Return type

ndarray

plio.io.io_gdal.array_to_raster(array, file_name, projection=None, geotransform=None, outformat='GTiff', ndv=None, bittype='GDT_Float64')[source]

Converts the given NumPy array to a raster format using the GeoDataset class.

Parameters
  • array (ndarray) – The data to be written via GDAL

  • file_name (str) – The output file PATH (relative or absolute)

  • projection (object) – A GDAL readable projection object, WKT string, PROJ4 string, etc. Default: None

  • geotransform (object) – A six parameter geotransformation Default:None.

  • outformat (str) – A GDAL supported output format Default: ‘GTiff’.

  • ndv (float) – The no data value for the given band. Default: None.

  • bittype (str) – A GDAL supported bittype, e.g. GDT_Int32 Default: GDT_Float64