Skip to content

Clarification of expected value for npoints in linear ring #26

Open

Description

@murdos

Current specification for polygons is:

for each ring there will be

an npoints unsigned varint giving the number of points in the ring
a pointarray of varints
rings are assumed to be implicitly closed, so the first and last point should not be the same

It would be interesting to specify if npoints should contain the real number of points of the ring, or the encoded number of points that should be read (thus excluding the last point of the ring).
Example with POLYGON((0 0,1 1,1 0,0 0)) : should npoints be 3 or 4?

Activity

  1. pramsey commented on Jan 28, 2022

    @pramsey
    Contributor

    npoints is the encoded number of points to be read, though in the case of your example, there is no rule about discarding the end points. Examining the code, point arrays are evaluated from front to back, and dupes in the stream are discarded, so the fact that start==end will not be noticed by the code and mostly both points will end up encoded.

  2. pramsey commented on Jan 28, 2022

    @pramsey
    Contributor

    So actually the spec and the (postgis) code disagree, which is interesting. postgis code definitely encodes all the (non duplicate) entries in the point array, and specified a minimum output size of 4 for polygon rings (so start==end).

    The postgis reader on the other hand does check for ring closure and adds a point if the start!=end. So it is tolerant of both closed and unclosed input.

    So it's not clear that the code can tell us anything about what the spec should be. @nicklasaven ?

  3. nicklasaven commented on Jan 29, 2022

    @nicklasaven

    I think that the spec should be that readers are supposed to handle both cases. For writers the prefered behavior is to not have same first and last point in the name of tinyness. I don't remember why it is worded as it is. Any objections to that?

  4. pramsey commented on Jan 29, 2022

    @pramsey
    Contributor

    Sounds good. So it's actually a number of statements

    • the npoints is the number of points in the encoded point list, including the duplicate end point if there is one
    • the polygon encoder may discard duplicate start/end points
    • the polygon decoder should accept point lists with either closed or unclosed rings
  5. nicklasaven commented on Jan 30, 2022

    @nicklasaven
  6. murdos commented on Jan 30, 2022

    @murdos
    ContributorAuthor

    Thanks for the clarification.
    I think it could also be worth mentioning in the specification that for linestrings, encoder may remove duplicate consecutive coordinates (either from input geometry or after applying encoding precision).
    So it would be excepted that encoding then decoding a geometry may produce a difference in the number of coordinates.
    WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions