use of com.vividsolutions.jts.geom.Polygon in project ddf by codice.
the class TestWfs10JTStoGML200Converter method testGMLToPolygonType.
@Test
public void testGMLToPolygonType() throws JAXBException, SAXException, IOException, ParseException, NullPointerException {
Polygon polygon = (Polygon) getGeometryFromWkt(POLYGON);
assertThat(polygon == null, is(Boolean.FALSE));
String polygonGML = Wfs10JTStoGML200Converter.convertGeometryToGML(polygon);
PolygonType polygonType = (PolygonType) Wfs10JTStoGML200Converter.convertGMLToGeometryType(polygonGML, Wfs10Constants.POLYGON);
assertThat(null != polygonType, is(Boolean.TRUE));
assertThat(polygonType.isSetInnerBoundaryIs(), is(Boolean.FALSE));
assertThat(polygonType.isSetOuterBoundaryIs(), is(Boolean.TRUE));
LinearRingMemberType linearRingMemberType = polygonType.getOuterBoundaryIs();
JAXBElement<? extends AbstractGeometryType> geometry = linearRingMemberType.getGeometry();
LinearRingType linearRingType = (LinearRingType) geometry.getValue();
String coordinates = linearRingType.getCoordinates().getValue().replaceAll("\n", "").trim();
assertThat(POLYGON_COORDS.equals(coordinates), is(Boolean.TRUE));
}
use of com.vividsolutions.jts.geom.Polygon in project GeoGig by boundlessgeo.
the class GeoGigFeatureSourceTest method testGetFeaturesFilter.
@Test
public void testGetFeaturesFilter() throws Exception {
SimpleFeatureCollection collection;
Set<List<Object>> actual;
Set<List<Object>> expected;
Filter filter;
filter = ff.id(Collections.singleton(ff.featureId(RepositoryTestCase.idP2)));
collection = pointsSource.getFeatures(new Query(pointsName, filter));
actual = Sets.newHashSet();
for (SimpleFeature f : toList(collection)) {
actual.add(f.getAttributes());
}
expected = Collections.singleton(((SimpleFeature) points2).getAttributes());
assertEquals(expected, actual);
ReferencedEnvelope queryBounds = boundsOf(points1, points2);
Polygon geometry = JTS.toGeometry(queryBounds);
filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
collection = pointsSource.getFeatures(new Query(pointsName, filter));
actual = Sets.newHashSet();
for (SimpleFeature f : toList(collection)) {
actual.add(f.getAttributes());
}
expected = ImmutableSet.of(((SimpleFeature) points1).getAttributes(), ((SimpleFeature) points2).getAttributes());
assertEquals(expected, actual);
ReferencedEnvelope transformedQueryBounds;
CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:3857");
transformedQueryBounds = queryBounds.transform(queryCrs, true);
geometry = JTS.toGeometry(transformedQueryBounds);
geometry.setUserData(queryCrs);
filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
collection = pointsSource.getFeatures(new Query(pointsName, filter));
actual = Sets.newHashSet();
for (SimpleFeature f : toList(collection)) {
actual.add(f.getAttributes());
}
expected = ImmutableSet.of(((SimpleFeature) points1).getAttributes(), ((SimpleFeature) points2).getAttributes());
assertEquals(expected.size(), actual.size());
assertEquals(expected, actual);
filter = ECQL.toFilter("sp = 'StringProp2_3' OR ip = 2000");
collection = linesSource.getFeatures(new Query(linesName, filter));
actual = Sets.newHashSet();
for (SimpleFeature f : toList(collection)) {
actual.add(f.getAttributes());
}
expected = ImmutableSet.of(((SimpleFeature) lines2).getAttributes(), ((SimpleFeature) lines3).getAttributes());
assertEquals(expected, actual);
}
use of com.vividsolutions.jts.geom.Polygon in project GeoGig by boundlessgeo.
the class LCSGeometryDiffImpl method geomToStringOfCoordinates.
private String geomToStringOfCoordinates(Optional<Geometry> opt) {
if (!opt.isPresent()) {
return "";
}
Function<Coordinate, String> printCoords = new Function<Coordinate, String>() {
@Override
@Nullable
public String apply(@Nullable Coordinate coord) {
return Double.toString(coord.x) + "," + Double.toString(coord.y);
}
};
StringBuilder sb = new StringBuilder();
Geometry geom = opt.get();
sb.append(geom.getGeometryType() + " ");
int n = geom.getNumGeometries();
for (int i = 0; i < n; i++) {
Geometry subgeom = geom.getGeometryN(i);
if (subgeom instanceof Polygon) {
Polygon polyg = (Polygon) subgeom;
Coordinate[] coords = polyg.getExteriorRing().getCoordinates();
Iterator<String> iter = Iterators.transform(Iterators.forArray(coords), printCoords);
sb.append(Joiner.on(' ').join(iter));
for (int j = 0; j < polyg.getNumInteriorRing(); j++) {
coords = polyg.getInteriorRingN(j).getCoordinates();
iter = Iterators.transform(Iterators.forArray(coords), printCoords);
sb.append(" " + INNER_RING_SEPARATOR + " ");
sb.append(Joiner.on(' ').join(iter));
}
if (i < n - 1) {
sb.append(" " + SUBGEOM_SEPARATOR + " ");
}
} else {
Coordinate[] coords = subgeom.getCoordinates();
Iterator<String> iter = Iterators.transform(Iterators.forArray(coords), printCoords);
sb.append(Joiner.on(' ').join(iter));
sb.append(" " + SUBGEOM_SEPARATOR + " ");
}
}
String s = sb.toString().trim();
return s;
}
use of com.vividsolutions.jts.geom.Polygon in project StreetComplete by westnordost.
the class GeoJsonReader method mergePolygons.
private void mergePolygons(ArrayList<Polygon> polygons) {
if (polygons.size() == 1)
return;
for (int i1 = 0; i1 < polygons.size() - 1; ++i1) {
Polygon p1 = polygons.get(i1);
for (int i2 = i1 + 1; i2 < polygons.size(); ++i2) {
Polygon p2 = polygons.get(i2);
// Geometry.union() seems to not have this optimization (bbox check)
if (!p1.getEnvelopeInternal().intersects(p2.getEnvelopeInternal()))
continue;
Geometry p1p2Union = p1.union(p2);
// if p1 and p2 wouldn't intersect, p1p2Union would be a GeometryCollection or MultiPolygon
if (p1p2Union instanceof Polygon) {
polygons.remove(i2);
polygons.set(i1, (Polygon) p1p2Union);
// start again at i1
--i1;
break;
}
}
}
}
use of com.vividsolutions.jts.geom.Polygon in project StreetComplete by westnordost.
the class JTSConst method toPolygons.
public static Geometry toPolygons(List<List<LatLon>> outer, List<List<LatLon>> inner) {
Map<LinearRing, ArrayList<LinearRing>> shellsWithHoles = toShellsWithHoles(outer, inner);
Polygon[] polys = new Polygon[shellsWithHoles.size()];
int i = 0;
for (Map.Entry<LinearRing, ArrayList<LinearRing>> shellWithHoles : shellsWithHoles.entrySet()) {
LinearRing shell = shellWithHoles.getKey();
ArrayList<LinearRing> holesList = shellWithHoles.getValue();
LinearRing[] holes = null;
if (holesList != null) {
holes = holesList.toArray(new LinearRing[holesList.size()]);
}
polys[i++] = factory.createPolygon(shell, holes);
}
if (polys.length == 1)
return polys[0];
else
return factory.createMultiPolygon(polys);
}
Aggregations