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])

Cut a point dataset using a shapefile.

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.

gridvolume(x, y, z, val, dxy, *[, dat, showlog])

Grid volume data.

lltomap(lat, lon)

Convert a latitude and longitude to a 1:50,000 map 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.

xy_to_r(x, y[, piter])

Convert x an y values on a section to r.

fast_sort(pointsin[, piter])

Fast sort of coordinate pairs.

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 – Reference to the parent routine. The default is None.

settings(nodialog=False)#

Entry point into item.

Parameters:

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

Returns:

True if successful, False otherwise.

Return type:

bool

saveproj()#

Save project data from class.

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 – Reference to the parent routine. The default is None.

setupui()#

Set up UI.

dxy_change()#

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

grid_method_change()#

When grid method is changed, this updated hidden controls.

grid_type_change()#

Check whether section is checked.

settings(nodialog=False)#

Entry point into item.

Parameters:

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

Returns:

True if successful, False otherwise.

Return type:

bool

saveproj()#

Save project data from class.

acceptall()#

Accept option.

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

Returns:

True if successful, False otherwise.

Return type:

bool

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 – Reference to the parent routine. The default is None.

setupui()#

Set up UI.

settings(nodialog=False)#

Entry point into item.

Parameters:

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

Returns:

True if successful, False otherwise.

Return type:

bool

saveproj()#

Save project data from class.

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 – Reference to the parent routine. The default is None.

setupui()#

Set up UI.

acceptall()#

Accept option.

run()#

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

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

Bases: pygmi.misc.BasicModule

GUI to split a text file into smaller text files.

Parameters:

parent – Reference to the parent routine. The default is None.

setupui()#

Set up UI.

change_method()#

Update fields when method changes.

get_ifile()#

Get input file information.

settings(nodialog=False)#

Entry point into item.

Parameters:

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

Returns:

True if successful, False otherwise.

Return type:

bool

saveproj()#

Save project data from class.

acceptall()#

Accept option.

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

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.typing.NDArray) – Grid data to blank.

  • x (numpy.typing.NDArray) – X coordinates.

  • y (numpy.typing.NDArray) – Y coordinates.

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

  • extent (list[float]) – Extent of grid.

  • dxy (float) – Cell size.

  • nullvalue (float) – Null or nodata value.

Returns:

Masked output array.

Return type:

ndarray

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

Cut a point dataset using a shapefile.

Parameters:
  • data (geopandas.GeoDataFrame) – GeoPandas GeoDataFrame

  • ifile (str) – Shapefile used to cut data

  • showlog (collections.abc.Callable[..., None]) – Display information. The default is print.

Returns:

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=ProgressBarText().iter)#

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) – Can be ‘bytes’, ‘files’ or ‘lines’. The default is ‘bytes’.

  • showlog (collections.abc.Callable[..., None]) – Display information. The default is print.

  • piter (collections.abc.Iterable) – Progress iterator. The default is 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.typing.NDArray) – X coordinate values.

  • y (numpy.typing.NDArray) – Y coordinate values.

  • z (numpy.typing.NDArray) – Z or data values.

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

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

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

  • bdist (float | None) – Blanking distance. The default is 4.0.

  • showlog (collections.abc.Callable[..., None]) – Display information. The default is print.

Returns:

Output raster dataset.

Return type:

Data

pygmi.vector.dataprep.gridvolume(x, y, z, val, dxy, *, dat=None, showlog=print)#

Grid volume data.

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

  • y (numpy.typing.NDArray) – Y coordinate values.

  • z (numpy.typing.NDArray) – Z coordinate values.

  • val (numpy.typing.NDArray) – Data values.

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

  • dat (pygmi.raster.datatypes.Data | None) – DEM data used to constrain surface. The default is None.

  • showlog (collections.abc.Callable[..., None]) – Display information. The default is print.

Returns:

Output raster dataset.

Return type:

VoxModel

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

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

Parameters:
  • lat (float) – Latitude.

  • lon (float) – Longitude.

Returns:

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 (pyproj.CRS) – Destination projection. The default is None.

  • showlog (collections.abc.Callable[..., None]) – Display information. The default is print.

Returns:

Output bounds, defined as (xmin, ymin, xmax, ymax).

Return type:

tuple of float

pygmi.vector.dataprep.maptovector(maplist)#

Create a vector layer from map numbers.

Parameters:

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

Returns:

GeoPandas GeoDataFrame

Return type:

GeoDataFrame

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

Do a quick grid.

Parameters:
  • x (numpy.typing.NDArray) – Array of x coordinates

  • y (numpy.typing.NDArray) – Array of y coordinates

  • z (numpy.typing.NDArray) – 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 (collections.abc.Callable[..., None]) – Routine to show text messages. The default is print.

Returns:

M x N array of z values

Return type:

MaskedArray

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

Reproject x and y coordinates.

Parameters:
  • x (numpy.typing.NDArray) – X coordinates

  • y (numpy.typing.NDArray) – Y coordinates

  • iwkt (str | int | pyproj.CRS) – Input wkt description or EPSG code (int) or CRS

  • owkt (str | int | pyproj.CRS) – Output wkt description or EPSG code (int) or CRS

  • showlog (collections.abc.Callable[..., None]) – Routine to show text messages. The default is print.

Returns:

  • xout (ndarray or None) – X coordinates.

  • yout (ndarray or None) – Y coordinates.

Return type:

tuple[numpy.typing.NDArray | None, numpy.typing.NDArray | None]

pygmi.vector.dataprep.xy_to_r(x, y, piter=iter)#

Convert x an y values on a section to r.

This will take into account r being reset for each depth.

Parameters:
  • x (numpy.typing.NDArray | float) – X coordinates

  • y (numpy.typing.NDArray | float) – Y coordinates

  • piter (collections.abc.Iterable) – Progress bar iterable, default is iter.

Returns:

r coordinates.

Return type:

ndarray

pygmi.vector.dataprep.fast_sort(pointsin, piter=iter)#

Fast sort of coordinate pairs.

Parameters:
  • pointsin (numpy.typing.NDArray) – Coordinates.

  • piter (collections.abc.Iterable) – Progress bar iterable, default is iter.

Returns:

Sorted coordinates.

Return type:

list