Search in sources :

Example 1 with CoordinateArraySequence

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;
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence)

Example 2 with CoordinateArraySequence

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());
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) UniqueCoordinateArrayFilter(org.locationtech.jts.util.UniqueCoordinateArrayFilter) Coordinate(org.locationtech.jts.geom.Coordinate) Point(org.locationtech.jts.geom.Point) Point(org.locationtech.jts.geom.Point) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence)

Example 3 with CoordinateArraySequence

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();
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) MultiPoint(org.locationtech.jts.geom.MultiPoint) Coordinate(org.locationtech.jts.geom.Coordinate) ArrayList(java.util.ArrayList) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence)

Example 4 with CoordinateArraySequence

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);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) TariffZone(org.rutebanken.tiamat.model.TariffZone) Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 5 with CoordinateArraySequence

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());
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) TopographicPlace(org.rutebanken.tiamat.model.TopographicPlace) Point(org.locationtech.jts.geom.Point) LinearRing(org.locationtech.jts.geom.LinearRing) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Aggregations

CoordinateArraySequence (org.locationtech.jts.geom.impl.CoordinateArraySequence)29 Coordinate (org.locationtech.jts.geom.Coordinate)28 Test (org.junit.Test)13 Point (org.locationtech.jts.geom.Point)13 Geometry (org.locationtech.jts.geom.Geometry)12 LinearRing (org.locationtech.jts.geom.LinearRing)12 TiamatIntegrationTest (org.rutebanken.tiamat.TiamatIntegrationTest)8 MultiPoint (org.locationtech.jts.geom.MultiPoint)7 EmbeddableMultilingualString (org.rutebanken.tiamat.model.EmbeddableMultilingualString)7 TariffZone (org.rutebanken.tiamat.model.TariffZone)5 TopographicPlace (org.rutebanken.tiamat.model.TopographicPlace)5 CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)4 Polygon (org.locationtech.jts.geom.Polygon)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 Instant (java.time.Instant)3 TypeBuilder (ma.glasnost.orika.metadata.TypeBuilder)3 ValidBetween (org.rutebanken.tiamat.model.ValidBetween)3 HashMap (java.util.HashMap)2 MappingContext (ma.glasnost.orika.MappingContext)2 PolygonType (net.opengis.gml._3.PolygonType)2