Search in sources :

Example 1 with WKTParser

use of org.geotools.geometry.text.WKTParser in project ddf by codice.

the class OpenSearchQueryTest method testWktParserPolygon.

@Test
@Ignore
public void testWktParserPolygon() throws Exception {
    String geometryWkt = "POLYGON(( 0 10, 0 30, 20 30, 20 10, 0 10 ))";
    GeometryBuilder builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
    WKTParser parser = new WKTParser(builder);
    // This fixed the NPE in parser.parse() - seems GeoTools has bug with
    // keeping the CRS hint set ...
    parser.setFactory(new PrimitiveFactoryImpl(DefaultGeographicCRS.WGS84));
    Geometry geometry = parser.parse(geometryWkt);
    CoordinateReferenceSystem crs = geometry.getCoordinateReferenceSystem();
    assertNotNull(crs);
    double[] coords = geometry.getCentroid().getCoordinate();
    LOGGER.debug("coords[0] = {},   coords[1] = {}", coords[0], coords[1]);
    // String geometryWkt2 = "POINT( 10 20 )";
    String geometryWkt2 = "POLYGON(( 10 15, 10 25, 15 25, 15 15, 10 15 ))";
    builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
    WKTParser parser2 = new WKTParser(builder);
    // This fixed the NPE in parser.parse() - seems GeoTools has bug with
    // keeping the CRS hint set ...
    parser2.setFactory(new PrimitiveFactoryImpl(DefaultGeographicCRS.WGS84));
    Geometry geometry2 = parser2.parse(geometryWkt2);
    double[] coords2 = geometry2.getCentroid().getCoordinate();
    LOGGER.debug("coords[0] = {},   coords[1] = {}", coords2[0], coords2[1]);
    // This fails - why?
    assertTrue(geometry.contains(geometry2));
}
Also used : Geometry(org.opengis.geometry.Geometry) PrimitiveFactoryImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PrimitiveFactoryImpl) WKTParser(org.geotools.geometry.text.WKTParser) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeometryBuilder(org.geotools.geometry.GeometryBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with WKTParser

use of org.geotools.geometry.text.WKTParser in project sldeditor by robward-scisys.

the class WKTConversion method initialise.

/**
 * Initialise the WKTParser object.
 */
private static void initialise() {
    Hints hints = new Hints(Hints.CRS, DefaultGeographicCRS.WGS84);
    PositionFactory positionFactory = GeometryFactoryFinder.getPositionFactory(hints);
    GeometryFactory geometryFactory = GeometryFactoryFinder.getGeometryFactory(hints);
    PrimitiveFactory primitiveFactory = GeometryFactoryFinder.getPrimitiveFactory(hints);
    AggregateFactory aggregateFactory = GeometryFactoryFinder.getAggregateFactory(hints);
    wktParser = new WKTParser(geometryFactory, primitiveFactory, positionFactory, aggregateFactory);
    wktTypeList.add(new WKTType(WKT_POINT, false, 1, "Point", false, false));
    wktTypeList.add(new WKTType(WKT_MULTIPOINT, true, 1, "Point", true, false));
    wktTypeList.add(new WKTType(WKT_LINESTRING, false, 2, "Line", false, false));
    wktTypeList.add(new WKTType("LINEARRING", false, 2, "Line", false, false));
    wktTypeList.add(new WKTType(WKT_MULTILINESTRING, true, 2, "Line", true, false));
    wktTypeList.add(new WKTType(WKT_POLYGON, false, -1, "Polygon", false, true));
    wktTypeList.add(new WKTType(WKT_MULTIPOLYGON, true, -1, "Polygon", true, true));
    for (WKTType wkyType : wktTypeList) {
        wktTypeMap.put(wkyType.getName(), wkyType);
    }
}
Also used : GeometryFactory(org.opengis.geometry.coordinate.GeometryFactory) Hints(org.geotools.factory.Hints) PositionFactory(org.opengis.geometry.PositionFactory) WKTParser(org.geotools.geometry.text.WKTParser) AggregateFactory(org.opengis.geometry.aggregate.AggregateFactory) PrimitiveFactory(org.opengis.geometry.primitive.PrimitiveFactory)

Example 3 with WKTParser

use of org.geotools.geometry.text.WKTParser in project sldeditor by robward-scisys.

the class FilterNodeTest method testSetFilter.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.expression.FilterNode#setFilter(org.opengis.filter.Filter, com.sldeditor.filter.v2.function.FilterConfigInterface)}.
 */
@Test
public void testSetFilter() {
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    FilterNode node = new FilterNode();
    // BinaryComparisonAbstract
    Filter filter = ff.greaterOrEqual(ff.literal(45), ff.literal(23));
    node.setFilter(filter, null);
    node.addFilter();
    String actual = node.toString();
    String expected = "Filter : " + Localisation.getString(ExpressionPanelv2.class, "FilterNode.filterNotSet");
    assertTrue(actual.compareTo(expected) == 0);
    assertEquals(filter, node.getFilter());
    FilterConfigInterface filterConfig = new IsGreaterThan();
    node.setFilter(filter, filterConfig);
    assertEquals(filterConfig, node.getFilterConfig());
    expected = "Filter : PropertyIsGreaterThan";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // PropertyIsLike
    filter = ff.like(ff.literal("abc def ghi"), "abc");
    filterConfig = new IsLike();
    node.setFilter(filter, filterConfig);
    expected = "Filter : Like";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // BinarySpatialOperator
    Hints hints = new Hints(Hints.CRS, DefaultGeographicCRS.WGS84);
    PositionFactory positionFactory = GeometryFactoryFinder.getPositionFactory(hints);
    GeometryFactory geometryFactory = GeometryFactoryFinder.getGeometryFactory(hints);
    PrimitiveFactory primitiveFactory = GeometryFactoryFinder.getPrimitiveFactory(hints);
    AggregateFactory aggregateFactory = GeometryFactoryFinder.getAggregateFactory(hints);
    WKTParser wktParser = new WKTParser(geometryFactory, primitiveFactory, positionFactory, aggregateFactory);
    Geometry geometry = null;
    try {
        geometry = wktParser.parse("POINT( 48.44 -123.37)");
    } catch (ParseException e) {
        e.printStackTrace();
        fail();
    }
    filter = ff.overlaps("property", geometry);
    filterConfig = new Overlaps();
    node.setFilter(filter, filterConfig);
    expected = "Filter : Overlaps";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Is Between
    filter = ff.between(ff.literal(25), ff.literal(5), ff.literal(50));
    filterConfig = new IsBetween();
    node.setFilter(filter, filterConfig);
    expected = "Filter : PropertyIsBetween";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Is Null
    filter = ff.isNull(ff.literal(12));
    filterConfig = new IsNull();
    node.setFilter(filter, filterConfig);
    expected = "Filter : IsNull";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // BinaryTemporalOperator
    filter = ff.after(ff.literal(12), ff.literal(312));
    filterConfig = new After();
    node.setFilter(filter, filterConfig);
    expected = "Filter : After";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Logic filter
    filter = ff.and(ff.after(ff.literal(12), ff.literal(312)), ff.between(ff.literal(25), ff.literal(5), ff.literal(50)));
    filterConfig = new And();
    node.setFilter(filter, filterConfig);
    expected = "Filter : And";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    node.addFilter();
}
Also used : ExpressionPanelv2(com.sldeditor.filter.v2.expression.ExpressionPanelv2) Overlaps(com.sldeditor.filter.v2.function.geometry.Overlaps) GeometryFactory(org.opengis.geometry.coordinate.GeometryFactory) Hints(org.geotools.factory.Hints) PositionFactory(org.opengis.geometry.PositionFactory) FilterNode(com.sldeditor.filter.v2.expression.FilterNode) IsBetween(com.sldeditor.filter.v2.function.property.IsBetween) FilterConfigInterface(com.sldeditor.filter.v2.function.FilterConfigInterface) IsGreaterThan(com.sldeditor.filter.v2.function.property.IsGreaterThan) WKTParser(org.geotools.geometry.text.WKTParser) IsLike(com.sldeditor.filter.v2.function.misc.IsLike) PrimitiveFactory(org.opengis.geometry.primitive.PrimitiveFactory) FilterFactory(org.opengis.filter.FilterFactory) Geometry(org.opengis.geometry.Geometry) Filter(org.opengis.filter.Filter) And(com.sldeditor.filter.v2.function.logic.And) After(com.sldeditor.filter.v2.function.temporal.After) IsNull(com.sldeditor.filter.v2.function.misc.IsNull) AggregateFactory(org.opengis.geometry.aggregate.AggregateFactory) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 4 with WKTParser

use of org.geotools.geometry.text.WKTParser in project ddf by codice.

the class OpenSearchQueryTest method testWktParser.

@Test
public void testWktParser() throws Exception {
    String geometryWkt = "POINT( 48.44 -123.37)";
    GeometryBuilder builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
    WKTParser parser = new WKTParser(builder);
    // This fixed the NPE in parser.parse() - seems GeoTools has bug with
    // keeping the CRS hint set ...
    parser.setFactory(new PrimitiveFactoryImpl(DefaultGeographicCRS.WGS84));
    Geometry geometry = parser.parse(geometryWkt);
    CoordinateReferenceSystem crs = geometry.getCoordinateReferenceSystem();
    assertNotNull(crs);
    String geometryWkt2 = "POINT( 48.44 -123.37)";
    builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
    WKTParser parser2 = new WKTParser(builder);
    Geometry geometry2 = parser2.parse(geometryWkt2);
    assertTrue(geometry2.intersects(geometry));
    double[] coords = geometry.getCentroid().getCoordinate();
    LOGGER.debug("coords[0] = {},   coords[1] = {}", coords[0], coords[1]);
}
Also used : Geometry(org.opengis.geometry.Geometry) PrimitiveFactoryImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PrimitiveFactoryImpl) WKTParser(org.geotools.geometry.text.WKTParser) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeometryBuilder(org.geotools.geometry.GeometryBuilder) Test(org.junit.Test)

Example 5 with WKTParser

use of org.geotools.geometry.text.WKTParser in project ddf by codice.

the class OpenSearchQueryTest method testWktParser.

@Test
public void testWktParser() throws Exception {
    String geometryWkt = "POINT( 48.44 -123.37)";
    GeometryBuilder builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
    WKTParser parser = new WKTParser(builder);
    // This fixed the NPE in parser.parse() - seems GeoTools has bug with
    // keeping the CRS hint set ...
    parser.setFactory(new PrimitiveFactoryImpl(DefaultGeographicCRS.WGS84));
    Geometry geometry = parser.parse(geometryWkt);
    CoordinateReferenceSystem crs = geometry.getCoordinateReferenceSystem();
    assertNotNull(crs);
    String geometryWkt2 = "POINT( 48.44 -123.37)";
    builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
    WKTParser parser2 = new WKTParser(builder);
    Geometry geometry2 = parser2.parse(geometryWkt2);
    assertTrue(geometry2.intersects(geometry));
    double[] coords = geometry.getCentroid().getCoordinate();
    LOGGER.debug("coords[0] = {},   coords[1] = {}", coords[0], coords[1]);
}
Also used : Geometry(org.opengis.geometry.Geometry) PrimitiveFactoryImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PrimitiveFactoryImpl) WKTParser(org.geotools.geometry.text.WKTParser) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeometryBuilder(org.geotools.geometry.GeometryBuilder) Test(org.junit.Test)

Aggregations

WKTParser (org.geotools.geometry.text.WKTParser)7 Geometry (org.opengis.geometry.Geometry)6 GeometryBuilder (org.geotools.geometry.GeometryBuilder)5 PrimitiveFactoryImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.PrimitiveFactoryImpl)5 Test (org.junit.Test)5 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)4 ParseException (java.text.ParseException)2 Hints (org.geotools.factory.Hints)2 Ignore (org.junit.Ignore)2 PositionFactory (org.opengis.geometry.PositionFactory)2 AggregateFactory (org.opengis.geometry.aggregate.AggregateFactory)2 GeometryFactory (org.opengis.geometry.coordinate.GeometryFactory)2 PrimitiveFactory (org.opengis.geometry.primitive.PrimitiveFactory)2 ExpressionPanelv2 (com.sldeditor.filter.v2.expression.ExpressionPanelv2)1 FilterNode (com.sldeditor.filter.v2.expression.FilterNode)1 FilterConfigInterface (com.sldeditor.filter.v2.function.FilterConfigInterface)1 Overlaps (com.sldeditor.filter.v2.function.geometry.Overlaps)1 And (com.sldeditor.filter.v2.function.logic.And)1 IsLike (com.sldeditor.filter.v2.function.misc.IsLike)1 IsNull (com.sldeditor.filter.v2.function.misc.IsNull)1