GIS Tools

Language

Made withfor the GIS community

Geometry Repair

Fix self-intersections and other geometry errors

Vector Editing

Drop files here or click to browse

Supported formats: GeoJSON

GeoJSON

Common Geometry Issues

  • Winding order: Outer rings should be counter-clockwise
  • Duplicate coords: Same point repeated consecutively
  • Unclosed rings: Polygon rings must close (first = last)
  • Null geometry: Features without geometry data
Original
Repaired

What Is Geometry Repair?

Geometry repair is the process of detecting and fixing invalid geometries in a vector GIS layer β€” the polygons with self-intersections, the bowtie shapes, the lines that double back on themselves, the rings wound the wrong way, the coordinates with NaN values, and the countless other little corruptions that accumulate in real-world spatial data. Every GIS practitioner has hit an error message like "invalid geometry at feature 23" or "ST_Intersects: TopologyException" and had to figure out how to fix a GeoJSON that looks fine visually but breaks downstream tools. Geometry Repair is the specialized utility that automates those fixes.

The most common invalid geometries are polygons with self-intersections ("bowties"), polygons with non-closed rings, polygons with inner rings that don't fit inside their outer ring, rings that are wound in the wrong direction according to the GeoJSON RFC 7946 spec, duplicate consecutive vertices, and features with empty geometry. Each of these breaks some downstream operation β€” buffer, intersect, union, or simply loading into PostGIS or ArcGIS β€” and each has a canonical repair strategy.

Our Geometry Repair tool runs client-side and fixes invalid geometry GeoJSON files using the same algorithms that power PostGIS ST_MakeValid, JTS IsValidOp / GeometryFixer, Shapely's make_valid and buffer(0) tricks, and the geojson-validator library. Drop a file, get a clean file. No uploads, no server round-trip, no waiting for a batch process to complete.

How Geometry Repair Works

Detecting Invalid Geometries

The first step is classification. The tool scans each feature and checks against a list of rules: is the ring closed? are there self-intersections? are there duplicate points? is the winding order correct? is the inner ring inside the outer ring? are coordinates finite? Each failure is labeled with a specific error type.

The Zero-Buffer Trick

The classic repair for self-intersecting polygons is to apply a zero-width buffer. The buffer operation passes the geometry through a planar sweep algorithm that naturally eliminates self-intersections by producing a valid result. A self-intersecting bowtie becomes a MultiPolygon of two triangles. This is the approach used in Shapely's buffer(0) idiom.

GeometryFixer / MakeValid

More modern algorithms use JTS's GeometryFixer or PostGIS ST_MakeValid, which explicitly classify each error and apply a targeted fix rather than relying on the zero-buffer side effect. This is more reliable for complex cases and preserves more of the original geometry.

Ring Winding Correction

GeoJSON RFC 7946 specifies that outer rings should be counter-clockwise and inner rings clockwise. Many files violate this. The repair tool detects and fixes winding automatically.

Duplicate Removal

Consecutive duplicate vertices contribute nothing to the geometry and can confuse downstream algorithms. They are stripped in the repair pass.

Key Parameters and Options

Enabled Checks

Toggle individual repairs: self-intersection, ring closure, winding order, duplicates, NaN coordinates, empty features.

Repair Strategy

Choose zero-buffer (fastest), GeometryFixer (more precise), or manual (flag but don't fix).

Tolerance

For near-duplicate vertex detection and coordinate snap.

Output Validity

Require strict RFC 7946 compliance or allow Google Maps-style permissive GeoJSON.

Practical Applications

Fixing Contractor Deliverables

Data from contractors and field crews often has minor validity issues. Repairing before acceptance saves downstream trouble.

PostGIS Loading

PostGIS refuses to accept invalid geometries in many operations. Repairing before shp2pgsql load prevents errors.

Overlay Operation Preparation

Intersect, union, and erase all fail on invalid inputs. Repair is step zero of any overlay workflow.

OSM Extract Cleanup

OpenStreetMap extracts sometimes contain invalid geometries where tags were mis-applied or ways were incomplete. Repair makes OSM data usable for analysis.

Open Data Portal Preparation

Before publishing to a public catalog, a repair pass catches many embarrassing errors that would be discovered by end users.

Integration With Desktop GIS

Desktop GIS tools have their own repair functions, but running a repair pass before import ensures consistent starting state.

Format Conversion Cleanup

Shapefile-to-GeoJSON and vice versa can introduce subtle issues. Repair normalizes the result.

Research Data Preparation

Academic research requires reproducible data; repair is part of making a dataset trustworthy.

Step-by-Step Workflow in gis.tools

  1. Open the Geometry Repair tool.
  2. Drop a GeoJSON, Shapefile, or KML file.
  3. The tool scans all features and reports invalid geometries by type.
  4. Review the list of detected issues.
  5. Pick a repair strategy (zero-buffer for speed, GeometryFixer for precision).
  6. Click Repair. The tool applies fixes and reports the changes.
  7. Verify the repaired layer on the map.
  8. Export as GeoJSON, Shapefile, or KML.
  9. Validate once more with the GeoJSON Validator & Fixer.

Worked Example

A GIS analyst receives a shapefile of flood zones from a state agency. Loading it into PostGIS fails with "self-intersection at or near point (X, Y)" on 17 features. She drops the shapefile into Geometry Repair. The tool detects 12 self-intersecting polygons, 3 unclosed rings, 2 duplicate vertex sequences, and 5 ring winding errors. She picks GeometryFixer as the strategy, clicks Repair, and gets back a clean file in three seconds. She spot-checks the repaired features against the originals (a few bowtie polygons became small MultiPolygons, which is the expected behavior) and loads the repaired shapefile into PostGIS without error. The 17-feature problem that would have been hours of manual editing is resolved in under a minute.

Common Pitfalls and Gotchas

  • Silent structural changes: A self-intersecting polygon becomes a MultiPolygon after repair. Verify this is acceptable.
  • Lost area: Small slivers can be eliminated by repair. For area-sensitive work, compute area before and after and compare.
  • Attribute loss: Very rare but possible if the repair splits a feature into multiple parts and the tool fails to duplicate attributes.
  • Wrong CRS for planar repair: Zero-buffer on WGS84 degrees can introduce tiny artifacts. Reproject to a metric CRS first for best results.
  • Cascading errors: Fixing one error can reveal another. Run repair iteratively until no more issues are found.
  • Over-repair: Some "invalid" geometries are intentional (deliberately overlapping donut holes). Review changes.
  • Validation framework differences: PostGIS, OGC, and RFC 7946 have slightly different validity rules. Make sure the tool you trust matches your downstream consumer.
  • Empty output: Some repair operations can collapse a degenerate geometry to nothing. The tool warns you.

Tips for Best Results

  • Always run repair before attempting overlays, buffers, or database loads.
  • For complex self-intersections, prefer GeometryFixer over zero-buffer.
  • Reproject to a metric CRS (UTM) before repairing if the source is lat/lon.
  • Keep the original file as a reference.
  • Run the GeoJSON Validator & Fixer after repair for a final check.
  • For very large layers, split into chunks and repair each chunk separately.
  • Log the number of repaired features for audit purposes.
  • Pair with Topology Helpers for related cleanup.

Comparison with Other GIS Approaches

PostGIS ST_MakeValid, JTS GeometryFixer, Shapely make_valid, and QGIS's "Fix Geometries" algorithm are the established references. Our browser tool uses the same underlying algorithms (via JSTS, the JavaScript port of JTS). The advantage is zero install and complete privacy β€” sensitive data stays in your browser.

Performance Considerations

Repair is O(n) to O(n log n) per feature depending on the algorithm. A layer with 100,000 features typically repairs in 5-20 seconds in the browser. Very large layers benefit from chunked processing.

Data Privacy and Browser-Based Processing

Invalid geometry repair happens entirely client-side. Confidential flood zones, cadastral layers, and infrastructure footprints never leave your machine.

Related GIS Concepts

  • Simple Features: the OGC specification defining valid geometry rules.
  • RFC 7946: the IETF specification for GeoJSON, with stricter winding rules.
  • Self-intersection: an edge that crosses another edge of the same geometry.
  • Bowtie: a common self-intersecting polygon shape with two triangles meeting at a point.
  • Make valid: the general term for geometry repair operations.

Frequently Asked Questions

How do I fix invalid geometry in a GeoJSON?

Drop the file into Geometry Repair and click Run. The tool detects and fixes self-intersections, unclosed rings, winding errors, and duplicates.

What causes self-intersecting polygons?

Digitizing errors, overlay artifacts, bad imports, or manual edits that cross existing boundaries.

Will repair change my data's shape?

Minor changes only β€” repair aims to preserve as much of the original as possible while making it valid.

Can I repair a shapefile?

Yes β€” drop the .zip and the repair process works the same way.

What's the difference between zero-buffer and GeometryFixer?

Zero-buffer is a side-effect trick that works for simple cases and is fast. GeometryFixer is a purpose-built algorithm that handles complex cases more precisely.

Related Tools on gis.tools

100% client-side processing - your data stays private and never leaves your device