// javac LandParser.java OSMLib.java Tag.java // java LandParser world mid import java.io.*; import java.util.*; import java.nio.ByteBuffer; public class LandParser { // final static double E7 = 10000000.0; //final static double B32 = 3.6*1024*1024*1024; // 0.9 * (2 の 32乗) final static double B32 = 1024*1024*1024; // 0.9 * (2 の 32乗) static int getX(long xy) { return (int)((xy & 0xffffffff00000000L) >> 32); } static int getY(long xy) { return (int) (xy & 0xffffffffL); } static long makeXY(int x, int y) { return (((long)x) << 32) | (y & 0xffffffffL); } static long makeXY(long x, long y) { return (x << 32) | (y & 0xffffffffL); } static int makeXY(short x, short y) { return (((int)x) << 16) | (y & 0xffff); } public static double Lon2X(double lon, int zoom) { return (lon + 180.0) / 360.0 * (1< xmax) xmax = x; if (y < ymin) ymin = y; if (y > ymax) ymax = y; poly[n/2] = makeXY(x, y); } if (poly[0] != poly[poly.length-1]) { System.out.println(line); // 閉ループではない continue; } if (mode != null && mode.charAt(0) != 'h') { double epsilon = (mode.charAt(0)=='m' ? 0.0005 : 0.005)/5; //System.out.printf("epsilon=%f\n", epsilon); OSMLib.SimplifySection(poly, 0, poly.length-2, epsilon); } float way_area = (float)Math.abs(OSMLib.calcWayArea(poly)); // 単位は 10u程度か? int head = 0x02; // polygon ByteBuffer bb = ByteBuffer.wrap(ba); bb.putInt((int)(xmin&0xffffffffL)); bb.putInt((int)(ymin&0xffffffffL)); bb.putInt((int)(xmax&0xffffffffL)); bb.putInt((int)(ymax&0xffffffffL)); //if ((int)(xmin&0xffffffffL) < 0) System.out.printf("%d\n", (int)(xmin&0xffffffffL)); bb.putInt(rid); bb.putLong(0L); // osm_id bb.putFloat(way_area); int key = Tag.Key.natural.ordinal(); int val = Tag.Val.land.ordinal(); bb.putInt(key); bb.putInt(val); int num_nodes = 0; for (long xy : poly) { if (xy > Long.MIN_VALUE) num_nodes++; } bb.putInt(num_nodes); int cntOut = 0; for (long xy : poly) { if (xy == Long.MIN_VALUE) continue; bb.putInt(getX(xy)); bb.putInt(getY(xy)); cntOut++; } if (num_nodes != cntOut || cntOut == 0) { System.out.printf("num_nodes = %d, cntOut = %d\n", num_nodes, cntOut); } int rec_length = bb.position(); if (rec_length >= (1<<23)) { System.out.printf("over flow. rec_length = %dBytes\n", rec_length); } else { head = head | (rec_length << 8); } dos.writeInt(head); dos.write(ba, 0, rec_length); } br.close(); bos.close(); dos.close(); } public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); LandParser.parse(args[0], args.length > 1 ? args[1] : null); long elapsed = System.currentTimeMillis() - start; System.out.printf("LandParser実行時間 = %.1f分\n", elapsed/1000.0/60); } }