/** * copy constructor - avoid clone !! */ public ProjectionImpl constructCopy() { return new Mercator(getOriginLon(), getParallel(), getFalseEasting(), getFalseNorthing()); }
/** * Construct a Mercator Projection. * * @param lon0 longitude of origin (degrees) * @param par standard parallel (degrees). cylinder cuts earth at this latitude. * @param false_easting false_easting in km * @param false_northing false_northing in km * @param radius earth radius in km */ public Mercator(double lon0, double par, double false_easting, double false_northing, double radius) { super("Mercator", false); this.lon0 = lon0; this.par = par; this.falseEasting = false_easting; this.falseNorthing = false_northing; this.earthRadius = radius; this.par_r = Math.toRadians(par); precalculate(); addParameter(CF.GRID_MAPPING_NAME, CF.MERCATOR); addParameter(CF.LONGITUDE_OF_PROJECTION_ORIGIN, lon0); addParameter(CF.STANDARD_PARALLEL, par); addParameter(CF.EARTH_RADIUS, earthRadius * 1000); if ((false_easting != 0.0) || (false_northing != 0.0)) { addParameter(CF.FALSE_EASTING, false_easting); addParameter(CF.FALSE_NORTHING, false_northing); addParameter(CDM.UNITS, "km"); } }
/** * Returns true if this represents the same Projection as proj. * * @param proj projection in question * @return true if this represents the same Projection as proj. */ public boolean equals(Object proj) { if (!(proj instanceof Mercator)) { return false; } Mercator oo = (Mercator) proj; return ((this.getParallel() == oo.getParallel()) && (this.getOriginLon() == oo.getOriginLon()) && this.defaultMapArea.equals(oo.defaultMapArea)); }
@Override protected Mercator createProjection(final ParameterValueGroup p) { if (p == null) return new Mercator(); return new Mercator(value(p, CF.LONGITUDE_OF_PROJECTION_ORIGIN), value(p, CF.STANDARD_PARALLEL), value(p, CF.FALSE_EASTING) / KILOMETRE, value(p, CF.FALSE_NORTHING) / KILOMETRE, earthRadius(p) / KILOMETRE); } }
public GdsHorizCoordSys makeHorizCoordSys() { // put longitude origin at first point - doesnt actually matter // param par standard parallel (degrees). cylinder cuts earth at this latitude. Earth earth = getEarth(); ucar.unidata.geoloc.projection.Mercator proj = new ucar.unidata.geoloc.projection.Mercator(lo1, lad, 0, 0, earth.getEquatorRadius() * .001); // find out where things start ProjectionPoint startP = proj.latLonToProj(new LatLonPointImpl(la1, lo1)); double startx = startP.getX(); double starty = startP.getY(); return new GdsHorizCoordSys(getNameShort(), template, getOctet4(7), scanMode, proj, startx, dX, starty, dY, getNxRaw(), getNyRaw(), getNptsInLine()); }
@Override public ProjectionCT makeCoordinateTransform(AttributeContainer ctv, String geoCoordinateUnits) { double par = readAttributeDouble( ctv, CF.STANDARD_PARALLEL, Double.NaN); if (Double.isNaN(par)) { double scale = readAttributeDouble( ctv, CF.SCALE_FACTOR_AT_PROJECTION_ORIGIN, Double.NaN); if (Double.isNaN(scale)) throw new IllegalArgumentException("Mercator projection must have attribute " + CF.STANDARD_PARALLEL + " or " + CF.SCALE_FACTOR_AT_PROJECTION_ORIGIN); par = ucar.unidata.geoloc.projection.Mercator.convertScaleToStandardParallel(scale); } readStandardParams(ctv, geoCoordinateUnits); ucar.unidata.geoloc.projection.Mercator proj = new ucar.unidata.geoloc.projection.Mercator( lon0, par, false_easting, false_northing, earth_radius); return new ProjectionCT(ctv.getName(), "FGDC", proj); } }
@Test public void testMercator() { testProjection(new Mercator()); Mercator p = new Mercator(); Mercator p2 = (Mercator) p.constructCopy(); assert p.equals(p2); }
/** * Set the origin longitude. * * @param lon the origin longitude. */ public void setOriginLon(double lon) { lon0 = lon; precalculate(); }
/** * Get the parameters as a String * * @return the parameters as a String */ public String paramsToString() { return " origin " + origin.toString() + " parellel: " + Format.d(getParallel(), 6); }
/** * Clone this projection * * @return a clone of this. */ public Object clone() { Mercator cl = (Mercator) super.clone(); cl.origin = new LatLonPointImpl(0.0, getOriginLon()); return cl; }
private CoordinateTransform makeEquitorialMercatorProjection(NetcdfDataset ds) { double lon0 = findAttributeDouble(ds, "XCENT"); double par = findAttributeDouble(ds, "P_ALP"); Mercator p = new Mercator(lon0, par, 0.0, 0.0, earthRadius); return new ProjectionCT("EquitorialMercator", "FGDC", p); }
public GdsHorizCoordSys makeHorizCoordSys() { // put longitude origin at first point - doesnt actually matter // param par standard parallel (degrees). cylinder cuts earth at this latitude. // LOOK dont have an elipsoidal Mercator projection Earth earth = getEarth(); ucar.unidata.geoloc.projection.Mercator proj = new ucar.unidata.geoloc.projection.Mercator(lo1, latin, 0, 0, earth.getEquatorRadius() * .001); // find out where things start ProjectionPoint startP = proj.latLonToProj(new LatLonPointImpl(la1, lo1)); double startx = startP.getX(); double starty = startP.getY(); return new GdsHorizCoordSys(getNameShort(), template, 0, scanMode, proj, startx, getDx(), starty, getDy(), getNx(), getNy(), null); }
public CoordinateTransform makeCoordinateTransform(NetcdfDataset ds, Variable ctv) { double par = readAttributeDouble( ctv, CF.STANDARD_PARALLEL, Double.NaN); if (Double.isNaN(par)) { double scale = readAttributeDouble( ctv, CF.SCALE_FACTOR_AT_PROJECTION_ORIGIN, Double.NaN); if (Double.isNaN(scale)) throw new IllegalArgumentException("Mercator projection must have attribute "+CF.STANDARD_PARALLEL+" or "+ CF.SCALE_FACTOR_AT_PROJECTION_ORIGIN); par = ucar.unidata.geoloc.projection.Mercator.convertScaleToStandardParallel(scale); } double lon0 = readAttributeDouble( ctv, CF.LONGITUDE_OF_PROJECTION_ORIGIN, Double.NaN); double lat0 = readAttributeDouble( ctv, CF.LATITUDE_OF_PROJECTION_ORIGIN, Double.NaN); // LOOK not used double false_easting = readAttributeDouble(ctv, CF.FALSE_EASTING, 0.0); double false_northing = readAttributeDouble(ctv, CF.FALSE_NORTHING, 0.0); double earth_radius = getEarthRadiusInKm(ctv); if ((false_easting != 0.0) || (false_northing != 0.0)) { double scalef = getFalseEastingScaleFactor(ds, ctv); false_easting *= scalef; false_northing *= scalef; } ucar.unidata.geoloc.projection.Mercator proj = new ucar.unidata.geoloc.projection.Mercator( lon0, par, false_easting, false_northing, earth_radius); return new ProjectionCT(ctv.getShortName(), "FGDC", proj); } }
private void addMercatorTags(Mercator proj) { geotiff.addGeoKey(new GeoKey(GeoKey.Tag.GTModelTypeGeoKey, GeoKey.TagValue.ModelType_Projected)); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.GTRasterTypeGeoKey, GeoKey.TagValue.RasterType_Area)); // define the "geographic Coordinate System" geotiff.addGeoKey(new GeoKey(GeoKey.Tag.GeographicTypeGeoKey, GeoKey.TagValue.GeographicType_WGS_84)); // geotiff.addGeoKey( new GeoKey( GeoKey.Tag.GeogLinearUnitsGeoKey, GeoKey.TagValue.ProjLinearUnits_METER)); // geotiff.addGeoKey( new GeoKey( GeoKey.Tag.GeogAngularUnitsGeoKey, GeoKey.TagValue.GeogAngularUnits_DEGREE)); // define the "coordinate transformation" geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjectedCSTypeGeoKey, GeoKey.TagValue.ProjectedCSType_UserDefined)); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.PCSCitationGeoKey, "Mercator")); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjectionGeoKey, GeoKey.TagValue.ProjectedCSType_UserDefined)); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjLinearUnitsGeoKey, GeoKey.TagValue.ProjLinearUnits_METER)); //geotiff.addGeoKey( new GeoKey( GeoKey.Tag.ProjLinearUnitsSizeGeoKey, 1.0)); // units of km // the specifics for mercator geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjCoordTransGeoKey, GeoKey.TagValue.ProjCoordTrans_Mercator)); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjNatOriginLongGeoKey, proj.getOriginLon())); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjNatOriginLatGeoKey, proj.getParallel())); // geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjStdParallel1GeoKey, proj.getParallel())); // geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjScaleAtNatOriginGeoKey, 1)); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjFalseEastingGeoKey, 0.0)); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjFalseNorthingGeoKey, 0.0)); }
/** * Set the first standard parallel * * @param par the first standard parallel */ public void setParallel(double par) { this.par = par; precalculate(); }
@Override public ProjectionImpl constructCopy() { ProjectionImpl result = new Mercator(getOriginLon(), getParallel(), getFalseEasting(), getFalseNorthing(), getEarthRadius()); result.setDefaultMapArea(defaultMapArea); result.setName(name); return result; }
private CoordinateTransform makeEquitorialMercatorProjection(NetcdfDataset ds) { double lon0 = findAttributeDouble(ds, "XCENT"); double par = findAttributeDouble(ds, "P_ALP"); Mercator p = new Mercator(lon0, par, 0.0, 0.0, earthRadius); return new ProjectionCT("EquitorialMercator", "FGDC", p); }
Mercator proj = new Mercator( lonDxDy, latDxDy); ProjectionPointImpl start = (ProjectionPointImpl) proj.latLonToProj( new LatLonPointImpl( lat0, lon0)); startx = start.getX(); starty = start.getY(); ProjectionPointImpl end = (ProjectionPointImpl) proj.latLonToProj( new LatLonPointImpl( latN, lonN)); dx = (end.getX() - startx) / nx; dy = (end.getY() - starty) / ny;
@Override public CoordinateTransform makeCoordinateTransform(NetcdfDataset ds, Variable ctv) { double par = readAttributeDouble( ctv, CF.STANDARD_PARALLEL, Double.NaN); if (Double.isNaN(par)) { double scale = readAttributeDouble( ctv, CF.SCALE_FACTOR_AT_PROJECTION_ORIGIN, Double.NaN); if (Double.isNaN(scale)) throw new IllegalArgumentException("Mercator projection must have attribute " + CF.STANDARD_PARALLEL + " or " + CF.SCALE_FACTOR_AT_PROJECTION_ORIGIN); par = ucar.unidata.geoloc.projection.Mercator.convertScaleToStandardParallel(scale); } double lon0 = readAttributeDouble( ctv, CF.LONGITUDE_OF_PROJECTION_ORIGIN, Double.NaN); double lat0 = readAttributeDouble( ctv, CF.LATITUDE_OF_PROJECTION_ORIGIN, Double.NaN); // LOOK not used double false_easting = readAttributeDouble(ctv, CF.FALSE_EASTING, 0.0); double false_northing = readAttributeDouble(ctv, CF.FALSE_NORTHING, 0.0); double earth_radius = getEarthRadiusInKm(ctv); if ((false_easting != 0.0) || (false_northing != 0.0)) { double scalef = getFalseEastingScaleFactor(ds, ctv); false_easting *= scalef; false_northing *= scalef; } ucar.unidata.geoloc.projection.Mercator proj = new ucar.unidata.geoloc.projection.Mercator( lon0, par, false_easting, false_northing, earth_radius); return new ProjectionCT(ctv.getShortName(), "FGDC", proj); } }
private void addMercatorTags(Mercator proj) { geotiff.addGeoKey(new GeoKey(GeoKey.Tag.GTModelTypeGeoKey, GeoKey.TagValue.ModelType_Projected)); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.GTRasterTypeGeoKey, GeoKey.TagValue.RasterType_Area)); // define the "geographic Coordinate System" geotiff.addGeoKey(new GeoKey(GeoKey.Tag.GeographicTypeGeoKey, GeoKey.TagValue.GeographicType_WGS_84)); // geotiff.addGeoKey( new GeoKey( GeoKey.Tag.GeogLinearUnitsGeoKey, GeoKey.TagValue.ProjLinearUnits_METER)); // geotiff.addGeoKey( new GeoKey( GeoKey.Tag.GeogAngularUnitsGeoKey, GeoKey.TagValue.GeogAngularUnits_DEGREE)); // define the "coordinate transformation" geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjectedCSTypeGeoKey, GeoKey.TagValue.ProjectedCSType_UserDefined)); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.PCSCitationGeoKey, "Mercator")); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjectionGeoKey, GeoKey.TagValue.ProjectedCSType_UserDefined)); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjLinearUnitsGeoKey, GeoKey.TagValue.ProjLinearUnits_METER)); //geotiff.addGeoKey( new GeoKey( GeoKey.Tag.ProjLinearUnitsSizeGeoKey, 1.0)); // units of km // the specifics for mercator geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjCoordTransGeoKey, GeoKey.TagValue.ProjCoordTrans_Mercator)); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjNatOriginLongGeoKey, proj.getOriginLon())); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjNatOriginLatGeoKey, proj.getParallel())); // geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjStdParallel1GeoKey, proj.getParallel())); // geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjScaleAtNatOriginGeoKey, 1)); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjFalseEastingGeoKey, 0.0)); geotiff.addGeoKey(new GeoKey(GeoKey.Tag.ProjFalseNorthingGeoKey, 0.0)); }