Skip to content

Commit

Permalink
Finish work with triangles
Browse files Browse the repository at this point in the history
Fixes #1 and fixes #4
  • Loading branch information
liberostelios committed Jul 15, 2020
1 parent e791c57 commit 96c63fa
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2474,23 +2474,9 @@
},
{
"cell_type": "code",
"execution_count": 770,
"execution_count": 847,
"metadata": {},
"outputs": [
{
"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=\"112469.68273864384 400206.19552712026 25.70578933232173 14.9668330149143\" preserveAspectRatio=\"xMinYMin meet\"><g transform=\"matrix(1,0,0,-1,0,800427.3578872555)\"><g><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"0.5141157866464345\" points=\"112470.6348049154,400207.1475933918 112478.60981040534,400209.1455361537\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"0.5141157866464345\" points=\"112478.60981040534,400209.1455361537 112488.83450508161,400214.03413020755 112488.98246687531,400214.1144670767 112489.1213974044,400214.20957235014 112494.4364617046,400218.26450988004\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"0.5141157866464345\" points=\"112494.4364617046,400218.26450988004 112494.2872331024,400220.2102938636\" opacity=\"0.8\" /></g></g></svg>"
],
"text/plain": [
"<shapely.geometry.multilinestring.MultiLineString at 0x1198a7910>"
]
},
"execution_count": 770,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"from shapely.ops import substring, split\n",
"\n",
Expand All @@ -2515,9 +2501,6 @@
" reverse --- Cut from the beginning or the end\n",
" \"\"\"\n",
" \n",
" # TODO: Fix this to work in any case (so even if the point to cut needs\n",
" # to eliminate completely a LineString of the MultiLineString).\n",
" \n",
" if line.type == \"LineString\":\n",
" dist = line.project(p)\n",
" if reverse:\n",
Expand All @@ -2526,11 +2509,23 @@
" return substring(line, dist, line.length)\n",
" \n",
" # Case of MultiLineString\n",
" one_line = linemerge(line)\n",
" \n",
" assert one_line.type == \"LineString\"\n",
" \n",
" geoms = []\n",
" for l in line.geoms:\n",
" if l.project(p) > 0 and l.project(p) < l.length:\n",
" geoms.append(cut_line(l, p, reverse))\n",
" else:\n",
" dist = one_line.project(p)\n",
" dist_start = one_line.project(l.boundary[0])\n",
" dist_end = one_line.project(l.boundary[1])\n",
" \n",
" if not reverse and dist_start <= dist and dist_end <= dist:\n",
" continue\n",
" elif reverse and dist_start >= dist and dist_end >= dist:\n",
" continue\n",
" geoms.append(l)\n",
" \n",
" return MultiLineString(geoms)\n",
Expand All @@ -2556,7 +2551,7 @@
" assert one_line.type == \"LineString\"\n",
" \n",
" p = Point(one_line.coords[1 if (f['u'] == nodeid) == (f['side'] == 1) else -2])\n",
" end_p = geom.boundary[0 if (f['u'] == nodeid) == (f['side'] == 1) else 1]\n",
" end_p = Point(one_line.coords[0 if (f['u'] == nodeid) == (f['side'] == 1) else -1])\n",
" \n",
" az = get_line_azimuth(f['axis_geom'].geoms[0], f['u'] != nodeid)\n",
" \n",
Expand All @@ -2567,11 +2562,14 @@
" cross_p = n[\"extended\"].intersection(geom)\n",
" if cross_p.type == \"LineString\":\n",
" continue\n",
" \n",
" \n",
" n_az = get_line_azimuth(n['axis_geom'].geoms[0], n['u'] != nodeid)\n",
" \n",
" angle = abs(n_az - az)\n",
" \n",
" if (angle < 70) and cross_p in one_line.boundary:\n",
" continue\n",
" \n",
" if angle < 120 or (angle > 240 and angle < 300):\n",
" l = 0\n",
" m = n\n",
Expand All @@ -2584,7 +2582,7 @@
" # We snap the \"remaining\" part of the road to the neighbour\n",
" geom = move_vertex(geom, p.coords[0], proj_p.coords[0])\n",
" geom = cut_line(geom, proj_p, (f['u'] == nodeid) == (f['side'] == 0))\n",
" \n",
" \n",
" # Connect the last part of the neighbour to this road\n",
" # We assume a single carriageway here\n",
" other_line = linemerge(m['trimmed'])\n",
Expand Down Expand Up @@ -2618,7 +2616,7 @@
" return geom\n",
" \n",
" lines = carriageways[carriageways['road_uuid'] == f['road_uuid']]\n",
" \n",
" \n",
" if is_dual_merge(lines, f['u']):\n",
" geom = fix_merged_at_intersection(geom, f, f['u'])\n",
"\n",
Expand All @@ -2633,8 +2631,11 @@
" geometry=\"snapped\",\n",
" crs=\"EPSG:28992\").to_file('output/carriageways_snapped.geojson', driver='GeoJSON')\n",
"\n",
"f = carriageways[carriageways['uuid'] == 3239592687].iloc[0]\n",
"fix_merged_feature(f)"
"# 3659445203\n",
"# 3596062575\n",
"# 3842874029\n",
"# f = carriageways[carriageways['uuid'] == 633889376].iloc[0]\n",
"# fix_merged_feature(f)"
]
},
{
Expand Down

0 comments on commit 96c63fa

Please sign in to comment.