/// <param name="latLong"> /// the point </param> /// <param name="tile"> /// the tile </param> /// <returns> true if the point is located in the given tile </returns> public static bool pointInTile(LatLong latLong, TileCoordinate tile) { if (latLong == null || tile == null) { return(false); } double lon1 = MercatorProjection.tileXToLongitude(tile.X, tile.Zoomlevel); double lon2 = MercatorProjection.tileXToLongitude(tile.X + 1, tile.Zoomlevel); double lat1 = MercatorProjection.tileYToLatitude(tile.Y, tile.Zoomlevel); double lat2 = MercatorProjection.tileYToLatitude(tile.Y + 1, tile.Zoomlevel); return(latLong.latitude <= lat1 && latLong.latitude >= lat2 && latLong.longitude >= lon1 && latLong.longitude <= lon2); }
private static double[] bufferInDegrees(long tileY, sbyte zoom, int enlargementInMeter) { if (enlargementInMeter == 0) { return(EPSILON_ZERO); } double[] epsilons = new double[2]; double lat = MercatorProjection.tileYToLatitude(tileY, zoom); epsilons[0] = LatLongUtils.latitudeDistance(enlargementInMeter); epsilons[1] = LatLongUtils.longitudeDistance(enlargementInMeter, lat); return(epsilons); }
private static Geometry tileToJTSGeometry(long tileX, long tileY, sbyte zoom, int enlargementInMeter) { double minLat = MercatorProjection.tileYToLatitude(tileY + 1, zoom); double maxLat = MercatorProjection.tileYToLatitude(tileY, zoom); double minLon = MercatorProjection.tileXToLongitude(tileX, zoom); double maxLon = MercatorProjection.tileXToLongitude(tileX + 1, zoom); double[] epsilons = bufferInDegrees(tileY, zoom, enlargementInMeter); minLon -= epsilons[1]; minLat -= epsilons[0]; maxLon += epsilons[1]; maxLat += epsilons[0]; Coordinate bottomLeft = new Coordinate(minLon, minLat); Coordinate topRight = new Coordinate(maxLon, maxLat); return(GEOMETRY_FACTORY.createLineString(new Coordinate[] { bottomLeft, topRight }).Envelope); }