Package chunmap.data.provider.shp

Source Code of chunmap.data.provider.shp.ShpDataSource

/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
*     2010-05-05  Jed Young  Creation
*/
package chunmap.data.provider.shp;

import java.io.IOException;
import java.nio.charset.Charset;
import java.sql.ResultSet;

import chunmap.data.feature.FeatureSchama;
import chunmap.data.feature.LayerMetadata;
import chunmap.data.provider.FeatureDataReader;
import chunmap.model.elem.Envelope;
import chunmap.model.geom.Geometry;

/**
* @author chunquedong
*
*/
public class ShpDataSource implements FeatureDataReader {
  private final ShapefileReader shpReader;
  private DbfReader dbfReader;

  public ShpDataSource(String path) {
    this(path,null);
  }
 
  public ShpDataSource(String path,Charset charset) {
    this.shpReader = new ShapefileReader(path);
    dbfReader=new DbfReader(path);
    dbfReader.setCharset(charset);
  }

  @Override
  public void close() {
    shpReader.close();
   
  }

  @Override
  public Object[] data(long index) {
    return dbfReader.getValues(index);
  }

  @Override
  public Envelope getEnvelop() {
    return shpReader.getEnvelop();
  }

  @Override
  public FeatureSchama getFeatureSchama() {
    return dbfReader.getFeatureSchama();
  }

  @Override
  public Geometry getGeometry(long id) {
    try {
      return shpReader.getGeometry(id);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }

  @Override
  public LayerMetadata getMetadata() {
    LayerMetadata meta = new LayerMetadata(shpReader.getName(),shpReader.getGeometryType());
        return meta;
  }

  @Override
  public Envelope getShapeEnvelop(long id) {
    try {
      return shpReader.getShapeEnvelop(id);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return new Envelope();
  }

  @Override
  public ResultSet query(String where) {
    throw new UnsupportedOperationException();
  }

  @Override
  public long size() {
    return shpReader.getShapeCount();
  }

}
TOP

Related Classes of chunmap.data.provider.shp.ShpDataSource

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.