如何在WKT中处理Circle?

时间:2017-01-19 20:32:29

标签: android parsing geotools wkt

我有一个json对象

区域:CIRCLE(28.625360369528934 77.2227479486792,3135.6)

如何使用WKTreader解析它

请帮助!!

2 个答案:

答案 0 :(得分:2)

你需要回到写出来的人那里解释Point p = gFactory.createPoint(28.625360369528934 77.2227479486792); Polygon circle = p.buffer( 3135.6 ); 不是WKT standard的一部分,他们应该停止制作它。

然后,最好的办法是生成一个多边形(200)的多边形,这些边近似于圆,可能使用JTS缓冲区方法。

use 5.010;
use strict;
use Term::ReadKey;

ReadMode 4; # It will turn off controls keys (eg. Ctrl+c)

my $key; 

# It will create a child so from here two processes will run.
# So for parent process fork() will return child process id
# And for child process fork() will return 0 id

my $pid = fork(); 

# This if block will execute by the child process and not by 
# parent because for child $pid is 0     

if(not $pid){

   while(1){

        # Do your main task here
        say "hi I'm sub process and contains the main task";
        sleep 2;
    }
}

# Parent will skip if block and will follow the following code
while (1) {

   $key = ReadKey(-1); # ReadKey(-1) will perform a non-blocked read

   if($key eq 'q'){    # if key pressed is 'q'

      `kill -9 $pid`;   # then if will run shell command kill and kill
                        # the child process
       ReadMode 0;      # Restore original settings for tty.

       exit;            # Finally exit from script

    } elsif( $key eq 'h' ) {

         say "Hey! you pressed $key key for help";
    } elsif( $key ne '' ) {

        say "Hey! You pressed $key";
    }
}

答案 1 :(得分:1)

另一种选择是接受中心点和半径。这将使您确定“区域”内或附近是否有其他地理形状。

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

这比生成数百个点稍微优雅,因为您可以完全无损地画出圆圈。唯一一次转换为多边形的方法是,如果共享不是完美的圆(那么这种方法将是“有损的”)。