verticapy.sql.geo.split_polygon_n#
- verticapy.sql.geo.split_polygon_n(p: str, nbins: int = 100) vDataFrame #
Splits a polygon into (nbins 2) smaller polygons of approximately equal total area. This process is inexact, and the split polygons have approximated edges; greater values for nbins produces more accurate and precise edge approximations.
Parameters#
- p: str
String representation of the polygon.
- nbins: int, optional
Number of bins used to cut the longitude and the latitude. Split polygons have approximated edges, and greater values for
nbins
leads to more accurate and precise edge approximations.
Returns#
- vDataFrame
output
vDataFrame
that includes the new polygons.
Examples#
We import
verticapy
:import verticapy as vp
Hint
By assigning an alias to
verticapy
, we mitigate the risk of code collisions with other libraries. This precaution is necessary because verticapy uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions fromverticapy
are used as intended without interfering with functions from other libraries.Let’s use the following polygon.
p = 'POLYGON ((121.334030916 31.5081948415, 121.334030917 31.5079167872, 121.333748304 31.5081948413, 121.334030916 31.5081948415))' poly = vp.vDataFrame({"triangle": [p]}) poly["triangle"].apply("ST_GeomFromText({})") poly["triangle"].geo_plot( color="white", edgecolor="black", )
Now, let’s proceed to split the polygon into multiple parts.
from verticapy.sql.geo import split_polygon_n split_p = split_polygon_n(p) display(split_p)
123gidInteger100%🌎Geometry(2024)100%1 99 2 100 3 199 4 200 5 201 6 299 7 300 8 301 9 302 10 399 11 400 12 401 13 402 14 403 15 499 16 500 17 501 18 502 19 503 20 504 Let’s visualize it.
split_p["geom"].geo_plot( color="white", edgecolor="black", )
Note
This function can be employed to partition the space into multiple smaller segments, enabling more precise analysis. It proves particularly useful for use cases such as analyzing density.