?? shapespecialist.java
字號:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/corba/com/bbn/openmap/layer/specialist/shape/ShapeSpecialist.java,v $// $RCSfile: ShapeSpecialist.java,v $// $Revision: 1.2.2.2 $// $Date: 2005/08/09 21:18:00 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.specialist.shape;import java.awt.Color;import java.io.File;import java.util.Properties;import java.util.Vector;import com.bbn.openmap.Environment;import com.bbn.openmap.MoreMath;import com.bbn.openmap.CSpecialist.MouseEvent;import com.bbn.openmap.CSpecialist.UGraphic;import com.bbn.openmap.CSpecialist.WidgetChange;import com.bbn.openmap.layer.shape.ESRIRecord;import com.bbn.openmap.layer.shape.SpatialIndex;import com.bbn.openmap.layer.specialist.SColor;import com.bbn.openmap.layer.specialist.SGraphic;import com.bbn.openmap.layer.specialist.Specialist;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * Implements the Specialist interface so that we can serve graphics * to OpenMap via CORBA. This specialist handles shape files, with the * coordinates in the shape files being in decimal degrees, not * pre-projected x-y coordinates. The specialist looks for a property * file to know where where the shape file and spatial index file is, * and how to color the shapes. */public class ShapeSpecialist extends Specialist { /** The name of the property that holds the name of the shape file. */ public final static String shapeFileProperty = "shapeFile"; /** * The name of the property that holds the name of the spatial * index file. */ public final static String spatialIndexProperty = "spatialIndex"; /** * The name of the property that holds the line color of the * graphics. */ public final static String lineColorProperty = "lineColor"; /** * The name of the property that holds the fill color of the * graphics. */ public final static String fillColorProperty = "fillColor"; /** The spatial index to use to pick the graphics to return. */ protected SpecialistSpatialIndex spatialIndex; /** The read-in properties. */ protected Properties properties = null; /** The color to outline the shapes. */ protected SColor lineColor = null; /** The color to fill the shapes. */ protected SColor fillColor = null;// final private static SColor nullColor = new SColor((short) 0, (short) 0, (short) 0);// final private static EStipple nullStipple = new EStipple(null, (short) 0, (short) 0, new byte[0]);// final private static EComp nullComp = new EComp(null, "");// final private static XYPoint nullP1 = new XYPoint((short) 0, (short) 0);// final private static XYPoint[] nullPA = new XYPoint[0];// final private static LLPoint nullLL1 = new LLPoint(0.0f, 0.0f); /** * default constructor is called when we're loading the class * directly into OpenMap. Not used. */ public ShapeSpecialist() { super("ShapeSpecialist", (short) 2, false); } /** * The real constructor to use. * * @param shapeFile the shapefile. * @param spatialIndexFile the created index file (.ssx) for this * shp file. */ public ShapeSpecialist(String shapeFile, String spatialIndexFile) { super("ShapeSpecialist", (short) 2, false); init(shapeFile, spatialIndexFile); } /** * Loads the spatial index from the two files. * * @param shapeFile the shapefile. * @param spatialIndexFile the created index file (.ssx) for this * shp file. */ public void init(String shapeFile, String spatialIndexFile) { spatialIndex = locateAndSetShapeData(shapeFile, spatialIndexFile); } /** * Gets the layer graphics. * * @param ll1 the upper left LLPoint. * @param ll2 the lower right LLPoint. * @return OMGraphicList */ protected Vector computeGraphics(com.bbn.openmap.CSpecialist.LLPoint ll1, com.bbn.openmap.CSpecialist.LLPoint ll2) { if (spatialIndex == null) return new Vector(); Vector list = null; // check for dateline anomaly on the screen. we check for // ll1.lon >= // ll2.lon, but we need to be careful of the check for // equality because // of floating point arguments... if ((ll1.lon > ll2.lon) || MoreMath.approximately_equal(ll1.lon, ll2.lon, .001f)) { if (Debug.debugging("shape")) { Debug.output("Dateline is on screen"); } double ymin = (double) Math.min(ll1.lat, ll2.lat); double ymax = (double) Math.max(ll1.lat, ll2.lat); try { ESRIRecord records1[] = spatialIndex.locateRecords(ll1.lon, ymin, 180.0d, ymax); ESRIRecord records2[] = spatialIndex.locateRecords(-180.0d, ymin, ll2.lon, ymax); int nRecords1 = records1.length; int nRecords2 = records2.length; list = new Vector(nRecords1 + nRecords2); for (int i = 0; i < nRecords1; i++) { ((ESRISpecialistRecord) records1[i]).writeGraphics(list, lineColor, fillColor); } for (int i = 0; i < nRecords2; i++) { ((ESRISpecialistRecord) records2[i]).writeGraphics(list, lineColor, fillColor); } } catch (java.io.IOException ex) { ex.printStackTrace(); } catch (com.bbn.openmap.io.FormatException fe) { fe.printStackTrace(); } } else { double xmin = (double) Math.min(ll1.lon, ll2.lon); double xmax = (double) Math.max(ll1.lon, ll2.lon); double ymin = (double) Math.min(ll1.lat, ll2.lat); double ymax = (double) Math.max(ll1.lat, ll2.lat); try { ESRIRecord records[] = spatialIndex.locateRecords(xmin, ymin, xmax, ymax); int nRecords = records.length; list = new Vector(nRecords); for (int i = 0; i < nRecords; i++) { ((ESRISpecialistRecord) records[i]).writeGraphics(list, lineColor, fillColor); } } catch (java.io.IOException ex) { ex.printStackTrace(); } catch (com.bbn.openmap.io.FormatException fe) { fe.printStackTrace();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -