topojson.ops
asvoid
asvoid(arr)
Utility function to create a 1-dimensional numpy void object (bytes) of a 2-dimensional array. This is useful for the function numpy.in1d(), since it only accepts 1-dimensional objects.
Parameters
Returns
np_array_bbox_points_line
np_array_bbox_points_line(line, tree_splitter)
Get junctions within bbox of line and return both as numpy array
Parameters
Returns
insert_coords_in_line
insert_coords_in_line(line, tree_splitter)
Insert coordinates that are on the line, but where no vertices exists
Parameters
Returns
fast_split
fast_split(line, splitter)
Split a LineString (numpy.array) with a Point or MultiPoint. This function is a replacement for the shapely.ops.split function, but faster.
Parameters
Returns
signed_area
signed_area(ring)
Compute the signed area of a ring (polygon)
Note: implementation is numpy variant of shapelyâs version: https://github.com/Toblerity/Shapely/blob/master/shapely/algorithms/cga.py
Parameters
Returns
is_ccw
is_ccw(ring)
Provide information if a given ring is clockwise or counterclockwise.
Parameters
Returns
properties_foreign
properties_foreign(objects)
Try to parse the object properties as foreign members. Reserved keys are: [type
, bbox
, coordinates
, geometries
, geometry
, properties
, features
]
If these keys are detected they will not be set as a foreign member and will remain nested within properties.
Only if the
Parameters
bounds
bounds(arr)
Returns a (minx, miny, maxx, maxy) tuple (float values) that bounds the object.
Parameters
Returns
compare_bounds
compare_bounds(b0, b1)
Function that compares two bounds with each other. Returns the max bound.
Parameters
Returns
np_array_from_lists
np_array_from_lists(nested_lists)
Function to create numpy array from nested lists. The shape of the numpy array are the number of nested lists (rows) x the length of the longest nested list (columns). Rows that contain less values are filled with np.nan values.
Parameters
Returns
lists_from_np_array
lists_from_np_array(np_array)
Function to convert numpy array to list, where elements set as np.nan are filtered
get_matches
get_matches(geoms, tree_idx)
Function to return the indices of the rtree that intersects with the input geometries
Parameters
Returns
select_unique
select_unique(data)
Function to return unique pairs within a numpy array. Example: input as [[1,2], [2,1]] will return as [[1,2]]
Parameters
Returns
select_unique_combs
select_unique_combs(linestrings)
Given a set of input linestrings will create unique couple combinations. Each combination created contains a couple of two linestrings where the envelope overlaps each other. Linestrings with non-overlapping envelopes are not returned as combination.
Parameters
Returns
quantize
quantize(linestrings, bbox, quant_factor=1000000.0)
Function that applies quantization. Quantization removes information by reducing the precision of each coordinate, effectively snapping each point to a regular grid.
Parameters
Returns
simplify
simplify(linestrings, epsilon, algorithm='dp', package='simplification', input_as='linestring', prevent_oversimplify=True)
Function that simplifies linestrings. The goal of line simplification is to reduce the number of points by deleting some trivial points, but without destroying the essential shape of the lines in the process.
One can choose between the Douglas-Peucker [âdpâ] algorithm (which simplifies a line based upon vertical interval) and VisvalingamâWhyatt [âvwâ] (which progressively removes points with the least-perceptible change).
Docs
- https://observablehq.com/@lemonnish/minify-topojson-in-the-browser
- https://github.com/topojson/topojson-simplify#planarTriangleArea
- https://www.jasondavies.com/simplify/
- https://bost.ocks.org/mike/simplify/
- https://pdfs.semanticscholar.org/9877/cdf50a15367bcb86649b67df8724425c5451.pdf
Parameters
linestrings
: list of shapely.geometry.LineStringsLineStrings that will be simplified
epsilon
: intSimplification factor. Normally this varies 1.0, 0.1 or 0.001 for ârdpâ and 30-100 for âvwâ.
algorithm
: str, optionalChoose between
dp
for Douglas-Peucker andvw
for VisvalingamâWhyatt. Defaults todp
, as its evaluation maintains to be good (Shi, W. & Cheung, C., 2006)
package
: str, optionalChoose between
simplification
orshapely
. Both packages contains simplification algorithms (shapely
onlydp
, andsimplification
bothdp
andvw
).
input_as
: str, optionalChoose between
linestring
orarray
. This function is being called from different locations with different input types. Chooselinestring
if the input type are shapely.geometry.LineString orarray
if the input are numpy.array coordinates
Returns
winding_order
winding_order(geom, order='CW_CCW')
Function that force a certain winding order on the resulting output geometries. One can choose between CCW_CW
and CW_CCW
.
CW_CCW
implies clockwise for exterior polygons and counterclockwise for interior polygons (aka the geographical right-hand-rule where the right hand is in the area of interest as you walk the line).
CCW_CW
implies counterclockwise for exterior polygons and clockwise for interior polygons (aka the mathematical right-hand-rule where the right hand curls around the polygonâs exterior with your thumb pointing âupâ (toward space), signing a positive area for the polygon in the signed area sense).
TopoJSON, and so this package, defaults to CW_CCW
, but depending on the application you might decide differently.
- https://bl.ocks.org/mbostock/a7bdfeb041e850799a8d3dce4d8c50c8
Only applies to Polygons and MultiPolygons.
Parameters
geom
: geometry or shapely.geometry.GeometryCollectionGeometry objects where the winding order will be forced upon.
order
: str, optionalChoose
CW_CCW
for clockwise for exterior- and counterclockwise for interior polygons orCCW_CW
for counterclockwise for exterior- and clockwise for interior polygons, by defaultCW_CCW
.
Returns
round_coordinates
round_coordinates(linestrings, rounding_precision)
Round all coordinates to a specified precision, e.g. rounding_precision=3
will round to 3 decimals on the resulting output geometries (after the topology is computed).
Parameters
Returns
prettify
prettify(topojson_object)
prettify TopoJSON Format output for readability.
Parameters
Returns
properties_level
properties_level(topojson_object, position='nested')
Define where the attributes of the geometry object should be placed. Choose between nested
or foreign
. Default is nested
where the attribute information is placed within the âpropertiesâ dictionary, part of the geometry. foreign
, tries to place the attributes on the same level as the geometry.
Parameters
delta_encoding
delta_encoding(linestrings)
Function to apply delta-encoding to linestrings.
Parameters
Returns
find_duplicates
find_duplicates(segments_list, type='array')
Function for solely detecting and recording duplicate LineStrings. The function converts sorts the coordinates of each linestring and gets the hash. Using the hashes it can quickly detect duplicates and return the indices.
Parameters
map_values
map_values(arr, search_vals, replace_vals)
This function replace values element-wise in a numpy array. Its quick and avoids a np.where-loop (which is slow). The result is a new array, not inplace.
Parameters
Returns