Reprojecting data from a remote url

By default shp-to-geojson does not reproject your data. There are a few other libraries which can help you do this, this is just an example showing 1 approach.

This example takes data from EPSG:102686, NAD 1983 StatePlane Massachusetts Mainland FIPS 2001 Feet, and makes it WGS84, suitable for display using leafletjs.

Uses proj4 and proj4geojson


const url = "https://cdn.rawgit.com/calvinmetcalf/shapefile-js/gh-pages/test/data/senate.shp"

const senate = new ShpToGeoJson({
  remotePath: url
})

// Call .load() and wait for the promise to be resolved
senate.load()
.then(() => {
    
  // Call the .getGeoJson() method
  const fcInWeirdProjection = senate.getGeoJson()
  const wgs84geojson = proj4geojson.to(gj, senate.summary.crs)
  const pointsLayer = L.geoJSON(wgs84geojson).addTo(map)
  
  // Automatically zoom to the data
  map.fitBounds(pointsLayer.getBounds())
})