Get json values

0

I have this json

{
    "type": "FeatureCollection",
    "features": [
        {
            "id": "0",
            "type": "Feature",
            "properties": {
                "Name": "L�nea G - Buenos Aires - Tapiales",
                "LINEA": "BELGRANO",
                "RAMAL": "G",
                "KM": 16,
                "ACTIVA": "SI",
                "CABECERAS": "González Catán",
                "SERVICIO": "Trenes urbanos",
                "CONCESION": " (Estatal, Nación)",
                "OBSERVAC": ""
            },
            "geometry": {
                "type": "LineString",
                "coordinates": [
                    [
                        -58.39323087479187,
                        -34.64522852285068
                    ],
                    [
                        -58.39493519860744,
                        -34.64593911202303
                    ],
                    [
                        -58.39540370387294,
                        -34.64612018963881
                    ],
                    [
                        -58.39577715270643,
                        -34.64624297063709
                    ]
                ]
            }
        }

When I go through it to get the coordinates

for feature in data['features']:
    print(feature['geometry']['coordinates'][0])

The result I get is

[-58.39323087479187, -34.64522852285068]

And I would need it to be like this example

latitud =-58.39323087479187
longitud=-34.64522852285068

and so on with the rest of the json reading for all other coordinates.

    
asked by Sebastian 23.02.2018 в 12:44
source

1 answer

0

First the JSON that you have passed is badly formed.

And the solution to your problem is this.

json = {
    "type": "FeatureCollection",
    "features": [
        {
            "id": "0",
            "type": "Feature",
                    "properties": {
                        "Name": "L�nea G - Buenos Aires - Tapiales",
                        "LINEA": "BELGRANO",
                        "RAMAL": "G",
                        "KM": 16,
                        "ACTIVA": "SI",
                        "CABECERAS": "González Catán",
                        "SERVICIO": "Trenes urbanos",
                        "CONCESION": " (Estatal, Nación)",
                        "OBSERVAC": ""
                    },
            "geometry": {
                        "type": "LineString",
                        "coordinates": [
                            [
                                -58.39323087479187,
                                -34.64522852285068
                            ],
                            [
                                -58.39493519860744,
                                -34.64593911202303
                            ],
                            [
                                -58.39540370387294,
                                -34.64612018963881
                            ],
                            [
                                -58.39577715270643,
                                -34.64624297063709
                            ]
                        ]
                    }
        }
    ]

}
extra = json['features'][0]['geometry']['coordinates']

for x in extra:
    print("latitud ", x[0], "londtidud ", x[1])
    
answered by 23.02.2018 / 15:34
source