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);
}
}
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();
}
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);
}
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;
}
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);
}
}
Aggregations