Search in sources :

Example 16 with OsmWay

use of de.topobyte.osm4j.core.model.iface.OsmWay in project osm4j-core by topobyte.

the class ImplUtil method clone.

public static Way clone(OsmWay way) {
    List<? extends OsmTag> tags = cloneTags(way);
    OsmMetadata metadata = cloneMetadata(way);
    TLongList nodes = new TLongArrayList(way.getNumberOfNodes());
    for (int i = 0; i < way.getNumberOfNodes(); i++) {
        nodes.add(way.getNodeId(i));
    }
    return new Way(way.getId(), nodes, tags, metadata);
}
Also used : OsmMetadata(de.topobyte.osm4j.core.model.iface.OsmMetadata) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) TLongList(com.slimjars.dist.gnu.trove.list.TLongList) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Way(de.topobyte.osm4j.core.model.impl.Way)

Example 17 with OsmWay

use of de.topobyte.osm4j.core.model.iface.OsmWay in project osm4j-core by topobyte.

the class TestWayIterator method test.

@Test
public void test() throws IOException {
    InMemoryListDataSet data = ListDataSetLoader.read(createInput().createIterator(true, true), true, true, true);
    OsmIteratorInput input = createInput().createIterator(true, true);
    WayIterator wayIterator = new WayIterator(input.getIterator());
    List<OsmWay> ways = Lists.newArrayList(wayIterator.iterator());
    input.close();
    assertEquals(data.getWays().size(), ways.size());
    for (int i = 0; i < ways.size(); i++) {
        OsmWay a = ways.get(i);
        OsmWay b = data.getWays().get(i);
        assertTrue(EqualityUtil.equals(a, b));
    }
}
Also used : OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) OsmIteratorInput(de.topobyte.osm4j.core.access.OsmIteratorInput) InMemoryListDataSet(de.topobyte.osm4j.core.dataset.InMemoryListDataSet) Test(org.junit.Test)

Example 18 with OsmWay

use of de.topobyte.osm4j.core.model.iface.OsmWay in project osm4j-geometry by topobyte.

the class ChainOfWays method toCoordinateSequence.

private CoordinateSequence toCoordinateSequence(OsmEntityProvider resolver) throws EntityNotFoundException {
    CoordinateSequenceFactory csf = factory.getCoordinateSequenceFactory();
    int len = getLength();
    CoordinateSequence points = csf.create(len, 2);
    int n = 0;
    for (int i = 0; i < segments.size(); i++) {
        WaySegment segment = segments.get(i);
        OsmWay way = segment.getWay();
        for (int k = 0; k < way.getNumberOfNodes(); k++) {
            if (k > 0 || i == 0) {
                OsmNode node = resolver.getNode(segment.getNodeId(k));
                points.setOrdinate(n, 0, node.getLongitude());
                points.setOrdinate(n, 1, node.getLatitude());
                n++;
            }
        }
    }
    return points;
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) CoordinateSequenceFactory(com.vividsolutions.jts.geom.CoordinateSequenceFactory)

Example 19 with OsmWay

use of de.topobyte.osm4j.core.model.iface.OsmWay in project osm4j-geometry by topobyte.

the class ChainOfWays method toSegmentRing.

public ChainOfNodes toSegmentRing() {
    if (segments.isEmpty()) {
        return new ChainOfNodes(new TLongArrayList());
    }
    int len = getLengthNonEmpty();
    TLongList ids = new TLongArrayList(len);
    for (int i = 0; i < segments.size(); i++) {
        WaySegment segment = segments.get(i);
        OsmWay way = segment.getWay();
        for (int k = 0; k < way.getNumberOfNodes(); k++) {
            if (k > 0 || i == 0) {
                ids.add(segment.getNodeId(k));
            }
        }
    }
    return new ChainOfNodes(ids);
}
Also used : OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) TLongList(com.slimjars.dist.gnu.trove.list.TLongList)

Example 20 with OsmWay

use of de.topobyte.osm4j.core.model.iface.OsmWay in project osm4j-geometry by topobyte.

the class RelationUtil method closeUnclosedRingWithStraightLine.

public static void closeUnclosedRingWithStraightLine(Collection<ChainOfWays> rings) {
    for (ChainOfWays ring : rings) {
        if (!ring.isClosed()) {
            logger.debug("unclosed ring with " + ring.getSegments().size() + " segments");
            List<WaySegment> segments = ring.getSegments();
            WaySegment rs1 = segments.get(0);
            WaySegment rs2 = segments.get(segments.size() - 1);
            long n1 = rs1.getNodeId(0);
            long n2 = rs2.getNodeId(rs2.getNumberOfNodes() - 1);
            TLongArrayList ids = new TLongArrayList();
            ids.add(n1);
            ids.add(n2);
            OsmWay filler = new Way(0L, ids);
            ring.addWay(filler);
        }
    }
}
Also used : OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) TLongArrayList(com.slimjars.dist.gnu.trove.list.array.TLongArrayList) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) Way(de.topobyte.osm4j.core.model.impl.Way)

Aggregations

OsmWay (de.topobyte.osm4j.core.model.iface.OsmWay)24 OsmNode (de.topobyte.osm4j.core.model.iface.OsmNode)10 ArrayList (java.util.ArrayList)10 TLongArrayList (com.slimjars.dist.gnu.trove.list.array.TLongArrayList)9 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)7 Way (de.topobyte.osm4j.core.model.impl.Way)7 OsmHandler (de.topobyte.osm4j.core.access.OsmHandler)4 OsmBounds (de.topobyte.osm4j.core.model.iface.OsmBounds)4 Node (de.topobyte.osm4j.core.model.impl.Node)4 Relation (de.topobyte.osm4j.core.model.impl.Relation)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 TLongIterator (com.slimjars.dist.gnu.trove.iterator.TLongIterator)3 EntityFinder (de.topobyte.osm4j.core.resolve.EntityFinder)3 EntityNotFoundException (de.topobyte.osm4j.core.resolve.EntityNotFoundException)3 EntityNotFoundStrategy (de.topobyte.osm4j.core.resolve.EntityNotFoundStrategy)3 TLongList (com.slimjars.dist.gnu.trove.list.TLongList)2 EntityContainer (de.topobyte.osm4j.core.model.iface.EntityContainer)2 OsmMetadata (de.topobyte.osm4j.core.model.iface.OsmMetadata)2 OsmRelationMember (de.topobyte.osm4j.core.model.iface.OsmRelationMember)2