![]() distance between points # ensures correct neighbourhoods for start and end pts of lines raster, array, geo_transform = raster2array ( raster_file_name ) pixel_width = geo_transform max_distance = np. ![]() The raster2line function is also implemented in the script.įrom flusstools.geotools import raster2array def raster2line ( raster_file_name, out_shp_fn, pixel_value ): """ Convert a raster to a line shapefile, where pixel_value determines line start and end points :param raster_file_name: STR of input raster file name, including directory must end on ".tif" :param out_shp_fn: STR of target shapefile name, including directory must end on ".shp" :param pixel_value: INT/FLOAT of a pixel value :return: None (writes new shapefile). prj projection file (recall descriptions in the shapefile section) using the spatial reference system of the input raster with the get_srs() function. If the distance between the points is smaller than max_distance, the function creates a line object from the two points and appends it to the multi_line object.Ĭreate a new shapefile (named out_shp_fn) using the create_shp() function (with integrated shapefile name length verification from flusstools geotools.create_shp()).Īdd the multi_line object as a new feature to the shapefile (according to the descriptions in the shapefile section).Ĭreate a. Point1 and point2 are required to get the distance between pairs of points. Iterate through all possible combinations of points (excluding combinations of points with themselves) with binations(iterable, r=number-of-combinations=2). Use the above-defined offset2coords function to append point coordinates to a points list.Ĭreate a multi_line object (instance of ogr.Geometry(ogr.wkbMultiLineString)), which represents the (void) final least cost path. Get the trajectory of pixels that have a user parameter-defined pixel_value (e.g., 1 to trace 1-pixels in the binary least_cost.tif) and throw an error if the trajectory is empty (i.e., np.count_nonzero(trajectory) is 0). ![]() Open a raster, its band as array, and geo_transform (geo-transformation) defined with the raster_file_name argument in the open_raster function from the raster section.Ĭalculate the maximum distance ( max_distance) between two pixels that are considered being connect-able, based on the hypothesis that the pixel height Δy and width Δx are the same: We name this function raster2line() and it builds on the following workflow: Next, we can write a core function to convert a raster dataset to a line shapefile. The offset is added 0.5 pixels in both x and y directions to meet the center of the pixel rather than the top-left pixel corner. Geospatial Open Source Python Libraries.Reservoir Volume (Sequent Peak Algorithm).1d Hydraulics (Manning-Strickler Formula).Integrated Development Environments (IDEs).12.2 Inverse Distance Weighted interpolation.11.3 Aggregation of spatio-temporal rasters.10.7.5 Extracting to polygons: multi-band.10.7.4 Extracting to polygons: single-band.10.7.3 Extracting to points: multi-band.10.7.2 Extracting to points: single-band.8 Geometric operations with vector layers.6.6 Generalizing raster algebra with st_apply.6.4.3 True color and false color images.6.4.1 Arithmetic and logical operations on layers.6.2.1 Selecting rows, column and layers.5.3.7 Visualization with plot, mapview and cubeview.4.4.3 Example: the rainfall.csv dataset.3.3.2 Function definition vs. function call.3.1.1 Times and time series classes in R.2.3.6 Consecutive and repetitive vectors. ![]() 2.3.3 Vector subsetting (individual elements).0.3.9 osmdata: Access to OpenStreetMap data.0.3.8 spatstat: Spatial point pattern analysis.0.3.7 spdep: Spatial dependence modelling.0.3.5 geosphere: Geometric calculations on longitude/latitude.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |