Polygon and Multipolygon distinguished by field type constraint - call for a generic AnyPoly type

View: New views
5 Messages — Rating Filter:   Alert me  

Polygon and Multipolygon distinguished by field type constraint - call for a generic AnyPoly type

by Ben Harper-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am looking for a way of creating a geometry field that has a
constrained type identical to the Shapefile spec.
Basically, Polygons and MultiPolygons are equals. Linestrings and
Multilinestrings are equals.
Is there a way to accomplish this with PostGIS?
If I make the field Polygon, then I can't insert Multipolygons, and vice versa.

Thanks,
Ben
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: Polygon and Multipolygon distinguished by fieldtype constraint - call for a generic AnyPoly type

by Suhr, Ralf :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You need two things:

1) change the geom constraint

ALTER TABLE YOUR_TABLE DROP CONSTRAINT enforce_geotype_geom;
ALTER TABLE YOUR_TABLE ADD CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) = 'POLYGON'::text OR geometrytype(geom) = 'MULTIPOLYGON'::text OR geom IS NULL);

2) Create a trigger with ST_Multi(NEW.geom) for your table

Be aware, that some functions don't working directly with Multigeometrys.

Ralf

-----Ursprüngliche Nachricht-----
Von: postgis-users-bounces@... [mailto:postgis-users-bounces@...] Im Auftrag von Ben Harper
Gesendet: Donnerstag, 2. Juli 2009 12:47
An: postgis-users@...
Betreff: [postgis-users] Polygon and Multipolygon distinguished by fieldtype constraint - call for a generic AnyPoly type


I am looking for a way of creating a geometry field that has a constrained type identical to the Shapefile spec. Basically, Polygons and MultiPolygons are equals. Linestrings and Multilinestrings are equals. Is there a way to accomplish this with PostGIS? If I make the field Polygon, then I can't insert Multipolygons, and vice versa.

Thanks,
Ben
_______________________________________________
postgis-users mailing list postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: Polygon and Multipolygon distinguished by fieldtype constraint - call for a generic AnyPoly type

by Ben Harper-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks - I'll give that a try.

On Thu, Jul 2, 2009 at 1:17 PM, Suhr, Ralf<Ralf.Suhr@...> wrote:

> You need two things:
>
> 1) change the geom constraint
>
> ALTER TABLE YOUR_TABLE DROP CONSTRAINT enforce_geotype_geom;
> ALTER TABLE YOUR_TABLE ADD CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) = 'POLYGON'::text OR geometrytype(geom) = 'MULTIPOLYGON'::text OR geom IS NULL);
>
> 2) Create a trigger with ST_Multi(NEW.geom) for your table
>
> Be aware, that some functions don't working directly with Multigeometrys.
>
> Ralf
>
> -----Ursprüngliche Nachricht-----
> Von: postgis-users-bounces@... [mailto:postgis-users-bounces@...] Im Auftrag von Ben Harper
> Gesendet: Donnerstag, 2. Juli 2009 12:47
> An: postgis-users@...
> Betreff: [postgis-users] Polygon and Multipolygon distinguished by fieldtype constraint - call for a generic AnyPoly type
>
>
> I am looking for a way of creating a geometry field that has a constrained type identical to the Shapefile spec. Basically, Polygons and MultiPolygons are equals. Linestrings and Multilinestrings are equals. Is there a way to accomplish this with PostGIS? If I make the field Polygon, then I can't insert Multipolygons, and vice versa.
>
> Thanks,
> Ben
> _______________________________________________
> postgis-users mailing list postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users
> _______________________________________________
> postgis-users mailing list
> postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: Polygon and Multipolygon distinguished by field type constraint - call for a generic AnyPoly type

by Ben Madin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Could you not just use a Geometry type?

cheers

Ben


On 02/07/2009, at 5:47 PM, Ben Harper wrote:

> I am looking for a way of creating a geometry field that has a
> constrained type identical to the Shapefile spec.
> Basically, Polygons and MultiPolygons are equals. Linestrings and
> Multilinestrings are equals.
> Is there a way to accomplish this with PostGIS?
> If I make the field Polygon, then I can't insert Multipolygons, and  
> vice versa.
>
> Thanks,
> Ben
> _______________________________________________
> postgis-users mailing list
> postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users

--

Ben Madin
REMOTE INFORMATION

t : +61 8 9192 5455
f : +61 8 9192 5535
m : 0448 887 220
Broome   WA   6725

ben@...



                                                        Out here, it pays to know...


_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: Polygon and Multipolygon distinguished by field type constraint - call for a generic AnyPoly type

by Ben Harper-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The reason I don't want to use a GEOMETRY type is because the rest of
my application stack is built to work with Shapefile-style homogeneous
geometry fields.
The alteration of the constraint, with Ralf suggested, works fine for
my purposes. It's not particularly interoperable, but that is fine for
me right now. I guess it is actually equivalent to creating the field
with a GEOMETRY type, and then simply altering the geometry_columns
table so that it is 'POLYGON', or whatever the case may be.

Ben


On Thu, Jul 2, 2009 at 4:21 PM, Ben Madin<ben@...> wrote:

> Could you not just use a Geometry type?
>
> cheers
>
> Ben
>
>
> On 02/07/2009, at 5:47 PM, Ben Harper wrote:
>
>> I am looking for a way of creating a geometry field that has a
>> constrained type identical to the Shapefile spec.
>> Basically, Polygons and MultiPolygons are equals. Linestrings and
>> Multilinestrings are equals.
>> Is there a way to accomplish this with PostGIS?
>> If I make the field Polygon, then I can't insert Multipolygons, and vice
>> versa.
>>
>> Thanks,
>> Ben
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users@...
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
> --
>
> Ben Madin
> REMOTE INFORMATION
>
> t : +61 8 9192 5455
> f : +61 8 9192 5535
> m : 0448 887 220
> Broome   WA   6725
>
> ben@...
>
>
>
>                                                        Out here, it pays to
> know...
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users