2

I have a set of coordinates that creates a polygon with holes in it. I'm using qgis with mmqgis to extract. How does MYSQL accept the WKT representation of a polygon with holes? By holes I mean areas within the perimeter of the polygon that belong to that of another polygon, they're voids in the shape.

Is it with something like GeomFromText('MULTIPOLYGON((0,0 3,3 0,3 0,0), (1,1 1,2 2,2 2,1))')?

The first set of coordinates is the main polygon, the second set is the inner?

1
  • I suggest you add a "wkt" tag on your question, as this is not specific for mysql or qgis.
    – Oyvind
    Aug 10, 2013 at 10:48

2 Answers 2

5

MySQL should be following the WKT specification that was detailed by the Open Geospatial Consortium's Simple Feature Access - Part 1: Common Architecture.

The text you have is not valid WKT, and no GIS software will accept it (generally it will raise a parse error). Commas are used to separate coordinates and spaces between components of each coordinate. Furthermore with polygons, each linear ring needs to be closed, such that the first and last coordinate are repeated. Lastly, with Multi- shapes, you need an additional nesting of parentheses to consider 1 or more polygons.

In all, the valid WKT approximation of your attempt is:

MULTIPOLYGON (((0 0, 3 3, 0 3, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1)))

Which is technically an invalid geometry, as it has a self-intersection at point (1 1). A valid polygon would have this interior ring completely contained within the outer ring, and not overlapping any other interior rings (if present).

JTS

If you want to get more familiar with WKT structures, I find JTS TestBuilder a really good program to visually interact with geometries.

1
  • 1
    I do not disagree, but in his case there is no need for a MULTIPOLYGON. I believe there is a chance he thought he needed a multipolygon type to create inner rings.
    – Oyvind
    Aug 11, 2013 at 8:42
2

This question is more generic than MySql and/or QGis, it actually targets the WKT standard.

What you are trying to create, is often referred to as a "donut polygon", with one or more holes (inner rings) in it.

However, this is not (necessarily) the same as a multipolygon. A multipolygon consists of two or more "islands", where each island may have one or more holes in it.

EDIT: I forgot to look at your actual vertices. While the first (outer) ring looks correct, there is an issue with your inner ring: The WKT standard requires that the first and last vertex in polygon rings has to be equal in order to validate.

So, in your case, unless you want several "islands", this a simple WKT polygon may be more appropriate (corrected with an additional vertex in the inner ring):

POLYGON((0 0, 3 3, 0 3, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))

There is a decent article about WKT on wikipedia:

http://en.wikipedia.org/wiki/Well-known_text

Also, there is the JTS, which ships with a GUI where you can enter WKT code and have it rendered (+ a lot of other useful functions): http://www.vividsolutions.com/jts/JTSHome.htm

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.