开发者社区 > 博文 > 【JUSTQL Reference】UDF介绍之创建对象
分享
  • 打开微信扫码分享

  • 点击前往QQ分享

  • 点击前往微博分享

  • 点击复制链接

【JUSTQL Reference】UDF介绍之创建对象

  • 京东城市JUST团队
  • 2021-01-26
  • IP归属:未知
  • 826浏览

引擎内置多种创建对象的方法,具体如下:

1.1.1.1  创建点对象

1.1.1.1.1 st_makePoint(double1, double2)

          st_makePoint(double1, double2) => 参数为两个double类型数字(分别为构建点的经纬度),返回的是几何对象POINT。我们可以传入两个数字:

select st_makePoint(120.22, 20.33) as udf_point

          直接传入参数本身,返回的是只有一行一列的表,列名为udf_point,值为POINT对象 POINT(120.22, 20.33)

假设我们有一张表,coordinate_table

pt_longitude

pt_latitude

111.11

22.11

111.22

22.22

111.33

22.33

我们可以使用这个udf接收表中的每行经纬度数据并转化为Point

select st_makePoint(pt_longitude, pt_latitude) as udf_point

from coordinate_table

传入参数所在表的列名以及表名,返回的则是一列多行的表格:

udf_point

POINT(111.11, 22.11)

POINT(111.22, 22.22)

POINT(111.33, 22.33)

1.1.1.1.2 st_pointFromGeoJson(geoJson)

功能

          根据给定点的geoJson返回点, st_pointFromGeoJson(geoJson)

input

          geoJson: 点的geoJson

output

         

example

select
st_pointFromGeoJson(
  '{"type":"FeatureCollection",
 "features":[
 {"type":"Feature",
 "properties":{"direction":"forward"},
 "geometry":{
 "type":"Point",
 "coordinates":[105.380859375,31.57853542647338]
 }}]}'
)

1.1.1.1.3 st_makePointFromWKT(wktString)

功能

          POINTWKT转为POINT对象, st_makePointFromWkt(wktString)

input

          wktString: pointWKT

           

output

          POINT对象

example

select st_makePointFromWkt('POINT(114.134488 22.614742)')

1.1.1.2 创建线对象

1.1.1.2.1 st_lineFromGeoJson(geoJson)

功能

          根据给定线的geoJson返回点, st_lineFromGeoJson(geoJson)

input

          geoJson: 线的geoJson

output

          线

example

select
st_lineFromGeoJson(
 '{"type":"Feature",
"properties":{},
"geometry":{
"type":"LineString",
"coordinates":[[105.6005859375,30.65681556429287],
[107.95166015624999,31.98944183792288],
[109.3798828125,30.031055426540206],
[107.7978515625,29.935895213372444]]
}}'
)

1.1.1.2.2 st_makeLine(collect_list(pt_column))

功能

          传入一个表的点集合,组装得到一条lineString, st_makeLine(collect_list(pt_column)) from tableName

input

          collect_list(pt_column): collect_listspark sql内置UDF,获取一列的所有元素集合

          pt_column为表的点列列名

output

          一条LineString

example

select st_makeLine(collect_list(poi_point)) from poi_table

1.1.1.2.3 st_lineFromPointSeries(column_name, seperator, coordinateFormat)

功能

          将用户原始数据中的coordinates列,变为LineString, st_lineFromPointSeries(column_name, seperator, coordinateFormat)

input

          若加入数据中coordinates列格式如下: 39.8988716 116.3934609;39.9002251 116.3933824;39.9291582 116.4554826;39.92548 116.4554634

          column_name: coordinates列名, seperator: coordinate间的分隔符,示例中则为";" ,coordinateFormat: coordinate的格式,示例中则为"lat lng"

          若加入数据中coordinates列格式如下: 116.3934609 39.8988716,116.3933824 39.9002251,116.4554826 39.9291582,116.4554634 39.92548

          column_name: coordinates列名, seperator: coordinate间的分隔符,示例中则为"," ,coordinateFormat: coordinate的格式,示例中则为"lng lat"

output

          coordinates组成的LineString

example

LOAD hdfs :'/just_test/sdline/reading'

to

just:sdlineTableName
Config
{
oid:"0",

--此处将索引为第三列的coordinates数据转换为LineString传入表的GEOM列中
geom:"st_lineFromPointSeries(3, ';','lat lng')",

time:"to_timestamp(2)",
crowd_number:"1"
}
separator ','

1.1.1.3 创建面对象

语法

          st_polygonFromGeoJson(geoJsonStr)

功能

          根据给定面的geoJson返回点, st_polygonFromGeoJson(geoJson)

input

          geoJson: 面的geoJson

output

         

example

select
st_polygonFromGeoJson(
'{"type":"Feature",
"properties":{},
"geometry":{
"type":"Polygon",
"coordinates":[
[[106.10595703125,33.33970700424026],
[106.32568359375,32.41706632846282],
[108.03955078125,32.2313896627376],
[108.25927734375,33.15594830078649],
[106.10595703125,33.33970700424026]]]
}}'
)

1.1.1.4 创建矩形对象

1.1.1.4.1 st_makeRectangleFromCoord(lng1,lat1,lng2,lat2)

功能

          传入两个点经纬度,转为一个长方形的POLYGON, st_makeRectangleFromCoord(lng1,lat1,lng2,lat2)

input

          lng1: 1longitutde

          lat1: 1latitude

          lng2: 2longitutde

          lat2: 2latitude Double

          为长方形的左下点和右上点,无视顺序

output

          POINT对象

example

select st_makeRectangleFromCoord(111.11, 22.22, 113.33, 22.33)

1.1.1.4.2 st_makeMBR(lng1,lat1,lng2,lat2)

功能

          传入一个Minimum Bounding Box的两个端点返回一个MBR(长方形的polygon), st_makeMBR(lng1,lat1,lng2,lat2)

input

          lng1: 1longitutde

          lat1: 1latitude

          lng2: 2longitutde

          lat2: 2latitude

          为长方形的左下点和右上点,无视顺序

output

          MBR

example

select st_makeMBR(111.11, 22.22, 113.33, 22.33)

1.1.1.4.3 st_makeBBox(lng_min, lat_min, lng_max, lat_max)

1.1.1.5 创建圆

1.1.1.5.1 st_makeCircleFromCoord(lng,lat,radius)

功能

          传入一个点的经纬度和半径(单位为m),得到一个圆形的POLYGON, st_makeCircleFromCoord (lng,lat,radius)

input

          lng: 圆心的经度值

          lat: 圆心的纬度值

          radius: 半径长度

output

          圆形POLYGON

example

select st_makeCircleFromCoord(114.134488, 22.614742, 500.0)

 

1.1.1.5.2 st_makeCircle(center, radius)

功能

          传入一个点和半径(单位为m),得到一个圆形的POLYGON, st_makeCircle(center,radius)

input

          center: 圆心 POINT

          radius: 半径长度

output

          圆形POLYGON

example

select st_makeCircle(st_makePoint(114.134488, 22.614742), 500.0)

1.1.1.6 创建轨迹对象

1.1.1.6.1 st_makeTrajectory(wktString)

功能

          传入一个LineStringWKT得到一条轨迹(无视时间的轨迹,将LineString的点映射为轨迹点,时间随机), st_makeTrajectory(wktString)

input

          wktString: 一条LineStringWKT String

output

          一条轨迹点的时间为随机生成的轨迹

example

select

st_makeTrajectory(

'LINESTRING (106.6416 26.632, 106.641 26.635,106.7091 26.5898)'

)

1.1.1.7 创建路网对象

1.1.1.7.1 st_makeRoadNetwork(collect_list(item))

功能

          传入一个表的路段集合,组装得到路网对象, st_makeRoadNetwork(collect_list(roadSegment_column)) from tableName

input

          collect_list(roadSegment_column): collect_listspark sql内置UDF,获取一列的所有元素集合;roadSegment_column为表的路段列列名

output

          路网对象

example

select st_makeRoadNetwork(collect_list(item)) from longgang_rn

1.1.1.8 获取几何对象对应的buffer

1.1.1.8.1 st_makeTrajBuffer(traj_column, radius)

功能

          传入轨迹和长度(单位为M,返回轨迹对应的缓冲区, st_makeTrajBuffer(traj_column, radius) from tableName

input

          traj_column:轨迹对象所在的列名

          radiusbuffer的半径

output

          缓冲区(几何对象)

example

select st_makeTrajBuffer(item, 2000.0) from guiyang

1.1.1.8.2 st_makeBuffer(geometry, radius)

功能

          传入一个几何对象和长度(单位为M,返回对应的缓冲区, st_makeBuffer(geometry, radius)

input

          geometry:几何对象

          radiusbuffer的半径

output

          缓冲区(几何对象)

example

select st_makeBuffer(st_makePoint(110,20), 500.0)

1.1.1.8.3 st_makeBufferFromWKT

功能

          传入一个几何对象的WKTString和长度(单位为M,返回对应的缓冲区, st_makeBuffer(wktString, radius)

input

          wktString:几何对象的wkt

          radiusbuffer的半径

output

          缓冲区(几何对象)

example

select st_makeBuffer('POINT(114.134488 22.614742)', 500.0)

1.1.1.9 创建最小凹包

1.1.1.9.1 st_makeConcaveHull (collect_list(geometry_column))

功能

          传入一个表的几何对象合集返回包裹住所有几何对象的最小凹包, st_makeConcaveHull(collect_list(geometry_column)) from tableName

input

          collect_list(geometry_column): collect_listspark sql内置UDF,获取一列的所有元素集合

          geometry_column为表的几何对象列列名

output

          凹包

example

select st_makeConcaveHull(collect_list(block)) from polygon_table

共0条评论