I are looking to implement a method to fix self-intersecting polygons by editing the vertex order. We want to take the polygon rings and re-arrange/add in vertices to make a valid polygon. This is similar to how ArcMap's Repair Geometry runs. I have used other methods such as PostGIS's ST_MakeValue, but we didn't like the results because it added extra area to the polygon. It is because of this, that I am looking to implement my own strategy.

I am looking to take the WKT of the feature shape and manually edit the coordinates. Doing something like a buffer operation, split and union, or anything else won't really work. What we want to do is be able to detect and add vertices to self-intersections similar to ArcMap's tool.

If I can get an explanation on some popular tools used to correct self-intersecting polygons and perhaps a code sample/algorithm sample, it would help me greatly.

closed as too broad by PolyGeo Jul 2 '16 at 1:24

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Buffering a self intersecting polygon by zero is a common method for fixing the error in many systems (GDAL, most spatial databases). Why won't this work in your situation? – MappaGnosis Apr 2 '15 at 7:23
  • I didn't think about buffering by 0 to see if it would 'reset' the shape. Basically, this is for a client who pays for services by the area of the shapes we create so they tend to frown on any process that adds more space to the shape. We found with ST_MakeValid with PostGID that it adds additional lines which in some cases, increases the area by hundreds of sq ft, which is why we're avoiding it. – Branco Apr 2 '15 at 12:13

Buffering by zero is a common 'hack' which works well in most cases, and it is not clear from your question why this is unacceptable for you. Spatially enabled databases like PostGIS (which is free) usually have an ST_MakeValid function, which should answer your needs. You can use this in conjunction with other tools such as ST_IsValidReason or ST_IsValidDetail. These tools will list the errors and their locations and could prove useful if you need to roll-you-own solution for some reason.

In addition to database method you have topology tools such as GRASS GIS Build and Clean tools (ArcGIS also has similar tools - licence restricts may apply though).

For diagnostic, you could look at Shapely. It has tools such as is_valid and validation.explainValidity (see the documentation).

I presume you are looking for free alternatives to ArcMap and you can get most of these tools with a good GUI, a Python API plus a Model Builder utility for automation via QGIS (which comes with GRASS, SAGA and connection utilities to PostGIS bundled as standard). QGIS also has a tool Check Geometry Validity. I suspect this is using something similar to the ST_IsValidReason, but this could prove useful as you say you want to fix errors manually. With this tool you can analyse a vector layer and then have QGIS list the errors. You can then select each error in the list and QGIS will jump to it and you can then perform your edits.

  • I talked this over with the guy who manages our PostGIS instance, and this is something similar to what he is doing. We are looking for more of a rearrange and add vertices option, so we can expand the fix to different devices away from the PostGIS installation. – Branco Apr 6 '15 at 12:39

I don't have a code sample. and this is purely commercial solution. But it is world class. 1Validate by 1Spatial. They have the capability of integrating Topology QA/QC into many GIS enterprise systems.

I got pretty far along looking at an oracle spatial/autocad map solution on •1Spatial Management Suite.
But that suite is just a suite of tools you implement on the data. I believe now they have some implementation on FME.


Building on @Brad Nesom's answer, if you're willing to look at an FME solution, there are some transformers that can help with your problem. But probably the most useful one would be the Geometry Validator. It has many options for identifying and repairing geometry errors. As you can see, the dialog contains many tests including Self-Intersections in 2D:

enter image description here

From the documentation:

If Attempt Repair is set to No, self-intersection points are detected.

If Attempt Repair is set to Yes, an input geometry with self-intersections will be divided into a collection of geometry parts that do not contain self-intersections. For example, a figure-8 polygon that has a “waist size” of 0 will be repaired into an IFMEMultiArea of two polygons. As another example, meshes, triangle strips and triangle fans will be repaired into composite surfaces.

Expect self-intersections to be detected in x and y only.

Duplicate coordinates (duplicate in x and y) are considered self-intersections and are reported as such. Duplicate consecutive coordinates are reported as a single self-intersection point.

Faces are rotated onto the x-y plane, self-intersected in x and y, and then un-rotated.

Aggregates, composite surfaces, meshes, triangle strips, and triangle fans are tested for self-intersection on a per-part (or per-face) basis, but the parts are not self-intersected against each other. Donut holes and rings are self-intersected against each other. For example, if a composite surface has a face that self-intersects, it will be output via the Failed or Repaired port. If a composite surface has two faces that intersect each other but do not self-intersect on their own, the composite surface will be output via the Passed port.

Self-intersections are reported via .location traits. When self-intersections are detected, but no self-intersection points are available for reporting, the transformer reports a nearby location.

Check Self-Touching Polygon

If set to Yes and if Attempt Repair is set to Yes, then donuts that have a hole touching the outer boundary will have the hole added to the outer boundary. This will convert the outer boundary to a pinch polygon. This option will only affect donut holes touching the original outer boundary. The donuts that have been repaired may become donuts without holes, and thus become degenerate.


If Java works for you, take a look into http://github.com/Esri/geometry-api-java. It has OperatorSimplify for polygon repair. It also has OperatorSimplifyOGC if you want the polygons to be also OGC compliant.


It seems that a "geometry repair" feature is completely missed from Open Source while is a full prerogative of enterprise solution. I use the FME GeometryValidator, even if this require to the geometry to be passed some times to the validator.

Grass have a v_clean function that works aligned to the topology, if I'm not wrong.

PostGIS have the ST_validReason() to find the (OGC)issue and a st_makevalid that "try to fix" but internally sets the ValidityStatus to "Valid" so it is not helpful in all cases ( even if resolve for the majority of the issues).

Usually all you can have are tricks, like buffer(0) or manual fix or pay.

Not the answer you're looking for? Browse other questions tagged or ask your own question.