コード例 #1
0
ファイル: MapDatabase.java プロジェクト: bily/VectorTileMap
  private int[][] readZoomTable(SubFileParameter subFileParameter) {
    int rows = subFileParameter.zoomLevelMax - subFileParameter.zoomLevelMin + 1;
    int[][] zoomTable = new int[rows][2];

    int cumulatedNumberOfPois = 0;
    int cumulatedNumberOfWays = 0;

    for (int row = 0; row < rows; ++row) {
      cumulatedNumberOfPois += mReadBuffer.readUnsignedInt();
      cumulatedNumberOfWays += mReadBuffer.readUnsignedInt();

      if (cumulatedNumberOfPois < 0 || cumulatedNumberOfPois > MAXIMUM_ZOOM_TABLE_OBJECTS) {
        LOG.warning("invalid cumulated number of POIs in row " + row + ' ' + cumulatedNumberOfPois);
        if (mDebugFile) {
          LOG.warning(DEBUG_SIGNATURE_BLOCK + mSignatureBlock);
        }
        return null;
      } else if (cumulatedNumberOfWays < 0 || cumulatedNumberOfWays > MAXIMUM_ZOOM_TABLE_OBJECTS) {
        LOG.warning("invalid cumulated number of ways in row " + row + ' ' + cumulatedNumberOfWays);
        if (sMapFileHeader.getMapFileInfo().debugFile) {
          LOG.warning(DEBUG_SIGNATURE_BLOCK + mSignatureBlock);
        }
        return null;
      }

      zoomTable[row][0] = cumulatedNumberOfPois;
      zoomTable[row][1] = cumulatedNumberOfWays;
    }

    return zoomTable;
  }
コード例 #2
0
ファイル: MapDatabase.java プロジェクト: bily/VectorTileMap
 /*
  * (non-Javadoc)
  * @see org.oscim.map.reader.IMapDatabase#getMapFileInfo()
  */
 @Override
 public MapFileInfo getMapInfo() {
   if (sMapFileHeader == null) {
     throw new IllegalStateException("no map file is currently opened");
   }
   return sMapFileHeader.getMapFileInfo();
 }
コード例 #3
0
ファイル: MapDatabase.java プロジェクト: bily/VectorTileMap
  /**
   * Processes the given number of ways.
   *
   * @param queryParameters the parameters of the current query.
   * @param mapDatabaseCallback the callback which handles the extracted ways.
   * @param numberOfWays how many ways should be processed.
   * @return true if the ways could be processed successfully, false otherwise.
   */
  private boolean processWays(
      QueryParameters queryParameters, IMapDatabaseCallback mapDatabaseCallback, int numberOfWays) {

    Tag[] tags = null;
    Tag[] wayTags = sMapFileHeader.getMapFileInfo().wayTags;
    int[] textPos = new int[3];
    // float[] labelPosition;
    boolean skippedWays = false;
    int wayDataBlocks;

    // skip string block
    int stringsSize = mReadBuffer.readUnsignedInt();
    stringOffset = mReadBuffer.getBufferPosition();
    mReadBuffer.skipBytes(stringsSize);

    for (int elementCounter = numberOfWays; elementCounter != 0; --elementCounter) {
      if (mDebugFile) {
        // get and check the way signature
        mSignatureWay = mReadBuffer.readUTF8EncodedString(SIGNATURE_LENGTH_WAY);
        if (!mSignatureWay.startsWith("---WayStart")) {
          LOG.warning("invalid way signature: " + mSignatureWay);
          LOG.warning(DEBUG_SIGNATURE_BLOCK + mSignatureBlock);
          return false;
        }
      }

      if (queryParameters.useTileBitmask) {
        elementCounter = mReadBuffer.skipWays(queryParameters.queryTileBitmask, elementCounter);

        if (elementCounter == 0) return true;

        if (elementCounter < 0) return false;

        if (mReadBuffer.lastTagPosition > 0) {
          int pos = mReadBuffer.getBufferPosition();
          mReadBuffer.setBufferPosition(mReadBuffer.lastTagPosition);

          byte numberOfTags = (byte) (mReadBuffer.readByte() & WAY_NUMBER_OF_TAGS_BITMASK);

          tags = mReadBuffer.readTags(wayTags, numberOfTags);
          if (tags == null) return false;

          skippedWays = true;

          mReadBuffer.setBufferPosition(pos);
        }
      } else {
        int wayDataSize = mReadBuffer.readUnsignedInt();
        if (wayDataSize < 0) {
          LOG.warning("invalid way data size: " + wayDataSize);
          if (mDebugFile) {
            LOG.warning(DEBUG_SIGNATURE_BLOCK + mSignatureBlock);
          }
          LOG.warning("EEEEEK way... 2");
          return false;
        }

        // ignore the way tile bitmask (2 bytes)
        mReadBuffer.skipBytes(2);
      }

      // get the special byte which encodes multiple flags
      byte specialByte = mReadBuffer.readByte();

      // bit 1-4 represent the layer
      byte layer = (byte) ((specialByte & WAY_LAYER_BITMASK) >>> WAY_LAYER_SHIFT);
      // bit 5-8 represent the number of tag IDs
      byte numberOfTags = (byte) (specialByte & WAY_NUMBER_OF_TAGS_BITMASK);

      boolean changed = skippedWays;
      skippedWays = false;

      if (numberOfTags != 0) {
        tags = mReadBuffer.readTags(wayTags, numberOfTags);
        changed = true;
      }
      if (tags == null) return false;

      // get the feature bitmask (1 byte)
      byte featureByte = mReadBuffer.readByte();

      // bit 1-6 enable optional features
      boolean featureWayDoubleDeltaEncoding =
          (featureByte & WAY_FEATURE_DOUBLE_DELTA_ENCODING) != 0;

      // check if the way has a name
      if ((featureByte & WAY_FEATURE_NAME) != 0) {
        textPos[0] = mReadBuffer.readUnsignedInt();
        String str = mReadBuffer.readUTF8EncodedStringAt(stringOffset + textPos[0]);
        // if (changed) {
        // Tag[] tmp = tags;
        // tags = new Tag[tmp.length + 1];
        // System.arraycopy(tmp, 0, tags, 0, tmp.length);
        // }
        // tags[tags.length - 1] = new Tag(Tag.TAG_KEY_NAME, str,
        // false);
      } else textPos[0] = -1;

      // check if the way has a house number
      if ((featureByte & WAY_FEATURE_HOUSE_NUMBER) != 0) {
        textPos[1] = mReadBuffer.readUnsignedInt();

      } else textPos[1] = -1;

      // check if the way has a reference
      if ((featureByte & WAY_FEATURE_REF) != 0) textPos[2] = mReadBuffer.readUnsignedInt();
      else textPos[2] = -1;

      if ((featureByte & WAY_FEATURE_LABEL_POSITION) != 0)
        // labelPosition =
        readOptionalLabelPosition();
      // else
      // labelPosition = null;

      if ((featureByte & WAY_FEATURE_DATA_BLOCKS_BYTE) != 0) {
        wayDataBlocks = mReadBuffer.readUnsignedInt();

        if (wayDataBlocks < 1) {
          LOG.warning("invalid number of way data blocks: " + wayDataBlocks);
          logDebugSignatures();
          return false;
        }
      } else {
        wayDataBlocks = 1;
      }

      for (int wayDataBlock = 0; wayDataBlock < wayDataBlocks; ++wayDataBlock) {
        short[] wayLengths = processWayDataBlock(featureWayDoubleDeltaEncoding);
        if (wayLengths == null) return false;

        // wayDataContainer.textPos = textPos;
        int l = wayLengths[0];

        boolean closed = mWayNodes[0] == mWayNodes[l - 2] && mWayNodes[1] == mWayNodes[l - 1];

        mapDatabaseCallback.renderWay(layer, tags, mWayNodes, wayLengths, closed);
      }
    }

    return true;
  }
コード例 #4
0
ファイル: MapDatabase.java プロジェクト: bily/VectorTileMap
  /**
   * Processes the given number of POIs.
   *
   * @param mapDatabaseCallback the callback which handles the extracted POIs.
   * @param numberOfPois how many POIs should be processed.
   * @return true if the POIs could be processed successfully, false otherwise.
   */
  private boolean processPOIs(IMapDatabaseCallback mapDatabaseCallback, int numberOfPois) {
    Tag[] poiTags = sMapFileHeader.getMapFileInfo().poiTags;
    Tag[] tags = null;

    for (int elementCounter = numberOfPois; elementCounter != 0; --elementCounter) {
      if (mDebugFile) {
        // get and check the POI signature
        mSignaturePoi = mReadBuffer.readUTF8EncodedString(SIGNATURE_LENGTH_POI);
        if (!mSignaturePoi.startsWith("***POIStart")) {
          LOG.warning("invalid POI signature: " + mSignaturePoi);
          LOG.warning(DEBUG_SIGNATURE_BLOCK + mSignatureBlock);
          return false;
        }
      }

      // Log.d("MapDatabase", "read POI");

      // get the POI latitude offset (VBE-S)
      int latitude = mTileLatitude + mReadBuffer.readSignedInt();

      // get the POI longitude offset (VBE-S)
      int longitude = mTileLongitude + mReadBuffer.readSignedInt();

      // get the special byte which encodes multiple flags
      byte specialByte = mReadBuffer.readByte();

      // bit 1-4 represent the layer
      byte layer = (byte) ((specialByte & POI_LAYER_BITMASK) >>> POI_LAYER_SHIFT);
      // bit 5-8 represent the number of tag IDs
      byte numberOfTags = (byte) (specialByte & POI_NUMBER_OF_TAGS_BITMASK);

      // boolean changed = false;

      if (numberOfTags != 0) {
        tags = mReadBuffer.readTags(poiTags, numberOfTags);
        // changed = true;
      }
      if (tags == null) return false;

      // get the feature bitmask (1 byte)
      byte featureByte = mReadBuffer.readByte();

      // bit 1-3 enable optional features

      // check if the POI has a name
      if ((featureByte & POI_FEATURE_NAME) != 0) {
        // int pos = mReadBuffer.getPositionAndSkip();
        String str = mReadBuffer.readUTF8EncodedString();

        Tag[] tmp = tags;
        tags = new Tag[tmp.length + 1];
        System.arraycopy(tmp, 0, tags, 0, tmp.length);
        tags[tags.length - 1] = new Tag("name", str, false);
      }

      // check if the POI has a house number
      if ((featureByte & POI_FEATURE_HOUSE_NUMBER) != 0) {
        // mReadBuffer.getPositionAndSkip();
        // String str =
        mReadBuffer.readUTF8EncodedString();
      }

      // check if the POI has an elevation
      if ((featureByte & POI_FEATURE_ELEVATION) != 0) {
        mReadBuffer.readSignedInt();
        // mReadBuffer.getPositionAndSkip();// tags.add(new
        // Tag(Tag.TAG_KEY_ELE,
        // Integer.toString(mReadBuffer.readSignedInt())));
      }

      mapDatabaseCallback.renderPointOfInterest(layer, tags, latitude, longitude);
    }

    return true;
  }