[postgis-devel] Minimum number of points in a POLYGON ring?

David Fuhry dfuhry at acm.org
Thu Sep 18 18:55:43 PDT 2008


Paul,

    Agreed, and as you suggest, it has to be taken to the extreme to 
work right.  I've come across a fair number of nearly-correct shapefiles 
that won't load using shp2pgsql, which prevents the possibility of in-db 
cleanup.

    I originally resisted the idea that almost any chunk of binary data 
should be loadable as a geometry.  One idea I had was a modification to 
shp2pgsql which would load the geometry data as type bytea (byte array). 
  Then the user could control the process of casting to geometry and 
handling errors.

    What put me off that idea, is that there's no way to clean up an 
erroneous geometry if it exists only in bytea form.  There's no 
st_buffer(bytea_col, 0) function to "repair" self-intersecting polygons, 
nor is there a way to add the necessary points to close unclosed rings.

    To give the user these opportunities, the geometry parser is sadly 
going to have to be extremely loose.  But I think that is the right 
thing to do.

Thanks,

Dave

One of the more recent relevant threads on this:
http://postgis.refractions.net/pipermail/postgis-devel/2008-July/003200.html

Paul Ramsey wrote:
> I'm quite worried about increasing the barriers to getting data into
> PostGIS. I think we should let in anything at all, and declare it's
> validity later. Effort should be spent on tools to (a) find bad data
> and (b) make bad data better. IMO
> 
> P
> 
> On Thu, Sep 18, 2008 at 9:03 AM, Kevin Neufeld <kneufeld at refractions.net> wrote:
>> My my readings, according to OGC, the number of points is vague, but the
>> ruleset is specific.  A Polygon is made up of a set of LinearRings
>> (following a set of rules about how they relate to eachother).  A LinearRing
>> is a LineString that is both closed (startpoint ~= endpoint) and simple
>> (does not self-intersect).  This implies that a linear ring must be made up
>> of at least 4 points (3 distinct points) to avoid self-intersection.
>>
>> So the parser check should probably be increased the check to 4, but making
>> sure the endpoints are equal (thus 3 distinct points).
>>
>> Does that help?
>> -- Kevin
>>
>> Mark Cave-Ayland wrote:
>>> Hi there,
>>>
>>> Having just been working on the parser again, I've just wanted to verify
>>> we are currently doing the check for the minimum number of points in a
>>> polygon ring correctly.
>>>
>>> Currently the parser enforces a minimum of 3 points in a ring - but given
>>> that the last point in a ring must be the same as the first point, do we
>>> need to increase this to 4? So in other words, is a polygon with no area
>>> simple?
>>>
>>> A bit of googling shows Informix believes the minimum number of points in
>>> a polygon should be 4 (see USE31 in
>>> http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.spatial.doc/spat310.htm),
>>> but that doesn't distinguish between whether that is for the whole polygon
>>> or just an individual ring. Can anyone clarify this with the OGC spec?
>>>
>>>
>>> Many thanks,
>>>
>>> Mark.
>>>
>> _______________________________________________
>> postgis-devel mailing list
>> postgis-devel at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-devel
>>
> _______________________________________________
> postgis-devel mailing list
> postgis-devel at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-devel



More information about the postgis-devel mailing list