CMIE CapEx utilities
Data munging
Apply these functions to columns from the CapEx database.
Karmana.latlong_string_to_points
— Functionlatlong_string_to_points(latlong_string)
Parses a string of the form lat1,long1 : lat2,long2 : lat3,long3 : ...
and returns a Vector of Point2e which define points as (long, lat).
Is robust to cutoff errors and other potential issues.
Karmana.points_weights
— Functionpoints_weights(latlong_strings::Vector{:< AbstractString}, costs::Vector{<: Real})
Parses strings of the form lat1,long1 : lat2,long2 : lat3,long3 : ...
and returns a Vector of Point2e which define points as (long, lat), as well as a vector of weights per point. If the string has more than one point defined, the weight is spread across all n
points such that each point has a weight of cost[i]/n
.
Returns (::Vector{Point2e}, ::Vector{<: Real}).
This format of data is often found in CMIE capex location data.
Geographic utilities
We also have geographic utilities, which use e.g. Rasters.
Maybe this section should be its own page, since the functionality is pretty orthogonal?
Annular rings
Karmana.annular_ring
— Functionannular_ring(f, source::Raster, lon, lat, outer_radius, inner_radius; pass_mask_size = false)
Returns the result of applying f
to the subset of source
which is masked by the annular ring defined by lon
, lat
, outer_radius
, inner_radius
. The annular ring is constructed in geodetic space, i.e., distance is physically preserved.
source
may be a 2D raster (in which case this function returns a value), or a 3D RasterStack or a RasterSeries of 2D rasters, in which case this function returns a Vector
of values.
Arguments
f
is a function which takes aRaster
and returns a value. This is the function which will be applied to the subset ofsource
which is masked by the constructed annular ring. The result off
is returned.source
is aRaster
which will be masked by the annular ring. This can be 2D, in which caseannular_ring
will return a single value, or 3D, in which caseannular_ring
will return aVector
of values.lon
,lat
are the coordinates of the centre of the annular ring, in degrees.outer_radius
andinner_radius
are the outer and inner radii of the annular ring, in metres.pass_mask_size
determines whether to pass a second argument tof
containing the number of points in the mask. This is useful if you are taking statistical measures.
How it works
- First, an annular ring polygon is created (in geodetic space, using
get_geodetic_circle
). - Next, the extent of the annular ring polygon is computed, and the
source
raster is subsetted to that extent. This is for efficiency, and so that the minimum possible number of multiplications are performed. - The annular ring polygon is rasterized, using
Rasters.boolmask
. - The subsetted
source
raster is multiplied by the rasterized annular ring polygon. - Finally,
f
is applied to the result of the multiplication.
Geodetically widened lines
Karmana.line_to_geodetic_width_poly
— Functionline_to_geodetic_width_poly(line::Vector{<: Point2}, width; geodesic = Proj.geod_geodesic(6378137, 1/298.257223563))
Returns a Vector{Point2{Float64}}
which represents a polygon which is width
metres wide, and follows the path of line
.
This is mostly useful for tracing wide lines on Raster maps.
Fundamentally, you can think of this function as creating a polygon from a line, with a specified width. There's no interpolation, though - if you want interpolation, pass an interpolated vector of points in.