rdp 0.12.8

An FFI wrapper for the Ramer–Douglas–Peucker and Visvalingam-Whyatt algorithms
Documentation
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# First, ensure you've run \"`cargo build --release`\" from the repo root"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0m\u001b[0m\u001b[32m\u001b[1m   Compiling\u001b[0m rdp v0.2.45 (file:///Users/sth/dev/rdp)\n",
      "\u001b[0m\u001b[0m\u001b[32m\u001b[1m    Finished\u001b[0m release [optimized] target(s) in 3.93 secs\n"
     ]
    }
   ],
   "source": [
    "!CARGO_INCREMENTAL=\"0\" cargo build --release"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# You'll need the GeoJSON and Shapely packages. Install using pip\n",
    "from ffi import simplify_coords, simplify_coords_vw\n",
    "from shapely.geometry import LineString, shape, Point\n",
    "import geojson\n",
    "\n",
    "from ipywidgets import interact, interactive, fixed, interact_manual\n",
    "import ipywidgets as widgets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <style>\n",
       "    div.output_svg div {\n",
       "        width:50% !important;\n",
       "        height:50% !important;\n",
       "    }\n",
       "    </style>\n",
       "    "
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from IPython.core.display import HTML\n",
    "HTML(\n",
    "    \"\"\"\n",
    "    <style>\n",
    "    div.output_svg div {\n",
    "        width:50% !important;\n",
    "        height:50% !important;\n",
    "    }\n",
    "    </style>\n",
    "    \"\"\"\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load a long LineString from GeoJSON"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "832\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"100.0\" height=\"100.0\" viewBox=\"-1.0001938400000001 51.982871159999995 0.3359836800000001 0.25231268000000995\" preserveAspectRatio=\"xMinYMin meet\"><g transform=\"matrix(1,0,0,-1,0,104.21805499999999)\"><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"0.006719673600000003\" points=\"-0.701206,52.220489 -0.701206,52.220485 -0.700731,52.220272 -0.697521,52.219863 -0.694064,52.219413 -0.693167,52.219326 -0.692289,52.21928 -0.691663,52.219402 -0.68997,52.219924 -0.689329,52.220287 -0.688109,52.221408 -0.687763,52.22153 -0.686421,52.221763 -0.68568,52.22182 -0.685305,52.221851 -0.684028,52.221916 -0.683046,52.221885 -0.680747,52.221691 -0.679648,52.221645 -0.679101,52.221714 -0.678365,52.221897 -0.677979,52.222503 -0.677754,52.222652 -0.677489,52.222728 -0.677259,52.22274 -0.677103,52.222728 -0.677071,52.22245 -0.676914,52.222171 -0.676797,52.221961 -0.676654,52.221637 -0.676681,52.221134 -0.676875,52.22071 -0.67714,52.219985 -0.677246,52.219234 -0.677387,52.21836 -0.677377,52.218238 -0.677417,52.217987 -0.677556,52.216899 -0.677668,52.215282 -0.67791,52.214523 -0.678637,52.213558 -0.679666,52.212017 -0.68047,52.210945 -0.680859,52.210647 -0.68129,52.210605 -0.681389,52.208835 -0.681614,52.206672 -0.681991,52.204463 -0.682364,52.202465 -0.68274,52.200462 -0.68289,52.198509 -0.682965,52.196666 -0.683149,52.196182 -0.683603,52.194965 -0.684064,52.194004 -0.684241,52.193172 -0.684388,52.191932 -0.684316,52.191169 -0.684253,52.189838 -0.6842,52.189201 -0.684195,52.188991 -0.684195,52.188854 -0.684204,52.188716 -0.684222,52.188583 -0.684259,52.188411 -0.684338,52.188182 -0.684406,52.188003 -0.684501,52.187816 -0.684617,52.187614 -0.684738,52.187431 -0.68498,52.18711 -0.685209,52.186859 -0.685402,52.186672 -0.685676,52.186424 -0.686385,52.185783 -0.686816,52.185337 -0.687045,52.185131 -0.687087,52.185077 -0.687121,52.185012 -0.687161,52.184871 -0.687136,52.184841 -0.687103,52.184757 -0.687103,52.184688 -0.687135,52.184623 -0.687188,52.184562 -0.687242,52.184524 -0.687355,52.184474 -0.687449,52.184452 -0.68757,52.184402 -0.687669,52.184337 -0.687782,52.184238 -0.688131,52.183097 -0.688433,52.182106 -0.688676,52.181171 -0.688849,52.180351 -0.689083,52.178966 -0.689394,52.177135 -0.690294,52.171955 -0.690372,52.171508 -0.690453,52.171188 -0.690582,52.170825 -0.690686,52.170597 -0.690865,52.170272 -0.69099,52.170066 -0.691116,52.169857 -0.691282,52.169624 -0.69161,52.169219 -0.691817,52.169013 -0.692108,52.168781 -0.692494,52.168502 -0.69275,52.168346 -0.692979,52.168224 -0.693163,52.168151 -0.693365,52.168098 -0.69364,52.168045 -0.694168,52.167972 -0.694766,52.167888 -0.695412,52.167789 -0.69587,52.167713 -0.696212,52.167648 -0.696508,52.167579 -0.696759,52.167499 -0.697006,52.1674 -0.697185,52.167312 -0.697373,52.167209 -0.697526,52.167102 -0.697657,52.166988 -0.69779,52.166847 -0.698311,52.166091 -0.700219,52.163684 -0.7003,52.163578 -0.700476,52.163345 -0.700539,52.163238 -0.700614,52.163089 -0.700704,52.162925 -0.700789,52.162773 -0.700921,52.162548 -0.700912,52.162342 -0.70083,52.162284 -0.70083,52.162216 -0.700874,52.162147 -0.700977,52.162113 -0.701229,52.161842 -0.701431,52.161312 -0.701862,52.160633 -0.702077,52.160202 -0.702104,52.160163 -0.70219,52.160007 -0.702239,52.159927 -0.702294,52.159858 -0.70241,52.159614 -0.702459,52.159488 -0.7025,52.159313 -0.702504,52.159118 -0.702455,52.158798 -0.702346,52.158477 -0.702316,52.15842 -0.702203,52.158103 -0.702176,52.158058 -0.701953,52.157695 -0.701768,52.157352 -0.701723,52.157226 -0.7017,52.157165 -0.701664,52.157047 -0.701615,52.156826 -0.701571,52.156669 -0.701548,52.156387 -0.701512,52.156063 -0.701512,52.15578 -0.701525,52.155624 -0.701575,52.155338 -0.701727,52.154644 -0.701826,52.154129 -0.70188,52.153797 -0.701893,52.153659 -0.701893,52.153541 -0.701889,52.153358 -0.701886,52.153305 -0.701889,52.153251 -0.701925,52.153045 -0.701961,52.15287 -0.70197,52.152812 -0.70201,52.152629 -0.702034,52.152572 -0.702086,52.152416 -0.702122,52.152309 -0.702127,52.152294 -0.70214,52.152187 -0.702136,52.152145 -0.702109,52.151985 -0.702029,52.151828 -0.701913,52.151641 -0.701777,52.15139 -0.701709,52.151214 -0.701741,52.151065 -0.70184,52.150894 -0.701911,52.150806 -0.702199,52.150474 -0.702634,52.149974 -0.702849,52.149723 -0.702887,52.149677 -0.703183,52.149341 -0.703684,52.148765 -0.703955,52.148433 -0.704398,52.14785 -0.705121,52.146759 -0.705174,52.146678 -0.705327,52.146419 -0.705548,52.145942 -0.705677,52.145565 -0.705776,52.145092 -0.705781,52.144565 -0.705758,52.144309 -0.705709,52.144077 -0.705686,52.143959 -0.70565,52.143825 -0.705471,52.143356 -0.705273,52.142894 -0.70508,52.142501 -0.704515,52.141265 -0.704305,52.140701 -0.704174,52.140274 -0.704049,52.139774 -0.703976,52.139328 -0.703918,52.138889 -0.703904,52.138481 -0.703936,52.136676 -0.703946,52.13636 -0.703946,52.13594 -0.703955,52.135734 -0.703999,52.134254 -0.704031,52.1319 -0.704016,52.131225 -0.703887,52.130077 -0.70368,52.129093 -0.703411,52.128234 -0.702894,52.126934 -0.702823,52.126766 -0.702559,52.126251 -0.702199,52.125507 -0.701458,52.12384 -0.700921,52.122684 -0.700726,52.122249 -0.700708,52.122211 -0.700548,52.121856 -0.700309,52.12133 -0.699911,52.120502 -0.699574,52.119915 -0.699232,52.119369 -0.699003,52.119007 -0.698756,52.118667 -0.698267,52.11803 -0.697566,52.117198 -0.69684,52.116455 -0.695457,52.115085 -0.694599,52.114238 -0.693784,52.113452 -0.692176,52.111881 -0.691605,52.11127 -0.69108,52.110607 -0.690691,52.109992 -0.690479,52.109565 -0.69047,52.109542 -0.690304,52.109157 -0.690182,52.10873 -0.690101,52.10831 -0.690079,52.107982 -0.690075,52.107627 -0.690083,52.107486 -0.690084,52.107463 -0.690097,52.107242 -0.690187,52.106822 -0.690269,52.106452 -0.690394,52.106029 -0.690699,52.105281 -0.690959,52.104724 -0.691432,52.103927 -0.692279,52.102657 -0.692359,52.102504 -0.692395,52.102386 -0.692395,52.102313 -0.692379,52.102237 -0.692333,52.102165 -0.692262,52.1021 -0.692121,52.102085 -0.691745,52.102027 -0.691619,52.101997 -0.691533,52.101959 -0.691472,52.101902 -0.691436,52.101825 -0.691435,52.101779 -0.691448,52.101734 -0.69148,52.101673 -0.691502,52.101646 -0.691529,52.101627 -0.691637,52.10139 -0.69165,52.101264 -0.691821,52.100822 -0.692162,52.099666 -0.692221,52.099449 -0.692395,52.098762 -0.692606,52.097942 -0.692985,52.096496 -0.693178,52.095829 -0.69395,52.092929 -0.694196,52.09196 -0.694483,52.090797 -0.69507,52.087989 -0.69582,52.084392 -0.695929,52.084033 -0.696067,52.083606 -0.696395,52.082881 -0.696594,52.082481 -0.696835,52.082107 -0.697382,52.081428 -0.697867,52.080924 -0.698241,52.080562 -0.698649,52.08023 -0.698809,52.080116 -0.699399,52.079696 -0.700282,52.079162 -0.700772,52.078899 -0.700946,52.078807 -0.701907,52.078369 -0.702697,52.078067 -0.703285,52.077865 -0.703761,52.07772 -0.703999,52.077671 -0.704242,52.077648 -0.704443,52.077655 -0.704578,52.077636 -0.704784,52.077568 -0.704807,52.077522 -0.70487,52.077453 -0.704996,52.077388 -0.705183,52.077358 -0.705291,52.077365 -0.70543,52.077396 -0.705652,52.077365 -0.706252,52.077175 -0.706553,52.077083 -0.706575,52.077003 -0.706588,52.076984 -0.706634,52.076938 -0.706741,52.076885 -0.706889,52.076858 -0.706984,52.076858 -0.707069,52.076873 -0.707185,52.076923 -0.707419,52.076934 -0.707679,52.076919 -0.708978,52.076698 -0.713322,52.076053 -0.720921,52.074947 -0.721141,52.074893 -0.721356,52.074825 -0.721414,52.074775 -0.721495,52.074737 -0.721617,52.074718 -0.721751,52.074726 -0.721868,52.074771 -0.722038,52.074779 -0.722209,52.074771 -0.72374,52.074523 -0.724772,52.074291 -0.72558,52.074058 -0.726375,52.073783 -0.72708,52.073493 -0.727604,52.073238 -0.728005,52.07304 -0.728421,52.072803 -0.729687,52.072013 -0.730526,52.071475 -0.731793,52.070621 -0.732457,52.070171 -0.733091,52.069747 -0.733665,52.069385 -0.735679,52.068225 -0.735855,52.06813 -0.736842,52.067619 -0.736855,52.067611 -0.737659,52.067226 -0.73853,52.066837 -0.738799,52.066642 -0.738804,52.066612 -0.738817,52.066562 -0.73888,52.066497 -0.738997,52.066444 -0.739145,52.066425 -0.739288,52.066444 -0.73967,52.066329 -0.740428,52.066036 -0.74099,52.065818 -0.741713,52.065555 -0.741964,52.065464 -0.743104,52.065074 -0.744414,52.064647 -0.744675,52.064571 -0.744868,52.064514 -0.745044,52.064464 -0.745233,52.064411 -0.745478,52.064342 -0.746322,52.06409 -0.74739,52.06385 -0.747592,52.063774 -0.747796,52.063655 -0.747834,52.063617 -0.747853,52.063598 -0.747929,52.063556 -0.748077,52.063518 -0.748141,52.063522 -0.748265,52.063537 -0.748496,52.063556 -0.748723,52.063541 -0.749689,52.063331 -0.750263,52.063205 -0.750739,52.063098 -0.751762,52.062873 -0.752031,52.062816 -0.752346,52.062747 -0.754321,52.062313 -0.75591,52.061965 -0.757054,52.061717 -0.757319,52.061656 -0.757521,52.061595 -0.757701,52.061466 -0.757768,52.061401 -0.75788,52.061355 -0.758002,52.061332 -0.758159,52.06134 -0.758277,52.061374 -0.758545,52.061389 -0.758769,52.061374 -0.759623,52.061199 -0.761911,52.060699 -0.762221,52.060634 -0.763299,52.060394 -0.764074,52.060222 -0.765969,52.059741 -0.766185,52.059677 -0.767809,52.0592 -0.767908,52.059169 -0.768443,52.059032 -0.77228,52.057834 -0.772393,52.057777 -0.772482,52.057712 -0.77258,52.05764 -0.772621,52.057544 -0.772679,52.057491 -0.772747,52.057453 -0.772872,52.057418 -0.77303,52.057411 -0.773174,52.057445 -0.773353,52.057449 -0.773507,52.057441 -0.773689,52.057392 -0.775059,52.05688 -0.776459,52.056388 -0.778236,52.055809 -0.780149,52.055282 -0.781155,52.055004 -0.782626,52.054576 -0.784758,52.053886 -0.784911,52.053833 -0.785068,52.053745 -0.785077,52.053695 -0.785109,52.053642 -0.785212,52.053565 -0.785351,52.053524 -0.785463,52.053524 -0.785737,52.053512 -0.785922,52.053489 -0.786083,52.053443 -0.786401,52.053348 -0.788345,52.052715 -0.790095,52.052135 -0.790891,52.051887 -0.792247,52.051456 -0.79384,52.05096 -0.794319,52.0508 -0.794903,52.050621 -0.79665,52.050033 -0.797268,52.049816 -0.797619,52.049694 -0.797789,52.049594 -0.797798,52.049552 -0.797834,52.049499 -0.797893,52.049446 -0.797955,52.049415 -0.798121,52.049377 -0.798197,52.049381 -0.798243,52.049385 -0.798319,52.0494 -0.798624,52.049388 -0.798944,52.049331 -0.800222,52.048919 -0.801124,52.048633 -0.801928,52.048377 -0.802709,52.048107 -0.802866,52.048049 -0.802928,52.048015 -0.802983,52.047969 -0.803054,52.047882 -0.80309,52.047821 -0.803118,52.047733 -0.803105,52.047702 -0.803094,52.047676 -0.80306,52.047588 -0.803023,52.047424 -0.803014,52.047348 -0.803023,52.047275 -0.80304,52.047187 -0.803077,52.0471 -0.803288,52.046756 -0.803374,52.046634 -0.803481,52.046543 -0.803579,52.046485 -0.803696,52.046405 -0.80384,52.046318 -0.803961,52.046272 -0.804199,52.046218 -0.804414,52.046199 -0.80454,52.046192 -0.804661,52.046195 -0.804881,52.046218 -0.805047,52.046249 -0.805155,52.046272 -0.805372,52.04636 -0.805469,52.046409 -0.805605,52.046489 -0.805707,52.046577 -0.805843,52.046707 -0.805869,52.046775 -0.805914,52.046871 -0.806071,52.047042 -0.806196,52.047172 -0.806362,52.047275 -0.806533,52.047344 -0.806748,52.047401 -0.807067,52.047481 -0.80919,52.048007 -0.810375,52.048297 -0.81292,52.04874 -0.821144,52.050048 -0.82368,52.050453 -0.824743,52.050621 -0.827019,52.051013 -0.828662,52.051391 -0.830493,52.051921 -0.832137,52.05252 -0.83342,52.053092 -0.834054,52.053386 -0.834717,52.053745 -0.835175,52.053993 -0.835633,52.054252 -0.836666,52.054931 -0.837254,52.055377 -0.837823,52.05585 -0.839224,52.057323 -0.839821,52.05791 -0.840278,52.058338 -0.840867,52.058818 -0.841544,52.059322 -0.842105,52.059734 -0.843007,52.060272 -0.844291,52.061008 -0.845312,52.061519 -0.846398,52.062007 -0.847492,52.062435 -0.848479,52.062782 -0.851024,52.063636 -0.851419,52.063766 -0.85164,52.063838 -0.852816,52.064224 -0.85308,52.064311 -0.853143,52.064331 -0.854018,52.064601 -0.85554,52.065017 -0.857121,52.065399 -0.858921,52.065757 -0.860284,52.065982 -0.861164,52.066104 -0.862322,52.066234 -0.864046,52.066349 -0.866519,52.066459 -0.868333,52.066539 -0.868463,52.066543 -0.868553,52.066543 -0.86862,52.066532 -0.86871,52.066505 -0.868804,52.066463 -0.868868,52.066425 -0.868939,52.066368 -0.869064,52.066253 -0.869097,52.066219 -0.869146,52.066177 -0.869262,52.066097 -0.869375,52.066043 -0.869544,52.065986 -0.869724,52.065952 -0.869895,52.065944 -0.870002,52.065948 -0.870272,52.065887 -0.870384,52.065856 -0.870523,52.065811 -0.87064,52.065761 -0.870756,52.065708 -0.870967,52.065589 -0.871214,52.065307 -0.871475,52.064971 -0.871722,52.064544 -0.871932,52.064052 -0.872032,52.063491 -0.872014,52.062992 -0.871946,52.062446 -0.871704,52.061752 -0.870321,52.058223 -0.870035,52.057441 -0.869927,52.056907 -0.869854,52.056365 -0.869878,52.056072 -0.869899,52.055835 -0.869984,52.055332 -0.870133,52.054862 -0.870317,52.054458 -0.870532,52.05408 -0.870753,52.053791 -0.87091,52.053569 -0.871183,52.053256 -0.871448,52.053001 -0.873266,52.051548 -0.873409,52.051216 -0.873346,52.051132 -0.873347,52.051033 -0.873401,52.05096 -0.873481,52.05091 -0.873737,52.050666 -0.874236,52.049922 -0.874451,52.049674 -0.874653,52.049457 -0.874986,52.049144 -0.875425,52.048774 -0.875882,52.048435 -0.876574,52.048 -0.878706,52.046844 -0.881354,52.045398 -0.883379,52.044231 -0.88408,52.043811 -0.885533,52.042938 -0.887145,52.04195 -0.88907,52.040775 -0.89488,52.03725 -0.896122,52.036533 -0.898016,52.035438 -0.900341,52.034175 -0.901279,52.033645 -0.903018,52.032592 -0.907119,52.029972 -0.908623,52.02898 -0.909826,52.028121 -0.910577,52.02742 -0.911271,52.026649 -0.912601,52.024925 -0.912982,52.024459 -0.913358,52.024066 -0.913623,52.023826 -0.914031,52.023498 -0.91462,52.023063 -0.915142,52.022747 -0.915665,52.022449 -0.916111,52.022216 -0.916644,52.021984 -0.917147,52.021835 -0.917946,52.021629 -0.91817,52.021564 -0.918349,52.021492 -0.918579,52.021373 -0.918816,52.021217 -0.919427,52.02082 -0.919701,52.020679 -0.919983,52.020591 -0.920222,52.020545 -0.920648,52.0205 -0.921124,52.020481 -0.921864,52.020481 -0.922548,52.020488 -0.923934,52.020465 -0.925262,52.020462 -0.926882,52.020492 -0.927583,52.020511 -0.92809,52.020519 -0.9284,52.020484 -0.92876,52.020385 -0.929226,52.020217 -0.929805,52.019996 -0.930389,52.01976 -0.932436,52.018859 -0.932938,52.0186 -0.933532,52.018272 -0.93455,52.017715 -0.935094,52.017414 -0.935752,52.017047 -0.936687,52.016483 -0.937786,52.015827 -0.938261,52.015552 -0.938797,52.015289 -0.939286,52.015094 -0.940798,52.014595 -0.941555,52.014339 -0.942862,52.013832 -0.944008,52.013393 -0.945026,52.013027 -0.945833,52.012733 -0.946292,52.012527 -0.946762,52.012264 -0.946815,52.012226 -0.947091,52.012027 -0.947255,52.011898 -0.947404,52.011768 -0.947632,52.011512 -0.947898,52.011219 -0.94847,52.010711 -0.949424,52.009887 -0.94986,52.009597 -0.950165,52.009414 -0.950704,52.009124 -0.951385,52.008739 -0.952175,52.008323 -0.952709,52.008083 -0.95333,52.007808 -0.95381,52.007637 -0.955139,52.007316 -0.955764,52.007179 -0.956433,52.007041 -0.957985,52.006782 -0.958176,52.006744 -0.959035,52.006576 -0.959916,52.006355 -0.960983,52.006069 -0.962644,52.00558 -0.963727,52.005241 -0.964642,52.004936 -0.96614,52.004386 -0.966498,52.00428 -0.967035,52.004138 -0.967321,52.004039 -0.968156,52.003696 -0.969771,52.003032 -0.97002,52.002925 -0.970444,52.0027 -0.970949,52.002376 -0.971214,52.002174 -0.971149,52.002117 -0.97113,52.002037 -0.971164,52.001976 -0.97125,52.001926 -0.971365,52.001907 -0.971465,52.001918 -0.971554,52.00196 -0.971603,52.002017 -0.972267,52.001983 -0.973048,52.001964 -0.974172,52.001979 -0.975365,52.002109 -0.976102,52.002227 -0.976723,52.002376 -0.977127,52.002452 -0.97773,52.00262 -0.978328,52.002815 -0.978793,52.002975 -0.979041,52.003044 -0.979144,52.00307 -0.979457,52.003124 -0.979861,52.003158 -0.980275,52.003147 -0.980446,52.003131 -0.980631,52.003093 -0.980818,52.003055 -0.980926,52.003032 -0.981477,52.002906 -0.981649,52.002864 -0.981722,52.002849 -0.981904,52.002803 -0.982282,52.002708 -0.982636,52.002605 -0.982915,52.002502 -0.983152,52.002403 -0.983418,52.002258 -0.984051,52.001987 -0.984321,52.001888 -0.984625,52.001804 -0.984812,52.001735 -0.985213,52.001472 -0.985238,52.001441 -0.985539,52.001304 -0.985788,52.001167 -0.985917,52.001094 -0.986025,52.001033 -0.986106,52.000988 -0.986182,52.000919 -0.986567,52.000667 -0.98685,52.000476 -0.987159,52.000301 -0.987426,52.000133 -0.987699,51.999969 -0.98775,51.999919 -0.987727,51.999801 -0.987726,51.999748 -0.987726,51.999702 -0.987717,51.99966 -0.987701,51.999626 -0.987668,51.999576 -0.987489,51.999378 -0.987447,51.999343 -0.9874,51.999309 -0.987038,51.999088 -0.986393,51.998626 -0.986065,51.998401 -0.985983,51.998336 -0.985877,51.998218 -0.985815,51.998115 -0.985752,51.997989 -0.985626,51.997722 -0.985585,51.997619 -0.985472,51.997367 -0.985413,51.997253 -0.985271,51.997028 -0.984652,51.995983 -0.984454,51.995685 -0.984244,51.995464 -0.984019,51.995315 -0.984019,51.995319\" opacity=\"0.8\" /></g></svg>"
      ],
      "text/plain": [
       "<shapely.geometry.linestring.LineString at 0x1061704e0>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Quite a long, complex LineString\n",
    "with open('examples/route1.geojson', 'r') as f:\n",
    "    orig_1 = shape(geojson.load(f))\n",
    "print(len(orig_1.coords))\n",
    "orig_1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Simplify it using Ramer–Douglas-Peucker"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "43\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"100.0\" height=\"100.0\" viewBox=\"-1.0001938400000001 51.98287516 0.3359836800000001 0.25230868000000584\" preserveAspectRatio=\"xMinYMin meet\"><g transform=\"matrix(1,0,0,-1,0,104.21805900000001)\"><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"0.006719673600000003\" points=\"-0.701206,52.220489 -0.692289,52.21928 -0.686421,52.221763 -0.677259,52.22274 -0.676654,52.221637 -0.67791,52.214523 -0.68129,52.210605 -0.684259,52.188411 -0.687782,52.184238 -0.690582,52.170825 -0.69275,52.168346 -0.697526,52.167102 -0.700476,52.163345 -0.7025,52.159313 -0.701741,52.151065 -0.705776,52.145092 -0.702823,52.126766 -0.699003,52.119007 -0.690101,52.10831 -0.695929,52.084033 -0.698649,52.08023 -0.706741,52.076885 -0.72558,52.074058 -0.738997,52.066444 -0.768443,52.059032 -0.802709,52.048107 -0.804414,52.046199 -0.832137,52.05252 -0.844291,52.061008 -0.853143,52.064331 -0.86862,52.066532 -0.872032,52.063491 -0.870133,52.054862 -0.874653,52.049457 -0.908623,52.02898 -0.91462,52.023063 -0.919983,52.020591 -0.929226,52.020217 -0.95333,52.007808 -0.97125,52.001926 -0.982915,52.002502 -0.98775,51.999919 -0.984019,51.995319\" opacity=\"0.8\" /></g></svg>"
      ],
      "text/plain": [
       "<shapely.geometry.linestring.LineString at 0x1083ff748>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "simplified_rdp = LineString(simplify_coords(orig_1.coords, 0.001))\n",
    "print(len(simplified_rdp.coords))\n",
    "simplified_rdp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Simplify it interactively"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def interactive_simplify_dp(inp_geom, threshold=0.005):\n",
    "    ls = LineString(simplify_coords(inp_geom, threshold))\n",
    "    return ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b8055c25e7e64bfc8859794a6602ab3d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=0.005, description='threshold', max=0.05, min=9e-06, step=1e-06), Outp…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.interactive_simplify_dp(inp_geom, threshold=0.005)>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "interact(interactive_simplify_dp, inp_geom=fixed(orig_1.coords), threshold=(0.000009, 0.050, 0.000001))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Simplify it using Visvalingam-Whyatt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0c3e8eee6aff491ea059c0ff7a3f8377",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=0.000175, description='threshold', max=0.0009, min=1e-06, step=5e-08),…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.interactive_simplify_vw(inp_geom, threshold=0.000175)>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def interactive_simplify_vw(inp_geom, threshold=.000175):\n",
    "    ls = LineString(simplify_coords_vw(inp_geom, threshold))\n",
    "    return ls\n",
    "\n",
    "interact(interactive_simplify_vw, inp_geom=fixed(orig_1.coords), threshold=(.0000010, .00090, .00000005))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# A more complex Polygon"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4e16639d205e4cd6b6ba9a3c2b32f414",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=100.0, description='threshold', max=1500.0, min=100.0, step=50.0), Out…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.interactive_simplify_vw(inp_geom, threshold=0.000175)>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with open('examples/polygon.json', 'r') as f:\n",
    "    poly = shape(geojson.load(f))\n",
    "\n",
    "interact(interactive_simplify_vw, inp_geom=fixed(poly.exterior.coords), threshold=(100., 1500., 50))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}