Proj4J / proj4j

proj4j migration from svn. Project details can be found at http://trac.osgeo.org/proj4j/
51 stars 24 forks source link

Javascript conversion help #16

Open xjpmauricio opened 4 years ago

xjpmauricio commented 4 years ago

How can I convert this javascript to this java library?

var latitude = 37.42342342342342, longitude = -122.08395287867832;

proj4.defs('EPSG:4326', "+title=long/lat:WGS84 +proj=longlat +a=6378137.0 +b=6356752.31424518 +ellps=WGS84 +datum=WGS84 +units=degrees");
proj4.defs('EPSG:20790', '+title=Hayford-Gauss Datum Lisboa (Militar) +proj=tmerc +lat_0=39.66666666666666 +lon_0=1 +k=1 +x_0=200000 +y_0=300000 +ellps=intl +towgs84=-283.088,-70.693,117.445,-1.157,0.059,-0.652,-4,058 +pm=lisbon +units=m +no_defs');

var latlng = [latitude,longitude];
var pointDest = proj4('EPSG:20790', 'EPSG:4326', latlng);
var coord = { long: pointDest[0], lat: pointDest[1] };

I've tried using the method factory.createFromParameters but I get all sorts of errors related with the parameters.

Any ideias?

xjpmauricio commented 4 years ago

I've tried this but I get all sorts of errors:

double latitude = 37.42342342342342, longitude = -122.08395287867832;
CRSFactory factory = new CRSFactory();
CoordinateReferenceSystem sourceCRS = factory.createFromParameters("EPSG:4326",
        "+title=long/lat:WGS84 +proj=longlat +a=6378137.0 +b=6356752.31424518 +ellps=WGS84 +datum=WGS84 +units=degrees\"");
CoordinateReferenceSystem targetCRS = factory.createFromParameters("EPSG:20790",
        "+title=Hayford-Gauss Datum Lisboa (Militar) +proj=tmerc +lat_0=39.66666666666666 +lon_0=1 +k=1 +x_0=200000 +y_0=300000 +ellps=intl +towgs84=-283.088,-70.693,117.445,-1.157,0.059,-0.652,-4,058 +pm=lisbon +units=m +no_defs");
CoordinateTransform transform = new CoordinateTransformFactory().createTransform(sourceCRS, targetCRS);
ProjCoordinate srcCoord = new ProjCoordinate(latitude, longitude);
ProjCoordinate destCoord = new ProjCoordinate();
transform.transform(srcCoord, destCoord);

Errors:

org.osgeo.proj4j.UnsupportedParameterException: Datum parameter is not supported