Search in sources :

Example 1 with Hints

use of org.geotools.factory.Hints 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 2 with Hints

use of org.geotools.factory.Hints 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 3 with Hints

use of org.geotools.factory.Hints in project onebusaway-application-modules by camsys.

the class ShapefileLibrary method loadShapeFile.

public static FeatureCollection<SimpleFeatureType, SimpleFeature> loadShapeFile(File path) throws Exception {
    _log.info("loading shapefile " + path.toURI());
    ShapefileDataStore dataStore = new ShapefileDataStore(path.toURI().toURL());
    _log.info("loaded!");
    String[] typeNames = dataStore.getTypeNames();
    String typeName = typeNames[0];
    FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = dataStore.getFeatureSource(typeName);
    CoordinateReferenceSystem sourceCRS = featureSource.getInfo().getCRS();
    _log.info("using sourceCRS=" + sourceCRS + " for typeName=" + typeName);
    Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
    CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints);
    CoordinateReferenceSystem worldCRS = factory.createCoordinateReferenceSystem("EPSG:4326");
    DefaultQuery query = new DefaultQuery(typeName);
    query.setCoordinateSystem(sourceCRS);
    query.setCoordinateSystemReproject(worldCRS);
    query.setHints(hints);
    return featureSource.getFeatures(query);
}
Also used : ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) DefaultQuery(org.geotools.data.DefaultQuery) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Hints(org.geotools.factory.Hints) CRSAuthorityFactory(org.opengis.referencing.crs.CRSAuthorityFactory) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 4 with Hints

use of org.geotools.factory.Hints in project OpenTripPlanner by opentripplanner.

the class GeotiffGridCoverageFactoryImpl method getGridCoverage.

@Override
public GridCoverage2D getGridCoverage() {
    try {
        // There is a serious standardization failure around the axis order of WGS84. See issue #1930.
        // GeoTools assumes strict EPSG axis order of (latitude, longitude) unless told otherwise.
        // Both NED and SRTM data use the longitude-first axis order, so OTP makes grid coverages
        // for unprojected DEMs assuming coordinates are in (longitude, latitude) order.
        Hints forceLongLat = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
        GeoTiffFormat format = new GeoTiffFormat();
        GeoTiffReader reader = format.getReader(path, forceLongLat);
        coverage = reader.read(null);
        LOG.info("Elevation model CRS is: {}", coverage.getCoordinateReferenceSystem2D());
    } catch (IOException e) {
        throw new RuntimeException("Error getting coverage automatically. ", e);
    }
    return coverage;
}
Also used : Hints(org.geotools.factory.Hints) GeoTiffFormat(org.geotools.gce.geotiff.GeoTiffFormat) GeoTiffReader(org.geotools.gce.geotiff.GeoTiffReader) IOException(java.io.IOException)

Example 5 with Hints

use of org.geotools.factory.Hints in project ddf by codice.

the class GeospatialUtil method transformToEPSG4326LonLatFormat.

/**
 * Transform a geometry to EPSG:4326 format with lon/lat coordinate ordering. NOTE: This method
 * will perform the transform swapping coordinates even if the sourceCrsName is EPSG:4326
 *
 * @param geometry - Geometry to transform
 * @param sourceCrsName - Source geometry's coordinate reference system
 * @return Geometry - Transformed geometry into EPSG:4326 lon/lat coordinate system
 */
public static Geometry transformToEPSG4326LonLatFormat(Geometry geometry, String sourceCrsName) throws GeoFormatException {
    if (geometry == null) {
        throw new GeoFormatException("Unable to convert null geometry");
    }
    // information
    if (sourceCrsName == null) {
        return geometry;
    }
    try {
        CoordinateReferenceSystem sourceCrs = CRS.decode(sourceCrsName);
        Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
        CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints);
        CoordinateReferenceSystem targetCRS = factory.createCoordinateReferenceSystem(EPSG_4326);
        MathTransform transform = CRS.findMathTransform(sourceCrs, targetCRS);
        return JTS.transform(geometry, transform);
    } catch (FactoryException | TransformException e) {
        throw new GeoFormatException("Unable to convert coordinate to " + EPSG_4326, e);
    }
}
Also used : Hints(org.geotools.factory.Hints) MathTransform(org.opengis.referencing.operation.MathTransform) FactoryException(org.opengis.referencing.FactoryException) GeoFormatException(org.codice.ddf.libs.geo.GeoFormatException) TransformException(org.opengis.referencing.operation.TransformException) CRSAuthorityFactory(org.opengis.referencing.crs.CRSAuthorityFactory) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

Hints (org.geotools.factory.Hints)9 CRSAuthorityFactory (org.opengis.referencing.crs.CRSAuthorityFactory)4 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)4 FactoryException (org.opengis.referencing.FactoryException)3 GeoFormatException (org.codice.ddf.libs.geo.GeoFormatException)2 Query (org.geotools.data.Query)2 WKTParser (org.geotools.geometry.text.WKTParser)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)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 ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)2 MathTransform (org.opengis.referencing.operation.MathTransform)2 TransformException (org.opengis.referencing.operation.TransformException)2 VendorOptionVersion (com.sldeditor.common.vendoroption.VendorOptionVersion)1 ExpressionPanelv2 (com.sldeditor.filter.v2.expression.ExpressionPanelv2)1 FilterNode (com.sldeditor.filter.v2.expression.FilterNode)1 FilterConfigInterface (com.sldeditor.filter.v2.function.FilterConfigInterface)1