栅格数据集的空间信息记录在数据库中 数据名_cat
表的shape
字段里。
行政区划建了个要素类(FeatureClass
)。注意和栅格数据集坐标系需要一致。
插一下矢量84转2000参考(这个文章)重点是需要先转成ITRF2000再在ArcCatalog里重新定义坐标系再回ArcMap里转。
行政区划要素类这里有名称和代码,当然还有几何属性shape
下面上SQL
这里先把cat表里的shape和行政区划的shape使用sde.st_intersects做相交,获取行政区划表里相交为true的县级行政区划代码。再使用array_to_string把代码转为逗号分隔的字符串存入目标表的county字段。
update test_table set county = (
select array_to_string(ARRAY(
select to_char(xzdm,'999999') xzdm from t_xzqh where
sde.st_intersects((select shape from raster_test_cat where objectid = mid),shape) = TRUE
),',')
) where county = '';
结果如下
下面根据县级行政区划代码更新市级代码
- 用string_to_array把县级行政区划代码转为array,用unnest展开
- 截取前四位(市级代码),去重
- 使用array_agg再转为array,用array_to_string转为字符串,和图像名称一起存入t1
- 使用t1更新目标表
with t1 as (
select fname,array_to_string(array_agg(cityarr),',') city from (
select distinct fname,substr(
unnest(string_to_array(county,',')
),1,5) cityarr from test_table where city = ''
) t2 group by fname
) update test_table t3 set city = t1.city from t1 where t3.fname = t1.fname
最终结果