[postgis-users] is there any 'common' geometry type?

Stephen Woodbridge woodbri at swoodbridge.com
Tue Apr 13 20:34:12 PDT 2010


Hi Li Li,

In general it is best practice to keep your tables homogeneous with 
respect to type of geometry. The reason for this is that many PostGIS 
function expect to operate on a specific type of geometry. Also a column 
in ralational databases is typically strongly typed, ie you do not 
normally expect to find character data in numeric columns, etc.

If you want to mix data in the geometry column then you can just drop 
the constraints on that table after you create it, but I do not think 
this is recommended. Or you can create it by hand like:

create table blahblah (
   gid serial,
   ...
   the_geom geometry);

and this table has no constraints on it and you can load any geometries 
into it.

-Steve

Li Li wrote:
> How to let the table allow both polygon and multipolygon?
> I create geometry column use  SELECT AddGeometryColumn
> ('','china_block','geom',4326,'POLYGON',2);
> I tried SELECT AddGeometryColumn ('','mytable','geom',4326,'MULTIPOLYGON',2);
> 
> it says
> ERROR:  column "geom" of relation "china_block" already exists
> CONTEXT:  SQL statement "ALTER TABLE public.china_block ADD COLUMN
> geom geometry "
> PL/pgSQL function "addgeometrycolumn" line 121 at EXECUTE statement
> SQL statement "SELECT AddGeometryColumn('', $1 , $2 , $3 , $4 , $5 , $6 )"
> PL/pgSQL function "addgeometrycolumn" line 4 at SQL statement
> 
> As you suggested, I can change POLYGON to MULTIPOLYGON.
> But if the column has LINESTRING and POLYGON, what should I do?
> 
> thanks.
> 
> 2010/4/13 Stephen Woodbridge <woodbri at swoodbridge.com>:
>> Li Li wrote:
>>> I have a table from oracle. a spatial column geom  is SDO_GEOMETRY. I
>>> migrated it to postgis. this geom column has record with type of
>>> POLYGON and MULTIPOLYGON. is there any common type that can store any
>>> geometry?
>> The common type in PostGIS is "geometry", but you can also change the
>> constraints you table to allow both POLYGON and MULTIPOLYGON.
>>
>> Or you can do something like:
>>
>> update mytable set the_geom = ST_Multi(the_geom)
>>  where ST_GeometryType = "POLYGON';
>>
>> -Steve W
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users




More information about the postgis-users mailing list