📄 vmap2shape.java
字号:
i = write; radians[write++] = radians[j]; radians[write++] = radians[j + 1]; } // check for mid-phase line if (ispolyg && (write == 6) && MoreMath.approximately_equal(radians[0], radians[4], eps) && MoreMath.approximately_equal(radians[1], radians[5], eps)) { write -= 2;// eliminate wrapped vertex } float[] newrads = new float[write]; System.arraycopy(radians, 0, newrads, 0, write); return newrads; } /** return true if we should throw away the poly */ protected boolean maybeThrowAwayPoly(OMPoly poly) { float[] radians = poly.getLatLonArray(); float lat, lon, thresh = ProjMath.degToRad(threshold); radians = coalesce_points(radians, 0.0001f, poly.isPolygon()); poly.setLocation(radians, OMGraphic.RADIANS);// install new if (radians.length < 4) { return true;// throw away } if (poly.isPolygon() && (radians.length < 6)) { return true; } int len = radians.length; float d; for (int i = 0; i < len; i += 2) { // test for proximity to 1-degree marks. this hopefully // avoids the problem of throwing away tiled slivers. // (don't throw away poly) lat = ProjMath.radToDeg(radians[i]); lon = ProjMath.radToDeg(radians[i + 1]); if (MoreMath.approximately_equal(lat, (float) (Math.round(lat)), zero_eps)) { return false; } if (MoreMath.approximately_equal(lon, (float) (Math.round(lon)), zero_eps)) { return false; } // check to see if all points fit within a certain // threshold. this should eliminate small islands and // countries like Luxembourg. sorry. for (int j = i + 2; j < radians.length; j += 2) { d = DrawUtil.distance(radians[i], radians[i + 1], radians[j], radians[j + 1]); // outside threshold, don't throw away if (!MoreMath.approximately_equal(d, 0f, thresh)) { return false; } } } if (poly.isPolygon()) { return true;// throw away } // throw away polyline if it's connected (island) return (MoreMath.approximately_equal(ProjMath.radToDeg(radians[0]), ProjMath.radToDeg(radians[radians.length - 2]), zero_eps) && MoreMath.approximately_equal(ProjMath.radToDeg(radians[1]), ProjMath.radToDeg(radians[radians.length - 1]), zero_eps)); } protected Properties loadProperties() { Properties props = new Properties(); try { props.load(new FileInputStream(propsFileName)); } catch (IOException e) { e.printStackTrace(); System.exit(1); } return props; } protected void setProperties(String prefix, Properties props) { String realPrefix = PropUtils.getScopedPropertyPrefix(prefix); String[] paths = PropUtils.initPathsFromProperties(props, realPrefix + VPFLayer.pathProperty); String defaultProperty = props.getProperty(realPrefix + VPFLayer.defaultLayerProperty); if (defaultProperty != null) { System.out.println("defaultProperty=" + defaultProperty); realPrefix = defaultProperty + "."; props = VPFLayer.getDefaultProperties(); } String coverage = props.getProperty(realPrefix + VPFLayer.coverageTypeProperty); if (coverage != null) { vmaptype = coverage; System.out.println("vmaptype=" + vmaptype); } initLST(paths); if (lst.getDatabaseName().equals("DCW")) { System.out.println("creating VPFLayerDCWWarehouse"); warehouse = new VPFLayerDCWWarehouse(); } else { System.out.println("creating VPFLayerGraphicWarehouse"); warehouse = new VPFLayerGraphicWarehouse(); } LayerGraphicWarehouseSupport.setDoThinning(doThinning); LayerGraphicWarehouseSupport.setFanEpsilon(fan_eps); warehouse.setProperties(realPrefix, props); } protected void initLST(String[] paths) { try { if (lst == null) { lst = new LibrarySelectionTable(paths); } } catch (com.bbn.openmap.io.FormatException f) { throw new java.lang.IllegalArgumentException(f.getMessage()); } } public OMGraphicList getRectangle() { int scale = 30000000; int width = 640; int height = 480; LatLonPoint upperLeft = new LatLonPoint(90.0f, -180.0f); LatLonPoint lowerRight = new LatLonPoint(-90.0f, 180.0f); warehouse.clear(); System.out.println("VMAP2Shape.getRectangle(): " + "calling drawTile with boundaries: " + upperLeft + lowerRight); long start = System.currentTimeMillis(); lst.drawTile(scale, width, height, vmaptype, warehouse, upperLeft, lowerRight); long stop = System.currentTimeMillis(); System.out.println("VMAP2Shape.getRectangle(): read time: " + ((stop - start) / 1000d) + " seconds"); return warehouse.getGraphics(); } public boolean isDoThinning() { return doThinning; } public void setDoThinning(boolean doThinning) { this.doThinning = doThinning; } public float getFan_eps() { return fan_eps; } public void setFan_eps(float fan_eps) { this.fan_eps = fan_eps; } public LibrarySelectionTable getLst() { return lst; } public void setLst(LibrarySelectionTable lst) { this.lst = lst; } public String getPrefix() { return prefix; } public void setPrefix(String prefix) { this.prefix = prefix; } public String getPropsFileName() { return propsFileName; } public void setPropsFileName(String propsFileName) { this.propsFileName = propsFileName; } public float getThreshold() { return threshold; } public void setThreshold(float threshold) { this.threshold = threshold; } public String getVmaptype() { return vmaptype; } public void setVmaptype(String vmaptype) { this.vmaptype = vmaptype; } public LayerGraphicWarehouseSupport getWarehouse() { return warehouse; } public void setWarehouse(LayerGraphicWarehouseSupport warehouse) { this.warehouse = warehouse; } public float getZero_eps() { return zero_eps; } public void setZero_eps(float zero_eps) { this.zero_eps = zero_eps; } public static void usage() { System.out.println("Usage: java VMAP2Shape [args] <outfile.shp>"); System.out.println("Arguments:"); System.out.println("\t-props <path> path to properties file"); System.out.println(" default: " + DEF_PROPS_FILE_NAME); System.out.println("\t-prefix <identifier> vmap properties prefix"); System.out.println(" default: " + DEF_PREFIX); System.out.println("\t-thin <eps> <thresh> do thinning"); System.out.println(" default eps=" + DEF_FAN_EPS + " thresh=" + DEF_THRESHOLD); System.exit(1); } public static void main(String args[]) { if ((args.length == 0) || ((args.length == 1) && (args[0].startsWith("-")))) { usage(); } com.bbn.openmap.util.Debug.init(System.getProperties()); VMAP2Shape c = new VMAP2Shape(); for (int i = 0; i < args.length - 1; i++) { if (args[i].equalsIgnoreCase("-props")) { c.setPropsFileName(args[++i]); } else if (args[i].equalsIgnoreCase("-prefix")) { c.setPrefix(args[++i]); } else if (args[i].equalsIgnoreCase("-thin")) { c.setDoThinning(true); c.setFan_eps(Float.valueOf(args[++i]).floatValue()); c.setThreshold(Float.valueOf(args[++i]).floatValue()); } else { usage(); } } c.writeShapeFile(args[args.length - 1]); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -