Package com.vividsolutions.jts.io

Examples of com.vividsolutions.jts.io.WKTReader


    if (!wkt || null == geometry) {
      log.debug("bean.getGeometry {}", geometry);
      return (Geometry) geometry;
    } else {
      try {
        WKTReader reader = new WKTReader(new GeometryFactory(new PrecisionModel(), srid));
        Geometry geom = reader.read((String) geometry);
        log.debug("bean.getGeometry {}", geom);
        return geom;
      } catch (Throwable t) {
        throw new LayerException(t, ExceptionCode.FEATURE_MODEL_PROBLEM, geometry);
      }


  }

  @Test
  public void create() throws ParseException, LayerException {
    Object created = null;
    WKTReader wktReader = new WKTReader();
    Point geometry = null;
    geometry = (Point) wktReader.read("POINT (0 0)");

    Object feature = (SimpleFeature)layer.getFeatureModel().newInstance("500");
    Map<String, Attribute> map = new HashMap<String, Attribute>();
    map.put("NAME", new StringAttribute("Tsjakamaka"));
    map.put("POP_OTHER", new IntegerAttribute(342));

    Assert.assertEquals("Heikant", featureModel.getAttribute(feature, ATTRIBUTE_NAME).getValue());
  }

  @Test
  public void setGeometry() throws Exception {
    WKTReader wktReader = new WKTReader();
    Point pt = (Point) wktReader.read("POINT (5 5)");
    featureModel.setGeometry(feature, pt);
    Assert.assertEquals(5, featureModel.getGeometry(feature).getCoordinate().x, 0.00001);
  }

    Assert.assertEquals("Luxembourg2", f.getAttribute(ATTRIBUTE_NAME));
  }

  @Test
  public void create() throws Exception {
    WKTReader wktReader = new WKTReader();
    Point geometry = (Point) wktReader.read("POINT (0 0)");

    SimpleFeatureBuilder build = new SimpleFeatureBuilder(layer.getSchema());
    SimpleFeature feature = build.buildFeature("100000", new Object[] { geometry, "Tsjakamaka", 342 });

    Object created = layer.create(feature);

  }

  @Test
  public void testTransformGeometry() throws Exception {
    TransformGeometryRequest request = new TransformGeometryRequest();
    WKTReader reader = new WKTReader();
    Geometry origin = converterService.toDto(reader.read("POLYGON((10 30, 20 30,20 40,10 40,10 30))"));
    request.setGeometry(origin);
    request.setSourceCrs(MERCATOR);
    request.setTargetCrs(LONLAT);
    // execute
    TransformGeometryResponse response = (TransformGeometryResponse) dispatcher.execute(

  }

  @Test
  public void testTransformGeometryCollection() throws Exception {
    TransformGeometryRequest request = new TransformGeometryRequest();
    WKTReader reader = new WKTReader();
    Geometry origin = converterService.toDto(reader.read("POLYGON((10 30, 20 30,20 40,10 40,10 30))"));
    List<Geometry> geometries = request.getGeometryCollection(); // assure not-null
    geometries.add(origin);
    request.setGeometryCollection(geometries); // assure setter is called/tested
    request.setSourceCrs(MERCATOR);
    request.setTargetCrs(LONLAT);

    Assert.assertEquals("Heikant", featureModel.getAttribute(feature, ATTRIBUTE_NAME).getValue());
  }

  @Test
  public void testSetGeometry() throws Exception {
    WKTReader wktReader = new WKTReader();
    Point pt = (Point) wktReader.read("POINT (5 5)");
    featureModel.setGeometry(feature, pt);
    Assert.assertEquals(5, featureModel.getGeometry(feature).getCoordinate().x, 0);
  }

  }

  @Test
  public void transformGeometryEmptyResultOnException() throws Exception {
    GeometryFactory geometryFactory = new GeometryFactory();
    WKTReader reader = new WKTReader( geometryFactory );
   
    Point point = (Point) reader.read("POINT (1 1)");
    Geometry geometry = geoService.transform(point, new ThrowingTransform());
    Assert.assertEquals(Point.class, geometry.getClass());
    Assert.assertTrue(geometry.isEmpty());
   
    LineString lineString = (LineString) reader.read("LINESTRING (0 1,1 1)");
    geometry = geoService.transform(lineString, new ThrowingTransform());
    Assert.assertEquals(LineString.class, geometry.getClass());
    Assert.assertTrue(geometry.isEmpty());
   
    Polygon polygon = (Polygon) reader.read("POLYGON ((0 0,1 1,0 1,0 0))");
    geometry = geoService.transform(polygon, new ThrowingTransform());
    Assert.assertEquals(Polygon.class, geometry.getClass());
    Assert.assertTrue(geometry.isEmpty());

    MultiPoint multipoint = (MultiPoint) reader.read("MULTIPOINT ((1 1),(2 1))");
    geometry = geoService.transform(multipoint, new ThrowingTransform());
    Assert.assertEquals(MultiPoint.class, geometry.getClass());
    Assert.assertTrue(geometry.isEmpty());
   
    MultiLineString multilineString = (MultiLineString) reader.read("MULTILINESTRING ((0 1,1 1),(0 2,2 2))");
    geometry = geoService.transform(multilineString, new ThrowingTransform());
    Assert.assertEquals(MultiLineString.class, geometry.getClass());
    Assert.assertTrue(geometry.isEmpty());
   
    MultiPolygon multipolygon = (MultiPolygon) reader.read("MULTIPOLYGON (((0 0,1 1,0 1,0 0)),((0 0,2 2,0 2,0 0)))");
    geometry = geoService.transform(multipolygon, new ThrowingTransform());
    Assert.assertEquals(MultiPolygon.class, geometry.getClass());
    Assert.assertTrue(geometry.isEmpty());
   
    Geometry collection = (GeometryCollection) reader.read("GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10)) ");
    geometry = geoService.transform(collection, new ThrowingTransform());
    Assert.assertEquals(GeometryCollection.class, geometry.getClass());
    Assert.assertTrue(geometry.isEmpty());
  }

      if (null == layer) {
        return null;
      }
      String area = layer.getVisibleArea();
      try {
        WKTReader wktReader = new WKTReader(new GeometryFactory(new PrecisionModel(), 0));
        return wktReader.read(area);
      } catch (ParseException pe) {
        throw new IllegalStateException("Could not parse geometry " + area, pe);
      }
    }

      if (null == layer) {
        return null;
      }
      String area = layer.getUpdateAuthorizedArea();
      try {
        WKTReader wktReader = new WKTReader(new GeometryFactory(new PrecisionModel(), 0));
        return wktReader.read(area);
      } catch (ParseException pe) {
        throw new IllegalStateException("Could not parse geometry " + area, pe);
      }
    }

TOP

Related Classes of com.vividsolutions.jts.io.WKTReader

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.