mapbox / csv2geojson

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

Add CRS support for point data #27

Closed MuellerMatthew closed 9 years ago

MuellerMatthew commented 9 years ago

The changes allow a Coordinate Reference System (CRS) name to be passed as an option to be used when converting a csv2geojson. The CRS name is then included when creating the new GeoJSON file which may not be using lat/long data, but instead might be using a custom x/y coordinate system, or alternative spatial model. This allows this leaflet plug-in to work with Proj4-leaflet in projecting custom coordinate csv data onto a map.

Example Code(using Proj4Leaflet to display custom coordinates used in GeoJSON):

var CSVLayer = new L.Proj.geoJson(null); // initialize blank layer

csv2geojson.csv2geojson('test.csv', { lonfield: 'y', latfield: 'x', crs: 'urn:ogc:def:crs:EPSG::2263' //Passing the NY Long Island State Plane Coordinate System name to be used in the GeoJSON. },CSVLayer) .addTo(map); //Adding new point layer to map. //Note: you will need to define the coordinate system before you can project it.

This will then convert:

x,y,name 990629.0, 207012.0,"Point 1" 980233.0, 205015.0,"Point 2"

into:

{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "name": "Point 1" }, "geometry": { "type": "Point", "coordinates": [ 990629, 207012 ] }, "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::2263" } } }, { "type": "Feature", "properties": { "name": "Point 2" }, "geometry": { "type": "Point", "coordinates": [ 980233, 205015 ] }, "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::2263" } } } ] }

sgillies commented 9 years ago

@MuellerMatthew FYI the GeoJSON authors have identified CRS other than CRS84 (WGS 84) as a data sharing anti-pattern and GeoJSON CRS is NOT RECOMMENDED in the latest GeoJSON revision: https://www.ietf.org/rfcdiff?url1=draft-butler-geojson-03&difftype=--html&submit=Go!&url2=draft-butler-geojson-04.

MuellerMatthew commented 9 years ago

From what I can tell, that is only a proposed change to the standards(and thus still subject to revisions), and it is not the actual GeoJSON standard.

tmcw commented 9 years ago

I'm cool with supporting this as an option, despite GeoJSON's eventual removal of it.

That said:

MuellerMatthew commented 9 years ago

Alright. Thanks for the feedback. I will make the changes and resubmit the pull request.