jq: error: синтаксическая ошибка, неожиданный конец $ (проблемы с цитированием оболочки Windows cmd?) - PullRequest
0 голосов
/ 30 октября 2018
type sols3json.json | jq-win64.exe  "[.[] | { "type": "FeatureCollection","features":[{  type: "Feature", "geometry":  {"type": "LineString","coordinates":  [  [.OpStartLongitude, .OpStartLatitude| tonumber],  [ .OpEndLongitude, .OpEndLatitude | tonumber] ]  },  properties: {name: .SolName}}]}"  > sols3.geojson

Я получаю jq: error: синтаксическая ошибка, неожиданный конец $ (проблемы с цитированием оболочки Windows cmd?) Что я делаю неправильно? Вывод должен быть таким:

{
"type": "FeatureCollection",
"features": 
    [
    {
    "properties": {
    "ccaa": "CATALUNYA",
    "prov": "LLEIDA",
    "dir": "N-IIA/SOSES/TORRES DE SEGRE/ALCARRàS",
    "roadnumber": "A-2",
    "tmc": "E17+02413"
    },
    "geometry": {
    "coordinates": [
    [
    0.4714937,
    41.5420936
    ],
    [
    0.4891472,
    41.5497014
    ]
    ],
    "type": "LineString"
    },
    "type": "Feature"
    }
    ]
}

1 Ответ

0 голосов
/ 30 октября 2018

Ваш вопрос довольно неясен, но, тем не менее, я правильно понимаю, это, вероятно, то, что вы хотите.

При условии, что ваш входной файл:

[
  {
    "TMC": "E17+02412",
    "ROADNUMBER": "A-2",
    "DIR": "E-90/AP-2/BARCELONA-ZARAGOZA (SOSES)",
    "PROV": "LLEIDA",
    "CCAA": "CATALUNYA",
    "StartLatitude": "41.5368273",
    "StartLongitude": "0.4387071",
    "EndLatitude": "41.5388396",
    "EndLongitude": "0.4638462"
  }
]

Вы можете фильтровать содержимое, используя этот фильтр jq:

jq 'map({ type: "Feature", "geometry": {"type": "LineString","coordinates": [ [.StartLongitude, .StartLatitude| tonumber], [ .EndLongitude, .EndLatitude | tonumber] ] }, properties: {tmc: .TMC, roadnumber: .ROADNUMBER, dir: .DIR, prov: .PROV, ccaa: .CCAA}})' file

В результате получаются новые данные JSON:

[
  {
    "type": "Feature",
    "geometry": {
      "type": "LineString",
      "coordinates": [
        [
          0.4387071,
          41.5368273
        ],
        [
          0.4638462,
          41.5388396
        ]
      ]
    },
    "properties": {
      "tmc": "E17+02412",
      "roadnumber": "A-2",
      "dir": "E-90/AP-2/BARCELONA-ZARAGOZA (SOSES)",
      "prov": "LLEIDA",
      "ccaa": "CATALUNYA"
    }
  }
]
...