How to handle Circle in WKT?
Asked Answered
H

2

8

I am having a json object as

area : CIRCLE (28.625360369528934 77.2227479486792, 3135.6)

how to parse it using WKTreader?

Handle answered 19/1, 2017 at 20:32 Comment(0)
S
4

You need to go back to whoever wrote it out and explain the CIRCLE is not a part of the WKT standard and they should stop producing it.

Your best bet then is to generate a polygon with a lot (200) sides that approximates the circle, probably using the JTS buffer method.

Point p = gFactory.createPoint(28.625360369528934 77.2227479486792);
Polygon circle = p.buffer( 3135.6 );
Stupid answered 20/1, 2017 at 17:23 Comment(4)
Thanks brother!! that help!!Handle
WKT does have support for curves - from v1.2.1: "The base Geometry class has subclasses for Point, Curve, Surface and GeometryCollection" NB circle not supported however a curve with identical start and endpoints will give a circleSupralapsarian
@Georgeofalltrades the phrase you quoted is about the geometry model in the abstract. The WKT serialization (covered in section 7 of the Common Architecture) makes no mention of a way to serialize curves though. I may be wrong about this, so if you think it's possible, could you elaborate on what a circle represented using curve would look like in WKT?Ovalle
You can represent a circle using a CircularString WKT, example: CIRCULARSTRING(4 1, 7 4, 4 7, 1 4, 4 1). See this link for more examples. You can wrap it in a CompoundCurve to get a surface out of it.Ungainly
F
3

Another option is to accept a central point and a radius. This will allow you to determine if another geographic shape is within 'the zone' or nearby.

{
   "wkt": "POINT(28.625360369528934 77.2227479486792)",
   "radius": 50
}

This is slightly more elegant than generating hundreds of points as you have a completely lossless articulation of the circle. The only time it would be better to convert into a polygon is if the share is not a perfect circle (then this approach would be 'lossy').

Fowlkes answered 17/10, 2019 at 10:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.