use of org.locationtech.jts.geom.impl.CoordinateArraySequence in project series-rest-api by 52North.
the class GeoJSONTest method randomMultiPoint.
private MultiPoint randomMultiPoint(int srid) {
Coordinate[] coordinates = new Coordinate[] { randomCoordinate(), randomCoordinate(), randomCoordinate(), randomCoordinate(), randomCoordinate(), randomCoordinate() };
CoordinateArraySequence coordinateSequence = new CoordinateArraySequence(coordinates);
MultiPoint geometry = geometryFactory.createMultiPoint(coordinateSequence);
geometry.setSRID(srid);
return geometry;
}
use of org.locationtech.jts.geom.impl.CoordinateArraySequence in project OpenTripPlanner by opentripplanner.
the class ConcaveHull method transformIntoPointGeometryCollection.
/**
* Transform into GeometryCollection.
*
* @param geom
* input geometry
* @return
* a geometry collection
*/
private static GeometryCollection transformIntoPointGeometryCollection(Geometry geom) {
UniqueCoordinateArrayFilter filter = new UniqueCoordinateArrayFilter();
geom.apply(filter);
Coordinate[] coord = filter.getCoordinates();
Geometry[] geometries = new Geometry[coord.length];
for (int i = 0; i < coord.length; i++) {
Coordinate[] c = new Coordinate[] { coord[i] };
CoordinateArraySequence cs = new CoordinateArraySequence(c);
geometries[i] = new Point(cs, geom.getFactory());
}
return new GeometryCollection(geometries, geom.getFactory());
}
use of org.locationtech.jts.geom.impl.CoordinateArraySequence in project geotoolkit by Geomatys.
the class DefaultMultiGeometry method getCentroid.
/**
* @{@inheritDoc }
*/
@Override
public Point getCentroid() {
List<Coordinate> coordinates = new ArrayList<Coordinate>();
for (AbstractGeometry geometry : this.geometries) {
if (geometry instanceof Geometry) {
Geometry g = (Geometry) geometry;
coordinates.addAll(Arrays.asList(g.getCoordinates()));
} else if (geometry instanceof MultiGeometry) {
MultiGeometry g = (MultiGeometry) geometry;
coordinates.addAll(Arrays.asList(g.getCoordinates()));
} else {
return null;
}
}
Point[] pointsArray = new Point[coordinates.size()];
for (int i = 0; i < pointsArray.length; i++) {
pointsArray[i] = new Point(new CoordinateArraySequence(new Coordinate[] { coordinates.get(i) }), GF);
}
MultiPoint multiPoint = new MultiPoint(pointsArray, GF);
return multiPoint.getCentroid();
}
use of org.locationtech.jts.geom.impl.CoordinateArraySequence in project tiamat by entur.
the class TariffZoneSaverServiceTest method saveNewTariffZone.
@Test
public void saveNewTariffZone() {
TariffZone newVersion = new TariffZone();
Geometry geometry = geometryFactory.createPoint(new Coordinate(9.84, 59.26)).buffer(20);
LinearRing linearRing = new LinearRing(new CoordinateArraySequence(geometry.getCoordinates()), geometryFactory);
newVersion.setPolygon(geometryFactory.createPolygon(linearRing, null));
TariffZone actual = tariffZoneSaverService.saveNewVersion(newVersion);
assertThat(actual.getPolygon()).isNotNull();
assertThat(actual.getVersion()).isEqualTo(1L);
}
use of org.locationtech.jts.geom.impl.CoordinateArraySequence in project tiamat by entur.
the class TopographicPlaceLookupServiceTest method findTopographicPlace.
/**
* Ensure that a stale version of a topographic place can exist without from date and to date
* and still getting the most recent topographic place from the lookup service.
* <p>
* (Old data might not have validity condition stored, as versioning for topographic places was implemented after
* the initial baselining of data)
* <p>
* Test is implemented after merging of two counties (Sør- and Nordtrøndelag), were municipalities got new IDs.
*/
@Test
public void findTopographicPlace() {
Point point = geometryFactory.createPoint(new Coordinate(9.84, 59.26));
Geometry geometry = point.buffer(20);
LinearRing linearRing = new LinearRing(new CoordinateArraySequence(geometry.getCoordinates()), geometryFactory);
TopographicPlace staleTopographicPlace = new TopographicPlace(new EmbeddableMultilingualString("Skaun"));
staleTopographicPlace.setCreated(Instant.EPOCH);
staleTopographicPlace.setPolygon(geometryFactory.createPolygon(linearRing, null));
staleTopographicPlace.setNetexId("KVE:TopographicPlace:1657");
staleTopographicPlace.setTopographicPlaceType(TopographicPlaceTypeEnumeration.MUNICIPALITY);
TopographicPlace newTopographicPlace = new TopographicPlace(new EmbeddableMultilingualString("Skaun"));
newTopographicPlace.setCreated(Instant.now());
newTopographicPlace.setPolygon(geometryFactory.createPolygon(linearRing, null));
newTopographicPlace.setNetexId("KVE:TopographicPlace:5029");
newTopographicPlace.setTopographicPlaceType(TopographicPlaceTypeEnumeration.MUNICIPALITY);
topographicPlaceRepository.save(staleTopographicPlace);
topographicPlaceRepository.save(newTopographicPlace);
topographicPlaceRepository.flush();
topographicPlaceLookupService.reset();
Optional<TopographicPlace> result = topographicPlaceLookupService.findTopographicPlace(point);
assertThat(result.isPresent()).describedAs("Found topographic place?").isTrue();
assertThat(result.get().getNetexId()).as("Topographic place found").isEqualTo(newTopographicPlace.getNetexId());
}
Aggregations