zoukankan      html  css  js  c++  java
  • PostGIS-将多面转换为单面(PostGIS

    Is it possible to import a shape file containing multipolygons into single polygon in PostGIS? Whenever I try importing a shape file of a polygon, it is stored as a multipolygon (as opposed to a single polygon) in a geom column. Thus, I am unable to extract it as a single polygon value from the multipolygon.

    All helpful suggestions much appreciated

    You can use ST_GeometryN together with ST_NumGeometries and the generate_series function to obtain what you need.

    Let's assume you have the table from Jakub's example:

    CREATE TABLE multi AS(
    SELECT 1 as id, 2 as test, ST_GeomFromText('MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0)),((1 1,2 1,2 2,1 2,1 1)), ((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))') AS geom
    );

    This one contains a multipolygon, an id and another column.

    To get each single polygon from the table including all other attributes try something like:

    SELECT id, test, ST_GeometryN(geom, generate_series(1, ST_NumGeometries(geom))) AS geom 
    FROM multi

    "id" and "test" are the values for each row in the original table. generate_series creates a series of numbers from 1 to the number of geometries in each row.

    Therefore you will split each multi geometry in its separate single geometry parts and the values in the other columns remain the same.

    Just replace the columns and table in the example with the columns from your exported shapefile and you will get the table with the single polygons.

    Hope this answers your question.

    原文:https://www.it1352.com/1761001.html

  • 相关阅读:
    机器学习Python包
    Linux网卡的相关配置总结
    [转]Ajax跨域请求
    [转]git在eclipse中的配置
    java代码运行linux shell操作
    虚拟机NAT模式无法上网问题的解决办法
    [转]关于网络通信,byte[]和String的转换问题
    ARP协议工作流程
    pycharm常用快捷键总结
    数据挖掘主要解决的四类问题
  • 原文地址:https://www.cnblogs.com/g120/p/14772409.html
Copyright © 2011-2022 走看看