Package com.vividsolutions.jts.geom

Examples of com.vividsolutions.jts.geom.Polygon


      MultiPoint mpoint = (MultiPoint) g;
      for (int i = 0; i < mpoint.getNumGeometries(); i++) {
        drawGeometry(mpoint.getGeometryN(i), symbol);
      }
    } else if (g instanceof Polygon) {
      Polygon poly = (Polygon) g;
      LineString shell = poly.getExteriorRing();
      int nHoles = poly.getNumInteriorRing();
      drawPathContent(shell.getCoordinates());
      for (int j = 0; j < nHoles; j++) {
        drawPathContent(poly.getInteriorRingN(j).getCoordinates());
      }
      template.closePathEoFillStroke();
    } else if (g instanceof LineString) {
      LineString line = (LineString) g;
      drawPathContent(line.getCoordinates());
View Full Code Here


  @Before
  public void setupBeans() throws LayerException {
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4329);
    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 });
    CustomBean cb = new CustomBean();
    cb.setId(1);
    cb.setGeometry(expected);
    cb.setName("testbean");
View Full Code Here

  @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));
  }
View Full Code Here

  public void readGeometry() throws LayerException {
    Object bean = layer.read("1");
    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});
    Geometry g = layer.getFeatureModel().getGeometry(bean);
    Assert.assertTrue(expected.equalsExact(g, 0.00001));
  }
View Full Code Here

  public void testPolygon() throws MarshallException, GeomajasException {
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(10000.0), 31300);
    CoordinateArraySequence coords = new CoordinateArraySequence(new Coordinate[] { new Coordinate(12.0, 34.23),
        new Coordinate(12.000, 54.555), new Coordinate(7, 8), new Coordinate(12.0, 34.23) });
    LinearRing ring = new LinearRing(coords, factory);
    Polygon p = new Polygon(ring, null, factory);
    Geometry dto = converter.toDto(p);

    JSONObject jtsJson = (JSONObject) jtsSerializer.marshall(null, p);
    JSONObject dtoJson = (JSONObject) dtoSerializer.marshall(null, dto);
    Assert.assertEquals(jtsJson.toString().length(), dtoJson.toString().length());
View Full Code Here

  public void testMultiPolygon() throws MarshallException, GeomajasException {
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(10000.0), 31300);
    CoordinateArraySequence coords = new CoordinateArraySequence(new Coordinate[] { new Coordinate(12.0, 34.23),
        new Coordinate(12.000, 54.555), new Coordinate(7, 8), new Coordinate(12.0, 34.23) });
    LinearRing ring = new LinearRing(coords, factory);
    Polygon p = new Polygon(ring, new LinearRing[] {}, factory);
    MultiPolygon m = new MultiPolygon(new Polygon[] { p }, factory);
    Geometry dto = converter.toDto(m);

    JSONObject jtsJson = (JSONObject) jtsSerializer.marshall(null, m);
    JSONObject dtoJson = (JSONObject) dtoSerializer.marshall(null, dto);
View Full Code Here

    // convert to most accurate precision model
    com.vividsolutions.jts.geom.Geometry jtsGeometry = converter.toInternal(request.getGeometry());
    if (!(jtsGeometry instanceof Polygon)) {
      throw new GeomajasException(ExceptionCode.UNEXPECTED_PROBLEM, "geometry has to be a Polygon");
    }
    Polygon polygon = (Polygon) converter.toInternal(request.getGeometry());

    // Convert to the polygons precision model:
    jtsGeometry = converter.toInternal(request.getSplitter());
    if (!(jtsGeometry instanceof LineString)) {
      throw new GeomajasException(ExceptionCode.UNEXPECTED_PROBLEM, "splitter has to be a LineString");
    }
    LineString preciseLine = (LineString) jtsGeometry;
    int precision = polygon.getPrecisionModel().getMaximumSignificantDigits() - 1;
    com.vividsolutions.jts.geom.Geometry bufferedLine = preciseLine.buffer(Math.pow(10.0, -precision));
    com.vividsolutions.jts.geom.Geometry diff = polygon.difference(bufferedLine);

    if (diff instanceof Polygon) {
      response.setGeometries(new Geometry[] { converter.toDto(diff) });
    } else if (diff instanceof MultiPolygon) {
      Geometry[] polygons = new Geometry[diff.getNumGeometries()];
View Full Code Here

       
    Geometry remainingGeometry = null;
   
    for (SimplePolygonXZ poly : intersectPolygons) {
     
      Polygon jtsPoly = polygonXZToJTSPolygon(poly);
     
      if (remainingGeometry == null) {
        remainingGeometry = jtsPoly;
      } else {
        remainingGeometry = remainingGeometry.intersection(jtsPoly);
View Full Code Here

    for (int i = 0; i < array.length; i++) {
      VectorXZ vertex = vertices.get(i);
      array[i] = vectorXZToJTSCoordinate(vertex);
    }
   
    return new Polygon(
        new LinearRing(new CoordinateArraySequence(array), GF),
        null, GF);
   
  }
View Full Code Here

    PolygonGenerator pg = new PolygonGenerator();
    pg.setGeometryFactory(geometryFactory);
    pg.setBoundingBox(new Envelope(0,10,0,10));
    pg.setNumberPoints(10);
   
    Polygon pt = (Polygon) pg.create();
   
    GMLWriter out = new GMLWriter();
    out.setPrefix("");
    out.write(pt,getWriter());
   
    GMLReader in = new GMLReader();
    Polygon pt2 = (Polygon) in.read(getReader(),geometryFactory);
   
    assertTrue("The input polygon is not the same as the output polygon",pt.equals(pt2));
  }
View Full Code Here

TOP

Related Classes of com.vividsolutions.jts.geom.Polygon

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.