forked from MapServer/MapServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDumpShp.java
More file actions
60 lines (48 loc) · 1.81 KB
/
DumpShp.java
File metadata and controls
60 lines (48 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import edu.umn.gis.mapscript.*;
/**
* <p>Title: Mapscript shape dump example.</p>
* <p>Description: A Java based mapscript to dump information from a shapefile.</p>
* @author Yew K Choo (ykchoo@geozervice.com)
* @version 1.0
*/
public class DumpShp {
public static String getShapeType(int type)
{
switch (type)
{
case 1: return "point";
case 3: return "arc";
case 5: return "polygon";
case 8: return "multipoint";
default: return "unknown";
}
}
public static void usage() {
System.err.println("Usage: DumpShp {shapefile.shp}");
System.exit(-1);
}
public static void main(String[] args) {
if (args.length != 1) usage();
shapefileObj shapefile = new shapefileObj (args[0],-1);
System.out.println ("Shapefile opened (type = " + getShapeType(shapefile.getType()) +
" with " + shapefile.getNumshapes() + " shapes).");
shapeObj shape = new shapeObj(-1);
for(int i=0; i<shapefile.getNumshapes(); i++) {
shapefile.get(i, shape);
System.out.println("Shape[" + i + "] has " + shape.getNumlines() + " part(s)");
System.out.println("bounds (" + shape.getBounds().getMinx() + "," + shape.getBounds().getMiny() + ")" +
"(" + shape.getBounds().getMaxx() + "," + shape.getBounds().getMaxy() + ")");
for(int j=0; j<shape.getNumlines(); j++) {
lineObj part = shape.get(j);
System.out.println("Part[" +j + "] has " + part.getNumpoints() + " point(s)");
for(int k=0; k<part.getNumpoints(); k++) {
pointObj point = part.get(k);
System.out.println("Point[" + k + "] = " + point.getX() + ", " + point.getY());
}
}
}
// shape.delete();
// shapefile.delete();
// mapscript.msCleanup();
}
}