8

I am having a json object as

area : CIRCLE (28.625360369528934 77.2227479486792, 3135.6)

how to parse it using WKTreader?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
codepeaker
  • 420
  • 8
  • 15

2 Answers2

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 );
Ian Turton
  • 10,018
  • 1
  • 28
  • 47
  • Thanks brother!! that help!! – codepeaker Jan 20 '17 at 19:29
  • 1
    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 circle – George of all trades Apr 03 '18 at 07:21
  • 1
    @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? – Jeen Broekstra Oct 20 '18 at 00:05
  • You can represent a circle using a `CircularString` WKT, example: `CIRCULARSTRING(4 1, 7 4, 4 7, 1 4, 4 1)`. See [this link](https://alastaira.wordpress.com/2011/01/31/the-circularstring-geometry-in-sql-server-11-denali/) for more examples. You can wrap it in a `CompoundCurve` to get a surface out of it. – BenMorel Jul 30 '21 at 22:01
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').