コード例 #1
0
  /**
   * Verifies that the record's shape type matches the expected one, typically that of the
   * shapefile. All non-null records in a Shapefile must be of the same type. Throws an exception if
   * the types do not match and the shape type is not <code>{@link Shapefile#SHAPE_NULL}</code>.
   * Records of type <code>SHAPE_NULL</code> are always valid, and may appear in any Shapefile.
   *
   * <p>For details, see the ESRI Shapefile specification at <a
   * href="http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf"/>, pages 4 and 5.
   *
   * @param shapefile the shapefile.
   * @param shapeType the record's shape type.
   * @throws WWRuntimeException if the shape types do not match.
   * @throws IllegalArgumentException if the specified shape type is null.
   */
  protected void validateShapeType(Shapefile shapefile, String shapeType) {
    if (shapeType == null) {
      String message = Logging.getMessage("nullValue.ShapeType");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (!shapeType.equals(shapefile.getShapeType()) && !shapeType.equals(Shapefile.SHAPE_NULL)) {
      String message = Logging.getMessage("SHP.UnsupportedShapeType", shapeType);
      Logging.logger().severe(message);
      throw new WWRuntimeException(message);
    }
  }
コード例 #2
0
  /**
   * Reads and parses the contents of a shapefile record from a specified buffer. The buffer's
   * current position must be the start of the record and will be the start of the next record when
   * the constructor returns.
   *
   * @param shapefile the containing {@link Shapefile}.
   * @param buffer the shapefile record {@link java.nio.ByteBuffer} to read from.
   */
  protected void readFromBuffer(Shapefile shapefile, ByteBuffer buffer) {
    // Read record number and record length - big endian.
    buffer.order(ByteOrder.BIG_ENDIAN);
    this.recordNumber = buffer.getInt();
    this.contentLengthInBytes = buffer.getInt() * 2;

    // Read shape type - little endian
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    int type = buffer.getInt();
    String shapeType = shapefile.getShapeType(type);
    this.validateShapeType(shapefile, shapeType);

    this.shapeType = shapeType;
    this.shapeFile = shapefile;

    this.doReadFromBuffer(shapefile, buffer);
  }
コード例 #3
0
 /**
  * Indicates whether the record is a shape type containing Z values.
  *
  * @return true if the record is a type containing Z values.
  */
 protected boolean isZType() {
   return Shapefile.isZType(this.getShapeType());
 }