Package chunmap.model.operate.overlay

Source Code of chunmap.model.operate.overlay.OverLayOp

/**
* 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.operate.overlay;

import java.util.ArrayList;
import java.util.List;

import chunmap.model.geom.MultiPolygon;
import chunmap.model.geom.Polygon;

/**
* @author chunquedong
*
*/
public class OverLayOp {

  public MultiPolygon computeIntersect(Polygon r1, Polygon r2) {
    FragmentCollection fragmentCollection = new FragmentCollection(r1, r2);
    List<Polygon> rs = fragmentCollection.getRing(Fragment.Inner,
        Fragment.Inner);

    return makeMultiPolygon(rs);
  }

  private MultiPolygon makeMultiPolygon(List<Polygon> rs) {
    if (rs.size() == 0)
      return null;
    List<Polygon> pgs = new ArrayList<Polygon>();
    for (Polygon r : rs) {
      pgs.add(r);
    }
    return new MultiPolygon(pgs);
  }

  public MultiPolygon computeUnion(Polygon r1, Polygon r2) {
    FragmentCollection fragmentCollection = new FragmentCollection(r1, r2);
    List<Polygon> rs = fragmentCollection.getRing(Fragment.Outer,
        Fragment.Outer);

    return makeMultiPolygon(rs);
  }

  public MultiPolygon computeDifference(Polygon r1, Polygon r2) {
    FragmentCollection fragmentCollection = new FragmentCollection(r1, r2);
    List<Polygon> rs = fragmentCollection.getRing(Fragment.Outer,
        Fragment.Inner);

    return makeMultiPolygon(rs);
  }
}
TOP

Related Classes of chunmap.model.operate.overlay.OverLayOp

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.