我们怎样才能提高函数 st_worldtorastercoordx(rast,geom) 的速度

How can we improve the speed of the function st_worldtorastercoordx(rast,geom)

1 背景

 As the wireless communication technology is developing faster and faster, the Long Term Evolution networks are widely installed all over the word.  Since the Long Term Evolution network is based on wide-band radio access technology, there is only one radio carrier available for most of the operator.   Since the frequency resource is limited, many telecom operators use same frequency TD-LTE networks. In the same frequency TD-LTE networks, overlapping coverage seriously impact download speed. RF optimization is a conventional method of controlling overlapping coverage. However, the network optimization resources are always limited, we must evaluate the wireless network coverage and quality as a whole, and identify the problems in priority. 
 Drive test data is widely used to evaluate the wireless network coverage and quality. And we will future associate the Drive test data with the map. Traditionally, we use a desktop software MapInfo to analysis the Drive test data point with the street and road, which is a very heavy labor task.   Recently, we find a new approach the PostGIS middleware, we could transfer the city maps into Raster data, we can we could future associate the Drive test data point with the city map raster data , just like we associate the Drive test data point with the polygon object.

在本文中,我们将介绍如何将地图点关联到Raster。我的问题是,如果函数 st_worldtorastercoordx(rast,geom) 当栅格对象中有超过 10000*10000 像素时,我们如何提高速度。此问题与中间件 PostGIS Raster 对象有关。

2 创建路测数据点对象

2.1 创建点对象字段

在上一个对象中,我们使用kettle中间件将Drive-test数据文件上传到Postgres-SQL数据库中。在数据库中,目的地 table 是 atu_sample,现在我们将更新 table 以添加一个几何对象“点”。 命令来了:

改变table atu_sample 添加列几何图形(点,4326)

2.2给点赋值

在路测数据文件中,我们有经纬度来表示空间位置,现在我们将它们转换为几何对象“点” 命令来了:

更新 atu_sample 设置 geom = st_geomfromtext('POINT('||经度||' '||纬度||')', 4326);

3 创建栅格数据

为了将点对象关联到栅格数据,我们必须首先设置一个栅格数据。在这篇文章中,我们将把矢量数据的城市地图转换成栅格数据。

3.1导入武汉市边界多边形

3.1.1 创建形状文件 在这个项目中,我们将武汉市边界多边形导入PostGIS数据库,武汉市是中国湖北省的省会城市。依赖于MAPinfo格式传输函数,GUI入口如下图所示: 从图中我们可以看出,目标文件的格式是ESRI Shape文件,这是PostGIS默认支持的格式。

3.1.2 创建PG脚本 然后我们将ESRI形状文件中的武汉城市地图传输到PostGIS脚本中。它依赖于工具shp2pgsql,它是PostGIS的一个插件组件。 命令来了:

shp2pgsql –W “GBK” -s 4326 wh_region.shp > 123.txt 这里的-s 4326代表坐标系参数,在以后的空间对象中会有一定的价值。

3.1.3 脚本执行 现在,我们将打开 PGADMIN,并将脚本传输到 PostGIS 数据库中,最后我们得到一个名为 wuhan 的数据库。执行脚本时,我们在 postGIS 中有空间数据 table。

3.2测量武汉边界的高度和宽度

3.2.1 绘制武汉市的凸包 enter image description here 图 2-4:武汉市的 ConvexHull 在图2-4中,我们绘制了武汉市的凸包,它会包围武汉市边界。

3.2.2 用尺子测量高度和宽度使用尺子工具
在Mapinfo中,我们有一个名为Ruler的工具,可以用来测量武汉市ConvexHull的高度和宽度。 enter image description here 图2-5 测量高度和宽度 最后我们得到数据:132.7KM和155.5KM.

3.3 创建武汉栅格数据 在我们的项目中,我们将创建 100*100 米的像素。所以我们先计算武汉市ConvexHull的高度和宽度的分割参数。根据我们之前测得的数据,高132.7KM,宽155.5KM,所以可以算出均分参数为1327和1555

3.3.1 创建光栅持久性 table 现在我们将创建一个 table 来存储栅格数据。 SQL命令来了: 创建 TABLE 个 myraster ( 去掉整数 NOT NULL, 栅格栅格, 约束 myrasters_pkey 主键(删除) );

3.3.2插入RASTER记录 在前面的步骤中,我们从 table wh_region 和 qually divide 参数中获得几何对象,我们可以使用函数 ST_AsRaster 创建栅格实例。 命令来了: 从 wh_region;

插入 myrasters SELECT gid,ST_AsRaster( geom ,1327, 1555, '8BUI')

4 将点关联到光栅 4.1 添加Drive测试点RASTER坐标数据字段 我们会找出这个点和Raster的关系,也就是说我们要找出某个点在哪个像素点。为了记录这个关系我们先在[=中加入两个数据域x整数和y整数100=] atu_sample。 命令来了: alter table atu_sample 添加列 x 整数; alter table atu_sample 添加 y 列整数;

4.2栅格映射

利用函数st_worldtorastercoordx(rast,geom)和st_worldtorastercoordy(rast,geom),我们可以很容易的找出某个点位于哪个像素点,并得到像素点坐标数据。然后我们将更新表格 命令来了:

更新 atu_sample set x =st_worldtorastercoordx(rast,geom) from myrasters;

更新 atu_sample 从 myrasters 设置 y =st_worldtorastercoordy(rast,geom);

几何:

4.3 Raster mapping的性能问题 在上面的例子中,我们有 12000 个点和一个 1327*1555 的栅格数据。完成任务需要超过 160 秒。在以后的项目中,我们将有超过 1200000 点,我们如何解决性能问题?

3.3请参考this article。您不必测量区域的尺寸即可将其转换为栅格。确保您使用非常小的切片生成切片栅格覆盖。

对于 4:您不必计算点在栅格中的位置。使用 ST_MakePoint() 从您的 table 坐标创建点,并确保它们位于正确的坐标系中。然后创建一个新的 table,将点投影到与具有 ST_Transform() 的光栅 table 相同的坐标系中,并索引此 table。然后用这样的查询查询像素值:

SELECT ST_Value(rast, geom) val
FROM rastertable, geomtable
WHERE ST_Intersects(rast, geom)