Код: Выделить всё
private void escribeMbTiles(String rutaMbtiles, String tilesSerialized, String codigoEquipamiento, String LCorner,
String UCorner) throws IOException, MBTilesWriteException {
double left, bottom, right, top;
String[] coords;
Tile[] tiles = new ObjectMapper().readValue(tilesSerialized, Tile[].class);
FileUtils.copyFile(new File(getUploadPath() + "Plantilla_Senderos.mbtiles"), new File(rutaMbtiles));
// Archivo a generar
MBTilesWriter w = new MBTilesWriter(new File(rutaMbtiles));
// Separar las coordenadas de la esquina inferior izquierda
coords = LCorner.split(" ");
bottom = Double.parseDouble(coords[0]);
left = Double.parseDouble(coords[1]);
// Separar las coordenadas de la esquina superior derecha
coords = UCorner.split(" ");
top = Double.parseDouble(coords[0]);
right = Double.parseDouble(coords[1]);
// Metadatos del mbtiles
MetadataEntry ent = new MetadataEntry();
logger.info("Metadata creado con la siguiente info:\ncodigo equipamiento: "+codigoEquipamiento+"\nTilesetType: "+MetadataEntry.TileSetType.BASE_LAYER+"\nTileMimeType: "+MetadataEntry.TileMimeType.JPG+"Bounds: l:"+left+", b:"+bottom+", r:"+right+", t:"+top);
ent.setTilesetName(codigoEquipamiento).setTilesetType(MetadataEntry.TileSetType.BASE_LAYER)
.setTilesetVersion("1.0").setTilesetDescription("Senderos oficiales de Andalucía")
.setTileMimeType(MetadataEntry.TileMimeType.JPG).setTilesetBounds(left, bottom, right, top);
w.addMetadataEntry(ent);
logger.info("Metadata insertado, se procede a recuperar los tiles");
for (Tile t : Tools.ordenacionMBTiles(tiles)) {
// Abrimos conexión seteando user-Agent
final HttpURLConnection conn = (HttpURLConnection) new URL(t.getUrl()).openConnection();
conn.setRequestProperty("User-Agent",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31");
// Fetch de la imagen url
InputStream in = new BufferedInputStream(conn.getInputStream());
// Extraer "z", "x" y "y" de la URL del tile
String[] coordenadas = t.getNombre().split("_");
if (coordenadas.length == 4) {
int zoom = Integer.parseInt(coordenadas[1]);
int column = Integer.parseInt(coordenadas[2]);
int row = Integer.valueOf(t.getRow());
// Agregar el tile al archivo MBTiles con los valores de "z", "x" y "y"
w.addTile(in, zoom, column, row);
}
}
w.close();
}
Код: Выделить всё
error de escritura mbtiles: org.imintel.mbtiles4j.MBTilesWriteException: Add metadata failed.
Я попробовал проверить этот шаблон MBTiles не поврежден (это не так)
Подробнее здесь: https://stackoverflow.com/questions/787 ... d-metadata