org.locationtech.jts.geom.Geometry.equals()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中org.locationtech.jts.geom.Geometry.equals()方法的一些代码示例,展示了Geometry.equals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry.equals()方法的具体详情如下:
包路径:org.locationtech.jts.geom.Geometry
类名称:Geometry
方法名:equals

Geometry.equals介绍

[英]Tests whether this geometry is structurally and numerically equal to a given Object. If the argument Object is not a Geometry, the result is false. Otherwise, the result is computed using #equalsExact(Geometry).

This method is provided to fulfill the Java contract for value-based object equality. In conjunction with #hashCode() it provides semantics which are most useful for using Geometrys as keys and values in Java collections.

Note that to produce the expected result the input geometries should be in normal form. It is the caller's responsibility to perform this where required (using Geometry#norm()or #normalize() as appropriate).
[中]测试此几何体在结构和数值上是否等于给定的Object。如果参数Object不是Geometry,则结果为false。否则,使用#equalsExact(几何体)计算结果。
提供此方法是为了实现基于值的对象相等的Java契约。它与#hashCode()结合使用,提供了在Java集合中将Geometry用作键和值时最有用的语义。
请注意,要产生预期结果,输入几何图形应为标准形式。调用方有责任在需要时执行此操作(根据需要使用Geometry#norm()或#normalize())。

代码示例

代码示例来源:origin: geotools/geotools

public boolean equals(Object obj) {
  return geometry.equals(obj);
}

代码示例来源:origin: locationtech/jts

private void doTestEquals(Geometry a, Geometry b, boolean equalsGeometry,
  boolean equalsObject, boolean equalsExact, boolean equalsHash) {
  assertEquals(equalsGeometry, a.equals(b));
  assertEquals(equalsObject, a.equals((Object) b));
  assertEquals(equalsExact, a.equalsExact(b));
  assertEquals(equalsHash, a.hashCode() == b.hashCode());
}

代码示例来源:origin: geotools/geotools

if (!g1.equals(g2)) {
  return false;

代码示例来源:origin: geotools/geotools

public ClippingFeatureIterator(
    SimpleFeatureIterator delegate,
    Geometry clip,
    SimpleFeatureType schema,
    boolean preserveZ) {
  this.delegate = delegate;
  // can we use the fast clipper?
  if (clip.getEnvelope().equals(clip)) {
    this.clipper = new GeometryClipper(clip.getEnvelopeInternal());
  } else {
    this.clip = clip;
  }
  fb = new SimpleFeatureBuilder(schema);
  this.preserveZ = preserveZ;
}

代码示例来源:origin: geotools/geotools

protected void assertAttributeValuesEqual(Object expected, Object actual) {
  if (expected == null) {
    assertNull(actual);
    return;
  }
  if (expected instanceof Geometry) {
    assertTrue(((Geometry) expected).equals((Geometry) actual));
    return;
  }
  assertEquals(expected, actual);
}

代码示例来源:origin: locationtech/geowave

@Override
 public boolean apply(Geometry geom1, Geometry geom2) {
  return geom1.equals(geom2);
 }
}

代码示例来源:origin: orbisgis/h2gis

public boolean equals(Object obj) {
  if (obj instanceof JtsGeometry) {
    Geometry other = ((JtsGeometry)obj).geom;
    if (this.geom == other) {
      return true;
    }
    if (this.geom != null && other != null) {
      return other.equals(this.geom);
    }
  }
  return false;
}

代码示例来源:origin: postgis/postgis-java

public boolean equals(Object obj) {
    if ((obj != null) && (obj instanceof JtsGeometry)) {
      Geometry other = ((JtsGeometry) obj).geom;
      if (this.geom == other) { // handles identity as well as both
                    // ==null
        return true;
      } else if (this.geom != null && other != null) {
        return other.equals(this.geom);
      }
    }
    return false;
  }
}

代码示例来源:origin: orbisgis/h2gis

/**
   * Return true if Geometry A is equal to Geometry B
   *
   * @param a Geometry Geometry.
   * @param b Geometry instance
   * @return true if Geometry A is equal to Geometry B
   */
  public static Boolean geomEquals(Geometry a, Geometry b) {
    if(a==null || b==null) {
      return null;
    }
    return a.equals(b);
  }
}

代码示例来源:origin: org.locationtech.geomesa/geomesa-cqengine

@Override
public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  Intersects<?, ?> that = (Intersects<?, ?>) o;
  if (!attribute.equals(that.attribute)) return false;
  return value.equals(that.value);
}

代码示例来源:origin: locationtech/geowave

@Override
public boolean compare(
  final Geometry dataGeometry,
  final PreparedGeometry constraintGeometry) {
 // This method is same as Geometry.equalsTopo which is
 // computationally expensive.
 // See equalsExact for quick structural equality
 return constraintGeometry.getGeometry().equals(dataGeometry);
}

代码示例来源:origin: org.opengeo/geodb

/**
 * Returns true if the given geometries represent the same geometry. Directionality is ignored.
 */
public static boolean ST_Equals( byte[] wkb1, byte[] wkb2) {
  if ( wkb1 == null || wkb2 == null ) {
    return false;
  }
  
  Geometry g1 = gFromWKB(wkb1);
  Geometry g2 = gFromWKB(wkb2);
  
  return g1.equals( g2 );
}

代码示例来源:origin: jdeolive/geodb

/**
 * Returns true if the given geometries represent the same geometry. Directionality is ignored.
 */
public static boolean ST_Equals( byte[] wkb1, byte[] wkb2) {
  if ( wkb1 == null || wkb2 == null ) {
    return false;
  }
  
  Geometry g1 = gFromWKB(wkb1);
  Geometry g2 = gFromWKB(wkb2);
  
  return g1.equals( g2 );
}

代码示例来源:origin: geotools/geotools

/** Test of evaluate method, of class FilterFunction_minimumCircle. */
  @Test
  public void testEvaluate() throws Exception {
    SimpleFeatureCollection featureCollection = FunctionTestFixture.polygons();

    // Test the Function
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
    Function exp = ff.function("mincircle", ff.property("geom"));
    SimpleFeatureIterator iter = featureCollection.features();
    while (iter.hasNext()) {
      SimpleFeature feature = iter.next();
      Geometry geom = (Geometry) feature.getDefaultGeometry();
      Geometry circle = new MinimumBoundingCircle(geom).getCircle();
      Object value = exp.evaluate(feature);
      assertTrue(value instanceof Polygon);
      assertTrue(circle.equals((Geometry) value));
    }
    iter.close();

    // Check for null safeness
    assertNull(exp.evaluate(null));
  }
}

代码示例来源:origin: geotools/geotools

/** Test of evaluate method, of class FilterFunction_minimumCircle. */
  @Test
  public void testEvaluate() throws Exception {
    SimpleFeatureCollection featureCollection = FunctionTestFixture.polygons();

    // Test the Function
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
    Function exp = ff.function("minrectangle", ff.property("geom"));
    SimpleFeatureIterator iter = featureCollection.features();
    while (iter.hasNext()) {
      SimpleFeature feature = iter.next();
      Geometry geom = (Geometry) feature.getDefaultGeometry();
      Geometry rectangle = new MinimumDiameter(geom).getMinimumRectangle();
      Object value = exp.evaluate(feature);
      assertTrue(value instanceof Polygon);
      assertTrue(rectangle.equals((Geometry) value));
    }
    iter.close();

    // Check for null safeness
    assertNull(exp.evaluate(null));
  }
}

代码示例来源:origin: locationtech/jts

public void testEqualsWithNull() throws Exception
{
 Geometry polygon = reader.read("POLYGON ((0 0, 0 50, 50 50, 50 0, 0 0))");
 assertTrue(! polygon.equals(null));
 final Object g = null;
 assertTrue(! polygon.equals(g));
}

代码示例来源:origin: locationtech/jts

public void testEquals1() throws Exception {
  Geometry polygon1 = reader.read(
      "POLYGON ((0 0, 0 50, 50 50, 50 0, 0 0))");
  Geometry polygon2 = reader.read(
      "POLYGON ((50 50, 50 0, 0 0, 0 50, 50 50))");
  assertTrue(polygon1.equals(polygon2));
}

代码示例来源:origin: org.n52.arctic-sea/shetland

private boolean checkSamplingGeometry(ObservationMergeIndicator indicator, OmObservation observation) {
  return !indicator.isSamplingGeometry()
      || (isSetSpatialFilteringProfileParameter() && observation.isSetSpatialFilteringProfileParameter()
          && getSpatialFilteringProfileParameter().getValue().getValue()
              .equals(observation.getSpatialFilteringProfileParameter().getValue().getValue()));
}

代码示例来源:origin: locationtech/jts

/**
 * @todo Enable when #isSimple implemented
 */
//  public void testLineStringIsSimple1() throws Exception {
//    Geometry g = reader.read("LINESTRING(10 10, 20 10, 15 20)");
//    assertTrue(g.isSimple());
//  }

 public void testLineStringGetBoundary1() throws Exception {
  LineString g = (LineString) reader.read("LINESTRING(10 10, 20 10, 15 20)");
  assertTrue(g.getBoundary() instanceof MultiPoint);
  MultiPoint boundary = (MultiPoint) g.getBoundary();
  assertTrue(boundary.getGeometryN(0).equals(g.getStartPoint()));
  assertTrue(boundary.getGeometryN(1).equals(g.getEndPoint()));
 }

代码示例来源:origin: locationtech/jts

public void doPredicates(Geometry a, Geometry b) throws Exception
{
 assertTrue( a.contains(b) == a.relate(b).isContains() );
 assertTrue( a.crosses(b) == a.relate(b).isCrosses(a.getDimension(), b.getDimension()) );
 assertTrue( a.disjoint(b) == a.relate(b).isDisjoint() );
 assertTrue( a.equals(b) == a.relate(b).isEquals(a.getDimension(), b.getDimension()) );
 assertTrue( a.intersects(b) == a.relate(b).isIntersects() );
 assertTrue( a.overlaps(b) == a.relate(b).isOverlaps(a.getDimension(), b.getDimension()) );
 assertTrue( a.touches(b) == a.relate(b).isTouches(a.getDimension(), b.getDimension()) );
 assertTrue( a.within(b) == a.relate(b).isWithin() );
}

相关文章