<jupyter_start><jupyter_text>First, ensure you've run "`cargo build --release`" from the repo root<jupyter_code>!CARGO_INCREMENTAL="0" cargo build --release
# You'll need the GeoJSON and Shapely packages. Install using pip
from ffi import simplify_coords, simplify_coords_vw
from shapely.geometry import LineString, shape, Point
import geojson

from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
from IPython.core.display import HTML
HTML(
    """
    <style>
    div.output_svg div {
        width:50% !important;
        height:50% !important;
    }
    </style>
    """
)<jupyter_output><empty_output><jupyter_text>Load a long LineString from GeoJSON<jupyter_code># Quite a long, complex LineString
with open('examples/route1.geojson', 'r') as f:
    orig_1 = shape(geojson.load(f))
print(len(orig_1.coords))
orig_1<jupyter_output>832<jupyter_text>Simplify it using Ramer–Douglas-Peucker<jupyter_code>simplified_rdp = LineString(simplify_coords(orig_1.coords, 0.001))
print(len(simplified_rdp.coords))
simplified_rdp<jupyter_output>43<jupyter_text>Simplify it interactively<jupyter_code>def interactive_simplify_dp(inp_geom, threshold=0.005):
    ls = LineString(simplify_coords(inp_geom, threshold))
    return ls
interact(interactive_simplify_dp, inp_geom=fixed(orig_1.coords), threshold=(0.000009, 0.050, 0.000001))<jupyter_output><empty_output><jupyter_text>Simplify it using Visvalingam-Whyatt<jupyter_code>def interactive_simplify_vw(inp_geom, threshold=.000175):
    ls = LineString(simplify_coords_vw(inp_geom, threshold))
    return ls

interact(interactive_simplify_vw, inp_geom=fixed(orig_1.coords), threshold=(.0000010, .00090, .00000005))<jupyter_output><empty_output><jupyter_text>A more complex Polygon<jupyter_code>with open('examples/polygon.json', 'r') as f:
    poly = shape(geojson.load(f))

interact(interactive_simplify_vw, inp_geom=fixed(poly.exterior.coords), threshold=(100., 1500., 50))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11194779116465864, 'fraction_numerical': 0.0391566265060241, 'mean_word_length': 7.168032786885246, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '486260', 'license': 'MIT', 'n_tokens_mistral': 811, 'n_tokens_neox': 722, 'n_words': 131, 'path': 'examples.ipynb', 'repo_name': 'urschrei/rdp', 'size': '1992'}