All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vividsolutions.jtstest.testbuilder.io.shapefile.ShapefileHeader Maven / Gradle / Ivy

The newest version!
/*
 * Header.java
 *
 * Created on February 12, 2002, 3:29 PM
 */

package com.vividsolutions.jtstest.testbuilder.io.shapefile;

import java.io.IOException;

import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.GeometryCollection;

/**
 *
 * @author  jamesm
 */
public class ShapefileHeader{
    private final static boolean DEBUG=false;
    private int fileCode = -1;
    public int fileLength = -1;
    private int indexLength = -1;
    private int version = -1;
    private int shapeType = -1;
    //private double[] bounds = new double[4];
    private Envelope bounds;
    
    public ShapefileHeader(EndianDataInputStream file) throws IOException {
      //  file.setLittleEndianMode(false);
        fileCode = file.readIntBE();
       // if(DEBUG)System.out.println("Sfh->Filecode "+fileCode);
        if ( fileCode != Shapefile.SHAPEFILE_ID )
            System.err.println("Sfh->WARNING filecode "+fileCode+" not a match for documented shapefile code "+Shapefile.SHAPEFILE_ID);
        
        for(int i=0;i<5;i++){
            int tmp = file.readIntBE();
           // if(DEBUG)System.out.println("Sfh->blank "+tmp);
        }
        fileLength = file.readIntBE();
        
      //  file.setLittleEndianMode(true);
        version=file.readIntLE();
        shapeType=file.readIntLE();
       
        //read in and for now ignore the bounding box
        for(int i = 0;i<4;i++){
            file.readDoubleLE();
        }
        
        //skip remaining unused bytes
       // file.setLittleEndianMode(false);//well they may not be unused forever...
        file.skipBytes(32);
    }
    
    public ShapefileHeader(GeometryCollection geometries,int dims) throws Exception
    {
        ShapeHandler handle;
        if (geometries.getNumGeometries() == 0)
        {
            handle = new PointHandler(); //default
        }
        else
        {
               handle = Shapefile.getShapeHandler(geometries.getGeometryN(0),dims);
        }
        int numShapes = geometries.getNumGeometries();
        shapeType = handle.getShapeType();
        version = Shapefile.VERSION;
        fileCode = Shapefile.SHAPEFILE_ID;
        bounds = geometries.getEnvelopeInternal();
        fileLength = 0;
        for(int i=0;itype "+fileCode+" size "+fileLength+" version "+ version + " Shape Type "+shapeType);
        return res;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy