Java Code Examples for com.vividsolutions.jts.geom.LinearRing

The following examples show how to use com.vividsolutions.jts.geom.LinearRing. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: xyz-hub   Author: heremaps   File: JTSHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Polygon.
 */
public static Polygon toPolygon(PolygonCoordinates coords) {
  if (coords == null) {
    return null;
  }

  LinearRing shell = toLinearRing(coords.get(0));
  if (coords.size() == 1) {
    return JTSHelper.factory.createPolygon(shell);
  }

  LinearRing[] holes = new LinearRing[coords.size() - 1];
  for (int i = 1; i < coords.size(); i++) {
    holes[i - 1] = toLinearRing(coords.get(i));
  }

  return JTSHelper.factory.createPolygon(shell, holes);
}
 
Example #2
Source Project: xyz-hub   Author: heremaps   File: JTSHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create GeoJSON Polygon coordinates.
 */
public static PolygonCoordinates createPolygonCoordinates(Polygon geom) {
  if (geom == null) {
    return null;
  }

  LinearRing shell = (LinearRing) geom.getExteriorRing();
  int lenInterior = geom.getNumInteriorRing();

  PolygonCoordinates polygonCoordinates = new PolygonCoordinates(lenInterior + 1);
  polygonCoordinates.add(createLinearRingCoordinates(shell));

  for (int i = 0; i < lenInterior; i++) {
    polygonCoordinates.add(createLinearRingCoordinates((LinearRing) geom.getInteriorRingN(i)));
  }

  return polygonCoordinates;
}
 
Example #3
/**
 * Create a GeoTools geometric linear-ring from coordinates in json.
 * 
 * @param json the json array of coordinates
 * @return the linear-ring
 */
public static LinearRing createLinearRingFromJson( JsonNode json )
{
    // Native array of coordinates to pass to GeoFactory
    Coordinate[] coords = new Coordinate[MapUtils.getNonEmptyNodes( json )];

    // Read the json array of coordinates
    for ( int i = 0; i < json.size(); i++ )
    {
        JsonNode node = json.get( i );
        
        if ( MapUtils.nodeIsNonEmpty( node ) )
        {
            coords[i] = createCoordinateFromJson( node );
        }
    }

    // Create the linear-ring from factory
    return FACTORY.createLinearRing( coords );
}
 
Example #4
Source Project: gama   Author: gama-platform   File: GamaGisFile.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected Geometry multiPolygonManagement(final Geometry geom) {
	if (geom instanceof MultiPolygon) {
		final Polygon gs[] = new Polygon[geom.getNumGeometries()];
		for (int i = 0; i < geom.getNumGeometries(); i++) {
			final Polygon p = (Polygon) geom.getGeometryN(i);
			final ICoordinates coords = GeometryUtils.getContourCoordinates(p);
			final LinearRing lr = GEOMETRY_FACTORY.createLinearRing(coords.toCoordinateArray());
			try (final Collector.AsList<LinearRing> holes = Collector.getList()) {
				for (int j = 0; j < p.getNumInteriorRing(); j++) {
					final LinearRing h = (LinearRing) p.getInteriorRingN(j);
					if (!hasNullElements(h.getCoordinates())) {
						holes.add(h);
					}
				}
				LinearRing[] stockArr = new LinearRing[holes.size()];
				stockArr = holes.items().toArray(stockArr);
				gs[i] = GEOMETRY_FACTORY.createPolygon(lr, stockArr);
			}
		}
		return GEOMETRY_FACTORY.createMultiPolygon(gs);
	}
	return geom;
}
 
Example #5
private com.vividsolutions.jts.geom.Geometry createJtsEmpty(Class<?> clazz) {
	if (Point.class.equals(clazz)) {
		return factory.createPoint((com.vividsolutions.jts.geom.Coordinate) null);
	} else if (LineString.class.equals(clazz)) {
		return factory.createLineString((com.vividsolutions.jts.geom.Coordinate[]) null);
	} else if (LinearRing.class.equals(clazz)) {
		return factory.createLinearRing((com.vividsolutions.jts.geom.Coordinate[]) null);
	} else if (Polygon.class.equals(clazz)) {
		return factory.createPolygon(null, null);
	} else if (MultiPoint.class.equals(clazz)) {
		return factory.createMultiPoint((Point[]) null);
	} else if (MultiLineString.class.equals(clazz)) {
		return factory.createMultiLineString((LineString[]) null);
	} else if (MultiPolygon.class.equals(clazz)) {
		return factory.createMultiPolygon((Polygon[]) null);
	} else {
		return null;
	}
}
 
Example #6
Source Project: gama   Author: gama-platform   File: GamaGeometryType.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static IShape buildTriangle(final double base, final double height, final ILocation location) {
	final Coordinate[] points = new Coordinate[4];
	final double z = location == null ? 0.0 : location.getZ();
	points[0] = new GamaPoint(-base / 2.0, height / 2, z);
	points[1] = new GamaPoint(0, -height / 2, z);
	points[2] = new GamaPoint(base / 2.0, height / 2, z);
	points[3] = points[0];
	final CoordinateSequenceFactory fact = GamaGeometryFactory.COORDINATES_FACTORY;
	final CoordinateSequence cs = fact.create(points);
	final LinearRing geom = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(cs);
	final Polygon p = GeometryUtils.GEOMETRY_FACTORY.createPolygon(geom, null);
	final IShape s = new GamaShape(p);
	if (location != null) {
		s.setLocation(location);
	}
	return s;
}
 
Example #7
Source Project: gama   Author: gama-platform   File: GamaGeometryType.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static IShape buildTriangle(final double side_size, final ILocation location) {
	final double h = Math.sqrt(3) / 2 * side_size;
	final Coordinate[] points = new Coordinate[4];
	final double x = location == null ? 0 : location.getX();
	final double y = location == null ? 0 : location.getY();
	final double z = location == null ? 0 : location.getZ();
	points[0] = new GamaPoint(x - side_size / 2.0, y + h / 3, z);
	points[1] = new GamaPoint(x, y - 2 * h / 3, z);
	points[2] = new GamaPoint(x + side_size / 2.0, y + h / 3, z);
	points[3] = points[0];
	final CoordinateSequenceFactory fact = GamaGeometryFactory.COORDINATES_FACTORY;
	final CoordinateSequence cs = fact.create(points);
	final LinearRing geom = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(cs);
	final Polygon p = GeometryUtils.GEOMETRY_FACTORY.createPolygon(geom, null);
	return new GamaShape(p);
}
 
Example #8
@Test
public void intersect50percentOverlapAlmost() throws Exception {
	// prepare command
	SearchByLocationRequest request = new SearchByLocationRequest();
	request.setCrs("EPSG:4326");
	request.setQueryType(SearchByLocationRequest.QUERY_INTERSECTS);
	request.setSearchType(SearchByLocationRequest.SEARCH_ALL_LAYERS);
	request.setRatio(0.5f);
	request.setLayerIds(new String[] {LAYER_ID});

	// create a rectangle that overlaps 49 %
	GeometryFactory factory = new GeometryFactory();
	LinearRing half1 = factory.createLinearRing(new Coordinate[] {new Coordinate(0, 0), new Coordinate(1, 0),
			new Coordinate(1, 0.49), new Coordinate(0, 0.49), new Coordinate(0, 0)});
	Polygon polygon = factory.createPolygon(half1, null);
	request.setLocation(converter.toDto(polygon));

	// execute
	SearchByLocationResponse response = (SearchByLocationResponse) dispatcher.execute(
			SearchByLocationRequest.COMMAND, request, null, "en");
	// test
	List<Feature> features = response.getFeatureMap().get(LAYER_ID);
	Assert.assertNull(features);
}
 
Example #9
@Test
public void jtsEmptyToDto() throws GeomajasException {
	Geometry p = converter.toDto(createJtsEmpty(Point.class));
	Assert.assertEquals(Geometry.POINT, p.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(p));
	Geometry ls = converter.toDto(createJtsEmpty(LineString.class));
	Assert.assertEquals(Geometry.LINE_STRING, ls.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(ls));
	Geometry lr = converter.toDto(createJtsEmpty(LinearRing.class));
	Assert.assertEquals(Geometry.LINEAR_RING, lr.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(lr));
	Geometry po = converter.toDto(createJtsEmpty(Polygon.class));
	Assert.assertEquals(Geometry.POLYGON, po.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(po));
	assertThat(po.getGeometries()).isNull();
	Geometry mp = converter.toDto(createJtsEmpty(MultiPoint.class));
	Assert.assertEquals(Geometry.MULTI_POINT, mp.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(mp));
	Geometry mpo = converter.toDto(createJtsEmpty(MultiPolygon.class));
	Assert.assertEquals(Geometry.MULTI_POLYGON, mpo.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(mpo));
	Geometry mls = converter.toDto(createJtsEmpty(MultiLineString.class));
	Assert.assertEquals(Geometry.MULTI_LINE_STRING, mls.getGeometryType());
	Assert.assertTrue(GeometryService.isEmpty(mls));
}
 
Example #10
@Test
public void dtoEmptyToJts() throws GeomajasException {
	// Test DTO Point to JTS:
	LineString ls = (LineString) converter.toInternal(createDtoEmpty(Geometry.LINE_STRING));
	Assert.assertTrue(ls.isEmpty());
	LinearRing lr = (LinearRing) converter.toInternal(createDtoEmpty(Geometry.LINEAR_RING));
	Assert.assertTrue(lr.isEmpty());
	MultiLineString mls = (MultiLineString) converter.toInternal(createDtoEmpty(Geometry.MULTI_LINE_STRING));
	Assert.assertTrue(mls.isEmpty());
	MultiPoint mp = (MultiPoint) converter.toInternal(createDtoEmpty(Geometry.MULTI_POINT));
	Assert.assertTrue(mp.isEmpty());
	MultiPolygon mpo = (MultiPolygon) converter.toInternal(createDtoEmpty(Geometry.MULTI_POLYGON));
	Assert.assertTrue(mpo.isEmpty());
	Point p = (Point) converter.toInternal(createDtoEmpty(Geometry.POINT));
	Assert.assertTrue(p.isEmpty());
	Polygon po = (Polygon) converter.toInternal(createDtoEmpty(Geometry.POLYGON));
	Assert.assertTrue(po.isEmpty());
}
 
Example #11
Source Project: jts   Author: metteo   File: KMLWriter.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
private void writeGeometry(Geometry g, int level, StringBuffer buf) {
  String attributes = "";
  if (g instanceof Point) {
    writePoint((Point) g, attributes, level, buf);
  } else if (g instanceof LinearRing) {
    writeLinearRing((LinearRing) g, attributes, true, level, buf);
  } else if (g instanceof LineString) {
    writeLineString((LineString) g, attributes, level, buf);
  } else if (g instanceof Polygon) {
    writePolygon((Polygon) g, attributes, level, buf);
  } else if (g instanceof GeometryCollection) {
    writeGeometryCollection((GeometryCollection) g, attributes, level, buf);
  }
  else 
    throw new IllegalArgumentException("Geometry type not supported: " + g.getGeometryType());
}
 
Example #12
Source Project: jts   Author: metteo   File: KMLWriter.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
private void writePolygon(Polygon p, String attributes, int level,
    StringBuffer buf) {
  startLine(geometryTag("Polygon", attributes) + "\n", level, buf);
  writeModifiers(level, buf);

  startLine("  <outerBoundaryIs>\n", level, buf);
  writeLinearRing((LinearRing) p.getExteriorRing(), null, false, level + 1, buf);
  startLine("  </outerBoundaryIs>\n", level, buf);

  for (int t = 0; t < p.getNumInteriorRing(); t++) {
    startLine("  <innerBoundaryIs>\n", level, buf);
    writeLinearRing((LinearRing) p.getInteriorRingN(t), null, false, level + 1, buf);
    startLine("  </innerBoundaryIs>\n", level, buf);
  }

  startLine("</Polygon>\n", level, buf);
}
 
Example #13
Source Project: jts   Author: metteo   File: HoleRemover.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public Polygon getResult()
{
  GeometryFactory gf = poly.getFactory();
  Polygon shell = gf.createPolygon((LinearRing) poly.getExteriorRing());
  
  List holes = new ArrayList();
  for (int i = 0; i < poly.getNumInteriorRing(); i++) {
    LinearRing hole = (LinearRing) poly.getInteriorRingN(i);
    if (! isRemoved.value(hole)) {
      holes.add(hole);
    }
  }
  // all holes valid, so return original
  if (holes.size() == poly.getNumInteriorRing())
    return poly;
  
  // return new polygon with covered holes only
  Polygon result = gf.createPolygon((LinearRing) poly.getExteriorRing(), 
      GeometryFactory.toLinearRingArray(holes));
  return result;
}
 
Example #14
Source Project: geomajas-project-server   Author: geomajas   File: GeoServiceImpl.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Geometry createCircle(final Point point, final double radius, final int nrPoints) {
	double x = point.getX();
	double y = point.getY();
	Coordinate[] coords = new Coordinate[nrPoints + 1];
	for (int i = 0; i < nrPoints; i++) {
		double angle = ((double) i / (double) nrPoints) * Math.PI * 2.0;
		double dx = Math.cos(angle) * radius;
		double dy = Math.sin(angle) * radius;
		coords[i] = new Coordinate(x + dx, y + dy);
	}
	coords[nrPoints] = coords[0];

	LinearRing ring = point.getFactory().createLinearRing(coords);
	return point.getFactory().createPolygon(ring, null);
}
 
Example #15
Source Project: jackson-datatype-jts   Author: bedatadriven   File: PolygonTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Polygon createGeometry() {
    LinearRing shell = gf.createLinearRing(new Coordinate[] {
            new Coordinate(102.0, 2.0), new Coordinate(103.0, 2.0),
            new Coordinate(103.0, 3.0), new Coordinate(102.0, 3.0),
            new Coordinate(102.0, 2.0) });
    LinearRing[] holes = new LinearRing[0];
    return gf.createPolygon(shell, holes);
}
 
Example #16
Source Project: xyz-hub   Author: heremaps   File: JTSHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a linear ring.
 */
public static LinearRing toLinearRing(LinearRingCoordinates coords) {
  if (coords == null) {
    return null;
  }

  Coordinate[] jtsCoords = new Coordinate[coords.size()];

  for (int i = 0; i < jtsCoords.length; i++) {
    jtsCoords[i] = toCoordinate(coords.get(i));
  }

  return factory.createLinearRing(jtsCoords);
}
 
Example #17
Source Project: xyz-hub   Author: heremaps   File: JTSHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create GeoJSON LinearRing coordinates.
 */
public static LinearRingCoordinates createLinearRingCoordinates(LinearRing geom) {
  if (geom == null) {
    return null;
  }

  int len = geom.getNumPoints();
  LinearRingCoordinates linearRingCoordinates = new LinearRingCoordinates(len);

  for (int i = 0; i < len; i++) {
    linearRingCoordinates.add(createPosition(geom.getCoordinateN(i)));
  }

  return linearRingCoordinates;
}
 
Example #18
Source Project: coordination_oru   Author: FedericoPecora   File: GeometrySmoother.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new {@code Polygon} whose exterior shell is a smoothed
 * version of the input {@code Polygon}.
 * <p>
 * Note: this method presently ignores holes.
 * 
 * @param p the input {@code Polygon}
 * 
 * @param alpha a value between 0 and 1 (inclusive) specifying the tightness
 *        of fit of the smoothed boundary (0 is loose)
 * 
 * @return the smoothed {@code Polygon}
 */
public Polygon smooth(Polygon p, double alpha) {
    Coordinate[] coords = p.getExteriorRing().getCoordinates();
    final int N = coords.length - 1;  // first coord == last coord
    
    Coordinate[][] controlPoints = getPolygonControlPoints(coords, N, alpha);
    
    List<Coordinate> smoothCoords = new ArrayList<Coordinate>();
    double dist;
    for (int i = 0; i < N; i++) {
        int next = (i + 1) % N;
        
        dist = coords[i].distance(coords[next]);
        if (dist < control.getMinLength()) {
            // segment too short - just copy input coordinate
            smoothCoords.add(new Coordinate(coords[i]));
            
        } else {
            int smoothN = control.getNumVertices(dist);
            Coordinate[] segment = cubicBezier(
                    coords[i], coords[next],
                    controlPoints[i][1], controlPoints[next][0],
                    smoothN);
        
            int copyN = i < N - 1 ? segment.length - 1 : segment.length;
            for (int k = 0; k < copyN; k++) {
                smoothCoords.add(segment[k]);
            }
        }
    }
    
    LinearRing shell = geomFactory.createLinearRing(smoothCoords.toArray(new Coordinate[0]));
    return geomFactory.createPolygon(shell, null);
}
 
Example #19
Source Project: geomajas-project-server   Author: geomajas   File: DefaultVmlDocument.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private void initDefaultWriters() {
	registerWriter(Point.class, new PointWriter());
	registerWriter(LineString.class, new LineStringWriter());
	registerWriter(LinearRing.class, new LineStringWriter());
	registerWriter(Polygon.class, new PolygonWriter());
	registerWriter(MultiPoint.class, new MultiPointWriter());
	registerWriter(MultiLineString.class, new MultiLineStringWriter());
	registerWriter(MultiPolygon.class, new MultiPolygonWriter());
	registerWriter(GeometryCollection.class, new GeometryCollectionWriter());
}
 
Example #20
Source Project: gama   Author: gama-platform   File: GamaGeometryFactory.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Linear rings are created using a simple coordinate array, without enforcing any clockwiseness condition.
 */
@Override
public LinearRing createLinearRing(final Coordinate[] coordinates) {
	Coordinate[] coords = coordinates;
	if (!isRing(coords)) {
		coords = (Coordinate[]) ArrayUtils.add(coords, coords[0]);
	}
	return createLinearRing(JTS_COORDINATES_FACTORY.create(coords));
}
 
Example #21
Source Project: gama   Author: gama-platform   File: GamaGeometryFactory.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Polygon buildRectangle(final Coordinate[] points) {
	final CoordinateSequenceFactory fact = GamaGeometryFactory.COORDINATES_FACTORY;
	final CoordinateSequence cs = fact.create(points);
	final LinearRing geom = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(cs);
	final Polygon p = GeometryUtils.GEOMETRY_FACTORY.createPolygon(geom, null);
	return p;
}
 
Example #22
Source Project: gama   Author: gama-platform   File: GamaGeometryFactory.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Polygons are created after ensuring that the coordinate sequence in them has been turned clockwise
 */

@Override
public Polygon createPolygon(final LinearRing shell, final LinearRing[] holes) {
	final LinearRing shellClockwise = turnClockwise(shell);
	if (holes != null) {
		for (int i = 0; i < holes.length; i++) {
			holes[i] = turnClockwise(holes[i]);
		}
	}
	return super.createPolygon(shellClockwise, holes);
}
 
Example #23
Source Project: rya   Author: apache   File: MongoGeoIndexerIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDcSearch() throws Exception {
    // test a ring around dc
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        f.setConf(conf);
        f.init();

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final Resource subject = vf.createIRI("foo:subj");
        final IRI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createIRI("foo:context");

        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();

        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));

        // test a ring outside the point
        final double[] OUT = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
        final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
        final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
    }
}
 
Example #24
Source Project: rya   Author: apache   File: MongoGeoIndexerIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteSearch() throws Exception {
    // test a ring around dc
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        f.setConf(conf);
        f.init();

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final Resource subject = vf.createIRI("foo:subj");
        final IRI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createIRI("foo:context");

        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();

        f.deleteStatement(convertStatement(statement));

        // test a ring that the point would be inside of if not deleted
        final double[] in = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(in, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));

        // test a ring that the point would be outside of if not deleted
        final double[] out = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
        final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(out, 2));
        final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));

        // test a ring for the whole world and make sure the point is gone
        // Geomesa is a little sensitive around lon 180, so we only go to 179
        final double[] world = { -180, 90, 179, 90, 179, -90, -180, -90, -180, 90 };
        final LinearRing rWorld = gf.createLinearRing(new PackedCoordinateSequence.Double(world, 2));
        final Polygon pWorld = gf.createPolygon(rWorld, new LinearRing[] {});
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pWorld, EMPTY_CONSTRAINTS)));
    }
}
 
Example #25
Source Project: rya   Author: apache   File: MongoGeoIndexerIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDcSearchWithContext() throws Exception {
    // test a ring around dc
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        f.setConf(conf);
        f.init();

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final Resource subject = vf.createIRI("foo:subj");
        final IRI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createIRI("foo:context");

        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();

        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});

        // query with correct context
        assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context))));

        // query with wrong context
        assertEquals(Sets.newHashSet(),
                getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createIRI("foo:context2")))));
    }
}
 
Example #26
Source Project: rya   Author: apache   File: MongoGeoIndexerIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDcSearchWithSubject() throws Exception {
    // test a ring around dc
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        f.setConf(conf);
        f.init();

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final Resource subject = vf.createIRI("foo:subj");
        final IRI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createIRI("foo:context");

        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();

        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});

        // query with correct subject
        assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject))));

        // query with wrong subject
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createIRI("foo:subj2")))));
    }
}
 
Example #27
Source Project: rya   Author: apache   File: MongoGeoIndexerIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDcSearchWithPredicate() throws Exception {
    // test a ring around dc
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        f.setConf(conf);
        f.init();

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final Resource subject = vf.createIRI("foo:subj");
        final IRI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createIRI("foo:context");

        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();

        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});

        // query with correct Predicate
        assertEquals(Sets.newHashSet(statement),
                getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(predicate)))));

        // query with wrong predicate
        assertEquals(Sets.newHashSet(),
                getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(vf.createIRI("other:pred"))))));
    }
}
 
Example #28
Source Project: rya   Author: apache   File: MongoGeoIndexerIT.java    License: Apache License 2.0 5 votes vote down vote up
public void testAntiMeridianSearch() throws Exception {
    // verify that a search works if the bounding box crosses the anti meridian
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        f.setConf(conf);
        f.init();

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final Resource context = vf.createIRI("foo:context");

        final Resource subjectEast = vf.createIRI("foo:subj:east");
        final IRI predicateEast = GeoConstants.GEO_AS_WKT;
        final Value objectEast = vf.createLiteral("Point(179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Statement statementEast = vf.createStatement(subjectEast, predicateEast, objectEast, context);
        f.storeStatement(convertStatement(statementEast));

        final Resource subjectWest = vf.createIRI("foo:subj:west");
        final IRI predicateWest = GeoConstants.GEO_AS_WKT;
        final Value objectWest = vf.createLiteral("Point(-179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Statement statementWest = vf.createStatement(subjectWest, predicateWest, objectWest, context);
        f.storeStatement(convertStatement(statementWest));

        f.flush();

        final double[] ONE = { 178.1, 1, -178, 1, -178, -1, 178.1, -1, 178.1, 1 };

        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));

        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});

        assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
    }
}
 
Example #29
Source Project: geomajas-project-server   Author: geomajas   File: DefaultSvgDocument.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private void initDefaultWriters() {
	registerWriter(Bbox.class, new BboxWriter());
	registerWriter(Point.class, new PointWriter());
	registerWriter(LineString.class, new LineStringWriter());
	registerWriter(LinearRing.class, new LineStringWriter());
	registerWriter(Polygon.class, new PolygonWriter());
	registerWriter(MultiPoint.class, new MultiPointWriter());
	registerWriter(MultiLineString.class, new MultiLineStringWriter());
	registerWriter(MultiPolygon.class, new MultiPolygonWriter());
	registerWriter(GeometryCollection.class, new GeometryCollectionWriter());
}
 
Example #30
Source Project: rya   Author: apache   File: GeoWaveIndexerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDcSearch() throws Exception {
    // test a ring around dc
    try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) {
        f.setConf(conf);
        f.purge(conf);

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final Resource subject = vf.createIRI("foo:subj");
        final IRI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createIRI("foo:context");

        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();

        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));

        // test a ring outside the point
        final double[] OUT = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
        final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
        final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
    }
}