Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle Circle in WKT?

I am having a json object as

area : CIRCLE (28.625360369528934 77.2227479486792, 3135.6)

how to parse it using WKTreader?

like image 573
codepeaker Avatar asked Jan 19 '17 20:01

codepeaker


2 Answers

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 );
like image 135
Ian Turton Avatar answered Oct 19 '22 20:10

Ian Turton


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').

like image 23
Tom Medhurst Avatar answered Oct 19 '22 22:10

Tom Medhurst