reproject icon indicating copy to clipboard operation
reproject copied to clipboard

Support Shapefile .prj file

Open stevage opened this issue 7 years ago • 4 comments

I'm interested to know what it would take to support reading Shapefile's .prj files. I had proposed this at shp2json, but maybe it belongs here.

Then one could do:

shp2json foo.shp | reproject --prj foo.prj > foo.geojson

stevage avatar Aug 20 '18 23:08 stevage

From my understanding, a Shape file's .prj will contain a WKT definition of the projection. Also, it looks like Proj4.js can parse WKT, although I have never tried it. So, I think a great solution would be to make it possible to supply files as definitions of from/to CRS, instead of just accepting EPSG codes.

I would envision something like adding --from-crs-file and --to-crs-file to handle this. Does that make sense to you?

perliedman avatar Aug 21 '18 08:08 perliedman

Thinking about this further, I added a small change that allows --from and --to to not only be CRS identifiers, but also actual CRS definitions.

I think this should solve your use case by using it as follows:

shp2json foo.shp | reproject --from $(cat foo.prj) --to=epsg:4326 --use-epsg-io > foo.geojson

I haven't tested exactly this, since shp2json doesn't work on the Windows machine I'm currently on, but that should be a detail.

Give it a spin and see if it works for you!

perliedman avatar Aug 21 '18 11:08 perliedman

Thanks, that does work. IMHO it would be simpler, more intuitive to have a command line option that directly supports a filename, rather than relying on the cat workaround.

stevage avatar Aug 21 '18 11:08 stevage

Agreed, that might be good. So maybe support --from-crs-file and --to-crs-file anyway, but let them rely on the same code.

perliedman avatar Aug 21 '18 11:08 perliedman