geo_intersection_line_with_polygon()
计算单线或多线与多边形或多多边形的交集。
语法
geo_intersection_line_with_polygon(
lineString,
polygon)
详细了解语法约定。
参数
客户 | 类型 | 必需 | 说明 |
---|---|---|---|
lineString | dynamic |
✔️ | GeoJSON 格式 的 LineString 或 MultiLineString。 |
polygon | dynamic |
✔️ | 采用 GeoJSON 格式的多边形或多多边形。 |
返回
采用 GeoJSON 格式的 dynamic 数据类型的相交。 如果 lineString 或 multiLineString 或者多边形或多多边形无效,查询将生成 null 结果。
注意
- 对按照 WGS-84 坐标参考系统表示的地理空间坐标进行解释。
- 用于测量地球上的距离的大地基准是一个球体。 直线边缘是球体上的测地线。
- 如果输入直线或多边形边缘是直笛卡尔线,请考虑使用 geo_line_densify() 或 geo_polygon_densify() 将平面边缘转换为测地线。
LineString 定义和约束
dynamic({"type": "LineString","coordinates": [[lng_1,lat_1], [lng_2,lat_2], ..., [lng_N,lat_N]]})
dynamic({"type": "MultiLineString","coordinates": [[line_1, line_2, ..., line_N]]})
- LineString 坐标数组必须至少包含两个条目。
- 如果 longitude 是 [-180, +180] 范围内的实数,而 latitude 是 [-90, +90] 范围内的实数,则坐标 [longitude,latitude] 必须有效。
- 边缘长度必须小于 180 度。 将选择两个顶点之间的最短边缘。
多边形定义和约束
dynamic({"type": "Polygon","coordinates": [LinearRingShell, LinearRingHole_1, ..., LinearRingHole_N]})
dynamic({"type": "MultiPolygon","coordinates": [[LinearRingShell, LinearRingHole_1, ..., LinearRingHole_N],..., [LinearRingShell, LinearRingHole_1, ..., LinearRingHole_M]]})
- LinearRingShell 是必需的,定义为
counterclockwise
有序坐标数组 [[lng_1,lat_1],...,[lng_i,lat_i],...,[lng_j,lat_j],...,[lng_1,lat_1]]。 只能有一个 shell。 - LinearRingHole 是可选的,定义为
clockwise
有序坐标数组 [[lng_1,lat_1],...,[lng_i,lat_i],...,[lng_j,lat_j],...,[lng_1,lat_1]]。 可以有任意数量的内部环和孔。 - LinearRing 顶点必须很独特,至少有三个坐标。 第一个坐标必须等于最后一个坐标。 至少需要四个条目。
- 坐标 [经度, 纬度] 必须有效。 经度必须是 [-180, +180] 范围内的实数,纬度必须是 [-90, +90] 范围内的实数。
- LinearRingShell 最多包含球体的一半。 LinearRing 将球体分成两个区域。 将选择这两个区域中较小的一个。
- LinearRing 边缘长度必须小于 180 度。 将选择两个顶点之间的最短边缘。
- LinearRing 不得交叉且不得共享边缘。 LinearRing 可以共享顶点。
- 多边形包含其顶点。
提示
使用文本 LineString 或 MultiLineString 以提高性能。
示例
以下示例计算直线和多边形之间的相交。 在此情况下,结果为直线。
let lineString = dynamic({"type":"LineString","coordinates":[[-73.985195,40.788275],[-73.974552,40.779761]]});
let polygon = dynamic({"type":"Polygon","coordinates":[[[-73.9712905883789,40.78580561168767],[-73.98004531860352,40.775276834803655],[-73.97000312805176,40.77852663535664],[-73.9712905883789,40.78580561168767]]]});
print intersection = geo_intersection_line_with_polygon(lineString, polygon)
输出
交集 |
---|
{"type": "LineString","coordinates": [[-73.975611956578192,40.78060906714618],[-73.974552,40.779761]]} |
以下示例计算直线和多边形之间的相交。 在此情况下,结果为多线。
let lineString = dynamic({"type":"LineString","coordinates":[[-110.522, 39.198],[-91.428, 40.880]]});
let polygon = dynamic({"type":"Polygon","coordinates":[[[-90.263,36.738],[-102.041,45.274],[-109.335,36.527],[-90.263,36.738]],[[-100.393,41.705],[-103.139,38.925],[-97.558,39.113],[-100.393,41.705]]]});
print intersection = geo_intersection_line_with_polygon(lineString, polygon)
输出
交集 |
---|
{"type": "MultiLineString","coordinates": [[[ -106.89353655881905, 39.769226209776306],[ -101.74448553679453, 40.373506008712525]],[[-99.136499431328858, 40.589336512699994],[-95.284527737311791, 40.799060242246348]]]} |
以下线和多边形不相交。
let lineString = dynamic({"type":"LineString","coordinates":[[1, 1],[2, 2]]});
let polygon = dynamic({"type":"Polygon","coordinates":[[[-73.9712905883789,40.78580561168767],[-73.98004531860352,40.775276834803655],[-73.97000312805176,40.77852663535664],[-73.9712905883789,40.78580561168767]]]});
print intersection = geo_intersection_line_with_polygon(lineString, polygon)
输出
交集 |
---|
{"type": "GeometryCollection","geometries": []} |
以下示例查找 NYC GeoJSON 道路表中与相关区域文本多边形相交的所有道路。
let area_of_interest = dynamic({"type":"Polygon","coordinates":[[[-73.95768642425537,40.80065354924362],[-73.9582872390747,40.80089719667298],[-73.95869493484497,40.80050736035672],[-73.9580512046814,40.80019873831593],[-73.95768642425537,40.80065354924362]]]});
NY_Manhattan_Roads
| project name = features.properties.Label, road = features.geometry
| project name, intersection = geo_intersection_line_with_polygon(road, area_of_interest)
| where array_length(intersection.geometries) != 0
输出
name | 交集 |
---|---|
CentralParkW | {"type":"MultiLineString","coordinates":[[[-73.958295846836933,40.800316027289647],[-73.9582724,40.8003415]],[[-73.958413422194482,40.80037239620097],[-73.9584093,40.8003797]]]} |
FrederickDouglassCir | {"type":"LineString","coordinates":[[-73.9579272943862,40.800751229494182],[-73.9579019,40.8007238],[-73.9578688,40.8006749],[-73.9578508,40.8006203],[-73.9578459,40.800570199999996],[-73.9578484,40.80053310000001],[-73.9578627,40.800486700000008],[-73.957913,40.800421100000008],[-73.9579668,40.8003923],[-73.9580189,40.80037260000001],[-73.9580543,40.8003616],[-73.9581237,40.8003395],[-73.9581778,40.8003365],[-73.9582724,40.8003415],[-73.958308,40.8003466],[-73.9583328,40.8003517],[-73.9583757,40.8003645],[-73.9584093,40.8003797],[-73.9584535,40.80041099999999],[-73.9584818,40.8004536],[-73.958507000000012,40.8004955],[-73.9585217,40.800562400000004],[-73.9585282,40.8006155],[-73.958416200000016,40.8007325],[-73.9583541,40.8007785],[-73.9582772,40.800811499999995],[-73.9582151,40.8008285],[-73.958145918999392,40.800839887820239]]} |
W110thSt | {"type":"MultiLineString","coordinates":[[[-73.957828446036331,40.800476476316327],[-73.9578627,40.800486700000008]],[[-73.9585282,40.8006155],[-73.958565492035873,40.800631133466972]],[[-73.958416200000016,40.8007325],[-73.958446850928084,40.800744577466617]]]} |
WestDr | {"type":"LineString","coordinates":[[-73.9580543,40.8003616],[-73.958009693938735,40.800250494588468]]} |
以下示例查找美国所有与相关区域文本线串相交的县。
let area_of_interest = dynamic({"type":"LineString","coordinates":[[-73.97159099578857,40.794513338780895],[-73.96738529205322,40.792758888618756],[-73.96978855133057,40.789769718601505]]});
US_Counties
| project name = features.properties.NAME, county = features.geometry
| project name, intersection = geo_intersection_line_with_polygon(area_of_interest, county)
| where array_length(intersection.geometries) != 0
输出
name | 交集 |
---|---|
纽约 | {"type": "LineString","coordinates": [[-73.971590995788574, 40.794513338780895], [-73.967385292053223, 40.792758888618756],[-73.969788551330566, 40.789769718601512]]} |
由于 LineString 无效,以下示例将返回 null 结果。
let lineString = dynamic({"type":"LineString","coordinates":[[-73.985195,40.788275]]});
let polygon = dynamic({"type":"Polygon","coordinates":[[[-73.95768642425537,40.80065354924362],[-73.9582872390747,40.80089719667298],[-73.95869493484497,40.80050736035672],[-73.9580512046814,40.80019873831593],[-73.95768642425537,40.80065354924362]]]});
print is_invalid = isnull(geo_intersection_2lines(lineString, polygon))
输出
无效 |
---|
1 |
由于多边形无效,以下示例将返回 null 结果。
let lineString = dynamic({"type":"LineString","coordinates":[[-73.97159099578857,40.794513338780895],[-73.96738529205322,40.792758888618756],[-73.96978855133057,40.789769718601505]]});
let polygon = dynamic({"type":"Polygon","coordinates":[]});
print is_invalid = isnull(geo_intersection_2lines(lineString, polygon))
输出
无效 |
---|
1 |