我正在尝试验证基于位置的应用程序在客户机/服务器之间传递的数据,但我找不到任何方法来验证PHP中的WKT字符串。我不愿意自己实现它,不是因为我懒惰或无能,而是因为我害怕出错,因为我以前从未处理过WKT。有没有什么方法可以让我验证或者我必须编写自己的验证器?
发布于 2012-04-03 08:22:55
我发现了这个类gisconverter.php,它可以将WKT转换为各种格式,或者将其他格式转换为WKT。如果WKT也不是格式良好的,它似乎会抛出一个异常。
示例:
$decoder = new gisconverter\WKT(); # create a WKT decoder in gisconverter namespace
try {
$geometry = $decoder->geomFromText('MULTIPOLYGON(((10 10,10 20,20 20,20 15,10 10)))'); # create a geometry from a given string input
print $geometry->toGeoJSON(); # output geometry in GeoJSON format
} catch (InvalidText $itex) {
echo "WKT was not well formed!";
} catch (Exception $ex) {
echo "General exception.";
}https://stackoverflow.com/questions/9985484
复制相似问题