org.json.simple.JSONAware#com.vividsolutions.jts.geom.Polygon源码实例Demo

下面列出了org.json.simple.JSONAware#com.vividsolutions.jts.geom.Polygon 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: OpenMapKitAndroid   文件: JTSModel.java
private void addOSMClosedWays(OSMDataSet ds) {
    List<OSMWay> closedWays = ds.getClosedWays();
    for (OSMWay w : closedWays) {
        if (!w.isModified() && OSMWay.containsModifiedWay(w.getId())) {
            continue;    
        }
        // Don't render or index ways that do not have all of their referenced nodes.
        if (w.incomplete()) {
            continue;
        }
        List<OSMNode> nodes = w.getNodes();
        Coordinate[] coords = coordArrayFromNodeList(nodes);
        Polygon poly = geometryFactory.createPolygon(coords);
        w.setJTSGeom(poly);
        Envelope envelope = poly.getEnvelopeInternal();
        spatialIndex.insert(envelope, w);
    }
}
 
@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);
}
 
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;
	}
}
 
源代码4 项目: jts   文件: Distance3DOp.java
private void computeMinDistanceOneMulti(PlanarPolygon3D poly, Geometry geom, boolean flip) {
	if (geom instanceof GeometryCollection) {
		int n = geom.getNumGeometries();
		for (int i = 0; i < n; i++) {
			Geometry g = geom.getGeometryN(i);
			computeMinDistanceOneMulti(poly, g, flip);
			if (isDone)	return;
		}
	}
	else {
		if (geom instanceof Point) {
			computeMinDistancePolygonPoint(poly, (Point) geom, flip);
			return;
		}
		if (geom instanceof LineString) {
			computeMinDistancePolygonLine(poly, (LineString) geom, flip);
			return;
		}
		if (geom instanceof Polygon) {
			computeMinDistancePolygonPolygon(poly, (Polygon) geom, flip);
			return;
		}
	}
}
 
源代码5 项目: jts   文件: WKBWriter.java
/**
 * Writes a {@link Geometry} to an {@link OutStream}.
 *
 * @param geom the geometry to write
 * @param os the out stream to write to
 * @throws IOException if an I/O error occurs
 */
public void write(Geometry geom, OutStream os) throws IOException
{
  if (geom instanceof Point)
    writePoint((Point) geom, os);
  // LinearRings will be written as LineStrings
  else if (geom instanceof LineString)
    writeLineString((LineString) geom, os);
  else if (geom instanceof Polygon)
    writePolygon((Polygon) geom, os);
  else if (geom instanceof MultiPoint)
    writeGeometryCollection(WKBConstants.wkbMultiPoint, 
        (MultiPoint) geom, os);
  else if (geom instanceof MultiLineString)
    writeGeometryCollection(WKBConstants.wkbMultiLineString,
        (MultiLineString) geom, os);
  else if (geom instanceof MultiPolygon)
    writeGeometryCollection(WKBConstants.wkbMultiPolygon,
        (MultiPolygon) geom, os);
  else if (geom instanceof GeometryCollection)
    writeGeometryCollection(WKBConstants.wkbGeometryCollection,
        (GeometryCollection) geom, os);
  else {
    Assert.shouldNeverReachHere("Unknown Geometry type");
  }
}
 
源代码6 项目: sldeditor   文件: AllowedAttributeTypes.java
/**
 * Initialise.
 */
private static void initialise()
{
    List<Class<?> > doubleList = new ArrayList<Class<?> >(Arrays.asList(Integer.class, Long.class, Double.class, Float.class));
    List<Class<?> > integerList = new ArrayList<Class<?> >(Arrays.asList(Integer.class, Long.class));
    List<Class<?> > stringList = new ArrayList<Class<?> >(Arrays.asList(String.class));
    List<Class<?> > geometryList = new ArrayList<Class<?> >(Arrays.asList(Point.class, LineString.class, Polygon.class, MultiPolygon.class, MultiPoint.class, MultiLineString.class));

    allowedClassTypeMap.put(String.class, stringList);
    allowedClassTypeMap.put(Double.class, doubleList);
    allowedClassTypeMap.put(Float.class, doubleList);
    allowedClassTypeMap.put(Integer.class, integerList);
    allowedClassTypeMap.put(Long.class, integerList);
    allowedClassTypeMap.put(Geometry.class, geometryList);

    List<Class<?> > objectList = new ArrayList<Class<?>>();
    objectList.addAll(doubleList);
    objectList.addAll(integerList);
    objectList.addAll(stringList);
    objectList.addAll(geometryList);
    allowedClassTypeMap.put(Object.class, objectList);
}
 
源代码7 项目: jts   文件: KMLWriter.java
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());
}
 
源代码8 项目: jts   文件: SameStructureTester.java
public static boolean isSameStructure(Geometry g1, Geometry g2)
{
  if (g1.getClass() != g2.getClass())
    return false;
  if (g1 instanceof GeometryCollection)
    return isSameStructureCollection((GeometryCollection) g1, (GeometryCollection) g2);
  else if (g1 instanceof Polygon)
    return isSameStructurePolygon((Polygon) g1, (Polygon) g2);
  else if (g1 instanceof LineString)
    return isSameStructureLineString((LineString) g1, (LineString) g2);
  else if (g1 instanceof Point)
    return isSameStructurePoint((Point) g1, (Point) g2);

  Assert.shouldNeverReachHere(
      "Unsupported Geometry class: " + g1.getClass().getName());
  return false;
}
 
/**
 * Writes the body for a <code>MultiPolygon</code> object. MultiPolygons are
 * encoded into SVG path elements. This function writes the different
 * polygons in one d-attribute of an SVG path element, separated by an 'M'
 * character. (in other words, it calls the super.writeBody for each
 * polygon).
 *
 * @param o The <code>MultiPolygon</code> to be encoded.
 */
public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException {
	document.writeElement("path", asChild);
	document.writeAttribute("fill-rule", "evenodd");
	document.writeAttributeStart("d");
	MultiPolygon mpoly = (MultiPolygon) o;
	for (int i = 0; i < mpoly.getNumGeometries(); i++) {
		Polygon poly = (Polygon) mpoly.getGeometryN(i);
		LineString shell = poly.getExteriorRing();
		int nHoles = poly.getNumInteriorRing();
		document.writeClosedPathContent(shell.getCoordinates());

		for (int j = 0; j < nHoles; j++) {
			document.writeClosedPathContent(poly.getInteriorRingN(j).getCoordinates());
		}
	}
	document.writeAttributeEnd();
}
 
源代码10 项目: gama   文件: GeometryUtils.java
private static Geometry buildPolygon(final List<List<ILocation>> listPoints) {
	final List<ILocation> coords = listPoints.get(0);
	final int nb = coords.size();
	final Coordinate[] coordinates = new Coordinate[nb];
	for (int i = 0; i < nb; i++) {
		coordinates[i] = (Coordinate) coords.get(i);
	}
	final int nbHoles = listPoints.size() - 1;
	LinearRing[] holes = null;
	if (nbHoles > 0) {
		holes = new LinearRing[nbHoles];
		for (int i = 0; i < nbHoles; i++) {
			final List<ILocation> coordsH = listPoints.get(i + 1);
			final int nbp = coordsH.size();
			final Coordinate[] coordinatesH = new Coordinate[nbp];
			for (int j = 0; j < nbp; j++) {
				coordinatesH[j] = (Coordinate) coordsH.get(j);
			}
			holes[i] = GEOMETRY_FACTORY.createLinearRing(coordinatesH);
		}
	}
	final Polygon poly = GEOMETRY_FACTORY.createPolygon(GEOMETRY_FACTORY.createLinearRing(coordinates), holes);
	return poly;
}
 
源代码11 项目: jts   文件: KMLWriter.java
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);
}
 
源代码12 项目: jts   文件: WKTWriter.java
/**
 *  Converts a <code>Polygon</code> to &lt;Polygon Text&gt; format, then
 *  appends it to the writer.
 *
 *@param  polygon  the <code>Polygon</code> to process
 *@param  writer   the output writer to append to
 */
private void appendPolygonText(Polygon polygon, int level, boolean indentFirst, Writer writer)
  throws IOException
{
  if (polygon.isEmpty()) {
    writer.write("EMPTY");
  }
  else {
    if (indentFirst) indent(level, writer);
    writer.write("(");
    appendLineStringText(polygon.getExteriorRing(), level, false, writer);
    for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
      writer.write(", ");
      appendLineStringText(polygon.getInteriorRingN(i), level + 1, true, writer);
    }
    writer.write(")");
  }
}
 
源代码13 项目: gama   文件: GeometryUtils.java
public static Geometry cleanGeometry(final Geometry g) {
	//follow the proposition of https://locationtech.github.io/jts/jts-faq.html#G1
	if (g == null || g.isEmpty()) return g; 
	Geometry g2 = g.buffer(0.0, BufferParameters.DEFAULT_QUADRANT_SEGMENTS,
			BufferParameters.CAP_FLAT);
	if (g2.isEmpty()) {
		if (g instanceof Polygon) {
			Polygon p = (Polygon) g;
			Geometry g3 = GeometryUtils.GEOMETRY_FACTORY.createPolygon(p.getExteriorRing().getCoordinates());
			for (int i = 0; i < p.getNumInteriorRing(); i++) {
				Geometry g4 = GeometryUtils.GEOMETRY_FACTORY.createPolygon(p.getInteriorRingN(i).getCoordinates());
				g3 = g3.difference(g4);
			}
			return g3;
		}else {
			return GeometryUtils.GEOMETRY_FACTORY.createGeometry(g);
		}
	}
	return g2;
}
 
源代码14 项目: gama   文件: GamaGeometryType.java
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;
}
 
源代码15 项目: gama   文件: SaveStatement.java
public static String getGeometryType(final List<? extends IShape> agents) {
	String geomType = "";
	for (final IShape be : agents) {
		final IShape geom = be.getGeometry();
		if (geom != null && geom.getInnerGeometry() != null) {
			geomType = geom.getInnerGeometry().getClass().getSimpleName();
			if (geom.getInnerGeometry().getNumGeometries() > 1) {
				if (geom.getInnerGeometry().getGeometryN(0).getClass() == Point.class) {
					geomType = MultiPoint.class.getSimpleName();
				} else if (geom.getInnerGeometry().getGeometryN(0).getClass() == LineString.class) {
					geomType = MultiLineString.class.getSimpleName();
				} else if (geom.getInnerGeometry().getGeometryN(0).getClass() == Polygon.class) {
					geomType = MultiPolygon.class.getSimpleName();
				}
				break;
			}
		}
	}
	if ("DynamicLineString".equals(geomType)) {
		geomType = LineString.class.getSimpleName();
	}
	return geomType;
}
 
源代码16 项目: jts   文件: OraReader.java
/**
 * Create MultiPolygon as encoded by elemInfo.
 *
 * @param oraGeom SDO_GEOMETRY attributes being read
 * @param coords the coordinates of the entire geometry
 * @return MultiPolygon
 */
private MultiPolygon readMultiPolygon(OraGeom oraGeom)
{
  int nElem = oraGeom.numElements();
  List geoms = new ArrayList();
  for (int i = 0; i < nElem; i++) {
    int etype = oraGeom.eType(i);
    if ((etype == OraGeom.ETYPE.POLYGON) || (etype == OraGeom.ETYPE.POLYGON_EXTERIOR)) {
      Polygon poly = readPolygon(oraGeom, i);
      i += poly.getNumInteriorRing(); // skip interior rings
      geoms.add(poly);
    } 
    else { // not a Polygon - stop reading
    	break;
    }
  }
  MultiPolygon polys = geometryFactory.createMultiPolygon(GeometryFactory.toPolygonArray(geoms));
  return polys;
}
 
@Test
public void testConversion() {
	// dto -> internal
	for (LayerType layerType : LayerType.values()) {
		if (layerType != LayerType.RASTER) {
			Class<? extends Geometry> c = converterService.toInternal(layerType);
			Assert.assertEquals(layerType.name(), c.getSimpleName().toUpperCase());
		} else {
			Assert.assertNull(converterService.toInternal(layerType));
		}
	}
	// internal -> dto
	Assert.assertEquals(LayerType.POINT, converterService.toDto(Point.class));
	Assert.assertEquals(LayerType.MULTIPOINT, converterService.toDto(MultiPoint.class));
	Assert.assertEquals(LayerType.LINESTRING, converterService.toDto(LineString.class));
	Assert.assertEquals(LayerType.MULTILINESTRING, converterService.toDto(MultiLineString.class));
	Assert.assertEquals(LayerType.POLYGON, converterService.toDto(Polygon.class));
	Assert.assertEquals(LayerType.MULTIPOLYGON, converterService.toDto(MultiPolygon.class));
	Assert.assertEquals(LayerType.GEOMETRY, converterService.toDto(Geometry.class));
}
 
源代码18 项目: gama   文件: GeometryDrawer.java
private void drawPolyhedron(final Polygon polygon, final boolean solid, final double height, final Color border) {
	final boolean hasHoles = getHolesNumber(polygon) > 0;
	// Draw bottom
	drawPolygon(polygon, solid, hasHoles ? border : null, true, true);
	_vertices.getNormal(true, height, _normal);
	try {
		gl.pushMatrix();
		gl.translateBy(_normal.x, _normal.y, _normal.z);
		// Draw top
		drawPolygon(polygon, solid, hasHoles ? border : null, true, false);
	} finally {
		gl.popMatrix();
	}
	gl.enableAlternateTexture();
	// Draw faces
	_vertices.visit((pj, pk) -> {
		_quadvertices.setTo(pk.x, pk.y, pk.z, pk.x + _normal.x, pk.y + _normal.y, pk.z + _normal.z,
				pj.x + _normal.x, pj.y + _normal.y, pj.z + _normal.z, pj.x, pj.y, pj.z, pk.x, pk.y, pk.z);
		gl.drawSimpleShape(_quadvertices, 4, solid, true, true, border);
	});

}
 
源代码19 项目: gama   文件: GeometryDrawer.java
private void drawPolygon(final Polygon p, final boolean solid, final Color border, final boolean clockwise,
		final boolean computeVertices) {
	if (computeVertices) {
		_vertices.setToYNegated(getContourCoordinates(p));
	}
	if (solid) {
		gl.setNormal(_vertices, clockwise);
		final boolean hasHoles = getHolesNumber(p) > 0;
		final int size = _vertices.size();
		if (hasHoles || size > 5) {
			gl.drawPolygon(p, _vertices, clockwise);
		} else {
			gl.drawSimpleShape(_vertices, size - 1, solid, clockwise, false, null);
		}
	}
	if (border != null) {
		gl.drawClosedLine(_vertices, border, -1);
		applyToInnerGeometries(p, ring -> gl.drawClosedLine(getYNegatedCoordinates(ring), border, -1));
	}
}
 
源代码20 项目: jts   文件: PolygonOverlayFunctions.java
public static Geometry overlaySnapRounded(Geometry g1, Geometry g2, double precisionTol)
{
  PrecisionModel pm = new PrecisionModel(precisionTol);
  GeometryFactory geomFact = g1.getFactory();
  
  List lines = LinearComponentExtracter.getLines(g1);
  // add second input's linework, if any
  if (g2 != null)
    LinearComponentExtracter.getLines(g2, lines);
  List nodedLinework = new GeometryNoder(pm).node(lines);
  // union the noded linework to remove duplicates
  Geometry nodedDedupedLinework = geomFact.buildGeometry(nodedLinework).union();
  
  // polygonize the result
  Polygonizer polygonizer = new Polygonizer();
  polygonizer.add(nodedDedupedLinework);
  Collection polys = polygonizer.getPolygons();
  
  // convert to collection for return
  Polygon[] polyArray = GeometryFactory.toPolygonArray(polys);
  return geomFact.createGeometryCollection(polyArray);
}
 
源代码21 项目: fiware-cepheus   文件: GeospatialTest.java
@Test
public void testGeometryMethod() {
    epService.getEPAdministrator().createEPL("create variable Geometry geoVar = geometry(\"POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))\")");
    Object value = epService.getEPRuntime().getVariableValue("geoVar");
    assertNotNull(value);
    assertThat(value, instanceOf(Polygon.class));

    Polygon poly = (Polygon)value;
    assertEquals(20, poly.getCoordinates()[0].getOrdinate(Coordinate.X), 0.001);
    assertEquals(10, poly.getCoordinates()[0].getOrdinate(Coordinate.Y), 0.001);
    assertEquals(30, poly.getCoordinates()[1].getOrdinate(Coordinate.X), 0.001);
    assertEquals(0, poly.getCoordinates()[1].getOrdinate(Coordinate.Y), 0.001);
    assertEquals(40, poly.getCoordinates()[2].getOrdinate(Coordinate.X), 0.001);
    assertEquals(10, poly.getCoordinates()[2].getOrdinate(Coordinate.Y), 0.001);
    assertEquals(30, poly.getCoordinates()[3].getOrdinate(Coordinate.X), 0.001);
    assertEquals(20, poly.getCoordinates()[3].getOrdinate(Coordinate.Y), 0.001);
    assertEquals(20, poly.getCoordinates()[4].getOrdinate(Coordinate.X), 0.001);
    assertEquals(10, poly.getCoordinates()[4].getOrdinate(Coordinate.Y), 0.001);
}
 
源代码22 项目: jts   文件: WKTWriterTest.java
public void testWriteMultiPolygon() throws Exception {
    Coordinate[] coordinates1 = { 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 linearRing1 = geometryFactory.createLinearRing(coordinates1);
    Polygon polygon1 = geometryFactory.createPolygon(linearRing1, new LinearRing[] { });
    Coordinate[] coordinates2 = { new Coordinate(60, 60, 0),
                                 new Coordinate(70, 70, 0),
                                 new Coordinate(80, 60, 0),
                                 new Coordinate(60, 60, 0) };
    LinearRing linearRing2 = geometryFactory.createLinearRing(coordinates2);
    Polygon polygon2 = geometryFactory.createPolygon(linearRing2, new LinearRing[] { });
    Polygon[] polygons = {polygon1, polygon2};
    MultiPolygon multiPolygon = geometryFactory.createMultiPolygon(polygons);
//    System.out.println("MULTIPOLYGON (((10 10, 10 20, 20 20, 20 15, 10 10)), ((60 60, 70 70, 80 60, 60 60)))");
//    System.out.println(writer.write(multiPolygon).toString());
    assertEquals("MULTIPOLYGON (((10 10, 10 20, 20 20, 20 15, 10 10)), ((60 60, 70 70, 80 60, 60 60)))", writer.write(multiPolygon).toString());
  }
 
源代码23 项目: sensorhub   文件: AbstractTestObsStorage.java
protected void testFilterFoiByRoi(Bbox bbox, int... foiNums)
{
    final Polygon poly = (Polygon)new GeometryFactory().toGeometry(bbox.toJtsEnvelope());
    FoiFilter filter = new FoiFilter()
    {
        public Polygon getRoi() { return poly; };
        public Collection<String> getProducerIDs() {return producerFilterList; };
    };
    
    // test retrieve objects
    Iterator<AbstractFeature> it = storage.getFois(filter);
    int i = 0;
    while (it.hasNext())
        assertEquals(FOI_UID_PREFIX + foiNums[i++], it.next().getUniqueIdentifier());
    assertEquals(foiNums.length, i);
    
    // test retrieve ids only
    Iterator<String> it2 = storage.getFoiIDs(filter);
    i = 0;
    while (it2.hasNext())
        assertEquals(FOI_UID_PREFIX + foiNums[i++], it2.next());
    assertEquals(foiNums.length, i);
}
 
@Test
public void testIntersectsFilter() throws GeomajasException, ParseException {
	Polygon poly1 = (Polygon) wkt.read("POLYGON((0 0,1 0,1 1,0 1,0 0))");
	Polygon touching = (Polygon) wkt.read("POLYGON((1 1,2 1,2 2,1 2,1 1))");
	Polygon disjoint = (Polygon) wkt.read("POLYGON((2 2,3 2,3 3,2 3,2 2))");
	Polygon overlapping = (Polygon) wkt.read("POLYGON((0.5 0.5,1.5 0.5,1.5 1.5,0.5 1.5,0.5 0.5))");
	Polygon within = (Polygon) wkt.read("POLYGON((0.1 0.1,0.9 0.1,0.9 0.9,0.1 0.9,0.1 0.1))");
	Polygon contains = (Polygon) wkt.read("POLYGON((-0.1 -0.1,1.1 -0.1,1.1 1.1,-0.1 1.1,-0.1 -0.1))");
	Filter filter = filterService.createIntersectsFilter(poly1, "geometry");
	TestFeature f = new TestFeature();
	f.expectAndReturn("geometry", touching);
	Assert.assertTrue(filter.evaluate(f));
	f.clear();
	f.expectAndReturn("geometry", disjoint);
	Assert.assertFalse(filter.evaluate(f));
	f.clear();
	f.expectAndReturn("geometry", overlapping);
	Assert.assertTrue(filter.evaluate(f));
	f.clear();
	f.expectAndReturn("geometry", within);
	Assert.assertTrue(filter.evaluate(f));
	f.clear();
	f.expectAndReturn("geometry", contains);
	Assert.assertTrue(filter.evaluate(f));
}
 
源代码25 项目: jts   文件: WKTWriter.java
/**
 *  Converts a <code>MultiPolygon</code> to &lt;MultiPolygon Text&gt; format,
 *  then appends it to the writer.
 *
 *@param  multiPolygon  the <code>MultiPolygon</code> to process
 *@param  writer        the output writer to append to
 */
private void appendMultiPolygonText(MultiPolygon multiPolygon, int level, Writer writer)
  throws IOException
{
  if (multiPolygon.isEmpty()) {
    writer.write("EMPTY");
  }
  else {
    int level2 = level;
    boolean doIndent = false;
    writer.write("(");
    for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
      if (i > 0) {
        writer.write(", ");
        level2 = level + 1;
        doIndent = true;
      }
      appendPolygonText((Polygon) multiPolygon.getGeometryN(i), level2, doIndent, writer);
    }
    writer.write(")");
  }
}
 
源代码26 项目: product-cep   文件: Disruption.java
public void end() {
    if (isMultiPolygon) {
        Polygon[] c = new Polygon[polygon.size()];
        c = polygon.toArray(c);
        geometry = geometryFactory.createMultiPolygon(c);
    }

}
 
@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[] { gf
            .createLinearRing(new Coordinate[] {
            new Coordinate(100.2, 0.2), new Coordinate(100.8, 0.2),
            new Coordinate(100.8, 0.8), new Coordinate(100.2, 0.8),
            new Coordinate(100.2, 0.2) }) };
    return gf.createPolygon(shell, holes);
}
 
源代码28 项目: xyz-hub   文件: JTSHelper.java
/**
 * Creates a MultiPolygon.
 */
public static MultiPolygon toMultiPolygon(MultiPolygonCoordinates coords) {
  if (coords == null) {
    return null;
  }

  Polygon[] polygons = new Polygon[coords.size()];

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

  return JTSHelper.factory.createMultiPolygon(polygons);
}
 
源代码29 项目: xyz-hub   文件: JTSHelper.java
/**
 * Creates a JTS Geometry from the provided GeoJSON geometry.
 */
@SuppressWarnings("unchecked")
public static <X extends Geometry> X toGeometry(com.here.xyz.models.geojson.implementation.Geometry geometry) {
  if (geometry == null) {
    return null;
  }

  if (geometry instanceof com.here.xyz.models.geojson.implementation.Point) {
    return (X) toPoint(((com.here.xyz.models.geojson.implementation.Point) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.MultiPoint) {
    return (X) toMultiPoint(((com.here.xyz.models.geojson.implementation.MultiPoint) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.LineString) {
    return (X) toLineString(((com.here.xyz.models.geojson.implementation.LineString) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.MultiLineString) {
    return (X) toMultiLineString(((com.here.xyz.models.geojson.implementation.MultiLineString) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.Polygon) {
    return (X) toPolygon(((com.here.xyz.models.geojson.implementation.Polygon) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.MultiPolygon) {
    return (X) toMultiPolygon(((com.here.xyz.models.geojson.implementation.MultiPolygon) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.GeometryCollection) {
    return (X) toGeometryCollection(((com.here.xyz.models.geojson.implementation.GeometryCollection) geometry));
  }
  return null;
}
 
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());
}