pygmi.vector.dataprep#

Data Preparation for Vector Data.

Classes#

PointCut

GUI to cut data using shapefiles.

DataGrid

GUI to grid point data.

DataReproj

GUI to reproject vector data.

Metadata

GUI to display and edit vector metadata.

TextFileSplit

GUI to split a text file into smaller text files.

Functions#

blanking(gdat, x, y, bdist, extent, dxy, nullvalue)

Blanks area further than a defined number of cells from input data.

cut_point(data, ifile[, showlog])

Cuts a point dataset.

txtlinecnt(filename)

Count lines in text file.

filesplit(ifile, num[, mode, showlog, piter])

Split an input file into a number of output files.

gridxyz(x, y, z, dxy, *[, nullvalue, method, bdist, ...])

Grid xyz data.

lltomap(lat, lon)

Convert a latitude and longitude to a 1:50,000 sheet name.

maptobounds(mapsheet[, crs_to, showlog])

Convert a South African map sheet name to bounds.

maptovector(maplist)

Create a vector layer from map numbers.

quickgrid(x, y, z, dxy, *[, numits, showlog])

Do a quick grid.

reprojxy(x, y, iwkt, owkt[, showlog])

Reproject x and y coordinates.

Module Contents#

class pygmi.vector.dataprep.PointCut(parent=None)#

Bases: pygmi.misc.BasicModule

GUI to cut data using shapefiles.

This class cuts point datasets using a boundary defined by a polygon shapefile.

Parameters:

parent (parent, optional) – Reference to the parent routine. The default is None.

settings(nodialog=False)#

Entry point into item.

Parameters:

nodialog (bool, optional) – Run settings without a dialog. The default is False.

Returns:

True if successful, False otherwise.

Return type:

bool

saveproj()#

Save project data from class.

Return type:

None.

class pygmi.vector.dataprep.DataGrid(parent=None)#

Bases: pygmi.misc.BasicModule

GUI to grid point data.

This class grids point data using a nearest neighbourhood technique.

Parameters:

parent (parent, optional) – Reference to the parent routine. The default is None.

setupui()#

Set up UI.

Return type:

None.

dxy_change()#

When dxy is changed on the interface, this updates rows and columns.

Return type:

None.

grid_method_change()#

When grid method is changed, this updated hidden controls.

Return type:

None.

settings(nodialog=False)#

Entry point into item.

Parameters:

nodialog (bool, optional) – Run settings without a dialog. The default is False.

Returns:

True if successful, False otherwise.

Return type:

bool

saveproj()#

Save project data from class.

Return type:

None.

acceptall()#

Accept option.

Updates self.outdata, which is used as input to other modules.

Return type:

None.

class pygmi.vector.dataprep.DataReproj(parent=None)#

Bases: pygmi.misc.BasicModule

GUI to reproject vector data.

This class reprojects datasets using the GeoPandas routines.

Parameters:

parent (parent, optional) – Reference to the parent routine. The default is None.

setupui()#

Set up UI.

Return type:

None.

acceptall()#

Accept option.

Updates self.outdata, which is used as input to other modules.

Return type:

None.

settings(nodialog=False)#

Entry point into item.

Parameters:

nodialog (bool, optional) – Run settings without a dialog. The default is False.

Returns:

True if successful, False otherwise.

Return type:

bool

saveproj()#

Save project data from class.

Return type:

None.

class pygmi.vector.dataprep.Metadata(parent=None)#

Bases: pygmi.misc.ContextModule

GUI to display and edit vector metadata.

This class allows the editing of the metadata for a vector dataset using a GUI.

Parameters:

parent (parent, optional) – Reference to the parent routine. The default is None.

banddata#

band data

Type:

dictionary

bandid#

dictionary of strings containing band names.

Type:

dictionary

setupui()#

Set up UI.

Return type:

None.

acceptall()#

Accept option.

Return type:

None.

run()#

Entry point into the routine, used to run context menu item.

Returns:

tmp – True if successful, False otherwise.

Return type:

bool

class pygmi.vector.dataprep.TextFileSplit(parent=None)#

Bases: pygmi.misc.BasicModule

GUI to split a text file into smaller text files.

Parameters:

parent (parent, optional) – Reference to the parent routine. The default is None.

setupui()#

Set up UI.

Return type:

None.

change_method()#

Update fields when method changes.

get_ifile()#

Get input file information.

Return type:

None.

settings(nodialog=False)#

Entry point into item.

Parameters:

nodialog (bool, optional) – Run settings without a dialog. The default is False.

Returns:

True if successful, False otherwise.

Return type:

bool

saveproj()#

Save project data from class.

Return type:

None.

acceptall()#

Accept option.

Updates self.outdata, which is used as input to other modules.

Return type:

None.

pygmi.vector.dataprep.blanking(gdat, x, y, bdist, extent, dxy, nullvalue)#

Blanks area further than a defined number of cells from input data.

Parameters:
  • gdat (numpy array) – grid data to blank.

  • x (numpy array) – x coordinates.

  • y (numpy array) – y coordinates.

  • bdist (int) – Blanking distance in units for cell.

  • extent (list) – extent of grid.

  • dxy (float) – Cell size.

  • Nullvalue (float) – Null or nodata value.

Returns:

mask – Mask to be used for blanking.

Return type:

numpy array

pygmi.vector.dataprep.cut_point(data, ifile, showlog=print)#

Cuts a point dataset.

Cut a point dataset using a shapefile.

Parameters:
  • data (GeoDataFrame) – GeoPandas GeoDataFrame

  • ifile (str) – shapefile used to cut data

Returns:

data – GeoPandas GeoDataFrame

Return type:

GeoDataFrame

pygmi.vector.dataprep.txtlinecnt(filename)#

Count lines in text file.

Parameters:

filename (str) – filename of text file.

Returns:

Total number of lines in a file.

Return type:

int

pygmi.vector.dataprep.filesplit(ifile, num, mode='bytes', showlog=print, piter=None)#

Split an input file into a number of output files.

Parameters:
  • ifile (str) – Input filename.

  • num (int) – Number of bytes or lines to split by.

  • mode (str, optional) – Can be ‘bytes’, ‘files’ or ‘lines’. The default is ‘bytes’.

  • showlog (function, optional) – Display information. The default is print.

  • piter (iter, optional) – Progress iterator. The default is None.

Return type:

None.

pygmi.vector.dataprep.gridxyz(x, y, z, dxy, *, nullvalue=1e+20, method='Nearest Neighbour', bdist=4.0, showlog=print)#

Grid xyz data.

Parameters:
  • x (numpy array) – X coordinate values.

  • y (numpy array) – Y coordinate values.

  • z (numpy array) – Z or data values.

  • dxy (float) – Grid cell size, in distance units.

  • nullvalue (float, optional) – null or nodata value. The default is 1e+20.

  • method (str, optional) – Gridding method. The default is ‘Nearest Neighbour’.

  • bdist (float, optional) – Blanking distance. The default is 4.0.

  • showlog (function, optional) – Display information. The default is print.

Returns:

dat – Output raster dataset.

Return type:

pygmi.raster.datatypes.Data.

pygmi.vector.dataprep.lltomap(lat, lon)#

Convert a latitude and longitude to a 1:50,000 sheet name.

Parameters:
  • lat (float) – Latitude.

  • lon (float) – Longitude.

Returns:

mapsheet – Map sheet number.

Return type:

str

pygmi.vector.dataprep.maptobounds(mapsheet, crs_to=None, showlog=print)#

Convert a South African map sheet name to bounds.

Parameters:
  • mapsheet (str) – Map sheet number. Four numbers and up to two letters denoting NE corner in latitude and longitude and quadrants (A to D). Eg, 2928AB is latitude 29, longitude 28, quadrant B of quadrant A.

  • crs_to (CRS, optional) – Destination projection. The default is None.

  • showlog (function, optional) – Display information. The default is print.

Returns:

bounds – output bounds.

Return type:

list

pygmi.vector.dataprep.maptovector(maplist)#

Create a vector layer from map numbers.

Parameters:

maplist (list) – List of strings containing map sheet numbers.

Returns:

data – GeoPandas GeoDataFrame

Return type:

GeoDataFrame

pygmi.vector.dataprep.quickgrid(x, y, z, dxy, *, numits=4, showlog=print)#

Do a quick grid.

Parameters:
  • x (numpy array) – array of x coordinates

  • y (numpy array) – array of y coordinates

  • z (numpy array) – array of z values - this is the column being gridded

  • dxy (float) – cell size for the grid, in both the x and y direction.

  • numits (int) – number of iterations. By default its 4. If this is negative, a maximum will be calculated and used.

  • showlog (function, optional) – Routine to show text messages. The default is print.

Returns:

newz – M x N array of z values

Return type:

numpy array

pygmi.vector.dataprep.reprojxy(x, y, iwkt, owkt, showlog=print)#

Reproject x and y coordinates.

Parameters:
  • x (numpy array or float) – x coordinates

  • y (numpy array or float) – y coordinates

  • iwkt (str, int, CRS) – Input wkt description or EPSG code (int) or CRS

  • owkt (str, int, CRS) – Output wkt description or EPSG code (int) or CRS

Returns:

  • xout (numpy array) – x coordinates.

  • yout (numpy array) – y coordinates.