doule6314 2015-05-26 06:32
浏览 33
已采纳

从文本到数组的坐标[preg_match]

Maybe someone can help me get coordinates from text to array?

I'm trying use preg_match but no success.

I can remove geometry":{"paths":[[[**" and **]]}}]}) then use some times 'explode' and get coo, but I don't like this idea

Coordinates:

"geometry":{"paths":
[[[485749.91999999998,6108180.6500000004],
[485722.35999999999,6108206],
[485691.14000000001,6108234.3099999996],
[485400.84999999998,6108513.1500000004],
[485368.60999999999,6108545.46],
[485301.53999999998,6108613.1900000004],
[484054.82000000001,6109868.9100000001],
[484051.17566666665,6109872.6840000004]]]}}]});
  • 写回答

2条回答 默认 最新

  • douhui3330 2015-05-26 06:40
    关注

    To figure out my approach in the comment above. Convert the string to valid JSON. Afterwards you can decode the string using json_decode():

    $jsonArr = json_decode('{' . substr($string, 0, -4), true);
    $coordinates= $jsonArr['geometry']['paths'][0]);
    
    var_dump($coordinates):
    

    So you end up with an array of coordinate pairs:

    array(8) {
      [0]=>
      array(2) {
        [0]=>
        float(485749.92)
        [1]=>
        float(6108180.65)
      }
      [1]=>
      array(2) {
        [0]=>
        float(485722.36)
        [1]=>
        int(6108206)
      }
      [2]=>
      array(2) {
        [0]=>
        float(485691.14)
        [1]=>
        float(6108234.31)
      }
      [3]=>
      array(2) {
        [0]=>
        float(485400.85)
        [1]=>
        float(6108513.15)
      }
      [4]=>
      array(2) {
        [0]=>
        float(485368.61)
        [1]=>
        float(6108545.46)
      }
      [5]=>
      array(2) {
        [0]=>
        float(485301.54)
        [1]=>
        float(6108613.19)
      }
      [6]=>
      array(2) {
        [0]=>
        float(484054.82)
        [1]=>
        float(6109868.91)
      }
      [7]=>
      array(2) {
        [0]=>
        float(484051.175667)
        [1]=>
        float(6109872.684)
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测