Exemplo n.º 1
0
 /**
  * Test created to check that we effectively retrieve a good representation of empty
  * multipolygons. indeed, a NullPointerException used to happen...
  *
  * @throws Exception
  */
 @Test
 public void testGeometryCollectionStringRepresentation() throws Exception {
   GeometryCollection mp = gf.createMultiPolygon(new Polygon[] {});
   Value val = ValueFactory.createValue(mp);
   String str = val.toString();
   assertEquals(str, "MULTIPOLYGON EMPTY");
   Polygon poly = gf.createPolygon(gf.createLinearRing(new Coordinate[] {}), new LinearRing[] {});
   assertTrue(poly.isEmpty());
   mp =
       gf.createMultiPolygon(
           new Polygon[] {
             poly,
           });
   val = ValueFactory.createValue(mp);
   str = val.toString();
   assertNotNull(str);
   Polygon polyBis =
       gf.createPolygon(
           gf.createLinearRing(
               new Coordinate[] {
                 new Coordinate(0, 0, 0),
                 new Coordinate(1, 1, 0),
                 new Coordinate(3, 4, 0),
                 new Coordinate(0, 0, 0),
               }),
           new LinearRing[] {});
   mp = gf.createMultiPolygon(new Polygon[] {poly, polyBis});
   val = ValueFactory.createValue(mp);
   str = val.toString();
   assertNotNull(str);
   GeometryCollection coll =
       gf.createGeometryCollection(
           new Geometry[] {
             gf.createPolygon(gf.createLinearRing(new Coordinate[] {}), new LinearRing[] {}),
             gf.createPolygon(
                 gf.createLinearRing(
                     new Coordinate[] {
                       new Coordinate(0, 0, 0),
                       new Coordinate(1, 1, 0),
                       new Coordinate(3, 4, 0),
                       new Coordinate(0, 0, 0),
                     }),
                 new LinearRing[] {})
           });
   mp = gf.createGeometryCollection(new Geometry[] {poly, coll, polyBis});
   val = ValueFactory.createValue(mp);
   str = val.toString();
   assertNotNull(str);
 }
  private Geometry parseGeometry(JsonNode root) {
    String typeName = root.get("type").asText();
    if (typeName.equals("Point")) {
      return gf.createPoint(parseCoordinate((ArrayNode) root.get("coordinates")));

    } else if (typeName.equals("MultiPoint")) {
      return gf.createMultiPoint(parseLineString(root.get("coordinates")));

    } else if (typeName.equals("LineString")) {
      return gf.createLineString(parseLineString(root.get("coordinates")));

    } else if (typeName.equals("MultiLineString")) {
      return gf.createMultiLineString(parseLineStrings(root.get("coordinates")));

    } else if (typeName.equals("Polygon")) {
      JsonNode arrayOfRings = root.get("coordinates");
      return parsePolygonCoordinates(arrayOfRings);

    } else if (typeName.equals("MultiPolygon")) {
      JsonNode arrayOfPolygons = root.get("coordinates");
      return gf.createMultiPolygon(parsePolygons(arrayOfPolygons));

    } else if (typeName.equals("GeometryCollection")) {
      return gf.createGeometryCollection(parseGeometries(root.get("geometries")));
    } else {
      throw new UnsupportedOperationException();
    }
  }
Exemplo n.º 3
0
 MultiPolygon createMultiPolygon(List list) {
   Polygon[] polys = new Polygon[ensureSize(list, 1).size()];
   for (int i = 0; i < list.size(); i++) {
     polys[i] = createPolygon((List) list.get(i));
   }
   return gf.createMultiPolygon(polys);
 }
  private Geometry parseMultiPolygon(int dimension, CoordinateReferenceSystem crs)
      throws XmlPullParserException, IOException, NoSuchAuthorityCodeException, FactoryException {

    parser.require(START_TAG, GML.NAMESPACE, GML.MultiPolygon.getLocalPart());

    Geometry geom;
    List<Polygon> polygons = new ArrayList<Polygon>(2);
    parser.nextTag();
    while (true) {
      parser.require(START_TAG, GML.NAMESPACE, GML.polygonMember.getLocalPart());
      parser.nextTag();
      parser.require(START_TAG, GML.NAMESPACE, GML.Polygon.getLocalPart());
      Polygon p = parsePolygon(dimension, crs);
      polygons.add(p);
      parser.nextTag();
      parser.require(END_TAG, GML.NAMESPACE, GML.polygonMember.getLocalPart());
      parser.nextTag();
      if (END_TAG == parser.getEventType()
          && GML.MultiPolygon.getLocalPart().equals(parser.getName())) {
        // we're done
        break;
      }
    }
    parser.require(END_TAG, GML.NAMESPACE, GML.MultiPolygon.getLocalPart());

    geom = geomFac.createMultiPolygon(polygons.toArray(new Polygon[polygons.size()]));
    return geom;
  }
  /**
   * Returns a completed multi type.
   *
   * @param geometryFactory The factory this method should use to create the multi type.
   * @return Appropriate multi geometry type.
   */
  public Geometry create(GeometryFactory geometryFactory) {
    if (internalType.equals("Point")) {
      Point[] pointArray = geometryFactory.toPointArray(geometries);
      MultiPoint multiPoint = geometryFactory.createMultiPoint(pointArray);
      multiPoint.setUserData(getSRS());
      multiPoint.setSRID(getSRID());
      LOGGER.fine("created " + multiPoint);

      return multiPoint;
    } else if (internalType.equals("LineString")) {
      LineString[] lineStringArray = geometryFactory.toLineStringArray(geometries);
      MultiLineString multiLineString = geometryFactory.createMultiLineString(lineStringArray);
      multiLineString.setUserData(getSRS());
      multiLineString.setSRID(getSRID());
      LOGGER.fine("created " + multiLineString);

      return multiLineString;
    } else if (internalType.equals("Polygon")) {
      Polygon[] polygonArray = geometryFactory.toPolygonArray(geometries);
      MultiPolygon multiPolygon = geometryFactory.createMultiPolygon(polygonArray);
      multiPolygon.setUserData(getSRS());
      multiPolygon.setSRID(getSRID());
      LOGGER.fine("created " + multiPolygon);

      return multiPolygon;
    } else {
      return null;
    }
  }
Exemplo n.º 6
0
 protected MultiPolygon decodeMultiPolygon(JsonNode node, GeometryFactory fac)
     throws GeoJSONException {
   JsonNode coordinates = requireCoordinates(node);
   Polygon[] polygons = new Polygon[coordinates.size()];
   for (int i = 0; i < coordinates.size(); ++i) {
     polygons[i] = decodePolygonCoordinates(coordinates.get(i), fac);
   }
   return fac.createMultiPolygon(polygons);
 }
Exemplo n.º 7
0
 /** We must be able to transform specialized collections to GeometryCollectionValues */
 @Test
 public void testGeometryCollectionConversions() throws Exception {
   Value val =
       ValueFactory.createValue(
           gf.createMultiPoint(
               new Coordinate[] {new Coordinate(0, 0, 0), new Coordinate(1, 2, 3)}));
   assertTrue(val instanceof DefaultMultiPointValue);
   Value val2 = val.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(val2 instanceof DefaultGeometryCollectionValue);
   // Let's be sure it's not a GeometryCollection just thanks to the inheritance
   assertFalse(val2 instanceof DefaultMultiPointValue);
   val =
       ValueFactory.createValue(
           gf.createMultiLineString(
               new LineString[] {
                 gf.createLineString(
                     new Coordinate[] {new Coordinate(0, 0, 0), new Coordinate(4, 2, 3)}),
                 gf.createLineString(
                     new Coordinate[] {new Coordinate(5, 6, 9), new Coordinate(5, 7, 1)})
               }));
   assertTrue(val instanceof DefaultMultiLineStringValue);
   val2 = val.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(val2 instanceof DefaultGeometryCollectionValue);
   // Let's be sure it's not a GeometryCollection just thanks to the inheritance
   assertFalse(val2 instanceof DefaultMultiPointValue);
   val =
       ValueFactory.createValue(
           gf.createMultiPolygon(
               new Polygon[] {
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(0, 3, 0),
                           new Coordinate(9, 0, 0),
                           new Coordinate(8, 7, 0),
                           new Coordinate(0, 3, 0)
                         }),
                     null),
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(10, 3, 0),
                           new Coordinate(9, 0, 0),
                           new Coordinate(8, 7, 0),
                           new Coordinate(10, 3, 0)
                         }),
                     null)
               }));
   assertTrue(val instanceof DefaultMultiPolygonValue);
   val2 = val.toType(Type.GEOMETRYCOLLECTION);
   assertTrue(val2 instanceof DefaultGeometryCollectionValue);
   // Let's be sure it's not a GeometryCollection just thanks to the inheritance
   assertFalse(val2 instanceof DefaultMultiPointValue);
 }
Exemplo n.º 8
0
  private MultiPolygon readMultiPolygon() throws IOException, ParseException {
    int numGeom = dis.readInt();
    Polygon[] geoms = new Polygon[numGeom];

    for (int i = 0; i < numGeom; i++) {
      Geometry g = readGeometry();
      if (!(g instanceof Polygon)) throw new ParseException(INVALID_GEOM_TYPE_MSG + "MultiPolygon");
      geoms[i] = (Polygon) g;
    }
    return factory.createMultiPolygon(geoms);
  }
Exemplo n.º 9
0
 static Geometry computeProductGeometry(Product product) {
   final GeneralPath[] paths = ProductUtils.createGeoBoundaryPaths(product);
   final Polygon[] polygons = new Polygon[paths.length];
   final GeometryFactory factory = new GeometryFactory();
   for (int i = 0; i < paths.length; i++) {
     polygons[i] = convertAwtPathToJtsPolygon(paths[i], factory);
   }
   final DouglasPeuckerSimplifier peuckerSimplifier =
       new DouglasPeuckerSimplifier(
           polygons.length == 1 ? polygons[0] : factory.createMultiPolygon(polygons));
   return peuckerSimplifier.getResultGeometry();
 }
Exemplo n.º 10
0
  /**
   * Convert a org.geojson.Xxxx geometry to a JTS geometry. Only support Point, Polygon,
   * MultiPolygon, LineString and MultiLineString for now.
   *
   * @param geoJsonGeom
   * @return The equivalent JTS geometry.
   * @throws UnsupportedGeometryException
   */
  public static Geometry convertGeoJsonToJtsGeometry(GeoJsonObject geoJsonGeom)
      throws UnsupportedGeometryException {
    if (geoJsonGeom instanceof org.geojson.Point) {
      org.geojson.Point geoJsonPoint = (org.geojson.Point) geoJsonGeom;
      return gf.createPoint(
          new Coordinate(
              geoJsonPoint.getCoordinates().getLongitude(),
              geoJsonPoint.getCoordinates().getLatitude()));

    } else if (geoJsonGeom instanceof org.geojson.Polygon) {
      org.geojson.Polygon geoJsonPolygon = (org.geojson.Polygon) geoJsonGeom;
      LinearRing shell = gf.createLinearRing(convertPath(geoJsonPolygon.getExteriorRing()));
      LinearRing[] holes = new LinearRing[geoJsonPolygon.getInteriorRings().size()];
      int i = 0;
      for (List<LngLatAlt> hole : geoJsonPolygon.getInteriorRings()) {
        holes[i++] = gf.createLinearRing(convertPath(hole));
      }
      return gf.createPolygon(shell, holes);

    } else if (geoJsonGeom instanceof org.geojson.MultiPolygon) {
      org.geojson.MultiPolygon geoJsonMultiPolygon = (org.geojson.MultiPolygon) geoJsonGeom;
      Polygon[] jtsPolygons = new Polygon[geoJsonMultiPolygon.getCoordinates().size()];
      int i = 0;
      for (List<List<LngLatAlt>> geoJsonRings : geoJsonMultiPolygon.getCoordinates()) {
        org.geojson.Polygon geoJsonPoly = new org.geojson.Polygon();
        for (List<LngLatAlt> geoJsonRing : geoJsonRings) geoJsonPoly.add(geoJsonRing);
        jtsPolygons[i++] = (Polygon) convertGeoJsonToJtsGeometry(geoJsonPoly);
      }
      return gf.createMultiPolygon(jtsPolygons);

    } else if (geoJsonGeom instanceof org.geojson.LineString) {
      org.geojson.LineString geoJsonLineString = (org.geojson.LineString) geoJsonGeom;
      return gf.createLineString(convertPath(geoJsonLineString.getCoordinates()));

    } else if (geoJsonGeom instanceof org.geojson.MultiLineString) {
      org.geojson.MultiLineString geoJsonMultiLineString =
          (org.geojson.MultiLineString) geoJsonGeom;
      LineString[] jtsLineStrings = new LineString[geoJsonMultiLineString.getCoordinates().size()];
      int i = 0;
      for (List<LngLatAlt> geoJsonPath : geoJsonMultiLineString.getCoordinates()) {
        org.geojson.LineString geoJsonLineString =
            new org.geojson.LineString(geoJsonPath.toArray(new LngLatAlt[geoJsonPath.size()]));
        jtsLineStrings[i++] = (LineString) convertGeoJsonToJtsGeometry(geoJsonLineString);
      }
      return gf.createMultiLineString(jtsLineStrings);
    }

    throw new UnsupportedGeometryException(geoJsonGeom.getClass().toString());
  }
Exemplo n.º 11
0
  @Test
  public void test3DGeoms() throws Exception {
    Coordinate[] coords2D =
        new Coordinate[] {
          new Coordinate(10, 10, 10),
          new Coordinate(40, 10, 10),
          new Coordinate(40, 40, 10),
          new Coordinate(10, 40, 10),
          new Coordinate(10, 10, 10),
        };
    Coordinate[] coords3D =
        new Coordinate[] {
          new Coordinate(10, 10),
          new Coordinate(40, 10),
          new Coordinate(40, 40),
          new Coordinate(10, 40),
          new Coordinate(10, 10),
        };

    Value p1 = ValueFactory.createValue(gf.createPoint(new Coordinate(10, 10, 10)));
    Value p2 = ValueFactory.createValue(gf.createPoint(new Coordinate(10, 10)));
    checkDifferent(p1, p2);

    LineString l1 = gf.createLineString(coords2D);
    p1 = ValueFactory.createValue(l1);
    LineString l2 = gf.createLineString(coords3D);
    p2 = ValueFactory.createValue(l2);
    checkDifferent(p1, p2);

    p1 = ValueFactory.createValue(gf.createMultiPoint(coords2D));
    p2 = ValueFactory.createValue(gf.createMultiPoint(coords3D));
    checkDifferent(p1, p2);

    Polygon pol1 = gf.createPolygon(gf.createLinearRing(coords2D), null);
    p1 = ValueFactory.createValue(pol1);
    Polygon pol2 = gf.createPolygon(gf.createLinearRing(coords3D), null);
    p2 = ValueFactory.createValue(pol2);
    checkDifferent(p1, p2);

    p1 = ValueFactory.createValue(gf.createMultiLineString(new LineString[] {l1}));
    p2 = ValueFactory.createValue(gf.createMultiLineString(new LineString[] {l2}));
    checkDifferent(p1, p2);

    p1 = ValueFactory.createValue(gf.createMultiPolygon(new Polygon[] {pol1}));
    p2 = ValueFactory.createValue(gf.createMultiPolygon(new Polygon[] {pol2}));
    checkDifferent(p1, p2);
  }
 public Object convert(Object obj) {
   GeometryFactory fac = new GeometryFactory();
   if (getBinding() == MultiPolygon.class && obj instanceof Polygon) {
     return fac.createMultiPolygon(new Polygon[] {(Polygon) obj});
   }
   if (getBinding() == MultiPoint.class && obj instanceof Point) {
     return fac.createMultiPoint(new Point[] {(Point) obj});
   }
   if (getBinding() == MultiLineString.class && obj instanceof LineString) {
     return fac.createMultiLineString(new LineString[] {(LineString) obj});
   }
   if (getBinding() == GeometryCollection.class && obj instanceof Geometry) {
     return fac.createGeometryCollection(
         new com.vividsolutions.jts.geom.Geometry[] {(com.vividsolutions.jts.geom.Geometry) obj});
   }
   return obj;
 }
Exemplo n.º 13
0
  @Test
  public void multiPolygon() throws Exception {
    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)
            });
    MultiPolygon multiPolygon =
        gf.createMultiPolygon(new Polygon[] {gf.createPolygon(shell, null)});

    assertRoundTrip(multiPolygon);
    assertThat(
        toJson(multiPolygon),
        equalTo(
            "{\"type\":\"MultiPolygon\",\"coordinates\":[[[[102.0,2.0],[103.0,2.0],[103.0,3.0],[102.0,3.0],[102.0,2.0]]]]}"));
  }
 public Geometry getGeometry() {
   int n = collection.size();
   if (MultiPolygon.class.isAssignableFrom(binding)) {
     Polygon[] array = new Polygon[n];
     for (int i = 0; i < n; i++) array[i] = (Polygon) collection.get(i);
     return factory.createMultiPolygon(array);
   }
   if (MultiLineString.class.isAssignableFrom(binding)) {
     LineString[] array = new LineString[n];
     for (int i = 0; i < n; i++) array[i] = (LineString) collection.get(i);
     return factory.createMultiLineString(array);
   }
   if (MultiPoint.class.isAssignableFrom(binding)) {
     Point[] array = new Point[n];
     for (int i = 0; i < n; i++) array[i] = (Point) collection.get(i);
     return factory.createMultiPoint(array);
   }
   return null;
 }
  private Geometry getGeographicBoundingBox(CoordinateReferenceSystem crs) {
    GeographicBoundingBox envelope = CRS.getGeographicBoundingBox(crs);
    if (envelope == null) {
      return null;
    }

    final double westBoundLongitude = envelope.getWestBoundLongitude();
    final double eastBoundLongitude = envelope.getEastBoundLongitude();
    final double southBoundLatitude = envelope.getSouthBoundLatitude();
    final double northBoundLatitude = envelope.getNorthBoundLatitude();

    final int numSteps = 80;
    Geometry geogBoundingGeom;

    if (westBoundLongitude < eastBoundLongitude) {
      geogBoundingGeom =
          createBoundingPolygon(
              westBoundLongitude,
              eastBoundLongitude,
              southBoundLatitude,
              northBoundLatitude,
              numSteps);
    } else {
      // the geographic bounds cross the day line (lon -180/180), trick it into two adjacent
      // polygons
      Polygon eastPolygon =
          createBoundingPolygon(
              -180, eastBoundLongitude, southBoundLatitude, northBoundLatitude, numSteps);

      Polygon westPolygon =
          createBoundingPolygon(
              westBoundLongitude, 180, southBoundLatitude, northBoundLatitude, numSteps);

      geogBoundingGeom = gf.createMultiPolygon(new Polygon[] {eastPolygon, westPolygon});
    }
    return geogBoundingGeom;
  }
Exemplo n.º 16
0
 public static Geometry getMultiPolygon3D() {
   return gf.createMultiPolygon(new Polygon[] {getPolygon3D(), getPolygon3D()});
 }
Exemplo n.º 17
0
 static MultiPolygon multiPolygon() {
   return gf.createMultiPolygon(new Polygon[] {polygon(), polygon()});
 }
Exemplo n.º 18
0
  /**
   * Returns a non-null default value for the class that is passed in. This is a helper class an
   * can't create a default class for any type but it does support:
   *
   * <ul>
   *   <li>String
   *   <li>Object - will return empty string
   *   <li>Number
   *   <li>Character
   *   <li>JTS Geometries
   * </ul>
   *
   * @param type
   * @return
   */
  public static Object defaultValue(Class type) {
    if (type == String.class || type == Object.class) {
      return "";
    }
    if (type == Integer.class) {
      return new Integer(0);
    }
    if (type == Double.class) {
      return new Double(0);
    }
    if (type == Long.class) {
      return new Long(0);
    }
    if (type == Short.class) {
      return new Short((short) 0);
    }
    if (type == Float.class) {
      return new Float(0.0f);
    }
    if (type == BigDecimal.class) {
      return BigDecimal.valueOf(0);
    }
    if (type == BigInteger.class) {
      return BigInteger.valueOf(0);
    }
    if (type == Character.class) {
      return new Character(' ');
    }
    if (type == Boolean.class) {
      return Boolean.FALSE;
    }
    if (type == Timestamp.class) return new Timestamp(System.currentTimeMillis());
    if (type == java.sql.Date.class) return new java.sql.Date(System.currentTimeMillis());
    if (type == java.sql.Time.class) return new java.sql.Time(System.currentTimeMillis());
    if (type == java.util.Date.class) return new java.util.Date();

    GeometryFactory fac = new GeometryFactory();
    Coordinate coordinate = new Coordinate(0, 0);
    Point point = fac.createPoint(coordinate);

    if (type == Point.class) {
      return point;
    }
    if (type == MultiPoint.class) {
      return fac.createMultiPoint(new Point[] {point});
    }
    if (type == LineString.class) {
      return fac.createLineString(
          new Coordinate[] {coordinate, coordinate, coordinate, coordinate});
    }
    LinearRing linearRing =
        fac.createLinearRing(new Coordinate[] {coordinate, coordinate, coordinate, coordinate});
    if (type == LinearRing.class) {
      return linearRing;
    }
    if (type == MultiLineString.class) {
      return fac.createMultiLineString(new LineString[] {linearRing});
    }
    Polygon polygon = fac.createPolygon(linearRing, new LinearRing[0]);
    if (type == Polygon.class) {
      return polygon;
    }
    if (type == MultiPolygon.class) {
      return fac.createMultiPolygon(new Polygon[] {polygon});
    }

    throw new IllegalArgumentException(type + " is not supported by this method");
  }
Exemplo n.º 19
0
 @Test
 public void testGeometryType() throws Exception {
   // We test the point
   Value val = ValueFactory.createValue(gf.createPoint(new Coordinate(2, 1)));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.POINT);
   // We test the multipoint
   val = ValueFactory.createValue(gf.createMultiPoint(new Coordinate[] {new Coordinate(2, 1)}));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.MULTIPOINT);
   // We test the LineString
   val =
       ValueFactory.createValue(
           gf.createLineString(new Coordinate[] {new Coordinate(2, 1), new Coordinate(2, 2)}));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.LINESTRING);
   // We test the MultiLineString
   val =
       ValueFactory.createValue(
           gf.createMultiLineString(
               new LineString[] {
                 gf.createLineString(new Coordinate[] {new Coordinate(2, 1), new Coordinate(2, 2)})
               }));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.MULTILINESTRING);
   // We test the Polygon
   val =
       ValueFactory.createValue(
           gf.createPolygon(
               gf.createLinearRing(
                   new Coordinate[] {
                     new Coordinate(2, 1),
                     new Coordinate(2, 2),
                     new Coordinate(4, 3),
                     new Coordinate(2, 1)
                   }),
               null));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.POLYGON);
   // We test the MultiPolygon
   val =
       ValueFactory.createValue(
           gf.createMultiPolygon(
               new Polygon[] {
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(2, 1),
                           new Coordinate(2, 2),
                           new Coordinate(4, 3),
                           new Coordinate(2, 1)
                         }),
                     null),
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(2, 1),
                           new Coordinate(2, 2),
                           new Coordinate(6, 3),
                           new Coordinate(2, 1)
                         }),
                     null)
               }));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue(val.getType() == Type.MULTIPOLYGON);
   // We test the GeometryCollection
   val =
       ValueFactory.createValue(
           gf.createGeometryCollection(
               new Geometry[] {
                 gf.createPolygon(
                     gf.createLinearRing(
                         new Coordinate[] {
                           new Coordinate(2, 1),
                           new Coordinate(2, 2),
                           new Coordinate(4, 3),
                           new Coordinate(2, 1)
                         }),
                     null),
                 gf.createPoint(new Coordinate(2, 1))
               }));
   assertTrue((val.getType() & Type.GEOMETRY) != 0);
   assertTrue((val.getType() & Type.GEOMETRYCOLLECTION) != 0);
 }
 protected MultiPolygon toMultiPolygon(ReferencedEnvelope env2) {
   GeometryFactory factory = new GeometryFactory();
   return factory.createMultiPolygon(new Polygon[] {toPolygon(env2)});
 }
Exemplo n.º 21
0
  /**
   * Writing test that only engages against a remote geoserver.
   *
   * <p>Makes reference to the standard featureTypes that geoserver ships with. NOTE: Ignoring this
   * test for now because it edits topp:states and GeoServer doesn't return the correct Feature IDs
   * on transactions against shapefiles
   */
  @Test
  @Ignore
  public void testWrite()
      throws NoSuchElementException, IllegalFilterException, IOException,
          IllegalAttributeException {
    if (url == null) return;

    Map m = new HashMap();
    m.put(WFSDataStoreFactory.URL.key, url);
    m.put(WFSDataStoreFactory.TIMEOUT.key, new Integer(10000000));
    DataStore post = (WFS_1_0_0_DataStore) (new WFSDataStoreFactory()).createDataStore(m);
    String typename = TO_EDIT_TYPE;
    SimpleFeatureType ft = post.getSchema(typename);
    SimpleFeatureSource fs = post.getFeatureSource(typename);
    class Watcher implements FeatureListener {
      public int count = 0;

      public void changed(FeatureEvent featureEvent) {
        System.out.println("Event " + featureEvent);
        count++;
      }
    }
    Watcher watcher = new Watcher();
    fs.addFeatureListener(watcher);

    Id startingFeatures = createFidFilter(fs);
    FilterFactory2 filterFac = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
    try {
      GeometryFactory gf = new GeometryFactory();
      MultiPolygon mp =
          gf.createMultiPolygon(
              new Polygon[] {
                gf.createPolygon(
                    gf.createLinearRing(
                        new Coordinate[] {
                          new Coordinate(-88.071564, 37.51099),
                          new Coordinate(-88.467644, 37.400757),
                          new Coordinate(-90.638329, 42.509361),
                          new Coordinate(-89.834618, 42.50346),
                          new Coordinate(-88.071564, 37.51099)
                        }),
                    new LinearRing[] {})
              });
      mp.setUserData("http://www.opengis.net/gml/srs/epsg.xml#" + EPSG_CODE);

      PropertyName geometryAttributeExpression =
          filterFac.property(ft.getGeometryDescriptor().getLocalName());
      PropertyIsNull geomNullCheck = filterFac.isNull(geometryAttributeExpression);
      Query query = new Query(typename, filterFac.not(geomNullCheck), 1, Query.ALL_NAMES, null);
      SimpleFeatureIterator inStore = fs.getFeatures(query).features();

      SimpleFeature f, f2;
      try {
        SimpleFeature feature = inStore.next();

        SimpleFeature copy = SimpleFeatureBuilder.deep(feature);
        SimpleFeature copy2 = SimpleFeatureBuilder.deep(feature);

        f = SimpleFeatureBuilder.build(ft, copy.getAttributes(), null);
        f2 = SimpleFeatureBuilder.build(ft, copy2.getAttributes(), null);
        assertFalse("Max Feature failed", inStore.hasNext());
      } finally {
        inStore.close();
      }

      org.geotools.util.logging.Logging.getLogger("org.geotools.data.wfs").setLevel(Level.FINE);
      SimpleFeatureCollection inserts = DataUtilities.collection(new SimpleFeature[] {f, f2});
      Id fp = WFSDataStoreWriteOnlineTest.doInsert(post, ft, inserts);

      // / okay now count ...
      FeatureReader<SimpleFeatureType, SimpleFeature> count =
          post.getFeatureReader(new Query(ft.getTypeName()), Transaction.AUTO_COMMIT);
      int i = 0;
      while (count.hasNext() && i < 3) {
        f = count.next();
        i++;
      }
      count.close();

      WFSDataStoreWriteOnlineTest.doDelete(post, ft, fp);
      WFSDataStoreWriteOnlineTest.doUpdate(post, ft, ATTRIBUTE_TO_EDIT, NEW_EDIT_VALUE);
      // assertFalse("events not fired", watcher.count == 0);
    } finally {
      try {
        ((SimpleFeatureStore) fs).removeFeatures(filterFac.not(startingFeatures));
      } catch (Exception e) {
        System.out.println(e);
      }
    }
  }
Exemplo n.º 22
0
  @RequestMapping(
      value = "/projects/{id}/cleanse",
      method = RequestMethod.POST,
      produces = "application/xml")
  @PreAuthorize("hasPermission(#project, 'write')")
  public void processCleanse(
      @ModelAttribute(value = "project") Project project,
      @RequestParam(value = "operation", required = true) String operation,
      @RequestParam(value = "fromDate", required = false) String fromDateString,
      @RequestParam(value = "toDate", required = false) String toDateString,
      @RequestParam(value = "animal") List<Long> animalIds,
      @RequestParam(value = "maxSpeed", required = false) Double maxSpeed,
      @RequestParam(value = "minArgosClass", required = false) String minArgosClassCode,
      @RequestParam(value = "maxDop", required = false) Double maxDop,
      HttpServletRequest request,
      HttpServletResponse response)
      throws IOException, RserveInterfaceException {
    Date fromDate = null;
    Date toDate = null;
    try {
      if (StringUtils.isNotBlank(fromDateString)) {
        fromDate = isoDateFormat.parse(fromDateString);
      }
      if (StringUtils.isNotBlank(toDateString)) {
        toDate = (toDateString == null) ? null : isoDateFormat.parse(toDateString);
      }
    } catch (java.text.ParseException e1) {
      PrintWriter out = response.getWriter();
      out.append("<?xml version=\"1.0\"?>\n");
      out.append("<cleanse-response xmlns=\"http://oztrack.org/xmlns#\">\n");
      out.append("    <error>Invalid date parameters</error>\n");
      out.append("</cleanse-response>\n");
      response.setStatus(200);
      return;
    }

    MultiPolygon multiPolygon = null;
    String[] polygonsWkt = request.getParameterValues("polygon");
    if ((polygonsWkt != null) && (polygonsWkt.length > 0)) {
      Hints hints = new Hints();
      hints.put(Hints.CRS, DefaultGeographicCRS.WGS84);
      GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(hints);
      WKTReader reader = new WKTReader(geometryFactory);
      ArrayList<Polygon> polygons = new ArrayList<Polygon>();
      for (String polygonWkt : polygonsWkt) {
        try {
          Polygon polygon = (Polygon) reader.read(polygonWkt);
          polygons.add(polygon);
        } catch (ParseException e) {
          throw new RuntimeException("Error reading polygon: " + polygonWkt, e);
        }
      }
      multiPolygon = geometryFactory.createMultiPolygon(polygons.toArray(new Polygon[0]));
    }

    Set<PositionFix> speedFilterPositionFixes = null;
    if (maxSpeed != null) {
      speedFilterPositionFixes = new HashSet<PositionFix>();
      SearchQuery searchQuery = new SearchQuery();
      searchQuery.setProject(project);
      searchQuery.setFromDate(fromDate);
      searchQuery.setToDate(toDate);
      searchQuery.setAnimalIds(animalIds);
      List<PositionFix> positionFixList = positionFixDao.getProjectPositionFixList(searchQuery);
      RserveInterface rserveInterface = new RserveInterface(rserveConnectionPool);
      Map<Long, Set<Date>> animalDates =
          rserveInterface.runSpeedFilter(project, positionFixList, maxSpeed);
      for (PositionFix positionFix : positionFixList) {
        Set<Date> dates = animalDates.get(positionFix.getAnimal().getId());
        // Need to create new java.util.Date here because positionFix.detectionTime is a
        // java.sql.Timestamp.
        // Date and Timestamp have same hashCode but their equals methods differ, breaking contains
        // call.
        if ((dates != null) && dates.contains(new Date(positionFix.getDetectionTime().getTime()))) {
          speedFilterPositionFixes.add(positionFix);
        }
      }
    }

    ArgosClass minArgosClass = ArgosClass.fromCode(minArgosClassCode);

    if (operation.equals("delete")) {
      int numDeleted =
          positionFixDao.setDeleted(
              project,
              fromDate,
              toDate,
              animalIds,
              multiPolygon,
              speedFilterPositionFixes,
              minArgosClass,
              maxDop,
              true);
      positionFixDao.renumberPositionFixes(project);
      PrintWriter out = response.getWriter();
      out.append("<?xml version=\"1.0\"?>\n");
      out.append("<cleanse-response xmlns=\"http://oztrack.org/xmlns#\">\n");
      out.append("    <num-deleted>" + numDeleted + "</num-deleted>\n");
      out.append("</cleanse-response>\n");
      response.setStatus(200);
      return;
    } else if (operation.equals("undelete")) {
      int numUndeleted =
          positionFixDao.setDeleted(
              project,
              fromDate,
              toDate,
              animalIds,
              multiPolygon,
              speedFilterPositionFixes,
              minArgosClass,
              maxDop,
              false);
      positionFixDao.renumberPositionFixes(project);
      PrintWriter out = response.getWriter();
      out.append("<?xml version=\"1.0\"?>\n");
      out.append("<cleanse-response xmlns=\"http://oztrack.org/xmlns#\">\n");
      out.append("    <num-undeleted>" + numUndeleted + "</num-undeleted>\n");
      out.append("</cleanse-response>\n");
      response.setStatus(200);
      return;
    } else {
      PrintWriter out = response.getWriter();
      out.append("<?xml version=\"1.0\"?>\n");
      out.append("<cleanse-response xmlns=\"http://oztrack.org/xmlns#\">\n");
      out.append("    <error>" + "Unknown operation: " + operation + "</error>\n");
      out.append("</cleanse-response>\n");
      response.setStatus(400);
      return;
    }
  }
Exemplo n.º 23
0
 public static Geometry getMultiPolygon2D() {
   return gf.createMultiPolygon(new Polygon[] {(Polygon) getPolygon()});
 }
Exemplo n.º 24
0
  @Test
  public void testSetup() throws Exception {
    EventListener l = new EventListener();
    EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    assertPixMapState(map, 1, 0, 0, 0);

    map.addPoint(10, 5, map.getGeoms().get(0).getShell());
    assertPixMapState(map, 1, 1, 0, 0);
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getX());
    assertEquals(5, map.getGeoms().get(0).getShell().getPoint(0).getY());
    assertEquals(EventType.ADD_POINT, l.event.getType());
    EditBlackboardEvent editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(null, editBlackboardEvent.getOldValue());
    assertEquals(Point.valueOf(10, 5), editBlackboardEvent.getNewValue());
    assertEquals(map.getGeoms().get(0).getShell(), editBlackboardEvent.getSource());

    map.addPoint(10, 10, map.getGeoms().get(0).getShell());

    assertPixMapState(map, 1, 2, 0, 0);
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getY());
    assertEquals(EventType.ADD_POINT, l.event.getType());
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(null, editBlackboardEvent.getOldValue());
    assertEquals(Point.valueOf(10, 10), editBlackboardEvent.getNewValue());
    assertEquals(map.getGeoms().get(0).getShell(), editBlackboardEvent.getSource());

    GeometryFactory factory = new GeometryFactory();
    Geometry geom = factory.createPoint(new Coordinate(10, 5));
    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    Map<Geometry, EditGeom> mapping = map.setGeometries(geom, null);
    assertNotNull(mapping.get(geom));
    assertEquals(ShapeType.POINT, mapping.get(geom).getShapeType());
    assertPixMapState(map, 1, 1, 0, 0);
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY());
    assertEquals(EventType.SET_GEOMS, l.event.getType());
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(1, ((List) editBlackboardEvent.getOldValue()).size());
    assertEquals(1, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());

    geom =
        factory.createMultiPoint(new Coordinate[] {new Coordinate(10, 5), new Coordinate(20, 10)});
    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    String string = "featureID"; // $NON-NLS-1$
    mapping = map.setGeometries(geom, string);
    EditGeom next = mapping.values().iterator().next();
    assertEquals(ShapeType.POINT, next.getShapeType());
    assertEquals(string, next.getFeatureIDRef().get());
    assertNotNull(mapping.get(geom.getGeometryN(0)));
    assertNotNull(mapping.get(geom.getGeometryN(1)));
    assertPixMapState(map, 2, 1, 0, 0);
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY());
    assertEquals(30, map.getGeoms().get(1).getShell().getPoint(0).getX());
    assertEquals(15, map.getGeoms().get(1).getShell().getPoint(0).getY());
    assertEquals(new Coordinate(10, 5), map.getGeoms().get(0).getShell().getCoord(0));
    assertEquals(new Coordinate(20, 10), map.getGeoms().get(1).getShell().getCoord(0));
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(2, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());

    LinearRing ring = createShellRing(factory, 10);

    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    mapping = map.setGeometries(ring, null);
    assertEquals(ShapeType.LINE, mapping.get(ring).getShapeType());
    assertNotNull(mapping.get(ring));
    assertPixMapState(map, 1, 5, 0, 0);
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY());
    assertEquals(30, map.getGeoms().get(0).getShell().getPoint(1).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getY());
    assertEquals(30, map.getGeoms().get(0).getShell().getPoint(2).getX());
    assertEquals(15, map.getGeoms().get(0).getShell().getPoint(2).getY());
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(3).getX());
    assertEquals(15, map.getGeoms().get(0).getShell().getPoint(3).getY());
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(4).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(4).getY());
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(1, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());

    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    Polygon polygon = createPolygon(factory, 10);
    mapping = map.setGeometries(polygon, null);
    assertEquals(ShapeType.POLYGON, mapping.get(polygon).getShapeType());
    assertNotNull(mapping.get(polygon));
    assertPixMapState(map, 1, 5, 1, 5);
    assertEquals(Point.valueOf(20, 10), map.getGeoms().get(0).getShell().getPoint(0));
    assertEquals(Point.valueOf(25, 12), map.getGeoms().get(0).getHoles().get(0).getPoint(0));
    assertEquals(Point.valueOf(30, 10), map.getGeoms().get(0).getShell().getPoint(1));
    assertEquals(Point.valueOf(28, 12), map.getGeoms().get(0).getHoles().get(0).getPoint(1));
    assertEquals(new Coordinate(15, 7), map.getGeoms().get(0).getHoles().get(0).getCoord(0));
    assertEquals(new Coordinate(18, 7), map.getGeoms().get(0).getHoles().get(0).getCoord(1));
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(1, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());

    geom =
        factory.createMultiPolygon(
            new Polygon[] {createPolygon(factory, 0), createPolygon(factory, 20)});

    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    mapping = map.setGeometries(geom, null);
    assertPixMapState(map, 2, 5, 1, 5);
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(2, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());
  }
Exemplo n.º 25
0
  private static FeatureCollection<?> buildResultList() {

    try {
      type = createSimpleResultType();
    } catch (NoSuchAuthorityCodeException ex) {
      Logger.getLogger(UnionTest.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FactoryException ex) {
      Logger.getLogger(UnionTest.class.getName()).log(Level.SEVERE, null, ex);
    }

    final FeatureCollection<Feature> featureList = DataUtilities.collection("", type);

    Feature myFeature;
    LinearRing ring =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(4, 7),
              new Coordinate(6, 7),
              new Coordinate(6, 5),
              new Coordinate(4, 5),
              new Coordinate(4, 7)
            });
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature1");
    sfb.set("color", "red");
    sfb.set("geom1", geometryFactory.createPolygon(ring, null));
    sfb.set("att", 20);
    myFeature = sfb.buildFeature("id-01-id-11");
    featureList.add(myFeature);

    LineString str =
        geometryFactory.createLineString(
            new Coordinate[] {new Coordinate(3, 5), new Coordinate(3, 6)});
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature1");
    sfb.set("color", "grey");
    sfb.set("geom1", str);
    sfb.set("att", 12);
    myFeature = sfb.buildFeature("id-01-id-15");
    featureList.add(myFeature);

    ring =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(3, 5),
              new Coordinate(3, 6),
              new Coordinate(3, 7),
              new Coordinate(4, 7),
              new Coordinate(4, 5),
              new Coordinate(3, 5)
            });
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature1");
    sfb.set("color", null);
    sfb.set("att", null);
    sfb.set("geom1", geometryFactory.createPolygon(ring, null));
    myFeature = sfb.buildFeature("id-01");
    featureList.add(myFeature);

    ring =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(7, 5),
              new Coordinate(8, 5),
              new Coordinate(8, 4),
              new Coordinate(7, 4),
              new Coordinate(7, 5)
            });
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature3");
    sfb.set("color", "blue");
    sfb.set("att", 20);
    sfb.set("geom1", geometryFactory.createPolygon(ring, null));
    myFeature = sfb.buildFeature("id-03-id-12");
    featureList.add(myFeature);

    ring =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(6, 4),
              new Coordinate(6, 5),
              new Coordinate(7, 5),
              new Coordinate(7, 4),
              new Coordinate(6, 4)
            });
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature3");
    sfb.set("color", "red");
    sfb.set("att", 20);
    sfb.set("geom1", geometryFactory.createPolygon(ring, null));
    myFeature = sfb.buildFeature("id-03-id-11");
    featureList.add(myFeature);

    ring =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(6, 2),
              new Coordinate(6, 4),
              new Coordinate(8, 4),
              new Coordinate(8, 2),
              new Coordinate(6, 2)
            });
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature3");
    sfb.set("color", "grey");
    sfb.set("att", 10);
    sfb.set("geom1", geometryFactory.createPolygon(ring, null));
    myFeature = sfb.buildFeature("id-03-id-13");
    featureList.add(myFeature);

    ring =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(7, 7),
              new Coordinate(8, 7),
              new Coordinate(8, 5),
              new Coordinate(7, 5),
              new Coordinate(7, 7)
            });
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature2");
    sfb.set("color", "blue");
    sfb.set("att", 20);
    sfb.set("geom1", geometryFactory.createPolygon(ring, null));
    myFeature = sfb.buildFeature("id-02-id-12");
    featureList.add(myFeature);

    ring =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(6, 5),
              new Coordinate(6, 7),
              new Coordinate(7, 7),
              new Coordinate(7, 5),
              new Coordinate(6, 5)
            });
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature2");
    sfb.set("color", "red");
    sfb.set("att", 20);
    sfb.set("geom1", geometryFactory.createPolygon(ring, null));
    myFeature = sfb.buildFeature("id-02-id-11");
    featureList.add(myFeature);

    ring =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(2, 3),
              new Coordinate(2, 4),
              new Coordinate(3, 4),
              new Coordinate(3, 3),
              new Coordinate(2, 3)
            });
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature4");
    sfb.set("color", null);
    sfb.set("att", null);
    sfb.set("geom1", geometryFactory.createPolygon(ring, null));
    myFeature = sfb.buildFeature("id-04");
    featureList.add(myFeature);

    ring =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(7, 7),
              new Coordinate(7, 8),
              new Coordinate(9, 8),
              new Coordinate(9, 4),
              new Coordinate(8, 4),
              new Coordinate(8, 5),
              new Coordinate(8, 7),
              new Coordinate(7, 7)
            });
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature12");
    sfb.set("color", "blue");
    sfb.set("att", 20);
    sfb.set("geom1", geometryFactory.createPolygon(ring, null));
    myFeature = sfb.buildFeature("id-12");
    featureList.add(myFeature);

    ring =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(8, 4),
              new Coordinate(9, 4),
              new Coordinate(9, 2),
              new Coordinate(8, 2),
              new Coordinate(8, 4)
            });
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature13");
    sfb.set("color", "grey");
    sfb.set("att", 10);
    sfb.set("geom1", geometryFactory.createPolygon(ring, null));
    myFeature = sfb.buildFeature("id-13");
    featureList.add(myFeature);

    ring =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(4, 2),
              new Coordinate(4, 3),
              new Coordinate(5, 3),
              new Coordinate(5, 2),
              new Coordinate(4, 2)
            });
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature14");
    sfb.set("color", "grey");
    sfb.set("att", 12);
    sfb.set("geom1", geometryFactory.createPolygon(ring, null));
    myFeature = sfb.buildFeature("id-14");
    featureList.add(myFeature);

    ring =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(4, 4),
              new Coordinate(4, 5),
              new Coordinate(6, 5),
              new Coordinate(6, 4),
              new Coordinate(4, 4)
            });
    LinearRing ring2 =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(6, 7),
              new Coordinate(4, 7),
              new Coordinate(4, 8),
              new Coordinate(7, 8),
              new Coordinate(7, 7),
              new Coordinate(6, 7)
            });
    Polygon poly1 = geometryFactory.createPolygon(ring, null);
    Polygon poly2 = geometryFactory.createPolygon(ring2, null);
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature11");
    sfb.set("color", "red");
    sfb.set("att", 20);
    sfb.set("geom1", geometryFactory.createMultiPolygon(new Polygon[] {poly1, poly2}));
    myFeature = sfb.buildFeature("id-11");
    featureList.add(myFeature);

    Feature myFeature5;
    ring =
        geometryFactory.createLinearRing(
            new Coordinate[] {
              new Coordinate(2.0, 5.0),
              new Coordinate(2.0, 6.0),
              new Coordinate(3.0, 6.0),
              new Coordinate(3.0, 5.0),
              new Coordinate(2.0, 5.0)
            });
    sfb = new SimpleFeatureBuilder(type);
    sfb.set("name", "feature15");
    sfb.set("color", "grey");
    sfb.set("geom1", geometryFactory.createPolygon(ring, null));
    sfb.set("att", 12);
    myFeature5 = sfb.buildFeature("id-15");
    featureList.add(myFeature5);

    return featureList;
  }