calvinmetcalf / shapefile-js

Convert a Shapefile to GeoJSON. Not many caveats.
http://calvinmetcalf.github.io/shapefile-js/
MIT License
735 stars 230 forks source link

Parsing error with vertical projection information in PRJ file. #49

Closed chriserickson closed 8 years ago

chriserickson commented 9 years ago

I have a shape file which has a PRJ file which defines a vertical projection. When trying to parse it, I get an error "Unexpected token ,".

The error appears to be from the first line this method, specifically the JSON.parse call.:

module.exports = function(wkt, self) {
  var lisp = JSON.parse(("," + wkt).replace(/\s*\,\s*([A-Z_0-9]+?)(\[)/g, ',["$1",').slice(1).replace(/\s*\,\s*([A-Z_0-9]+?)\]/g, ',"$1"]'));
  var type = lisp.shift();
  var name = lisp.shift();
  lisp.unshift(['name', name]);
  lisp.unshift(['type', type]);
  lisp.unshift('output');
  var obj = {};
  sExpr(lisp, obj);
  cleanWKT(obj.output);
  return extend(self, obj.output);
};

An example PRJ is:

PROJCS[
    "Custom_NAD_1983_UTM_Zone_17N",
    GEOGCS["GCS_North_American_1983",
        DATUM["D_North_American_1983",
            SPHEROID["GRS_1980",6378137.0,298.257222101]
        ],
        PRIMEM["Greenwich",0.0],
        UNIT["Degree",0.0174532925199433]
    ],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["False_Easting",1640416.666666667],
    PARAMETER["False_Northing",0.0],
    PARAMETER["Central_Meridian",-81.0],
    PARAMETER["Scale_Factor",0.9996],
    PARAMETER["Latitude_Of_Origin",0.0],
    UNIT["Foot_US",0.3048006096012192]
],
VERTCS["NAVD_1988",
    VDATUM["North_American_Vertical_Datum_1988"],
    PARAMETER["Vertical_Shift",0.0],
    PARAMETER["Direction",1.0],
    UNIT["Meter",1.0]
]
calvinmetcalf commented 9 years ago

we rely on proj4js when I comes to parsing those

timbonicus commented 8 years ago

This is fixed in proj4js issue #120.