use cases

Unclosed Polygon Rings in a Field Boundary File and How iKML Cleans Them

A polygon in KML and GeoJSON is a ring of positions that ends where it starts. The last position must repeat the first, exactly. It looks redundant, and that’s exactly why it gets left out: a farm management app, a script that turns a CSV of corners into KML, or a person editing coordinates by hand writes the four corners of a field and stops.

What happens next depends on the program reading the file. Some close the ring silently. Some draw it as a line, so the field has an outline but no area. Some refuse the shape, and the field is simply missing from the map, with the other fields drawn around the gap.

Checking the Boundaries

An agronomist receives field boundaries from a farm and wants them in a GIS before calculating areas:

$ ikml check fields.kml
fields.kml (kml, 804 bytes)

  ERROR   ring-unclosed  Placemark 'Field 7' (line 6)
          The outer ring does not end on its first point.
  ERROR   ring-too-short  Placemark 'Sliver' (line 18)
          The outer ring has 3 positions. A ring needs at least 4 (three corners
          plus the closing point).
  ERROR   line-too-short  Placemark 'Stub' (line 26)
          The line has 1 position. A line needs at least 2.

3 error(s), 0 warning(s), 0 note(s).

Three shapes, three different problems. Field 7 has its four corners and just doesn’t close. Sliver has three positions: two distinct points and the closing point back at the first. It has no area at all, so something is missing from the data. Stub is a line with a single point.

ikml check finding an unclosed ring, a ring too short to have an area and a one-point line, then ikml clean closing the ring and leaving the other two for a person to decide.

What Cleaning Can and Can’t Do

$ ikml clean fields.kml fields-clean.kml --report
Cleaned fields.kml (kml) to fields-clean.kml (kml, 775 bytes).

Changes (1):
  ring-unclosed      Closed the outer ring by repeating its first point at the end.
                     at Placemark 'Field 7' (line 6)

Nothing is lost converting kml to kml.

Before: 3 error(s), 0 warning(s). After: 2 error(s), 0 warning(s).

Closing a ring is safe: the closing point is defined by the format, and adding it changes nothing about the shape anyone intended. So clean does it and says where. The other two errors stay, because fixing them would mean inventing a corner or a point. Those go back to whoever made the file, with the placemark names and line numbers to look at.

Before Anyone Calculates an Area

An unclosed field that a program “fixes” by dropping it doesn’t show up as an error anywhere downstream. It shows up as a total area that’s a field short. Checking the file before import turns that into a line in a report, which is a lot easier to explain than a wrong number in an invoice.