mapbox / csv2geojson

magically convert csv files to geojson files
http://mapbox.github.io/csv2geojson/
MIT License
364 stars 82 forks source link

Working with GeometryCollections #40

Closed martgnz closed 8 years ago

martgnz commented 8 years ago

I have a CSV which I would like to transform into a GeometryCollection.

country_dest country_dest_lng country_dest_lat country_org country_org_lat country_org_lng value
Albania 20.168331 41.153332 Iran (Islamic Rep. of) 38.4703541 47.0571193 42
Albania 20.168331 41.153332 Iraq 33.223191 43.679291 1

Using the web interface this is the output of my CSV:

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "country_dest": "Albania",
                "country_org": "Iran (Islamic Rep. of)",
                "country_org_lat": "38.4703541",
                "country_org_lng": "47.0571193",
                "value": "42"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    20.168331,
                    41.153332
                ]
            }
        },
        {
            "type": "Feature",
            "properties": {
                "country_dest": "Albania",
                "country_org": "Iraq",
                "country_org_lat": "33.223191",
                "country_org_lng": "43.679291",
                "value": "1"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    20.168331,
                    41.153332
                ]
            }
        }
    ]
}

And here is the desired output:

{
    type: "GeometryCollection",
    geometries: [
        {   "type": "LineString",
            "coordinates": [[-77.05, 38.91], [116.35, 39.91]],
            "properties": {"value": 10}
        },
        {   "type": "LineString",
            "coordinates": [[-39.927962, -5.058878], [46.587640, -18.909864]],
            "properties": {"value": 180}
        }
    ]
}

Do you know if this is possible with csv2geojson?

Thanks!

sgillies commented 8 years ago

@martgnz csv2geojson turns CSV rows into GeoJSON Features. You would need to extend it do accomplish what you're looking for.

Interoperability note: there's no such thing as "properties" on a GeoJSON geometry object. The latest revision of the GeoJSON spec, the one soon to be published by the IETF, doesn't allow you to change the semantics of a geometry object by adding "properties". See https://tools.ietf.org/html/draft-ietf-geojson-03#section-7.1.