4

I'm writing a basic parser for common WKT.

The Wikipedia entry for Well-known text says that both of these are equivalent.

MULTIPOINT (10 40, 40 30, 20 20, 30 10)
MULTIPOINT ((10 40), (40 30), (20 20), (30 10))

The first one is standard, but I can't find official documentation stating that the nested parenthesis is actually valid.

Does anybody know if the second version is valid?

4

WKT is defined in the document "OpenGIS® Implementation Standard for Geographic information - Simple feature access - Part 1: Common architecture" http://portal.opengeospatial.org/files/?artifact_id=25355.

In the standard MultiPoint WKT is defined as

<multipoint text> ::= <empty set> | <left paren>
<point text>
{<comma> <point text>}*
<right paren>

So, comma separated list of "point text" elements between parenthesis. Let's have a look at point text

<point text> ::= <empty set> | <left paren> <point> <right
paren>

It seems that parenthesis are part of point text and thus they should be included also in the multipoint text. The example in table 6 indeed has

MultiPoint ((10 10), (20 20))

However, earlier in the standard in section 6.1.2.6.3 Zero-dimensional geometry values there are examples like

multipoint m(1 0 4, 1 1 1, 1 2 2, 3 1 4, 5 3 4)

So both versions appear in the standard text and the nested parenthesis are for sure valid. Probably a carefull reading of section 7.2 Component description - 7.2.1 BNF Introduction justifies also the use without inner parenthesis.

The WKT parser of JTS Topology Suite accepts both variants as input but outputs only the nested version.

  • Exactly what I was looking for. Thanks for pointing me the spec. – tidwall Jun 28 '16 at 0:05
3

In Python also

With Shapely (port of the GEOS library)

from shapely.wkt import loads
poly1 = loads("MULTIPOINT ((10 40), (40 30), (20 20), (30 10))")
poly2 = loads("MULTIPOINT (10 40, 40 30, 20 20, 30 10)")
print poly1
MULTIPOINT ((10 40), (40 30), (20 20), (30 10))
print poly2
MULTIPOINT (10 40, 40 30, 20 20, 30 10)
# convert to GeoJson
mapping(poly1)
{'type': 'MultiPoint', 'coordinates': ((10.0, 40.0), (40.0, 30.0), (20.0, 20.0), (30.0, 10.0))}
mapping(poly2)
{'type': 'MultiPoint', 'coordinates': ((10.0, 40.0), (40.0, 30.0), (20.0, 20.0), (30.0, 10.0))}

With osgeo.ogr (GDAL/OGR)

from osgeo import ogr
poly1  = ogr.CreateGeometryFromWkt("MULTIPOINT ((10 40), (40 30), (20 20), (30 10))")
poly2  = ogr.CreateGeometryFromWkt("MULTIPOINT (10 40, 40 30, 20 20, 30 10)")
poly1.ExportToJson()
'{ "type": "MultiPoint", "coordinates": [ [ 10.0, 40.0 ], [ 40.0, 30.0 ], [ 20.0, 20.0 ], [ 30.0, 10.0 ] ] }'
poly2.ExportToJson()
'{ "type": "MultiPoint", "coordinates": [ [ 10.0, 40.0 ], [ 40.0, 30.0 ], [ 20.0, 20.0 ], [ 30.0, 10.0 ] ] }'

With geomet (simple Python)

from geomet import wkt
wkt.loads("MULTIPOINT (10 40, 40 30, 20 20, 30 10)")
{'type': 'MultiPoint', 'coordinates': [[10.0, 40.0], [40.0, 30.0], [20.0, 20.0], [30.0, 10.0]]}
wkt.loads("MULTIPOINT ((10 40), (40 30), (20 20), (30 10))")
{'type': 'MultiPoint', 'coordinates': [[10.0, 40.0], [40.0, 30.0], [20.0, 20.0], [30.0, 10.0]]}

But geodatabases as Oracle, use only the "MULTIPOINT ((10 40), (40 30), (20 20), (30 10))" specification.

2

readWKT from the rgeos package in R reads them both as valid and identical:

> readWKT("MULTIPOINT (10 40, 40 30, 20 20, 30 10)")
SpatialPoints:
   x  y
1 10 40
1 40 30
1 20 20
1 30 10
Coordinate Reference System (CRS) arguments: NA 
> readWKT("MULTIPOINT ((10 40), (40 30), (20 20), (30 10))")
SpatialPoints:
   x  y
1 10 40
1 40 30
1 20 20
1 30 10
Coordinate Reference System (CRS) arguments: NA 

But unless the standard document I'm reading has been updated then the first one isn't valid and the second one is.

http://www.opengeospatial.org/standards/sfa (latest version there)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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