/*********************************
* DescribeShape.java
* Uses the NVS shapefile library
* to read the specified shapefile
* and then display its points,
* records, type, and bouding box.
*
*********************************/
import com.nvs.shapefile.*;
import java.io.*;
import java.util.*;
public class DescribeShape
{
private static String strFilename;
public static void main(String args[])
{
if(args.length < 1)
{
System.out.println("Usage: DescribeShape <shapefile>");
return;
}
strFilename = args[0];
new DescribeShape();
}
public DescribeShape()
{
Shapefile shp = null;
try
{
shp = new Shapefile(strFilename);
}
catch(FileNotFoundException e)
{
System.err.println(e.getMessage());
}
catch(IOException e)
{
System.err.println(e.getMessage());
}
System.out.println("Type: " + shp.getType());
Iterator itrShapeObjects = shp.getShapeObjects().iterator();
while(itrShapeObjects.hasNext())
{
ShapeObject obj = (ShapeObject)itrShapeObjects.next();
System.out.println("Shape object: type " + obj.getType());
System.out.println("\tBoundingBox");
if(obj.getType() != Shapefile.SHAPETYPE_POINT)
{
BoundingBox box = obj.getBoundingBox();
System.out.println("\t\tXmin: \t" + box.getXMin());
System.out.println("\t\tXmax: \t" + box.getXMax());
System.out.println("\t\tYmin: \t" + box.getYMin());
System.out.println("\t\tYmax: \t" + box.getYMax());
}
Iterator itrPoints = obj.getPoints().iterator();
int i = 0;
while(itrPoints.hasNext())
{
Point pt = (Point)itrPoints.next();
System.out.println(i + ":\t\tx: " + pt.getX() + " y: " + pt.getY());
i++;
}
System.out.println("\trecords: ");
Record rec = obj.getRecord();
Iterator itrFields = rec.getFields().iterator();
while(itrFields.hasNext())
{
RecordField rf = (RecordField)itrFields.next();
System.out.println("\t\tname: " + rf.getName() + "\tvalue: " + rf.getValue());
}
}
}
}