turf-junkyard / turf-meta

Functional helpers for Turf modules.
5 stars 3 forks source link

ringEach #10

Open morganherlocker opened 9 years ago

morganherlocker commented 9 years ago

Get each LinearRing from a Polygon, MultiPolygon, LineString, MultiLineString, or GeometryCollection. LinearRings are defined roundabout-ly in the geojson spec, and are useful for loads of algorithms.

These algorithms often need to know if the ring is a line, an outer ring (aka 'hull'), or an inner ring (aka 'hole'). Thoughts on delineation and this potential output format?

\cc @tchannel @tmcw @lyzidiamond @rukku

[
  {
    "type": "hull",
    "ring": [
      [
        -86.484375,
        -3.162455530237848
      ],
      [
        -86.484375,
        53.74871079689897
      ],
      [
        -23.203125,
        53.74871079689897
      ],
      [
        -23.203125,
        -3.162455530237848
      ],
      [
        -86.484375,
        -3.162455530237848
      ]
    ]
  },
  {
    "type": "hole",
    "ring": [
      [
        -63.6328125,
        24.5271348225978
      ],
      [
        -63.6328125,
        38.548165423046584
      ],
      [
        -49.21875,
        38.548165423046584
      ],
      [
        -49.21875,
        24.5271348225978
      ],
      [
        -63.6328125,
        24.5271348225978
      ]
    ]
  },
  {
    "type": "line",
    "ring": [
      [
        -46.7578125,
        66.51326044311188
      ],
      [
        1.0546875,
        55.37911044801047
      ],
      [
        -1.0546875,
        39.095962936305504
      ]
    ]
  }
]
tmcw commented 9 years ago

I think something like

eachRing(geojson, function(ring, type, index, index1, index2) {
});

Would work? That way we can pass in rings unchanged and avoid creating a new object

morganherlocker commented 9 years ago

Oh nice, i like that. What's the indexN? Ring depth?

tcql commented 9 years ago

:+1: something like this would simplify lots of things, including stuff like the greiner-hormann code. Especially with the ability to filter between hulls/holes

tmcw commented 9 years ago

Yep, ring within multipolygon. I guess 2 indexes would be enough

lyzidiamond commented 9 years ago

future todo: write a "wtf are linear rings" blog post

morganherlocker commented 9 years ago

@lyzidiamond yeah, the geojson spec is actually a bit vague about linear rings, but my understanding is something like:

  1. a ring of coordinates
  2. a 'closed' linear ring is an array of coordinates where the first and last positions are equivalent

Might be nice to have this as a linkable part of the spec similar to bbox, which is also "sort-of-geojson-but-sort-of-not".

sgillies commented 9 years ago

Yep, the GeoJSON spec is unclear. Rings are better explained (that's the intention, at least) in http://tools.ietf.org/html/draft-butler-geojson-05#section-2.1.6. All the JSON arrays in a Polygon's coordinates that match the definition of LineString coordinates are linear rings. There aren't any rings in any other context according to the draft.

tmcw commented 9 years ago

future todo: write a "wtf are linear rings" blog post

I have this written, just need to do some final sketches and post.

AbelVM commented 9 years ago

I have some stuff done in this direction in my own projects, some kind of parser to play with rings in a not-so-painful way. If I can find some spare time, I could manage to put it al together and commit to TURF