gis_func module

This module contains GIS functions.

gis_func.arr2shp_contour(arr, f_shp, contourLevels=None, contourBase=None, contourInterval=None, exe_gdal_contour=None, screen_output=False)

Function to create an ESRI shapefile with contour lines from a raster, using gdal_contour.

Parameters:

arr : str or rasterArr object

Raster file name or rasterArr object.

f_shp : str

The ESRI shape file to be created.

contourLevels : numpy ndarray, array-like or None (optional)

Fixed contour levels.

contourBase : int, float or None (optional)

Base value: offset from zero relative to which to interpret interval between contour levels..

contourInterval : int, float or None (optional)

Interval between contour levels.

exe_gdal_contour : str or None (optional)

File name of the gdal_contour executable. If exe_gdal_contour is None then ‘gdal_contour’ is used; this only works if ‘gdal_contour’ is known to the system (e.g. in the PATH environment).

screen_output : bool (optional)

True = output of gdal’s process to the screen. False = no output of gdal’s process to the screen.

gis_func.delete_shp(f_shp)

Function to delete an ESRI shapefile including all associated files.

Parameters:

f_shp : str

The ESRI shapefile to be deleted.

gis_func.gen2shp(f_gen, f_shp, f_table=None, fld_id=’ID’, shptype=None)

Function to convert an ArcInfo generate file into an ESRI shapefile.

Parameters:

f_gen : str

The ArcInfo generate file to be converted.

f_shp : str

The ESRI shapefile to be created (*.shp).

f_table : str or None (optional)

Table file containing data to be included in the shapefile. This file may be a comma-separated file (*.csv), dbf file (*.dbf), iMOD ipf file (*.ipf) or space-separated file.

The table file is structured in fields (columns) and records (rows). It should contain a name for each field. Comma-separated and space-separated files should contain 1 header line with the field names.

fld_id : str or None (optional)

Field name of the field to link the table data to the IDs of the shapes in the generate file.

If f_table is specified and fld_id is not a field name in f_table then an error is raised.

If f_table is not specified then fld_id is used as field name for the IDs of the shapes in the generate file. However, if fld_id is None in this case then the default name ‘ID’ is used.

shptype : str or None (optional)

Type of the shapes: ‘POINT’, ‘POLYLINE’ or ‘POLYGON’.

If shptype is None the type will be the same as the gen file.

gis_func.get_gen_data(f_gen, f_table=None, fld_id=’ID’, l_flds=None, fld_str=None, center_points=False, return_shapelyGeoms=False)

Function to get the data of an ArcInfo generate file.

Parameters:

f_gen : str

The ArcInfo generate file to be converted.

f_table : str or None (optional)

Table file containing data linked to the generate file. This file may be a comma-separated file (*.csv), dbf file (*.dbf), iMOD ipf file (*.ipf) or space-separated file.

The table file is structured in fields (columns) and records (rows). It should contain a name for each field. Comma-separated and space-separated files should contain 1 header line with the field names.

fld_id : str or None (optional)

Field name of the field to link the table data to the IDs of the shapes in the generate file.

l_flds : list or None (optional)

List of field names to read. If l_flds is None all fields are read.

fld_str : str or None (optional)

An arbitrary string which is scanned for occurences of field names. Occuring field names will be included in the list of fields to be read.

Such a string could originate from user input, e.g. a condition string which is specified in an input file for a tool.

center_points : bool (optional)

True = return additionally the x,y coordinates of the centers of the polylines or polygons.

False = do not return the x,y coordinates of the centers of the polylines or polygons.

return_shapelyGeoms : bool (optional)

True = return shapely geometries in stead of xy array/list.

False = do not return shapely geometries.

Returns:

shptype : str

Type of the shapes: ‘POINT’, ‘POLYLINE’ or ‘POLYGON’.

xy : list or numpy ndarray

The x,y coordinates of the shapes.

If shptype is ‘POINT’ this is a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If shptype is ‘POLYLINE’ or ‘POLYGON’ this is a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

If return_shapelyGeoms is True then a list of shapely geometries (Point, LineString or Polygon) is returned in stead of the above mentioned xy array/list.

data : numpy recarray

The data belonging to the shapes.

The number of records is equal to the number of shapes (i.e. the length of xy).

xy_center : numpy ndarray

The x,y coordinates of the centers of the polylines or polygons.

Only returned if center_points is True.

If return_shapelyGeoms is True then a list of shapely Point geometries is returned.

i_center : numpy ndarray

Index numbers of the center points refering to the data belonging to the shapes.

Only returned if center_points is True.

gis_func.get_iff_data(f_iff, shptype=’POLYLINE’, line_parts=True, return_shapelyGeoms=False)

Function to get the data of an iMOD iff file.

Parameters:

f_iff : str

The iMOD iff file to be read.

shptype : str (optional)

Type of the shapes to be returned: ‘POINT’ or ‘POLYLINE’.

line_parts : bool (optional)

True = polylines are returned in parts (individual line segments); only relevant if shptype is ‘POLYLINE’.

False = polylines are returned as whole lines (multi segments).

return_shapelyGeoms : bool (optional)

True = return shapely geometries in stead of xy array/list.

False = do not return shapely geometries.

Returns:

shptype : str

Type of the shapes: ‘POINT’ or ‘POLYLINE’.

xy : list or numpy ndarray

The x,y coordinates of the shapes.

If shptype is ‘POINT’ this is a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If shptype is ‘POLYLINE’ this is a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

If return_shapelyGeoms is True then a list of shapely geometries (Point, LineString or Polygon) is returned in stead of the above mentioned xy array/list.

data : numpy recarray

The data belonging to the shapes.

The number of records is equal to the number of shapes (i.e. the length of xy).

If shptype is ‘POINT’ the fields are: ‘particle’, ‘lay’, ‘row’, ‘col’, ‘x’, ‘y’, ‘z’, ‘time’, ‘velocity’.

If shptype is ‘POLYLINE’ the fields are: ‘particle’, ‘lay_start’, ‘row_start’, ‘col_start’, ‘x_start’, ‘y_start’, ‘z_start’, ‘time_start’, ‘lay_end’, ‘row_end’, ‘col_end’, ‘x_end’, ‘y_end’, ‘z_end’, ‘time_end’, ‘velocity’.

gis_func.get_isg_data(f_isg, return_shapelyGeoms=False, return_dataMinMax=False)

Function to get the data of an iMOD isg file.

Parameters:

f_isg : str

The iMOD isg file to be read.

return_shapelyGeoms : bool (optional)

True = return shapely geometries in stead of xy array/list.

False = do not return shapely geometries.

return_dataMinMax : bool (optional)

True = return min and max values in data tables

False = do not return min and max values in data tables

Returns:

result : tuple

Three sets of data: the isg lines, the isd1 (calculation) points and the isc1 (cross section) points:

(isg shptype,isg xy,isg data), (isd1 shptype,isd1 xy,isd1 data), (isc1 shptype,isc1 xy,isc1 data)

Isg:

  • shptype : ‘POLYLINE’.
  • xy : list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].
  • data : numpy recarray with the data belonging to the lines.

Isd1 and isc1:

  • shptype : ‘POINT’.
  • xy : Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].
  • data : numpy recarray with the data belonging to the points.

If return_shapelyGeoms is True then a list of shapely geometries (Point, LineString) is returned in stead of the above mentioned xy array/list.

gis_func.get_shp_data(f_shp, l_flds=None, fld_str=None, center_points=False, l_extent=None, return_shapelyGeoms=False)

Function to get the data of an ESRI shape file.

Parameters:

f_shp : str

The ESRI shape file to be converted.

l_flds : list or None (optional)

List of field names to read. If l_flds is None all fields are read.

fld_str : str or None (optional)

An arbitrary string which is scanned for occurences of field names. Occuring field names will be included in the list of fields to be read.

Such a string could originate from user input, e.g. a condition string which is specified in an input file for a tool.

center_points : bool (optional)

True = return additionally the x,y coordinates of the centers of the polylines or polygons.

False = do not return the x,y coordinates of the centers of the polylines or polygons.

l_extent : list (optional)

A list containing xll, yll, xur and yur of the target extent (in this order).

Shapes which are entirely outside this extent are not returned.

return_shapelyGeoms : bool (optional)

True = return shapely geometries in stead of xy array/list.

False = do not return shapely geometries.

Returns:

shptype : str

Type of the shapes: ‘POINT’, ‘POLYLINE’ or ‘POLYGON’.

xy : list or numpy ndarray

The x,y coordinates of the shapes.

If shptype is ‘POINT’ this is a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If shptype is ‘POLYLINE’ or ‘POLYGON’ this is a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

If return_shapelyGeoms is True then a list of shapely geometries (Point, LineString or Polygon) is returned in stead of the above mentioned xy array/list.

data : numpy recarray

The data belonging to the shapes.

The number of records is equal to the number of shapes (i.e. the length of xy).

xy_center : numpy ndarray

The x,y coordinates of the centers of the polylines or polygons.

Only returned if center_points is True.

If return_shapelyGeoms is True then a list of shapely Point geometries is returned.

i_center : numpy ndarray

Index numbers of the center points refering to the data belonging to the shapes.

Only returned if center_points is True.

i_center_shapes : list

List with for each center point the index numbers of the shapes on which the center point is based.

Only returned if center_points is True.

gis_func.get_shptype(xy_or_geom)

Function to get the shape type of a xy array/list or shapely geometry/geometries.

Parameters:

xy_or_geom : array, list or shapely geometry

XY array/list: Nx2 array (points) or list of Nx2 arrays (polylines, polygons).

Single shapely geometry or list of shapely geometries.

Returns:

shptype : str

Shape type: ‘POINT’, ‘POLYLINE’ or ‘POLYGON’.

gis_func.intersect_poly(poly1, poly2)

Function to get the intersection points of a set of polylines or polygons with another set of polylines or polygons.

Parameters:

poly1 : list

The x,y coordinates of the first set of polylines/polygons.

This should be a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

The length of the list is the number of polylines/polygons; N is the number of vertices of the polyline/polygon.

poly2 : list

The x,y coordinates of the second set of polylines/polygons.

This should be a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

The length of the list is the number of polylines/polygons; N is the number of vertices of the polyline/polygon.

Returns:

xy_intersect : list

The x,y coordinates of the intersection points.

This is a NxMxLx2 shaped list. N is the number of polylines/polygons in the first set; M is the number of polylines/polygons in the second set. L is the number of intersection points.

gis_func.latlong2rd(latitude, longitude, h_wgs=None)

Function to convert LatLong coordinates to RD coordinates.

WGS84 ellipsoid is assumed.

Parameters:

latitude : float

Latitude in [decimal degrees].

longitude : float

Longitude in [decimal degrees].

h_wgs : float or None (optional)

Elevation in [m] relative to WGS84 ellipsoid.

Returns:

x_rd : float

RD x coordinate in [m].

y_rd : float

RD y coordinate in [m].

z_nap : float or None

Elevation (z coordinate) in [m +NAP].

If h_wgs is None then z_nap will be None too.

gis_func.latlong2utm(latitude, longitude, utm_zone=None, utm_letter=None, return_zone=False)

Function to convert LatLong coordinates to UTM coordinates.

WGS84 ellipsoid is assumed.

Parameters:

latitude : float

Latitude in [decimal degrees].

longitude : float

Longitude in [decimal degrees].

utm_zone : int (optional)

UTM zone.

utm_letter : str (optional)

UTM letter designator.

return_zone : bool (optional)

True = return UTM zone (incl. UTM letter)

False = do not return UTM zone

Returns:

easting : int or float

UTM easting (x coordinate) in [m].

northing : int or float

UTM northing (y coordinate) in [m].

UTM zone : str (optional)

UTM zone (incl. UTM letter)

Only return if return_zone is True.

gis_func.point_in_polygon(xy_point, xy_poly)

Function to perform a point-in-polygon test for a set of points and a set of polygons.

Parameters:

xy_point : array or array_like

The x,y coordinates of the points.

This should be a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

N is the number of points.

xy_poly : list

The x,y coordinates of the set of polygons.

This should be a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

The length of the list is the number of polygons; N is the number of vertices of the polygon.

Returns:

pip : numpy ndarray

This is a NxM array of type ‘bool’. N is the number of points; M is the number of polygons.

True = point in polygon.

False = point not in polygon.

gis_func.points_polygons2val(xy, f_shp, l_flds=None, nodata=-9999, dxy_split_polygons=1e+31)

Function to extract polygon values of an ESRI shape file on points.

Parameters:

xy : list, array or array_like (2-D)

The x,y coordinates of the points: Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

This can also be a list of shapely point geometries.

f_shp : str

Input polygon shape file.

l_flds : list or None (optional)

List of field names to read. If l_flds is None all fields are read.

nodata : float, int (optional)

Nodata value to be applied.

dxy_split_polygons : float (optional)

Returns:

result : numpy recarray

gis_func.poly2slopes_intersects(xy_poly, nodata=1.23456789e+31)

Function to calculate the slopes and y-axis intersects of all line elements of a set of polylines or polygons.

Parameters:

xy_poly : list

The x,y coordinates of the set of polylines/polygons.

This should be a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

The length of the list is the number of polylines/polygons; N is the number of vertices of the polyline/polygon.

nodata : int or float (optional)

Nodata value to be returned for an infinite slope or intersect.

Returns:

slopes : list

The slopes of all line elements of the set of polylines/polygons.

This is a list of arrays with N values. The length of the list is the number of polylines/polygons; N is the number of line element of the polyline/polygon.

intersects : list

The y-axis intersects of all line elements of the set of polylines/polygons.

This is a list of arrays with N values. The length of the list is the number of polylines/polygons; N is the number of line element of the polyline/polygon.

gis_func.polyline2interval_points(xy_poly, interval, all_vert=True, end_vert=True, mid_point=False, startend_shift=0.0)

Function to get points at a regular interval along the polylines in a set of polylines.

Parameters:

xy_poly : list

The x,y coordinates of the set of polylines.

This should be a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

The length of the list is the number of polylines; N is the number of vertices of the polyline.

interval : float

Interval distance.

all_vert : bool (optional)

True = the vertices are included as points, even if they are not at the specified interval distance.

False = the vertices are not included, unless they are at the specified interval distance.

end_vert : bool (optional)

True = the end vertex is included as point, even if it is not at the specified interval distance.

False = the end vertex is not included, unless it is at the specified interval distance or all_vert is True.

startend_shift : float (optional)

If not 0.0 the first point is shifted forward over a distance of startend_shift and the last point is shifted backward over a distance of startend_shift.

Returns:

output : list of numpy recarrays

Each recarray belongs to a polyline in the set of polylines. It is a table with the fields ‘X’, ‘Y’ and ‘DIST’ being the x coordinates, y coordinates and distances of the points.

gis_func.polyline_idf2val(xy_poly, fl_idf, interval, nodata=None, interpolate=True, all_vert=True)

Function to get values of a list of IDF files at a regular interval along the polylines in a set of polylines.

Parameters:

xy_poly : list

The x,y coordinates of the set of polylines.

This should be a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

The length of the list is the number of polylines; N is the number of vertices of the polyline.

fl_idf : list

List of IDF files or rasterArr objects.

interval : float

Interval distance.

interpolate : bool (optional)

Flag for linear interpolation from cell centers to x,y location.

True = enable linear interpolation

False = disable linear interpolation

all_vert : bool (optional)

True = the vertices are included as points, even if they are not at the specified interval distance.

False = the vertices are not included, unless they are at the specified interval distance.

Returns:

output : list of numpy recarrays

Each recarray belongs to a polyline in the set of polylines. It is a table; the first 3 fields are ‘X’, ‘Y’, ‘DIST’ being the x coordinates, y coordinates and distances of the points. The subsequent fields contain the values of the IDF files. The name of these fields is the basename of the IDF files.

gis_func.rd2latlong(x_rd, y_rd, z_nap=None)

Function to convert RD coordinates to LatLong coordinates.

WGS84 ellipsoid is assumed.

Parameters:

x_rd : int or float

RD x coordinate in [m].

y_rd : int or float

RD y coordinate in [m].

z_nap : int or float (optional)

Elevation (z coordinate) in [m +NAP].

If z_nap is None the elevation is set to 0.0 m +NAP.

Returns:

latitude : float

Latitude in [decimal degrees].

longitude : float

Longitude in [decimal degrees].

h_wgs : float or None

Elevation in [m] relative to WGS84 ellipsoid.

If z_nap is None then h will be None too.

gis_func.shapelyGeoms2arr(geoms, gi, shptype=None, data=None, field=None, nodata=None, set_gi_extent=True, all_touched=False)

Function to rasterize shapely geometries using GDAL’s RasterizeLayer function.

Parameters:

geoms : list

List of shapely geometries of type ‘Point’, ‘LineString’, ‘LinearRing’ or ‘Polygon’.

gi : list or dict

Dict or list with basic geographical information according to rasterArr object.

See Geographical information

The geographical information is used to set the cell sizes, cell boundaries and (depending on set_gi_extent) the extent.

shptype : str or None (optional)

Type of the shapes: ‘POINT’, ‘POLYLINE’ or ‘POLYGON’.

If shptype is None the type is determined from geoms. If the shapes are points shptype is ignored.

data : numpy recarray or None (optional)

The data belonging to the shapes.

The number of records should be equal to the number of shapes (i.e. the length of geoms).

field : str or None (optional)

Name of the field to be rasterized.

If field is None or does not exist in the shapefile the shapes are rasterized to the value 1. This is faster than rasterizing a specific field.

nodata : float, int or None (optional)

set_gi_extent : bool (optional)

True = the extent is taken from gi.

False = the extent is taken from the shapefile itself. The cell sizes and cell boundaries are taken from gi.

all_touched : bool (optional)

True = Option to rasterize shapefiles using all cells that touch the border of the shape.

False = Option disabled.

Returns:

result : rasterArr object

gis_func.shapelyGeoms2shp(f_shp, geoms, shptype=None, data=None)

Function to write shapely geometries to an ESRI shape file.

Parameters:

f_shp : str

The ESRI shape file to be created.

geoms : list

List of shapely geometries of type ‘Point’, ‘LineString’, ‘LinearRing’ or ‘Polygon’.

shptype : str or None (optional)

Type of the shapes: ‘POINT’, ‘POLYLINE’ or ‘POLYGON’.

If shptype is None the type is determined from geoms.

data : numpy recarray or None (optional)

The data belonging to the shapes.

The number of records should be equal to the number of shapes (i.e. the length of geoms).

gis_func.shapelyGeoms2xy(geoms)

Function to convert shapely geometries to xy array/list.

Parameters:

geoms : list

List of shapely geometries of type ‘Point’, ‘LineString’, ‘LinearRing’ or ‘Polygon’.

Returns:

shptype : str

Type of the shapes: ‘POINT’, ‘POLYLINE’ or ‘POLYGON’.

xy : list or numpy ndarray

The x,y coordinates of the shapes.

If shptype is ‘POINT’ this is a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If shptype is ‘POLYLINE’ or ‘POLYGON’ this is a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

gis_func.shp2arr(f_shape, gi, field=None, nodata=None, set_gi_extent=True, all_touched=False)

Function to rasterize an ESRI shapefile using GDAL’s RasterizeLayer function.

Does not work to create non-equidistant rasters.

Parameters:

f_shape : str or osgeo.ogr.Layer object

Shapefile or osgeo.ogr.Layer object.

Recognized features are point, line and polygon shapefiles. Multi-part features are supported.

gi : list or dict

Dict or list with basic geographical information according to rasterArr object.

See Geographical information

The geographical information is used to set the cell sizes, cell boundaries and (depending on set_gi_extent) the extent.

field : str or None (optional)

Name of the field to be rasterized.

If field is None or does not exist in the shapefile the shapes are rasterized to the value 1. This is faster than rasterizing a specific field.

nodata : float, int or None (optional)

set_gi_extent : bool (optional)

True = the extent is taken from gi.

False = the extent is taken from the shapefile itself. The cell sizes and cell boundaries are taken from gi.

all_touched : bool (optional)

True = Option to rasterize shapefiles using all cells that touch the border of the shape.

False = Option disabled.

Returns:

result : rasterArr object

gis_func.shp2arr_PIL(f_shape, gi, field=None, precision=1, frac=0.5, st=None, set_gi_extent=True)

Function to rasterize an ESRI shapefile using PIL.

Does not work to create non-equidistant rasters.

Parameters:

f_shape : str

Shapefile.

Recognized features are point, line and polygon shapefiles. Multi-part features are supported.

gi : list or dict

Dict or list with basic geographical information according to rasterArr object.

See Geographical information

The geographical information is used to set the cell sizes, cell boundaries and (depending on set_gi_extent) the extent.

field : str or None (optional)

Name of the field to be rasterized.

If field is None or does not exist in the shapefile the shapes are rasterized to the value 1. This is faster than rasterizing a specific field.

precision : int (optional)

Precision number (>= 0).

If precision is >0 then the shape file is rasterized to the downscaled raster and thereafter upscaled again. The downscale factor is precision*+1, e.g. if *precision is 1 the downscaling factor is 2, meaning that the cell sizes are divided by 2. This could give a better (more precise) result. See also the parameter frac.

The higher the precision number, the slower the calculation. Memory error could occur if the number is too large.

frac : float (optional)

Fraction (range 0-1). This fraction is used in the upscaling mentioned above (see parameter precision) to determine which resulting cell are covered by the shape and which not.

st : str or None (optional)

Shape type. Recognized are: ‘point’, ‘line’ and polygon’. These overrule the shape type of each shape, if possible.

If st is None the shape type of the shapes is not changed.

set_gi_extent : bool (optional)

True = the extent is taken from gi.

Note that first the shapefile is rasterized to the full extent of the shapefile and thereafter clipped to the extent of gi.

False = the extent is taken from the shapefile itself. The cell sizes and cell boundaries are taken from gi.

Returns:

result : rasterArr object

gis_func.shp2arr_refined(f_shape, gi, field=None, nodata=None, set_gi_extent=True, downscale_factor=5, x_split=5, y_split=5, frac=0.5, method=’mean’, all_touched=False)

Function to rasterize an ESRI shapefile using GDAL’s RasterizeLayer function by using a refined underlying grid.

Does not work to create non-equidistant rasters.

Parameters:

f_shape : str

Shapefile.

Recognized features are point, line and polygon shapefiles. Multi-part features are supported.

gi : list or dict

Dict or list with basic geographical information according to rasterArr object.

See Geographical information

The geographical information is used to set the cell sizes, cell boundaries and (depending on set_gi_extent) the extent.

field : str or None (optional)

Name of the field to be rasterized.

If field is None or does not exist in the shapefile the shapes are rasterized to the value 1. This is faster than rasterizing a specific field.

nodata : float, int or None (optional)

set_gi_extent : bool (optional)

True = the extent is taken from gi.

False = the extent is taken from the shapefile itself. The cell sizes and cell boundaries are taken from gi.

downscale_factor : int (optional)

Downscaling factor (refinement factor); 1 or greater.

x_split : int (optional)

Number of times the grid is splitted in x direction; 1 or greater. Grid splitting is needed to avoid memory errors if the refined grid become to large.

y_split : int (optional)

Number of times the grid is splitted in y direction; 1 or greater. Grid splitting is needed to avoid memory errors if the refined grid become to large.

frac : float (optional)

Fraction (range 0-1). This fraction is used in the upscaling to determine which resulting cells are covered by the shape and which not.

method : str or None (optional)

The rescaling/resampling method for upscaling the refined grid to the final grid. Possible methods are: ‘sum’, ‘min’, ‘max’, ‘harm’, ‘log10’, ‘log’, ‘mean’, ‘sample’, None.

all_touched : bool (optional)

True = Option to rasterize shapefiles using all cells that touch the border of the shape.

False = Option disabled.

Returns:

result : rasterArr object

gis_func.shp2gen(f_shp, f_gen, fld_id=None, f_table=None, shptype=None)

Function to convert an ESRI shapefile into an ArcInfo generate file.

Parameters:

f_shp : str

The ESRI shapefile to be converted (*.shp).

f_gen : str

The ArcInfo generate file to be created.

fld_id : str or None (optional)

Field name of the field to be used for the IDs of the shapes in the generate file.

If fld_id is None then the first field of the shapefile is used.

f_table : str or None (optional)

Table file to be created, containing the data from the shapefile. This file may be a comma-separated file (*.csv), dbf file (*.dbf), iMOD ipf file (*.ipf) or space-separated file.

shptype : str or None (optional)

Type of the shapes: ‘POINT’, ‘POLYLINE’ or ‘POLYGON’.

If shptype is None the type will be the same as the shapefile.

See also

ESRI shapefile

gis_func.shp2shapelyGeoms(f_shp, center_points=False, l_extent=None)

Function to get the shapes of an ESRI shape file as shapely geometries.

Parameters:

f_shp : str

The ESRI shape file to be converted.

center_points : bool (optional)

True = return additionally the x,y coordinates of the centers of the shapes.

False = do not return the x,y coordinates of the centers of the shapes.

l_extent : list (optional)

A list containing xll, yll, xur and yur of the target extent (in this order).

Shapes which are entirely outside this extent are not returned.

Returns:

shptype : str

Type of the shapes: ‘POINT’, ‘POLYLINE’ or ‘POLYGON’.

geoms : list

List of shapely geometries of type ‘Point’, ‘LineString’ or ‘Polygon’.

i_data : numpy ndarray

Index numbers of the shapes refering to the data belonging to the shape file.

xy_center : numpy ndarray

The x,y coordinates of the centers of the polylines or polygons.

Only returned if center_points is True.

i_center : numpy ndarray

Index numbers of the center points refering to the data belonging to the shapes.

Only returned if center_points is True.

i_center_shapes : list

List with for each center point the index numbers of the shapes on which the center point is based.

Only returned if center_points is True.

gis_func.shp2xy(f_shp, l_flds=None, fld_str=None, center_points=False, l_extent=None)

Function to get the data of an ESRI shape file.

Parameters:

f_shp : str

The ESRI shape file to be converted.

l_flds : list or None (optional)

List of field names to read. If l_flds is None all fields are read.

fld_str : str or None (optional)

An arbitrary string which is scanned for occurences of field names. Occuring field names will be included in the list of fields to be read.

Such a string could originate from user input, e.g. a condition string which is specified in an input file for a tool.

center_points : bool (optional)

True = return additionally the x,y coordinates of the centers of the polylines or polygons.

False = do not return the x,y coordinates of the centers of the polylines or polygons.

l_extent : list (optional)

A list containing xll, yll, xur and yur of the target extent (in this order).

Shapes which are entirely outside this extent are not returned.

Returns:

shptype : str

Type of the shapes: ‘POINT’, ‘POLYLINE’ or ‘POLYGON’.

xy : list or numpy ndarray

The x,y coordinates of the shapes.

If shptype is ‘POINT’ this is a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If shptype is ‘POLYLINE’ or ‘POLYGON’ this is a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

data : numpy recarray

The data belonging to the shapes.

The number of records is equal to the number of shapes (i.e. the length of xy).

xy_center: numpy ndarray

The x,y coordinates of the centers of the polylines or polygons.

Only returned if center_points is True.

i_center : numpy ndarray

Index numbers of the center points refering to the data belonging to the shapes.

Only returned if center_points is True.

i_center_shapes : list

List with for each center point the index numbers of the shapes on which the center point is based.

Only returned if center_points is True.

gis_func.split_polygons(polygons, data_polygons=None, dxy_split_polygons=1e+31)

Function to split shapely polygons in regular blocks.

gis_func.utm2latlong(utm_zone, easting, northing, northernHemisphere=True)

Function to convert UTM coordinates to LatLong coordinates.

WGS84 ellipsoid is assumed.

Parameters:

utm_zone : int

UTM zone.

easting : int or float

UTM easting (x coordinate) in [m].

northing : int or float

UTM northing (y coordinate) in [m].

northernHemisphere : bool (optional)

True = northern hemisphere

False = southern hemisphere

Returns:

latitude : float

Latitude in [decimal degrees].

longitude : float

Longitude in [decimal degrees].

See also

LL_UTM

gis_func.write_gen(f_gen, xy, shptype=None, data=None, fld_id=None, f_table=None)

Function to write an ArcInfo generate file.

Parameters:

f_gen : str

The ArcInfo generate file to be created.

xy : list or numpy ndarray

The x,y coordinates of the shapes.

If the type of the shapes is ‘POINT’ this should be a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If the type of the shapes is ‘POLYLINE’ or ‘POLYGON’ this should be a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

shptype : str or None (optional)

Type of the shapes: ‘POINT’, ‘POLYLINE’ or ‘POLYGON’.

If shptype is None the type is determined from xy. If the shapes are points shptype is ignored.

data : numpy recarray or None (optional)

The data belonging to the shapes.

The number of records should be equal to the number of shapes (i.e. the length of xy).

fld_id : str or None (optional)

Field name of the field in the data array to be used for the IDs of the shapes in the generate file.

If fld_id is None or can not be linked to the data array of data then the IDs will be index numbers.

If the field contains non-unique values then the IDs will be index numbers.

f_table : str or None (optional)

Table file to be created, containing the data of data. This file may be a comma-separated file (*.csv), dbf file (*.dbf), iMOD ipf file (*.ipf) or space-separated file.

If f_table is None or data is None no table file will be created.

gis_func.write_isg(f_lines, f_points, f_isg, fld_points=[‘ILINE’, ‘DIST’, ‘ZP’, ‘WP’, ‘BOT’, ‘RES’, ‘INF’], startendyr=[1980, 2020], l_crs=[2.0, 10.0, 25.0])

Function to write an iMOD isg file.

The isg file is based on a line shape file (water courses) and a point shape file (calculation points on the lines).

Parameters:

f_lines : str

File name of the line shape file.

f_points : str

File name of the point shape or table file. If this is a table file the fields ‘shapeX’ and ‘shapeY’ are expected to be included.

f_isg : str

File name of the isg file.

fld_points : list or tuple (optional)

List of fields of the point shape file for the necessary ISG parameters.

The fields are (in this order): line index number corresponding to the line shape file, distance on the line, summer level, winter level, bottom level, resistance, infiltration factor.

startendyr : list or tuple (optional)

List with start year and end year of the summer/winter level time series.

l_crs : list or tuple (optional)

List with the parameter values for the default cross section: width, depth, K-manning.

gis_func.write_shp(f_shp, xy, shptype=None, data=None)

Function to write an ESRI shape file.

Parameters:

f_shp : str

The ESRI shape file to be created.

xy : list or numpy ndarray

The x,y coordinates of the shapes.

If the type of the shapes is ‘POINT’ this should be a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If the type of the shapes is ‘POLYLINE’ or ‘POLYGON’ this should be a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

This can also be a list of shapely point geometries.

shptype : str or None (optional)

Type of the shapes: ‘POINT’, ‘POLYLINE’ or ‘POLYGON’.

If shptype is None the type is determined from xy. If the shapes are points shptype is ignored.

data : numpy recarray or None (optional)

The data belonging to the shapes.

The number of records should be equal to the number of shapes (i.e. the length of xy).

gis_func.xy2shapelyGeoms(xy, shptype=None)

Function to convert xy array/list to shapely geometries.

Parameters:

xy : list or numpy ndarray

The x,y coordinates of the shapes.

If shptype is ‘POINT’ this is a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If shptype is ‘POLYLINE’ or ‘POLYGON’ this is a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

shptype : str (optional)

Type of the shapes: ‘POINT’, ‘POLYLINE’ or ‘POLYGON’.

Returns:

geoms : list

List of shapely geometries of type ‘Point’, ‘LineString’ or ‘Polygon’.

gis_func.xy_reproject(xy, crs_in, crs_out)

Function to reproject x,y coordinates of shapes.

Parameters:

xy : list or numpy ndarray

The x,y coordinates of the shapes to be reprojected.

If the type of the shapes is ‘POINT’ this should be a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If the type of the shapes is ‘POLYLINE’ or ‘POLYGON’ this should be a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

crs_in : int or str

Input crs reference.

One of the following forms:

Integer: EPSG reference number.

String: ‘EPSG:i’ where i denotes a EPSG reference number.

String: ‘UTMiC’ where i denotes a UTM zone number and C denotes ‘N’ or ‘S’ for the hemisphere.

String: GDAL’s so called WellKnownGeogCS string, e.g. ‘WGS84’.

String: Ohter recognized strings are: ‘amersfoort’, ‘rd’, ‘gda94’, ‘gda94_vicgrid’

String: WKT string

crs_out : int or str

Output crs reference.

Same possible forms as crs_in.

Returns:

xy_out : list or numpy ndarray

The reprojected x,y coordinates of the shapes.

If the type of the shapes is ‘POINT’ this is a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If the type of the shapes is ‘POLYLINE’ or ‘POLYGON’ this is a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

gis_func.xy_rotate(xy, rot_CwRad, xy_rot=[0, 0], rot_inDeg=False)

Function to rotate x,y coordinates of shapes.

Parameters:

xy : list or numpy ndarray

The x,y coordinates of the shapes to be reprojected.

If the type of the shapes is ‘POINT’ this should be a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If the type of the shapes is ‘POLYLINE’ or ‘POLYGON’ this should be a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

rot_CwRad : float

The rotation angle in clock-wise radians.

xy_rot : list, tuple or numpy ndarray (optional)

The x,y coordinates (1-D) of the point around which the rotation should be done.

rot_inDeg : bool (optional)

True = rotation angle rot_CwRad is given in degrees.

False = rotation angle is not given in degrees.

Returns:

xy_out : list or numpy ndarray

The reprojected x,y coordinates of the shapes.

If the type of the shapes is ‘POINT’ this is a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If the type of the shapes is ‘POLYLINE’ or ‘POLYGON’ this is a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

gis_func.xy_shift(xy, xy_shift=[0, 0], backward=False)

Function to shift/translate x,y coordinates of shapes.

Parameters:

xy : list or numpy ndarray

The x,y coordinates of the shapes to be reprojected.

If the type of the shapes is ‘POINT’ this should be a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If the type of the shapes is ‘POLYLINE’ or ‘POLYGON’ this should be a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].

xy_shift : list, tuple or numpy ndarray (optional)

The shift in x and y direction (1-D).

backward : bool (optional)

True = the shift is done ‘backward’ (in oposite direction).

False = the shift is done ‘forward’ (normal direction).

Returns:

xy_out : list or numpy ndarray

The shifted x,y coordinates of the shapes.

If the type of the shapes is ‘POINT’ this is a Nx2 array: [(x1,y1), (x2,y2) … (xN,yN)].

If the type of the shapes is ‘POLYLINE’ or ‘POLYGON’ this is a list of Nx2 arrays: [[(x1,y1),(x2,y2) .. (xN,yN)], [(x1,y1),(x2,y2) .. (xM,yM)] …].