com.vividsolutions.jts.geom.LinearRing Java Examples

The following examples show how to use com.vividsolutions.jts.geom.LinearRing. 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 File: GamaGisFile.java    From gama with GNU General Public License v3.0 8 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 #2
Source File: JTSHelper.java    From xyz-hub with 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 #3
Source File: SearchByLocationCommandTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@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 #4
Source File: HoleRemover.java    From jts with 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 #5
Source File: KMLWriter.java    From jts with 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 #6
Source File: GamaGeometryType.java    From gama with 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 #7
Source File: GamaGeometryType.java    From gama with 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 #8
Source File: GeometryConverterTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #9
Source File: GeometryConverterTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@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
Source File: KMLWriter.java    From jts with 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 #11
Source File: GeoToolsPrimitiveFromJsonFactory.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 #12
Source File: GeoServiceImpl.java    From geomajas-project-server with 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 #13
Source File: JTSHelper.java    From xyz-hub with 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 #14
Source File: GeometryConverterTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@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 #15
Source File: StyleConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private Geometry toSimpleGeometry(GeometryFactory factory, AbstractGeometryInfo geom) throws LayerException {
	Geometry geometry = null;
	if (geom instanceof PointTypeInfo) {
		PointTypeInfo point = (PointTypeInfo) geom;
		if (point.ifCoord()) {
			geometry = factory.createPoint(getCoordinates(Collections.singletonList(point.getCoord()))[0]);
		} else if (point.ifCoordinates()) {
			geometry = factory.createPoint(getCoordinates(point.getCoordinates())[0]);
		}
	} else if (geom instanceof LineStringTypeInfo) {
		LineStringTypeInfo linestring = (LineStringTypeInfo) geom;
		if (linestring.ifCoordList()) {
			geometry = factory.createLineString(getCoordinates(linestring.getCoordList()));
		} else if (linestring.ifCoordinates()) {
			geometry = factory.createLineString(getCoordinates(linestring.getCoordinates()));
		}
	} else if (geom instanceof PolygonTypeInfo) {
		PolygonTypeInfo polygon = (PolygonTypeInfo) geom;
		OuterBoundaryIsInfo outer = polygon.getOuterBoundaryIs();
		LinearRing shell = toLinearRing(factory, outer.getLinearRing());
		if (polygon.getInnerBoundaryIList() == null) {
			geometry = factory.createPolygon(shell, null);
		} else {
			LinearRing[] holes = new LinearRing[polygon.getInnerBoundaryIList().size()];
			int i = 0;
			for (InnerBoundaryIsInfo inner : polygon.getInnerBoundaryIList()) {
				holes[i++] = toLinearRing(factory, inner.getLinearRing());
			}
			geometry = factory.createPolygon(shell, holes);
		}
	}
	return geometry;
}
 
Example #16
Source File: PolygonTest.java    From jackson-datatype-jts with 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 #17
Source File: MiscellaneousTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @todo Enable when #isSimple implemented
 */
//  public void testLineStringIsSimple2() throws Exception {
//    Geometry g = reader.read("LINESTRING(10 10, 20 10, 15 20, 15 0)");
//    assertTrue(! g.isSimple());
//  }

  public void testLinearRingIsSimple() throws Exception {
    Coordinate[] coordinates = { new Coordinate(10, 10, 0),
                                 new Coordinate(10, 20, 0),
                                 new Coordinate(20, 20, 0),
                                 new Coordinate(20, 15, 0),
                                 new Coordinate(10, 10, 0) };
    LinearRing linearRing = geometryFactory.createLinearRing(coordinates);
    assertTrue(linearRing.isSimple());
  }
 
Example #18
Source File: GeometryConverterTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private Polygon createJtsPolygon() {
	LinearRing shell = factory.createLinearRing(new com.vividsolutions.jts.geom.Coordinate[] { jtsC1, jtsC2, jtsC3,
			jtsC4, jtsC1 });
	LinearRing hole = factory.createLinearRing(new com.vividsolutions.jts.geom.Coordinate[] { jtsC5, jtsC6, jtsC7,
			jtsC8, jtsC5 });
	return factory.createPolygon(shell, new LinearRing[] { hole });
}
 
Example #19
Source File: CustomBeanLayerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void readGeometry() throws LayerException {
	GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326);
	LinearRing shell = factory.createLinearRing(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0),
			new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0), });
	Polygon p = factory.createPolygon(shell, null);
	MultiPolygon expected = factory.createMultiPolygon(new Polygon[] { p });
	Assert.assertTrue(((CustomBean) layer.read("1")).getGeometry().equalsExact(expected));
}
 
Example #20
Source File: WKTWriterTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testWritePolygon() throws Exception {
  Coordinate[] coordinates = { new Coordinate(10, 10, 0),
                               new Coordinate(10, 20, 0),
                               new Coordinate(20, 20, 0),
                               new Coordinate(20, 15, 0),
                               new Coordinate(10, 10, 0) };
  LinearRing linearRing = geometryFactory.createLinearRing(coordinates);
  Polygon polygon = geometryFactory.createPolygon(linearRing, new LinearRing[] { });
  assertEquals("POLYGON ((10 10, 10 20, 20 20, 20 15, 10 10))", writer.write(polygon).toString());
}
 
Example #21
Source File: ValidClosedRingTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testBadGeometryCollection()
{
  GeometryCollection gc = (GeometryCollection) fromWKT("GEOMETRYCOLLECTION ( POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1) )), POINT(0 0) )");
  Polygon poly = (Polygon) gc.getGeometryN(0);
  updateNonClosedRing((LinearRing) poly.getInteriorRingN(0));
  checkIsValid(poly, false);
}
 
Example #22
Source File: MiscellaneousTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testBoundaryOfEmptyGeometry() throws Exception {
  assertTrue(geometryFactory.createPoint((Coordinate)null).getBoundary().getClass() == GeometryCollection.class);
  assertTrue(geometryFactory.createLinearRing(new Coordinate[] { }).getBoundary().getClass() == MultiPoint.class);
  assertTrue(geometryFactory.createLineString(new Coordinate[] { }).getBoundary().getClass() == MultiPoint.class);
  assertTrue(geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { }), new LinearRing[] { }).getBoundary().getClass() == MultiLineString.class);
  assertTrue(geometryFactory.createMultiPolygon(new Polygon[] { }).getBoundary().getClass() == MultiLineString.class);
  assertTrue(geometryFactory.createMultiLineString(new LineString[] { }).getBoundary().getClass() == MultiPoint.class);
  assertTrue(geometryFactory.createMultiPoint(new Point[] { }).getBoundary().getClass() == GeometryCollection.class);
  try {
    geometryFactory.createGeometryCollection(new Geometry[] { }).getBoundary();
    assertTrue(false);
  }
  catch (IllegalArgumentException e) {
  }
}
 
Example #23
Source File: GeometryBoxDeleter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Coordinate[] edit(Coordinate[] coords,
    Geometry geometry)
{
  if (isEdited) return coords;
  if (! hasVertexInBox(coords))
    return coords;
  // only delete vertices of first component found
  
  int minLen = 2;
  if (geometry instanceof LinearRing) minLen = 4;
  
  Coordinate[] newPts = new Coordinate[coords.length];
  int newIndex = 0;
  for (int i = 0; i < coords.length; i++) {
    if (! env.contains(coords[i])) {
      newPts[newIndex++] = coords[i];
    }
  }
  Coordinate[] nonNullPts = CoordinateArrays.removeNull(newPts);
  Coordinate[] finalPts = nonNullPts;
  
  // close ring if required
  if (geometry instanceof LinearRing) {
    if (nonNullPts.length > 1 && ! nonNullPts[nonNullPts.length - 1].equals2D(nonNullPts[0])) {
      Coordinate[] ringPts = new Coordinate[nonNullPts.length + 1];
      CoordinateArrays.copyDeep(nonNullPts, 0, ringPts, 0, nonNullPts.length);
      ringPts[ringPts.length-1] = new Coordinate(ringPts[0]);
      finalPts = ringPts;
    }
  }
  
  // don't change if would make geometry invalid
  if (finalPts.length < minLen)
    return coords;

  isEdited = true;
  return finalPts; 
}
 
Example #24
Source File: GeoIndexerTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testDcSearchWithSubject() throws Exception {
    // test a ring around dc
    try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
        f.setConf(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[] {});

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

        // query with wrong subject
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createIRI("foo:subj2")))));
    }
}
 
Example #25
Source File: StyleConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private LinearRing toLinearRing(GeometryFactory factory, LinearRingTypeInfo linearRing) throws LayerException {
	LinearRing ring = null;
	if (linearRing.ifCoordList()) {
		ring = factory.createLinearRing(getCoordinates(linearRing.getCoordList()));
	} else if (linearRing.ifCoordinates()) {
		ring = factory.createLinearRing(getCoordinates(linearRing.getCoordinates()));
	}
	return ring;
}
 
Example #26
Source File: GeometryCoordinateReplacer.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static int minimumNonEmptyCoordinatesSize(Geometry geom) {
  if (geom instanceof LinearRing)
    return 4;
  if (geom instanceof LineString)
    return 2;
  return 0;
}
 
Example #27
Source File: GeoIndexerTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testDcSearchWithSubjectAndContext() throws Exception {
    // test a ring around dc
    try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
        f.setConf(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[] {});

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

        // query with wrong context
        Assert.assertEquals(Sets.newHashSet(),
                getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createIRI("foo:context2")))));

        // query with wrong subject
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createIRI("foo:subj2")))));
    }
}
 
Example #28
Source File: KMLWriter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void writeLinearRing(LinearRing lr, String attributes, 
    boolean writeModifiers, int level,
    StringBuffer buf) {
// <LinearRing><coordinates>...</coordinates></LinearRing>
  startLine(geometryTag("LinearRing", attributes) + "\n", level, buf);
  if (writeModifiers) writeModifiers(level, buf);
  write(lr.getCoordinates(), level + 1, buf);
  startLine("</LinearRing>\n", level, buf);
}
 
Example #29
Source File: GeoIndexerTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testDcSearchWithPredicate() throws Exception {
    // test a ring around dc
    try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
        f.setConf(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[] {});

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

        // query with wrong predicate
        Assert.assertEquals(Sets.newHashSet(),
                getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(vf.createIRI("other:pred"))))));
    }
}
 
Example #30
Source File: GeoIndexerTest.java    From rya with 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 GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
        f.setConf(conf);

        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[] {});

        Assert.assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
    }
}