Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getCenterAndExtent(ds, projection) {
var extent;
// Convert datasource extent to lon/lat when saving
var fromProj = new mapnik.Projection(projection);
var toProj = new mapnik.Projection('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs');
if (fromProj === toProj) {
try {
extent = ds.extent();
} catch (err) {
return invalid('Error obtaining extent of Mapnik datasource.');
}
} else {
try {
var trans = new mapnik.ProjTransform(fromProj, toProj);
//Bounding box
extent = trans.forward(ds.extent());
} catch (err) {
return invalid('Error obtaining extent of Mapnik datasource.');
}
}
//Center point of bounding box (extent)
var center = [0.5 * (extent[0] + extent[2]), 0.5 * (extent[1] + extent[3])];
var results = {
extent: extent,
center: center
};
return results;
}
/**
delete newdoc.bbox;
}
var geom = f.geometry();
if (srs == '+init=epsg:4326') {
geom.toJSON(function(err,json_string) {
newdoc.geometry = JSON.parse(json_string);
docs.push(newdoc);
i++;
immediate(feature);
});
} else {
var from = new mapnik.Projection(srs);
var to = new mapnik.Projection('+init=epsg:4326');
var tr = new mapnik.ProjTransform(from,to);
geom.toJSON({transform:tr},function(err,json_string) {
newdoc.geometry = JSON.parse(json_string);
docs.push(newdoc);
i++;
immediate(feature);
});
}
}
Raster.prototype.getExtent = function(callback) {
var current = new mapnik.Projection(this.projection);
var wgs84 = new mapnik.Projection('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs');
var extent;
var transform;
try {
extent = this.mapnikDatasource.extent();
} catch (err) {
return callback(invalid('Invalid raster: could not read extent'));
}
if (current !== wgs84) {
try {
transform = new mapnik.ProjTransform(current, wgs84);
extent = transform.forward(extent);
} catch (err) {
return callback(invalid('Invalid raster: Unable to compute bounds. X or Y values exceed limits of provided CRS.'));
}
}
return callback(null, extent);
};
this.getProjection(function(err, projection) {
if (err) return callback(err);
var current = new mapnik.Projection(projection);
var wgs84 = new mapnik.Projection('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs');
var transform;
if (current !== wgs84) {
transform = new mapnik.ProjTransform(current, wgs84);
try {
extent = transform.forward(extent);
} catch (err) {
return callback(invalid('Unable to get extent. Failed to forward project to WGS84 coordinates.'));
}
}
_this._extent = extent;
return callback(null, _this._extent);
});
};