Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pairwise_linestring_intersection example in user guide #989

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 95 additions & 7 deletions docs/source/user_guide/cuspatial_api_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,94 @@
"With some careful grouping, one can reconstruct the original complete polygons that fall within the range."
isVoid marked this conversation as resolved.
Show resolved Hide resolved
isVoid marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"cell_type": "markdown",
"id": "3b33ce2b-965f-42a1-a89e-66d7ca80d907",
"metadata": {},
"source": [
"## Set Operations"
]
},
{
"cell_type": "markdown",
"id": "d73548f3-c9bb-43ff-9788-858f3b7d08e4",
"metadata": {},
"source": [
"### Linestring Intersections\n",
"\n",
"cuSpatial provides a linestring-linestring intersection algorithm to compute the overlapping geometries between two linestrings.\n",
"The API also returns the ids for each returned geometry to help user to trace back the source geometry."
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "cc72a44d-a9bf-4432-9898-de899ac45869",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(<cudf.core.column.numerical.NumericalColumn object at 0x7f5cabd553c0>\n",
"[\n",
" 0,\n",
" 144\n",
"]\n",
"dtype: int32, 0 POINT (-130.53611 54.80275)\n",
"1 POINT (-130.53611 54.80278)\n",
"2 POINT (-130.53611 54.80275)\n",
"3 POINT (-129.98000 55.28500)\n",
"4 POINT (-130.53611 54.80278)\n",
" ... \n",
"139 LINESTRING (-113.00000 49.00000, -113.00000 49...\n",
"140 LINESTRING (-83.89077 46.11693, -83.61613 46.1...\n",
"141 LINESTRING (-116.04818 49.00000, -116.04818 49...\n",
"142 LINESTRING (-120.00000 49.00000, -117.03121 49...\n",
"143 LINESTRING (-122.84000 49.00000, -120.00000 49...\n",
"Length: 144, dtype: geometry, lhs_linestring_id \\\n",
"0 [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ... \n",
"\n",
" lhs_segment_id \\\n",
"0 [18, 16, 18, 15, 17, 137, 14, 16, 13, 15, 14, ... \n",
"\n",
" rhs_linestring_id \\\n",
"0 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... \n",
"\n",
" rhs_segment_id \n",
"0 [9, 10, 10, 11, 11, 28, 12, 12, 13, 13, 14, 15... )\n"
]
}
],
"source": [
"from cuspatial.core.binops.intersection import pairwise_linestring_intersection\n",
"\n",
"host_dataframe = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n",
"usa_boundary = cuspatial.from_geopandas(host_dataframe[host_dataframe.name == \"United States of America\"].geometry.boundary)\n",
"canada_boundary = cuspatial.from_geopandas(host_dataframe[host_dataframe.name == \"Canada\"].geometry.boundary)\n",
"\n",
"boundary_intersections = pairwise_linestring_intersection(usa_boundary, canada_boundary)\n",
"\n",
"print(boundary_intersections)"
]
},
{
"cell_type": "markdown",
"id": "63f651fd-99e0-4c62-953c-9d1caf9145bf",
"metadata": {},
"source": [
"The result contains 3 series/dataframes.\n",
"\n",
"The first integer series shows that the first row of the result contains 144 geometries.\n",
"\n",
"The second element is a geoseries that contains the intersecting geometries, including points and linestrings.\n",
"\n",
"The third element is a dataframe that contains IDs to the input segments and linestrings, 4 for each result row.\n",
"Each represents ids to lhs, rhs linestring and segment ids."
]
},
{
"cell_type": "markdown",
"id": "a17bd64a",
Expand All @@ -976,7 +1064,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"id": "bf7b2256",
"metadata": {
"tags": []
Expand All @@ -993,7 +1081,7 @@
"dtype: int64"
]
},
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -1078,7 +1166,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"id": "e3a0a9a3-0bdd-4f05-bcb5-7db4b99a44a3",
"metadata": {
"tags": []
Expand Down Expand Up @@ -1142,7 +1230,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 21,
"id": "023bd25a-35be-435d-ab0b-ecbd7a47e147",
"metadata": {
"tags": []
Expand Down Expand Up @@ -1201,7 +1289,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 22,
"id": "784aff8e-c9ed-4a81-aa87-bf301b3b90af",
"metadata": {
"tags": []
Expand All @@ -1216,7 +1304,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 23,
"id": "fea24c78-cf5c-45c6-b860-338238e61323",
"metadata": {
"tags": []
Expand Down Expand Up @@ -1301,7 +1389,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.10.9"
},
"vscode": {
"interpreter": {
Expand Down