Package chunmap.model.crs.proj

Source Code of chunmap.model.crs.proj.ReProjection

/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
*     2010-05-05  Jed Young  Creation
*/
package chunmap.model.crs.proj;

import chunmap.data.feature.Feature;
import chunmap.data.feature.ShapeFeature;
import chunmap.data.feature.VisitAction;
import chunmap.model.coord.TransformChain;
import chunmap.model.crs.CoordinateRef;
import chunmap.model.geom.Geometry;

public class ReProjection implements VisitAction {

  private TransformChain trans=null;

  public ReProjection(CoordinateRef target, CoordinateRef source) {
    boolean sourceOk = (source != null && source.getProjection() != null);
    boolean targetOk = (target != null && target.getProjection() != null);

        if (!sourceOk && !targetOk)
        {
            return;
        }
        if (sourceOk && targetOk)
        {
            if (source.getProjection().getName().equals(target.getProjection().getName()))
                return;
        }

        //OK! go on

        trans = new TransformChain();

        if (sourceOk)
        {
            trans.add(source.getProjection().getReverseTransform());
        }
        if (targetOk)
        {
           trans.add(target.getProjection().getTransform());
        }
  }

  @Override
  public void execute(Feature obj) {
    if (trans == null) return;
    if (obj instanceof ShapeFeature) {
      ShapeFeature shape = (ShapeFeature) obj;
      Geometry g = (shape.getGeometry());
      if (g == null)
        return;
      Geometry ng = g.transform(trans);
      shape.setGeometry(ng);
    }
  }
}
TOP

Related Classes of chunmap.model.crs.proj.ReProjection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.