How to use the proj4.default function in proj4

To help you get started, we’ve selected a few proj4 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sat-utils / sat-api / packages / sentinel / index.js View on Github external
'urn:ogc:def:crs:', ''
  ).replace('8.8.1:', '')
  const from = epsg[crs]
  //const to = proj4.default.defs('EPSG:4326', '+proj=longlat +datum=WGS84 +no_defs');
  const to = '+proj=longlat +datum=WGS84 +over'

  //console.log(`${geojson.type} ${JSON.stringify(geojson)}`)
  if (geojson.type === 'Polygon') {
    geojson = {
      type: 'Polygon',
      coordinates: [geojson.coordinates[0].map((c) => proj4.default(from, to, c))]
    }
  } else if (geojson.type === 'Point') {
    geojson = {
      type: 'Point',
      coordinates: proj4.default(from, to, geojson.coordinates)
    }
  } else {
    throw Error('cannot process non Point or Polygon geometries')
  }
  if (kinks(geojson).features.length > 0) {
    throw Error('self-intersecting polygon')
  }
  return geojson
}
github TerriaJS / terriajs / lib / Models / ArcGisMapServerCatalogItem.js View on Github external
function getRectangleFromLayer(thisLayerJson) {
  var extent = thisLayerJson.extent;
  if (
    defined(extent) &&
    extent.spatialReference &&
    extent.spatialReference.wkid
  ) {
    var wkid = "EPSG:" + extent.spatialReference.wkid;
    if (!defined(proj4definitions[wkid])) {
      return undefined;
    }

    var source = new proj4.Proj(proj4definitions[wkid]);
    var dest = new proj4.Proj("EPSG:4326");

    var p = proj4(source, dest, [extent.xmin, extent.ymin]);

    var west = p[0];
    var south = p[1];

    p = proj4(source, dest, [extent.xmax, extent.ymax]);

    var east = p[0];
    var north = p[1];

    return Rectangle.fromDegrees(west, south, east, north);
  }

  return undefined;
}
github galaxyproject / galaxy / config / plugins / visualizations / openlayers / src / script.js View on Github external
function TransCoord(x, y) {
    if(proj4) {
        var p = proj4.default(EPSG4326, [parseFloat(x), parseFloat(y)]);
        return {x: p[0], y: p[1]};
    }
}
github TerriaJS / terriajs / lib / Models / ArcGisMapServerCatalogItem.js View on Github external
extent.spatialReference.wkid
  ) {
    var wkid = "EPSG:" + extent.spatialReference.wkid;
    if (!defined(proj4definitions[wkid])) {
      return undefined;
    }

    var source = new proj4.Proj(proj4definitions[wkid]);
    var dest = new proj4.Proj("EPSG:4326");

    var p = proj4(source, dest, [extent.xmin, extent.ymin]);

    var west = p[0];
    var south = p[1];

    p = proj4(source, dest, [extent.xmax, extent.ymax]);

    var east = p[0];
    var north = p[1];

    return Rectangle.fromDegrees(west, south, east, north);
  }

  return undefined;
}
github TerriaJS / terriajs / lib / Map / Reproject.js View on Github external
reprojectPoint: function(coordinates, sourceCode, destCode) {
    var source = new proj4.Proj(Proj4Definitions[sourceCode]);
    var dest = new proj4.Proj(Proj4Definitions[destCode]);
    return proj4(source, dest, coordinates);
  },

proj4

Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.

MIT
Latest version published 29 days ago

Package Health Score

89 / 100
Full package analysis

Similar packages