private Image getMapImage (TileIndex tile) { WebMercatorTilePyramid mercator = new WebMercatorTilePyramid(); Rectangle2D bounds = mercator.getEPSG_900913Bounds(tile, null); String url = String.format("http://129.206.228.72/cached/osm?LAYERS=osm_auto:all&STYLES=&" + "SRS=EPSG%%3A900913&FORMAT=image%%2Fpng&SERVICE=WMS&VERSION=1.1.1" + "&REQUEST=GetMap&BBOX=%.3f,%.3f,%.3f,%.3f&WIDTH=1024&HEIGHT=1024", bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMaxY()); try { return getToolkit().getImage(new URL(url)); } catch (MalformedURLException e) { return null; } }
@Override public TileIndex rootToTile (Point2D point, int level) { return rootToTile(point, level, 256, 256); }
protected double linearToGudermannian (double value) { // convert linear coordinates into their equivalent gudermannian counterparts return gudermannian( (value / EPSG_900913_LATITUDE) * Math.PI ); }
/** * Get the tiling projection used to create the tile pyramid described by * this metadata object. */ public TilePyramid getTilePyramid () { try { String projection = _metaData.getString("projection"); if ("EPSG:4326".equals(projection)) { JSONArray bounds = _metaData.getJSONArray("bounds"); double xMin = bounds.getDouble(0); double yMin = bounds.getDouble(1); double xMax = bounds.getDouble(2); double yMax = bounds.getDouble(3); return new AOITilePyramid(xMin, yMin, xMax, yMax); } else if ("EPSG:900913".equals(projection) || "EPSG:3857".equals(projection)) { return new WebMercatorTilePyramid(); } } catch (JSONException e) { LOGGER.log(Level.WARNING, "Bad projection data in tile pyramid", e); } return null; }
@Test public void testRoundTripTransformation () { for (int level=0; level<4; ++level) { int pow2 = 1 << level; for (int x = 0; x<pow2; ++x) { for (int y=0; y<pow2; ++y) { TileIndex t0 = new TileIndex(level, x, y); Rectangle2D tileBounds = _mercator.getTileBounds(t0); TileIndex t1 = _mercator.rootToTile(getCenter(tileBounds), level); Assert.assertEquals(t0, t1); for (int dx=0; dx<t0.getXBins(); ++dx) { for (int dy=0; dy<t0.getYBins(); ++dy) { BinIndex b0 = new BinIndex(dx, dy); Rectangle2D binBounds = _mercator.getBinBounds(t0, b0); BinIndex b1 = _mercator.rootToBin(getCenter(binBounds), t0); Assert.assertEquals(b0, b1); } } } } } }
@Ignore @Test public void isolateTestCases () { WebMercatorTilePyramid mercator = new WebMercatorTilePyramid(); for (int y=-3; y<4; ++y) { BinIndex bin = new BinIndex(127+x, 127+y); Rectangle2D bounds = mercator.getBinBounds(tile, bin); int reps = Math.max(0, 16-((x*x+y*y))); for (int i=0; i<reps; ++i) { BinIndex xbin = new BinIndex(131+n, 127); BinIndex ybin = new BinIndex(127, 131+n); Rectangle2D xbounds = mercator.getBinBounds(tile, xbin); Rectangle2D ybounds = mercator.getBinBounds(tile, ybin); for (int i=0; i<16; ++i) { System.out.println(String.format("ais(3.0), 0, 'test ship', '', %.6f, %.6f, 0.0, 0.0, 1207040300, 'TEST', 0203011000",
@Test public void testBounds () { int minBinX = 1000; int maxBinX = -1000; int minBinY = 1000; int maxBinY = -1000; for (int i=0; i<10000000; ++i) { double longitude = Math.random()*180-180; double latitude = Math.random()*90-90; Point2D pt = new Point2D.Double(longitude, latitude); TileIndex tile = _mercator.rootToTile(pt, 1); if (0 != tile.getX() || 0 != tile.getY()) continue; BinIndex bin = _mercator.rootToBin(pt, tile); if (bin.getX() < minBinX) minBinX = bin.getX(); if (bin.getX() > maxBinX) maxBinX = bin.getX(); if (bin.getY() < minBinY) minBinY = bin.getY(); if (bin.getY() > maxBinY) maxBinY = bin.getY(); } Assert.assertEquals(0, minBinX); Assert.assertEquals(0, minBinY); Assert.assertEquals(255, maxBinX); Assert.assertEquals(255, maxBinY); }
@Test public void testBoundingBoxes () { TileIndex tile = new TileIndex(10, 14, 6, 256, 256); Rectangle2D tileBounds = _mercator.getTileBounds(tile); BinIndex bll = new BinIndex(0, 255); BinIndex bur = new BinIndex(255, 0); Rectangle2D llBounds = _mercator.getBinBounds(tile, bll); Rectangle2D urBounds = _mercator.getBinBounds(tile, bur); Assert.assertEquals(llBounds.getMinX(), tileBounds.getMinX(), EPSILON); Assert.assertEquals(urBounds.getMaxX(), tileBounds.getMaxX(), EPSILON); Assert.assertEquals(llBounds.getMinY(), tileBounds.getMinY(), EPSILON); Assert.assertEquals(urBounds.getMaxY(), tileBounds.getMaxY(), EPSILON); }
Rectangle2D realBounds = _mercator.getBinBounds(tile, bin); Assert.assertEquals(1.0, _mercator.getBinOverlap(tile, bin, realBounds), EPSILON); realBounds.getWidth() / 2.0, realBounds.getHeight()); Assert.assertEquals(0.5, _mercator.getBinOverlap(tile, bin, leftHalf), EPSILON); realBounds.getWidth() / 2.0, realBounds.getHeight()); Assert.assertEquals(0.5, _mercator.getBinOverlap(tile, bin, rightHalf), EPSILON); realBounds.getWidth(), realBounds.getHeight() / 2.0); double topOverlap = _mercator.getBinOverlap(tile, bin, topHalf); Assert.assertTrue(0.5 > topOverlap); Assert.assertTrue(0.0 < topOverlap); realBounds.getWidth(), realBounds.getHeight() / 2.0); double bottomOverlap = _mercator.getBinOverlap(tile, bin, bottomHalf); Assert.assertTrue(0.5 < bottomOverlap); Assert.assertTrue(1.0 > bottomOverlap); realBounds.getHeight() / 2.0); Assert.assertEquals(bottomOverlap / 2.0,
@Test public void testEPSG900913Projection () { TileIndex tile = new TileIndex(1, 0, 0); Rectangle2D bounds = _mercator.getEPSG_900913Bounds(tile, null); Assert.assertEquals(-20037508.342789244, bounds.getMinX(), EPSILON); Assert.assertEquals(-20037508.342789244, bounds.getMinY(), EPSILON); Assert.assertEquals(0, bounds.getMaxX(), EPSILON); Assert.assertEquals(0, bounds.getMaxY(), EPSILON); tile = new TileIndex(3, 1, 2); bounds = _mercator.getEPSG_900913Bounds(tile, null); Assert.assertEquals(-15028131.257091932, bounds.getMinX(), WORLD_SCALE_EPSILON); Assert.assertEquals(-10018754.171394622, bounds.getMaxX(), WORLD_SCALE_EPSILON); Assert.assertEquals(-10018754.171394622 , bounds.getMinY(), WORLD_SCALE_EPSILON); Assert.assertEquals(-5009377.085697312, bounds.getMaxY(), WORLD_SCALE_EPSILON); }
@Test public void testLevel0 () { TileIndex tile = new TileIndex(0, 0, 0); Rectangle2D tileBounds = _mercator.getTileBounds(tile); Assert.assertEquals(-180.0, tileBounds.getMinX(), EPSILON); Assert.assertEquals(180.0, tileBounds.getMaxX(), EPSILON); Assert.assertEquals(-85.05112877980659, tileBounds.getMinY(), EPSILON); Assert.assertEquals(85.05112877980659, tileBounds.getMaxY(), EPSILON); }
protected double gudermannianToLinear (double value) { // convert gudermannian coordinates into their equivalent linear counterparts return (gudermannianInv( value ) / Math.PI) * EPSG_900913_LATITUDE; }
@Test public void testBoundingBoxDirection () { TileIndex tile = new TileIndex(5, 23, 17); BinIndex bin = new BinIndex(34, 78); Rectangle2D bounds = _mercator.getBinBounds(tile, bin); Assert.assertTrue(bounds.getMaxX() > bounds.getMinX()); Assert.assertTrue(bounds.getMaxY() > bounds.getMinY()); }
@Before public void setup () { _mercator = new WebMercatorTilePyramid(); }
@Test public void testLevel2 () { TileIndex tile; Rectangle2D bounds; tile = new TileIndex(2, 0, 0); bounds = _mercator.getTileBounds(tile); Assert.assertEquals(-180.0, bounds.getMinX(), EPSILON); Assert.assertEquals(-85.05112877980659, bounds.getMinY(), EPSILON); Assert.assertEquals(-90.0, bounds.getMaxX(), EPSILON); Assert.assertEquals(-66.51326044311186, bounds.getMaxY(), EPSILON); tile = new TileIndex(2, 3, 3); bounds = _mercator.getTileBounds(tile); Assert.assertEquals(180.0, bounds.getMaxX(), EPSILON); Assert.assertEquals(85.05112877980659, bounds.getMaxY(), EPSILON); Assert.assertEquals(90.0, bounds.getMinX(), EPSILON); Assert.assertEquals(66.51326044311186, bounds.getMinY(), EPSILON); }
@Override protected TilePyramid create () throws ConfigurationException { String pyramidType = getPropertyValue(PYRAMID_TYPE).toLowerCase(); if ("webmercator".equals(pyramidType) || "epsg:900913".equals(pyramidType) || "epsg:3857".equals(pyramidType)) { return new WebMercatorTilePyramid(); } else if ("areaofinterest".equals(pyramidType) || "epsg:4326".equals(pyramidType)) { double minX = getPropertyValue(MINIMUM_X); double maxX = getPropertyValue(MAXIMUM_X); double minY = getPropertyValue(MINIMUM_Y); double maxY = getPropertyValue(MAXIMUM_Y); return new AOITilePyramid(minX, minY, maxX, maxY); } else { throw new ConfigurationException("Unrecognized pyramid type "+pyramidType); } } }
@Override public TileIndex rootToTile (double x, double y, int level) { return rootToTile(x, y, level, 256, 256); }
@Test public void testLevel1 () { TileIndex tile; Rectangle2D bounds; tile = new TileIndex(1, 0, 0); bounds = _mercator.getTileBounds(tile); Assert.assertEquals(-180.0, bounds.getMinX(), EPSILON); Assert.assertEquals(-85.05112877980659, bounds.getMinY(), EPSILON); Assert.assertEquals(0.0, bounds.getMaxX(), EPSILON); Assert.assertEquals(0.0, bounds.getMaxY(), EPSILON); tile = new TileIndex(1, 0, 1); bounds = _mercator.getTileBounds(tile); Assert.assertEquals(-180.0, bounds.getMinX(), EPSILON); Assert.assertEquals(0.0, bounds.getMinY(), EPSILON); Assert.assertEquals(0.0, bounds.getMaxX(), EPSILON); Assert.assertEquals(85.05112877980659, bounds.getMaxY(), EPSILON); tile = new TileIndex(1, 1, 0); bounds = _mercator.getTileBounds(tile); Assert.assertEquals(0.0, bounds.getMinX(), EPSILON); Assert.assertEquals(-85.05112877980659, bounds.getMinY(), EPSILON); Assert.assertEquals(180.0, bounds.getMaxX(), EPSILON); Assert.assertEquals(0.0, bounds.getMaxY(), EPSILON); tile = new TileIndex(1, 1, 1); bounds = _mercator.getTileBounds(tile); Assert.assertEquals(0.0, bounds.getMinX(), EPSILON); Assert.assertEquals(0.0, bounds.getMinY(), EPSILON); Assert.assertEquals(180.0, bounds.getMaxX(), EPSILON); Assert.assertEquals(85.05112877980659, bounds.getMaxY(), EPSILON); }
@Before public void setup () { _pyramid = new WebMercatorTilePyramid(); _indexer = new AnnotationIndexerImpl(); }
@Before public void setup () { _pyramid = new WebMercatorTilePyramid(); _indexer = new AnnotationIndexerImpl(); }