Quantcast
Channel: Question and Answer » json
Viewing all articles
Browse latest Browse all 148

Generate GeoJSON from MongDB Query

$
0
0

I want to extract my MongoDB query in a GeoJSON format it order to be able to visualize the result. I use Robomongo, which seems to be able to generate a JSON format. After I run the query, this file gets produced:

{"result" : [ 
        {
            "_id" : ObjectId("5627ff79ce2790eea0d96ba3"),
            "type" : "FeatureCollection",
            "crs" : {
                "type" : "name",
                "properties" : {
                    "name" : "urn:ogc:def:crs:OGC:1.3:CRS84"
                }
            },
            "features" : {
                "type" : "Feature",
                "properties" : {
                    "id" : 1250.0000000000000000,
                    "osm_id" : 87222664.0000000000000000,
                    "name" : "29th Avenue Station",
                    "type" : "yes"
                },
                "geometry" : {
                    "type" : "MultiPolygon",
                    "coordinates" : [ 
                        [ 
                            [ 
                                [ 
                                    -123.0463325098070600, 
                                    49.2443216480303650
                                ], 
                                [ 
                                    -123.0462832242164000, 
                                    49.2443726938207080
                                ], 
                                [ 
                                    -123.0453115101814800, 
                                    49.2439719550299630
                                ], 
                                [ 
                                    -123.0453609634102200, 
                                    49.2439209930586800
                                ], 
                                [ 
                                    -123.0463325098070600, 
                                    49.2443216480303650
                                ]
                            ]
                        ]
                    ]
                }
            }
        }, 
        {
            "_id" : ObjectId("5627ff79ce2790eea0d96ba3"),
            "type" : "FeatureCollection",
            "crs" : {
                "type" : "name",
                "properties" : {
                    "name" : "urn:ogc:def:crs:OGC:1.3:CRS84"
                }
            },
            "features" : {
                "type" : "Feature",
                "properties" : {
                    "id" : 9033.0000000000000000,
                    "osm_id" : 197598621.0000000000000000,
                    "name" : "Electric Avenue",
                    "type" : "yes"
                },
                "geometry" : {
                    "type" : "MultiPolygon",
                    "coordinates" : [ 
                        [ 
                            [ 
                                [ 
                                    -123.1247329764166500, 
                                    49.2812495473848170
                                ], 
                                [ 
                                    -123.1243329081781800, 
                                    49.2815073747264310
                                ], 
                                [ 
                                    -123.1244402803578200, 
                                    49.2815791238176080
                                ], 
                                [ 
                                    -123.1247323058644000, 
                                    49.2817758470851000
                                ], 
                                [ 
                                    -123.1243665196099100, 
                                    49.2820086963552630
                                ], 
                                [ 
                                    -123.1243131268866800, 
                                    49.2820425592440760
                                ], 
                                [ 
                                    -123.1242579739638100, 
                                    49.2820068523365650
                                ], 
                                [ 
                                    -123.1237645313239900, 
                                    49.2816875856446760
                                ], 
                                [ 
                                    -123.1237276509500200, 
                                    49.2816641163157950
                                ], 
                                [ 
                                    -123.1236146628952400, 
                                    49.2815920319484920
                                ], 
                                [ 
                                    -123.1237309198922500, 
                                    49.2815131582396190
                                ], 
                                [ 
                                    -123.1237663753426800, 
                                    49.2814915329294370
                                ], 
                                [ 
                                    -123.1240143120385500, 
                                    49.2813217993901840
                                ], 
                                [ 
                                    -123.1240598257727800, 
                                    49.2812880203204030
                                ], 
                                [ 
                                    -123.1244141288199200, 
                                    49.2810538299457330
                                ], 
                                [ 
                                    -123.1246444635191300, 
                                    49.2811970766709630
                                ], 
                                [ 
                                    -123.1247329764166500, 
                                    49.2812495473848170
                                ]
                            ]
                        ]
                    ]
                }
            }
        }, 
        {
            "_id" : ObjectId("5628022bce2790eea0d96baa"),
            "type" : "FeatureCollection",
            "crs" : {
                "type" : "name",
                "properties" : {
                    "name" : "urn:ogc:def:crs:OGC:1.3:CRS84"
                }
            },
            "features" : {
                "type" : "Feature",
                "properties" : {
                    "id" : 721.0000000000000000,
                    "osm_id" : 60007793.0000000000000000,
                    "name" : "1st Avenue Marketplace",
                    "type" : "retail",
                    "area" : 0.0000020000000000,
                    "z_order" : 7.0000000000000000
                },
                "geometry" : {
                    "type" : "MultiPolygon",
                    "coordinates" : [ 
                        [ 
                            [ 
                                [ 
                                    -123.0468456499193300, 
                                    49.2685273271100070
                                ], 
                                [ 
                                    -123.0468340828929600, 
                                    49.2693428862887970
                                ], 
                                [ 
                                    -123.0443349346427300, 
                                    49.2693247813779180
                                ], 
                                [ 
                                    -123.0443671211509300, 
                                    49.2685336973564180
                                ], 
                                [ 
                                    -123.0468456499193300, 
                                    49.2685273271100070
                                ]
                            ]
                        ]
                    ]
                }
            }
        }
    ],
    "ok" : 1.0000000000000000
}

I am trying to test the validity of my file using GeoJSONLint but it prompts that the file is not serializeable.

Do you know how can I extract a GeoJSON from a query or somehow convert the JSON to GeoJSON? My file seems to follow the GeoJSON specifications but I was not able to find any tool to do the job.


Viewing all articles
Browse latest Browse all 148

Latest Images

Trending Articles



Latest Images