calvinmetcalf / shapefile-js

Convert a Shapefile to GeoJSON. Not many caveats.
http://calvinmetcalf.github.io/shapefile-js/
715 stars 228 forks source link

Prime meridian information seems to be ignored in some cases #81

Closed starsway closed 6 years ago

starsway commented 6 years ago

Hi,

I have been trying to process data in shapefile format with the attached .prj file in well-known text format (wkt).

test_case_prj.txt

The results I get are wrong: they are shifted to the West. With exactly the same input data, QGIS displays data correctly.

I soon became aware that 'long0' was not initialized, though it is used in the forward and inverse functions for Lambert Conformal Conic transformations.

If I set it to the value held in the prj file converted in radians in the initialization function associated to 'lcc':

          if (! this.long0) {
            this.long0 = 0.04079234433; // This is 2° 20' 14,025" East
          }

then I get the expected results.

I also noticed that the following lines were commented in function cleanWKT:

if (wkt.type === 'GEOGCS') {
        geogcs = wkt;
      }
      if (geogcs) {
        //if(wkt.GEOGCS.PRIMEM&&wkt.GEOGCS.PRIMEM.convert){
        //  wkt.from_greenwich=wkt.GEOGCS.PRIMEM.convert*D2R;
        //}
        if (geogcs.DATUM) {

If I uncomment the three lines above instead of forcing the value of 'long0', then I also get the expected results.

It looks like the prime meridian information held in the prj file is simply ignored:

PROJCS["Lambert_Conformal_Conic", GEOGCS["GCS_unnamed ellipse", DATUM["D_unknown",SPHEROID["Unknown",6378249.2,293.466020999993]], PRIMEM["Unknown",2.337229167], UNIT["Degree",0.017453292519943295]],

Any help or insight would be highly appreciated.

Many thanks and kind regards.

calvinmetcalf commented 6 years ago

we actually use proj4 internally so I moved this to proj4js/proj4js#259

starsway commented 6 years ago

Thank you very much. I have just realized that the problem was indeed affecting upstream project https://github.com/proj4js/proj4js... Thanks for moving this issue before I did.