use of com.vividsolutions.jts.geom.GeometryFactory in project eol-globi-data by jhpoelen.
the class DatasetImporterForRaymond method calculateCentroidOfBBox.
protected static LatLng calculateCentroidOfBBox(double left, double top, double right, double bottom) {
LatLng latLng;
if (left == right && top == bottom) {
latLng = new LatLng(top, left);
} else {
Coordinate[] points = { GeoUtil.getCoordinate(top, left), GeoUtil.getCoordinate(top, right), GeoUtil.getCoordinate(bottom, right), GeoUtil.getCoordinate(bottom, left), GeoUtil.getCoordinate(top, left) };
GeometryFactory geometryFactory = new GeometryFactory();
Polygon polygon = geometryFactory.createPolygon(points);
Point centroid = polygon.getCentroid();
latLng = new LatLng(centroid.getCoordinate().y, centroid.getCoordinate().x);
}
return latLng;
}
use of com.vividsolutions.jts.geom.GeometryFactory in project graphhopper by graphhopper.
the class Utils method toWKT.
public static String toWKT(PointList list) {
int n = list.size();
GeometryFactory factory = new GeometryFactory();
Coordinate[] coords = new Coordinate[n];
for (int i = 0; i < coords.length; i++) {
coords[i] = new Coordinate(list.getLon(i), list.getLat(i));
}
return factory.createLineString(coords).toText();
}
use of com.vividsolutions.jts.geom.GeometryFactory in project ddf by codice.
the class TestCswRecordMapperFilterVisitor method testVisitDWithin.
@Test
public void testVisitDWithin() {
GeometryFactory geoFactory = new GeometryFactory();
double val = 10;
Expression pt1 = factory.literal(geoFactory.createPoint(new Coordinate(4, 5)));
Expression pt2 = factory.literal(geoFactory.createPoint(new Coordinate(6, 7)));
DWithin filter = factory.dwithin(pt1, pt2, val, "meters");
DWithin duplicate = (DWithin) visitor.visit(filter, null);
assertThat(duplicate.getExpression1(), is(pt1));
assertThat(duplicate.getExpression2(), is(pt2));
assertThat(duplicate.getDistanceUnits(), is(UomOgcMapping.METRE.name()));
assertThat(duplicate.getDistance(), is(val));
}
use of com.vividsolutions.jts.geom.GeometryFactory in project GeoGig by boundlessgeo.
the class ImportOpTest method testAdaptFeatureType.
@Test
public void testAdaptFeatureType() throws Exception {
ImportOp importOp = geogig.command(ImportOp.class);
importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
importOp.setTable("shpLikeTable");
importOp.setDestinationPath("table");
importOp.call();
Optional<RevFeature> feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:table/feature1").call(RevFeature.class);
assertTrue(feature.isPresent());
RevFeatureType originalFeatureType = geogig.command(ResolveFeatureType.class).setRefSpec("WORK_HEAD:table/feature1").call().get();
importOp.setTable("shpLikeTable2");
importOp.call();
feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:table/feature1").call(RevFeature.class);
assertTrue(feature.isPresent());
RevFeatureType featureType = geogig.command(ResolveFeatureType.class).setRefSpec("WORK_HEAD:table/feature1").call().get();
assertEquals(originalFeatureType.getId(), featureType.getId());
GeometryFactory gf = new GeometryFactory();
ImmutableList<Optional<Object>> values = feature.get().getValues();
assertEquals(values.get(0).get(), gf.createPoint(new Coordinate(0, 7)));
assertEquals(values.get(1).get(), 3.2);
assertEquals(values.get(2).get(), 1100.0);
importOp.setTable("GeoJsonLikeTable");
importOp.call();
feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:table/feature1").call(RevFeature.class);
assertTrue(feature.isPresent());
featureType = geogig.command(ResolveFeatureType.class).setRefSpec("WORK_HEAD:table/feature1").call().get();
assertEquals(originalFeatureType.getId(), featureType.getId());
values = feature.get().getValues();
assertEquals(values.get(0).get(), gf.createPoint(new Coordinate(0, 8)));
assertEquals(values.get(1).get(), 4.2);
assertEquals(values.get(2).get(), 1200.0);
}
use of com.vividsolutions.jts.geom.GeometryFactory in project GeoGig by boundlessgeo.
the class TestHelper method createTestFactory.
public static AbstractDataStoreFactory createTestFactory() throws Exception {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setCRS(CRS.decode("EPSG:4326"));
builder.add("geom", Point.class);
builder.add("label", String.class);
builder.setName("table1");
SimpleFeatureType type = builder.buildFeatureType();
SimpleFeatureTypeBuilder builder2 = new SimpleFeatureTypeBuilder();
builder2.setCRS(CRS.decode("EPSG:4326"));
builder2.add("geom", Point.class);
builder2.add("name", String.class);
builder2.setName("table2");
SimpleFeatureType type2 = builder2.buildFeatureType();
SimpleFeatureTypeBuilder builder3 = new SimpleFeatureTypeBuilder();
builder3.setCRS(CRS.decode("EPSG:4326"));
builder3.add("geom", Point.class);
builder3.add("name", String.class);
builder3.add("number", Long.class);
builder3.setName("table3");
SimpleFeatureTypeBuilder builder4 = new SimpleFeatureTypeBuilder();
builder4.setCRS(CRS.decode("EPSG:4326"));
builder4.add("geom", Point.class);
builder4.add("number", Double.class);
builder4.setName("table4");
// A table with a shp-like structure
SimpleFeatureTypeBuilder builderShp = new SimpleFeatureTypeBuilder();
builderShp.setCRS(CRS.decode("EPSG:4326"));
builderShp.add("the_geom", Point.class);
builderShp.add("number", Double.class);
builderShp.add("number2", Double.class);
builderShp.setName("shpLikeTable");
SimpleFeatureTypeBuilder builderShp2 = new SimpleFeatureTypeBuilder();
builderShp2.setCRS(CRS.decode("EPSG:4326"));
builderShp2.add("the_geom", Point.class);
builderShp2.add("number", Double.class);
builderShp2.add("number2", Integer.class);
builderShp2.setName("shpLikeTable2");
// A table with a geojson-like structure
SimpleFeatureTypeBuilder builderGeoJson = new SimpleFeatureTypeBuilder();
builderGeoJson.setCRS(CRS.decode("EPSG:4326"));
builderGeoJson.add("number", Double.class);
builderGeoJson.add("number2", Double.class);
builderGeoJson.add("geom", Point.class);
builderGeoJson.setName("GeoJsonLikeTable");
SimpleFeatureTypeBuilder builderGeoJson2 = new SimpleFeatureTypeBuilder();
builderGeoJson2.setCRS(CRS.decode("EPSG:23030"));
builderGeoJson2.add("number", Double.class);
builderGeoJson2.add("number2", Double.class);
builderGeoJson2.add("geom", Point.class);
builderGeoJson2.setName("GeoJsonLikeTable2");
SimpleFeatureType type3 = builder3.buildFeatureType();
SimpleFeatureType typeShp = builderShp.buildFeatureType();
SimpleFeatureType typeShp2 = builderShp2.buildFeatureType();
SimpleFeatureType typeGeoJson = builderGeoJson.buildFeatureType();
SimpleFeatureType typeGeoJson2 = builderGeoJson2.buildFeatureType();
GeometryFactory gf = new GeometryFactory();
SimpleFeature f1 = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(5, 8)), "feature1" }, "table1.feature1");
SimpleFeature f2 = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(5, 4)), "feature2" }, "table1.feature2");
SimpleFeature f3 = SimpleFeatureBuilder.build(type2, new Object[] { gf.createPoint(new Coordinate(3, 2)), "feature3" }, "table2.feature3");
SimpleFeature f4 = SimpleFeatureBuilder.build(type3, new Object[] { gf.createPoint(new Coordinate(0, 5)), "feature4", 1000 }, "table2.feature4");
SimpleFeature f5 = SimpleFeatureBuilder.build(typeShp, new Object[] { gf.createPoint(new Coordinate(0, 6)), 2.2, 1000 }, "feature1");
SimpleFeature f6 = SimpleFeatureBuilder.build(typeShp2, new Object[] { gf.createPoint(new Coordinate(0, 7)), 3.2, 1100.0 }, "feature1");
SimpleFeature f7 = SimpleFeatureBuilder.build(typeGeoJson, new Object[] { 4.2, 1200, gf.createPoint(new Coordinate(0, 8)) }, "feature1");
SimpleFeature f8 = SimpleFeatureBuilder.build(typeGeoJson2, new Object[] { 4.2, 1200, gf.createPoint(new Coordinate(0, 9)) }, "feature1");
MemoryDataStore testDataStore = new MemoryDataStore();
testDataStore.addFeature(f1);
testDataStore.addFeature(f2);
testDataStore.addFeature(f3);
testDataStore.addFeature(f4);
testDataStore.addFeature(f5);
testDataStore.addFeature(f6);
testDataStore.addFeature(f7);
testDataStore.addFeature(f8);
testDataStore.createSchema(builder4.buildFeatureType());
final AbstractDataStoreFactory factory = mock(AbstractDataStoreFactory.class);
when(factory.createDataStore(anyMapOf(String.class, Serializable.class))).thenReturn(testDataStore);
when(factory.canProcess(anyMapOf(String.class, Serializable.class))).thenReturn(true);
return factory;
}
Aggregations