protected void initializeSphere( WorldWindow wwd, SphereAirspace sphere, boolean fitShapeToViewport) { // Creates a sphere in the center of the viewport. Attempts to guess at a reasonable size and // height. Position position = ShapeUtils.getNewShapePosition(wwd); double sizeInMeters = fitShapeToViewport ? ShapeUtils.getViewportScaleFactor(wwd) : DEFAULT_SHAPE_SIZE_METERS; sphere.setLocation(new LatLon(position)); sphere.setRadius(sizeInMeters / 2.0); }
public void setAngle(float angle) { float a = ShapeUtils.normalizeAngle(angle); if (this.angle != a) { this.angle = a; calculateShape(); } }
/** @param recBuf */ public SHPPolyLine3D(byte[] recBuf) { super(recBuf); int pointsStart = 0; int sumPoints = 0; envelope = ShapeUtils.readBox(recBuf, 4); numParts = ByteUtils.readLEInt(recBuffer, 36); numPoints = ByteUtils.readLEInt(recBuffer, 40); pointsStart = ShapeConst.PARTS_START + (numParts * 4); points = new SHPPoint[numParts][]; for (int j = 0; j < numParts; j++) { int firstPointNo = 0; int nextFirstPointNo = 0; int offset = 0; int lnumPoints = 0; // get number of first point of current part out of ESRI shape Record: firstPointNo = ByteUtils.readLEInt(recBuffer, ShapeConst.PARTS_START + (j * 4)); // calculate offset of part in bytes, count from the beginning of recordbuffer offset = pointsStart + (firstPointNo * 16); // get number of first point of next part ... if (j < numParts - 1) { // ... usually out of ESRI shape Record nextFirstPointNo = ByteUtils.readLEInt(recBuffer, ShapeConst.PARTS_START + ((j + 1) * 4)); } // ... for the last part as total number of points else if (j == numParts - 1) { nextFirstPointNo = numPoints; } // calculate number of points per part due to distance and // calculate some checksum for the total number of points to be worked lnumPoints = nextFirstPointNo - firstPointNo; sumPoints += lnumPoints; // allocate memory for the j-th part points[j] = new SHPPoint[lnumPoints]; int zPos = pointsStart + 16 * numPoints + 16; // create the points of the j-th part from the buffer for (int i = 0; i < lnumPoints; i++) { double z = ByteUtils.readLEDouble(recBuffer, zPos); zPos += 8; SHPPoint dummyPoint = new SHPPoint(recBuf, offset + (i * 16)); points[j][i] = new SHPPoint3D(dummyPoint.x, dummyPoint.y, z); } } }
public Fan(float cx, float cy, Shape blade, int blades, float angle, float bladeCx) { validateBladeCx(bladeCx); validateBlades(blades); this.cx = cx; this.cy = cy; this.blade = blade; this.angle = ShapeUtils.normalizeAngle(angle); this.bladeCx = bladeCx; this.blades = blades; calculateShape(); }
/** * method: writeHeader(int filelength, byte shptype,SHPEnvelope mbr)<br> * Writes a header into the shape file.<br> * * @param filelength * @param shptype * @param mbr * @throws IOException */ public void writeHeader(int filelength, int shptype, SHPEnvelope mbr) throws IOException { header = new byte[ShapeConst.SHAPE_FILE_HEADER_LENGTH]; ByteUtils.writeBEInt(header, 0, ShapeConst.SHAPE_FILE_CODE); ByteUtils.writeBEInt(header, 24, filelength / 2); ByteUtils.writeLEInt(header, 28, ShapeConst.SHAPE_FILE_VERSION); ByteUtils.writeLEInt(header, 32, shptype); ShapeUtils.writeBox(header, 36, mbr); rafShp.seek(0); rafShp.write(header, 0, ShapeConst.SHAPE_FILE_HEADER_LENGTH); }
protected void initializePolygon(WorldWindow wwd, Polygon polygon, boolean fitShapeToViewport) { // Creates a rectangle in the center of the viewport. Attempts to guess at a reasonable size // and height. Position position = ShapeUtils.getNewShapePosition(wwd); Angle heading = ShapeUtils.getNewShapeHeading(wwd, true); double sizeInMeters = fitShapeToViewport ? ShapeUtils.getViewportScaleFactor(wwd) : DEFAULT_SHAPE_SIZE_METERS; java.util.List<LatLon> locations = ShapeUtils.createSquareInViewport(wwd, position, heading, sizeInMeters); double maxElevation = -Double.MAX_VALUE; Globe globe = wwd.getModel().getGlobe(); for (LatLon ll : locations) { double e = globe.getElevation(ll.getLatitude(), ll.getLongitude()); if (e > maxElevation) maxElevation = e; } polygon.setAltitudes(0.0, maxElevation + sizeInMeters); polygon.setTerrainConforming(true, false); polygon.setLocations(locations); }
private void calculateShape() { float t = 360 / blades; float a = angle; a = a > 360 ? a - 360 : a; fan = new Area(); for (int i = 0; i < blades; i++) { Shape b = new Area(blade); Rectangle2D bounds = b.getBounds2D(); b = AffineTransform.getTranslateInstance( cx - bounds.getX() - bounds.getWidth() / 2, cy - bounds.getY()) .createTransformedShape(b); bounds = b.getBounds2D(); float bcx = (float) ((bounds.getWidth() * bladeCx) + bounds.getX()); b = ShapeUtils.rotate(b, a, bcx, cy); ((Area) fan).add(new Area(b)); a += t; a = a > 360 ? a - 360 : a; } }
/** * Reads and parses the header of the file. Values from the header<br> * are stored in the fields of this class.<br> */ private void readHeader() throws IOException { header = new byte[ShapeConst.SHAPE_FILE_HEADER_LENGTH]; /* * Make sure we're at the beginning of the file */ rafShp.seek(0); rafShp.read(header, 0, ShapeConst.SHAPE_FILE_HEADER_LENGTH); int fileCode = ByteUtils.readBEInt(header, 0); if (fileCode != ShapeConst.SHAPE_FILE_CODE) { throw new IOException("Invalid file code, " + "probably not a shape file"); } fileVersion = ByteUtils.readLEInt(header, 28); if (fileVersion != ShapeConst.SHAPE_FILE_VERSION) { throw new IOException("Unable to read shape files with version " + fileVersion); } fileLength = ByteUtils.readBEInt(header, 24); /* * convert from 16-bit words to 8-bit bytes */ fileLength *= 2; fileShapeType = ByteUtils.readLEInt(header, 32); /* * read ESRIBoundingBox and convert to SHPEnvelope */ fileMBR = new SHPEnvelope(ShapeUtils.readBox(header, 36)); }