-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "bbdf8e16-751d-4948-8fd9-b837e22c6ad1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import shapely" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "63be5462-f8a9-4e0d-9ef6-13783d138150", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"p = shapely.Polygon([(100, 120), (100, 200), \n", | ||
" (200, 180), (200, 100)])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "3e9d6eda-784d-4230-bdad-f57130f111b5", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"image/svg+xml": [ | ||
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"108.0\" height=\"108.0\" viewBox=\"96.0 96.0 108.0 108.0\" preserveAspectRatio=\"xMinYMin meet\"><g transform=\"matrix(1,0,0,-1,0,300.0)\"><path fill-rule=\"evenodd\" fill=\"#66cc99\" stroke=\"#555555\" stroke-width=\"2.0\" opacity=\"0.6\" d=\"M 100.0,120.0 L 100.0,200.0 L 200.0,180.0 L 200.0,100.0 L 100.0,120.0 z\" /></g></svg>" | ||
], | ||
"text/plain": [ | ||
"<POLYGON ((100 120, 100 200, 200 180, 200 100, 100 120))>" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"p" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "26a819a7-1f07-4e7a-8c5d-c5bd6f580696", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ls = shapely.LineString([(90, 120), (220, 120)])\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 22, | ||
"id": "79349323-d4ab-4a81-86fc-bdce716bbbd2", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"lls = []\n", | ||
"for y in range(95, 206, 4):\n", | ||
" lls.append(shapely.LineString([(90, y), (220, y)]))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 23, | ||
"id": "9a90abe1-68d4-4cb8-8a33-ea388058aa82", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"lls = shapely.MultiLineString(lls)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 24, | ||
"id": "cae77404-c4ac-47a3-b802-ddf45e7d2754", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"image/svg+xml": [ | ||
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"140.39999999999998\" height=\"118.39999999999999\" viewBox=\"84.8 89.8 140.39999999999998 118.39999999999999\" preserveAspectRatio=\"xMinYMin meet\"><g transform=\"matrix(1,0,0,-1,0,298.0)\"><g><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,95.0 220.0,95.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,99.0 220.0,99.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,103.0 220.0,103.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,107.0 220.0,107.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,111.0 220.0,111.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,115.0 220.0,115.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,119.0 220.0,119.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,123.0 220.0,123.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,127.0 220.0,127.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,131.0 220.0,131.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,135.0 220.0,135.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,139.0 220.0,139.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,143.0 220.0,143.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,147.0 220.0,147.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,151.0 220.0,151.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,155.0 220.0,155.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,159.0 220.0,159.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,163.0 220.0,163.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,167.0 220.0,167.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,171.0 220.0,171.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,175.0 220.0,175.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,179.0 220.0,179.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,183.0 220.0,183.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,187.0 220.0,187.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,191.0 220.0,191.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,195.0 220.0,195.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,199.0 220.0,199.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"90.0,203.0 220.0,203.0\" opacity=\"0.8\" /></g></g></svg>" | ||
], | ||
"text/plain": [ | ||
"<MULTILINESTRING ((90 95, 220 95), (90 99, 220 99), (90 103, 220 103), (90 1...>" | ||
] | ||
}, | ||
"execution_count": 24, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"lls\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 25, | ||
"id": "f26e2e72-dbc4-42de-90b8-9299578d733c", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"image/svg+xml": [ | ||
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"108.0\" height=\"104.0\" viewBox=\"96.0 99.0 108.0 104.0\" preserveAspectRatio=\"xMinYMin meet\"><g transform=\"matrix(1,0,0,-1,0,302.0)\"><g><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"185.0,103.0 200.0,103.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"165.0,107.0 200.0,107.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"145.0,111.0 200.0,111.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"125.0,115.0 200.0,115.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"105.0,119.0 200.0,119.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,123.0 200.0,123.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,127.0 200.0,127.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,131.0 200.0,131.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,135.0 200.0,135.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,139.0 200.0,139.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,143.0 200.0,143.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,147.0 200.0,147.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,151.0 200.0,151.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,155.0 200.0,155.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,159.0 200.0,159.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,163.0 200.0,163.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,167.0 200.0,167.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,171.0 200.0,171.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,175.0 200.0,175.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,179.0 200.0,179.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,183.0 185.0,183.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,187.0 165.0,187.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,191.0 145.0,191.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,195.0 125.0,195.0\" opacity=\"0.8\" /><polyline fill=\"none\" stroke=\"#66cc99\" stroke-width=\"2.0\" points=\"100.0,199.0 105.0,199.0\" opacity=\"0.8\" /></g></g></svg>" | ||
], | ||
"text/plain": [ | ||
"<MULTILINESTRING ((185 103, 200 103), (165 107, 200 107), (145 111, 200 111)...>" | ||
] | ||
}, | ||
"execution_count": 25, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"p.intersection(lls)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 21, | ||
"id": "5012337e-b5ca-43e3-a1e0-7719ae33d18c", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"shapely.geometry.collection.GeometryCollection" | ||
] | ||
}, | ||
"execution_count": 21, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"type(_)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "py5", | ||
"language": "python", | ||
"name": "py5" | ||
}, | ||
"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.12.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |