问题描述:

I am trying to overlay data about the Chesapeake Bay Watershed over an OpenLayers map. The problem is, no matter how I try to project the data, the watershed (drawn with d3) is not in the correct position. The code I'm using to zoom to the watershed is here:

zoomToWatershed: function() {

// Remove any svg currently on the map

CP.MapFunctions.reset();

// Fetch data from Flask

CP.RequestHandler.get(

"/get_data/watershed_topo",

function(json) {

ws = JSON.parse(json);

watershed_coords = ws.features[0].geometry.coordinates[0];

CP.map.setCenter(CP.cumberland, CP.watershed_zoom);

watershed_coords.forEach(function(pair) {

// Transform from NAD83 to Web Mercator

var t = proj4(proj4.defs["EPSG:4269"], proj4.defs["SR-ORG:7483"], pair);

// Get the pixel values

px = CP.map.getViewPortPxFromLonLat(

new OpenLayers.LonLat(t[0], t[1])

);

pair[0] = px.x;

pair[1] = px.y;

});

// console.log(watershed_coords);

CP.canvas.append("path")

.datum(watershed_coords)

.attr("d", d3.svg.line())

.attr("class", "watershed");

}

);

}

The shape file that I am using for the watershed had no .prj file, but the metadata on the ftp server said that the projection used was NAD83 (EPSG4269), hence the conversion. SR-ORG:7483 is the equivalent of EPSG:900913, or the web-standard cartographic projection.

The Proj4js parts are defined in a separate js file like so:

proj4.defs["EPSG:4269"] = "+proj=longlat +ellps=GRS80 +datum=NAD83 +no_defs";

proj4.defs["SR-ORG:6864"] = "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=637813 +b=6378137 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";

proj4.defs["SR-ORG:7483"] = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m [email protected] +wktext +no_defs";

My question is: where am I going wrong? I have tested both web-standard cartographic projections (i.e. EPSG:900913 and EPSG:3857, which I'm pretty sure are actually the same thing), as well as the standard EPSG:4326.

相关阅读:
Top