当前位置: 首页>>代码示例>>Java>>正文


Java SpatialContext.GEO属性代码示例

本文整理汇总了Java中com.spatial4j.core.context.SpatialContext.GEO属性的典型用法代码示例。如果您正苦于以下问题:Java SpatialContext.GEO属性的具体用法?Java SpatialContext.GEO怎么用?Java SpatialContext.GEO使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.spatial4j.core.context.SpatialContext的用法示例。


在下文中一共展示了SpatialContext.GEO属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testQueries

@Test
public void testQueries() throws IOException {
  String name = StrategyTestCase.QTEST_Cities_Intersects_BBox;

  InputStream in = getClass().getClassLoader().getResourceAsStream(name);
  SpatialContext ctx = SpatialContext.GEO;
  Iterator<SpatialTestQuery> iter = SpatialTestQuery.getTestQueries(
      new SpatialArgsParser(), ctx, name, in );//closes the InputStream
  List<SpatialTestQuery> tests = new ArrayList<>();
  while( iter.hasNext() ) {
    tests.add( iter.next() );
  }
  Assert.assertEquals( 3, tests.size() );

  SpatialTestQuery sf = tests.get(0);
  // assert
  Assert.assertEquals( 1, sf.ids.size() );
  Assert.assertTrue( sf.ids.get(0).equals( "G5391959" ) );
  Assert.assertTrue( sf.args.getShape() instanceof Rectangle);
  Assert.assertEquals(SpatialOperation.Intersects, sf.args.getOperation());
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:TestTestFramework.java

示例2: calcDistanceFromErrPct

@Test
public void calcDistanceFromErrPct() {
  final SpatialContext ctx = SpatialContext.GEO;
  final double DEP = 0.5;//distErrPct

  //the result is the diagonal distance from the center to the closest corner,
  // times distErrPct

  Shape superwide = ctx.makeRectangle(-180, 180, 0, 0);
  //0 distErrPct means 0 distance always
  assertEquals(0, SpatialArgs.calcDistanceFromErrPct(superwide, 0, ctx), 0);
  assertEquals(180 * DEP, SpatialArgs.calcDistanceFromErrPct(superwide, DEP, ctx), 0);

  Shape supertall = ctx.makeRectangle(0, 0, -90, 90);
  assertEquals(90 * DEP, SpatialArgs.calcDistanceFromErrPct(supertall, DEP, ctx), 0);

  Shape upperhalf = ctx.makeRectangle(-180, 180, 0, 90);
  assertEquals(45 * DEP, SpatialArgs.calcDistanceFromErrPct(upperhalf, DEP, ctx), 0.0001);

  Shape midCircle = ctx.makeCircle(0, 0, 45);
  assertEquals(60 * DEP, SpatialArgs.calcDistanceFromErrPct(midCircle, DEP, ctx), 0.0001);
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:SpatialArgsTest.java

示例3: testQueries

@Test
public void testQueries() throws IOException {
  String name = StrategyTestCase.QTEST_Cities_Intersects_BBox;

  InputStream in = getClass().getClassLoader().getResourceAsStream(name);
  SpatialContext ctx = SpatialContext.GEO;
  Iterator<SpatialTestQuery> iter = SpatialTestQuery.getTestQueries(
      new SpatialArgsParser(), ctx, name, in );
  List<SpatialTestQuery> tests = new ArrayList<SpatialTestQuery>();
  while( iter.hasNext() ) {
    tests.add( iter.next() );
  }
  Assert.assertEquals( 3, tests.size() );

  SpatialTestQuery sf = tests.get(0);
 // assert
  Assert.assertEquals( 1, sf.ids.size() );
  Assert.assertTrue( sf.ids.get(0).equals( "G5391959" ) );
  Assert.assertTrue( sf.args.getShape() instanceof Rectangle);
  Assert.assertEquals( SpatialOperation.Intersects, sf.args.getOperation() );
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:21,代码来源:TestTestFramework.java

示例4: configure

@Override
public void configure(String fieldNameForThisInstance, Map<String, String> properties, Configuration configuration) {
  _ctx = SpatialContext.GEO;
  _grid = getSpatialPrefixTree(fieldNameForThisInstance, properties);
  boolean docValue = false;
  if (properties.get(DOC_VALUE) != null) {
    docValue = true;
  }
  _strategy = new RecursivePrefixTreeStrategy(_grid, fieldNameForThisInstance, docValue);
  _shapeReadWriter = new ShapeReadWriter<SpatialContext>(_ctx);
  addSupportedIndexedShapes(Shape.class);
  addSupportedOperations(SpatialOperation.IsDisjointTo);
  addSupportedOperations(SpatialOperation.Intersects);
  addSupportedOperations(SpatialOperation.IsWithin);
  addSupportedOperations(SpatialOperation.Contains);
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:16,代码来源:SpatialRecursivePrefixTreeStrategyFieldTypeDefinition.java

示例5: test28

@Test
public void test28() throws ParseException {
  SpatialContext ctx = SpatialContext.GEO;
  ShapeReadWriter<SpatialContext> shapeReadWriter = new ShapeReadWriter<SpatialContext>(ctx);
  int maxLevels = 11;
  SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);
  RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, "a.id_gis", false);
  Circle circle = ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(10, DistanceUtils.EARTH_MEAN_RADIUS_KM));
  SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);

  String writeSpatialArgs = SpatialArgsParser.writeSpatialArgs(args, shapeReadWriter);

  // This has to be done because of rounding.
  SpatialArgs spatialArgs = SpatialArgsParser.parse(writeSpatialArgs, shapeReadWriter);
  Query q1 = sq(strategy.makeQuery(spatialArgs));
  Query q = parseSq("a.id_gis:\"" + writeSpatialArgs + "\"");
  boolean equals = q1.equals(q);
  assertTrue(equals);
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:19,代码来源:SuperParserTest.java

示例6: GeoProperty

public GeoProperty(Property prop) {
  this.prop = prop;
  this.spatialctx = SpatialContext.GEO;

  int maxlevels = 11; // FIXME: how to compute?
  GeohashPrefixTree grid = new GeohashPrefixTree(spatialctx, maxlevels);
  this.strategy = new RecursivePrefixTreeStrategy(grid, prop.getName());
}
 
开发者ID:enricopal,项目名称:STEM,代码行数:8,代码来源:GeoProperty.java

示例7: getDistance

/**
 * Returns distance (in meters) between 2 points.
 *
 * @param point1 Must not be null
 * @param point2 Must not be null
 * @return distance in meters
 */
public static double getDistance(Point point1, Point point2) {
	Assert.notNull(point1, "point1 must not be null");
	Assert.notNull(point2, "point2 must not be null");

	final SpatialContext ctx = SpatialContext.GEO;
	com.spatial4j.core.shape.Point p1 = ctx.makePoint(point1.getLongitude(), point1.getLatitude());
	com.spatial4j.core.shape.Point p2 = ctx.makePoint(point2.getLongitude(), point2.getLatitude());

	return DistanceUtils.degrees2Dist(ctx.getDistCalc().distance(p1, p2), DistanceUtils.EARTH_MEAN_RADIUS_KM) * 1000;
}
 
开发者ID:ghillert,项目名称:gps-vehicle-simulator,代码行数:17,代码来源:NavUtils.java

示例8: setupGeohashGrid

public void setupGeohashGrid(int maxLevels) {
  this.ctx = SpatialContext.GEO;
  //A fairly shallow grid, and default 2.5% distErrPct
  if (maxLevels == -1)
    maxLevels = randomIntBetween(1, 3);//max 16k cells (32^3)
  this.grid = new GeohashPrefixTree(ctx, maxLevels);
  this.strategy = new RecursivePrefixTreeStrategy(grid, getClass().getSimpleName());
}
 
开发者ID:europeana,项目名称:search,代码行数:8,代码来源:SpatialOpRecursivePrefixTreeTest.java

示例9: testShapePair

@Test
public void testShapePair() {
  ctx = SpatialContext.GEO;
  setupCtx2D(ctx);

  Shape leftShape = new ShapePair(ctx.makeRectangle(-74, -56, -8, 1), ctx.makeRectangle(-180, 134, -90, 90), true);
  Shape queryShape = ctx.makeRectangle(-180, 180, -90, 90);
  assertEquals(SpatialRelation.WITHIN, leftShape.relate(queryShape));
}
 
开发者ID:europeana,项目名称:search,代码行数:9,代码来源:SpatialOpRecursivePrefixTreeTest.java

示例10: testNGramPrefixGridLosAngeles

@Test
  public void testNGramPrefixGridLosAngeles() throws IOException {
    SpatialContext ctx = SpatialContext.GEO;
    TermQueryPrefixTreeStrategy prefixGridStrategy = new TermQueryPrefixTreeStrategy(new QuadPrefixTree(ctx), "geo");

    Shape point = ctx.makePoint(-118.243680, 34.052230);

    Document losAngeles = new Document();
    losAngeles.add(new StringField("name", "Los Angeles", Field.Store.YES));
    for (IndexableField field : prefixGridStrategy.createIndexableFields(point)) {
      losAngeles.add(field);
    }
    losAngeles.add(new StoredField(prefixGridStrategy.getFieldName(), point.toString()));//just for diagnostics

    addDocumentsAndCommit(Arrays.asList(losAngeles));

    // This won't work with simple spatial context...
    SpatialArgsParser spatialArgsParser = new SpatialArgsParser();
    // TODO... use a non polygon query
//    SpatialArgs spatialArgs = spatialArgsParser.parse(
//        "Intersects(POLYGON((-127.00390625 39.8125,-112.765625 39.98828125,-111.53515625 31.375,-125.94921875 30.14453125,-127.00390625 39.8125)))",
//        new SimpleSpatialContext());

//    Query query = prefixGridStrategy.makeQuery(spatialArgs, fieldInfo);
//    SearchResults searchResults = executeQuery(query, 1);
//    assertEquals(1, searchResults.numFound);
  }
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:TestTermQueryPrefixGridStrategy.java

示例11: init

protected void init() {
  //Typical geospatial context
  //  These can also be constructed from SpatialContextFactory
  this.ctx = SpatialContext.GEO;

  int maxLevels = 11;//results in sub-meter precision for geohash
  //TODO demo lookup by detail distance
  //  This can also be constructed from SpatialPrefixTreeFactory
  SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);

  this.strategy = new RecursivePrefixTreeStrategy(grid, "myGeoField");

  this.directory = new RAMDirectory();
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:SpatialExample.java

示例12: testOperations

@Test
@Repeat(iterations = 20)
public void testOperations() throws IOException {
  //setup
  if (random().nextInt(4) > 0) {//75% of the time choose geo (more interesting to test)
    this.ctx = SpatialContext.GEO;
  } else {
    SpatialContextFactory factory = new SpatialContextFactory();
    factory.geo = false;
    factory.worldBounds = new RectangleImpl(-300, 300, -100, 100, null);
    this.ctx = factory.newSpatialContext();
  }
  this.strategy = new BBoxStrategy(ctx, "bbox");
  //test we can disable docValues for predicate tests
  if (random().nextBoolean()) {
    BBoxStrategy bboxStrategy = (BBoxStrategy) strategy;
    FieldType fieldType = new FieldType(bboxStrategy.getFieldType());
    fieldType.setDocValueType(null);
    bboxStrategy.setFieldType(fieldType);
  }
  for (SpatialOperation operation : SpatialOperation.values()) {
    if (operation == SpatialOperation.Overlaps)
      continue;//unsupported
    testOperationRandomShapes(operation);

    deleteAll();
    commit();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:29,代码来源:TestBBoxStrategy.java

示例13: setUp

@Before
@Override
public void setUp() throws Exception {
  super.setUp();
  this.ctx = SpatialContext.GEO;
  this.strategy = new PointVectorStrategy(ctx, getClass().getSimpleName());
}
 
开发者ID:europeana,项目名称:search,代码行数:7,代码来源:TestPointVectorStrategy.java

示例14: setUp

@Before
@Override
public void setUp() throws Exception {
  super.setUp();
  this.ctx = SpatialContext.GEO;
  this.strategy = new SerializedDVStrategy(ctx, "serialized");
}
 
开发者ID:europeana,项目名称:search,代码行数:7,代码来源:SerializedStrategyTest.java

示例15: OLuceneSpatialIndexManager

public OLuceneSpatialIndexManager(OShapeFactory factory) {
  super();
  this.ctx = SpatialContext.GEO;
  this.factory = factory;
  SpatialPrefixTree grid = new GeohashPrefixTree(ctx, 11);
  this.strategy = new RecursivePrefixTreeStrategy(grid, "location");
}
 
开发者ID:orientechnologies,项目名称:orientdb-lucene,代码行数:7,代码来源:OLuceneSpatialIndexManager.java


注:本文中的com.spatial4j.core.context.SpatialContext.GEO属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。