Search in sources :

Example 6 with SerializableNode

use of org.bboxdb.tools.converter.osm.util.SerializableNode in project bboxdb by jnidzwetzki.

the class OSMJDBCNodeStore method getNodeForId.

/**
 * Get the id for the node
 * @param nodeId
 * @return
 * @throws SQLException
 */
public SerializableNode getNodeForId(final long nodeId) throws SQLException {
    final int connectionNumber = getDatabaseForNode(nodeId);
    final PreparedStatement selectNode = selectNodeStatements.get(connectionNumber);
    selectNode.setLong(1, nodeId);
    final ResultSet result = selectNode.executeQuery();
    if (!result.next()) {
        throw new RuntimeException("Unable to find node for way: " + nodeId);
    }
    final byte[] nodeBytes = result.getBytes(1);
    result.close();
    final SerializableNode node = SerializableNode.fromByteArray(nodeBytes);
    return node;
}
Also used : ResultSet(java.sql.ResultSet) SerializableNode(org.bboxdb.tools.converter.osm.util.SerializableNode) PreparedStatement(java.sql.PreparedStatement)

Example 7 with SerializableNode

use of org.bboxdb.tools.converter.osm.util.SerializableNode in project bboxdb by jnidzwetzki.

the class OSMDataConverter method handleWay.

/**
 * Handle a way
 * @param entityContainer
 */
protected void handleWay(final Way way) {
    try {
        for (final OSMType osmType : filter.keySet()) {
            final OSMTagEntityFilter entityFilter = filter.get(osmType);
            if (entityFilter.match(way.getTags())) {
                final Polygon geometricalStructure = new Polygon(way.getId());
                for (final Tag tag : way.getTags()) {
                    geometricalStructure.addProperty(tag.getKey(), tag.getValue());
                }
                // Perform search async
                for (final WayNode wayNode : way.getWayNodes()) {
                    final SerializableNode node = osmNodeStore.getNodeForId(wayNode.getNodeId());
                    geometricalStructure.addPoint(node.getLatitude(), node.getLongitude());
                }
                writePolygonToOutput(osmType, geometricalStructure);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : OSMTagEntityFilter(org.bboxdb.tools.converter.osm.filter.OSMTagEntityFilter) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) SerializableNode(org.bboxdb.tools.converter.osm.util.SerializableNode) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) Polygon(org.bboxdb.tools.converter.osm.util.Polygon) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Aggregations

SerializableNode (org.bboxdb.tools.converter.osm.util.SerializableNode)7 PreparedStatement (java.sql.PreparedStatement)2 Database (com.sleepycat.je.Database)1 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1 OperationStatus (com.sleepycat.je.OperationStatus)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 ParseException (org.apache.commons.cli.ParseException)1 Tuple (org.bboxdb.storage.entity.Tuple)1 OSMTagEntityFilter (org.bboxdb.tools.converter.osm.filter.OSMTagEntityFilter)1 Polygon (org.bboxdb.tools.converter.osm.util.Polygon)1 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)1 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)1