I want to merge multiple geometries with Geotools (starting off with one geometry) but the result is a polygon that has a clockwise orientation. This gives an invalid geometry.

This is my code for the merge:

    GeometryCollection geometryCollection =
    (GeometryCollection) factory.createGeometryCollection(list.toArray(new Geometry[list.size()]));
    Geometry all =  geometryCollection.union();

Why would something give an invalid geometry and what can I use to test for orientation?


1 Answer 1


JTS polygons are clockwise (see http://tsusiatsoftware.net/jts/jts-faq/jts-faq.html#B6 for an explanation of why).

Why it would give you an invalid geometry is a difficult question to answer with out seeing your input polygons. Most likely causes are self intersection, self touching, invalid geometry in input list.

  • So if a geometry 'isValid()' then I should reverse it to be able to insert it into SQL server (using WKT). Any quick way of changing the orientation, or must I breakdown the polygon, reverse point order and create it again..
    – user31025
    Jun 30, 2014 at 10:46
  • Sorry, should have read the whole answer mentioned above
    – user31025
    Jun 30, 2014 at 10:54
  • Use the GeoTools data store and it will handle it seamlessly for you.
    – Ian Turton
    Jun 30, 2014 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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