Package chunmap.model.relate.relateop

Source Code of chunmap.model.relate.relateop.LineString_LineString

/**
* 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.relate.relateop;

import java.util.List;

import chunmap.model.coord.CPoint;
import chunmap.model.elem.PointLineBag;
import chunmap.model.geom.GeoPoint;
import chunmap.model.geom.Geometry;
import chunmap.model.geom.LineString;
import chunmap.model.relate.ComputeIm;
import static chunmap.model.relate.IntersectionMatrix.*;

/**
* disjion,over,touch,with,contain,equals
*
* @author chunquedong
*
*/
public class LineString_LineString extends ComputeIm {

  public LineString_LineString(LineString l1, LineString l2) {
    g1 = l1;
    g2 = l2;
  }

  @Override
  protected int inner2innerDim(Geometry g1, Geometry g2) {
    LineString l1 = (LineString) g1;
    LineString l2 = (LineString) g2;

    PointLineBag bag = l1.intersection(l2);

    if (bag.getLineStringSize() > 0)
      return LineDim;
    else if (bag.getPointSize() > 0) {
      if (isInner(l1, l2, bag.getPointList())) {
        return PointDim;
      }
    }
    return EmptyDim;
  }

  private boolean isInner(LineString l1, LineString l2, List<GeoPoint> points) {
    for (GeoPoint p : points) {
      if (!isBorder(l1, l2, p.getCoordinate())) {
        return true;
      }
    }
    return false;
  }

  // 是边界点
  private boolean isBorder(LineString l1, LineString l2, CPoint p) {
    return p.equals(l1.firstPoint()) || p.equals(l1.lastPoint())
        || p.equals(l2.firstPoint()) || p.equals(l2.lastPoint());
  }

  // ------------------------------------------------------------

  @Override
  protected boolean within(Geometry g1, Geometry g2) {
    if (im.get(Inner, Inner) != LineDim)
      return false;

    LineString l1 = (LineString) g1;
    LineString l2 = (LineString) g2;

    if (l2.containLineString(l1)) {
      return true;
    }

    return false;
  }

}
TOP

Related Classes of chunmap.model.relate.relateop.LineString_LineString

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.