shapefile icon indicating copy to clipboard operation
shapefile copied to clipboard

Convert coordinates to WGS 84 base on the .prj file

Open knut-forkalsrud opened this issue 4 years ago • 0 comments

Let me preface this with a disclaimer: Don't merge this! Consider it a sketch for a possible feature addition, nothing more.

The question of "reprojection" has come up several times, in issue 5, issue 27 and issue 50. For beginners like me it easily trips us up when trying to follow tutorials online, but with our own map data. In retrospect I now realize that I could simply have skipped the projection step, instead of getting only garbage when trying to project something that is already projected. There are Stack Overflow answers describing this in great detail. Before I came to that realization I took a stab at "fixing" the coordinates. It worked for me, so I'll share it here for other that may be looking for the same.

This uses proj4js to read the "well known" text of the coordinate reference system. Then as we read in coordinates from the .shp file we map each to WGS 84 using the same proj4js library.

https://tools.ietf.org/html/rfc7946#section-4 suggests that's the only allowed coordinate reference system in GeoJSON.

Unfortunately this is a bit of a hack, it breaks with streaming nature of the program. It also affects only the command line shp2json. Accommodations for library use are lacking. There should be a command line switch for deciding to use the .prj transform this or not. Arguably the mapping should not be conflated with reading, but it was the most convenient way for me to make it work. Tests are absent.

knut-forkalsrud avatar Feb 06 '21 21:02 knut-forkalsrud