/** * Container for an osm node (pre-pocessor version) * * @author ab */ package btools.mapcreator; import java.io.IOException; import btools.util.ByteDataWriter; public class OsmNodeP implements Comparable { public static final int SIGNLON_BITMASK = 0x80; public static final int SIGNLAT_BITMASK = 0x40; public static final int TRANSFERNODE_BITMASK = 0x20; public static final int WRITEDESC_BITMASK = 0x10; public static final int SKIPDETAILS_BITMASK = 0x08; public static final int NODEDESC_BITMASK = 0x04; /** * The latitude */ public int ilat; /** * The longitude */ public int ilon; /** * The links to other nodes */ public OsmLinkP firstlink = null; /** * The elevation */ public short selev; public boolean isBorder = false; public final static int NO_BRIDGE_BIT = 1; public final static int NO_TUNNEL_BIT = 2; public final static int LCN_BIT = 4; public final static int CR_BIT = 8; public byte wayBits = 0; // interface OsmPos public int getILat() { return ilat; } public int getILon() { return ilon; } public short getSElev() { // if all bridge or all tunnel, elevation=no-data return ( wayBits & NO_BRIDGE_BIT ) == 0 || ( wayBits & NO_TUNNEL_BIT ) == 0 ? Short.MIN_VALUE : selev; } public double getElev() { return selev / 4.; } public void addLink( OsmLinkP link ) { if ( firstlink != null ) link.next = firstlink; firstlink = link; } public byte[] getNodeDecsription() { return null; } public void writeNodeData( ByteDataWriter os, boolean writeVarLength, byte[] abBuf ) throws IOException { int lonIdx = ilon/62500; int latIdx = ilat/62500; // buffer the body to first calc size ByteDataWriter os2 = new ByteDataWriter( abBuf ); os2.writeShort( getSElev() ); // hack: write node-desc as link tag (copy cycleway-bits) byte[] nodeDescription = getNodeDecsription(); for( OsmLinkP link0 = firstlink; link0 != null; link0 = link0.next ) { int ilonref = ilon; int ilatref = ilat; OsmLinkP link = link0; OsmNodeP origin = this; int skipDetailBit = link0.counterLinkWritten() ? SKIPDETAILS_BITMASK : 0; // first pass just to see if that link is consistent while( link != null ) { OsmNodeP target = link.targetNode; if ( !target.isTransferNode() ) { break; } // next link is the one (of two), does does'nt point back for( link = target.firstlink; link != null; link = link.next ) { if ( link.targetNode != origin ) break; } origin = target; } if ( link == null ) continue; // dead end if ( skipDetailBit == 0) { link = link0; } origin = this; byte[] lastDescription = null; while( link != null ) { if ( link.descriptionBitmap == null && skipDetailBit == 0 ) throw new IllegalArgumentException( "missing way description..."); OsmNodeP target = link.targetNode; int tranferbit = target.isTransferNode() ? TRANSFERNODE_BITMASK : 0; int nodedescbit = nodeDescription != null ? NODEDESC_BITMASK : 0; int writedescbit = 0; if ( skipDetailBit == 0 ) // check if description changed { int inverseBitByteIndex = writeVarLength ? 0 : 7; boolean inverseDirection = link instanceof OsmLinkPReverse; byte[] ab = link.descriptionBitmap; int abLen = ab.length; int lastLen = lastDescription == null ? 0 : lastDescription.length; boolean equalsCurrent = abLen == lastLen; if ( equalsCurrent ) { for( int i=0; i id2 ) return 1; return 0; } }