use of net.osmand.osm.MapRenderingTypes.MapRulType in project OsmAnd-tools by osmandapp.
the class IndexVectorMapCreator method processingLowLevelWays.
public void processingLowLevelWays(IProgress progress) throws SQLException {
mapLowLevelBinaryStat.executeBatch();
mapLowLevelBinaryStat.close();
pStatements.remove(mapLowLevelBinaryStat);
mapLowLevelBinaryStat = null;
mapConnection.commit();
PreparedStatement startStat = mapConnection.prepareStatement("SELECT id, end_node, nodes, name, type, addType FROM low_level_map_objects" + " WHERE start_node = ? AND level = ?");
PreparedStatement endStat = mapConnection.prepareStatement("SELECT id, start_node, nodes, name, type, addType FROM low_level_map_objects" + " WHERE end_node = ? AND level = ?");
Statement selectStatement = mapConnection.createStatement();
ResultSet rs = selectStatement.executeQuery("SELECT id, start_node, end_node, nodes, name, type, addType, level FROM low_level_map_objects");
TLongHashSet visitedWays = new TLongHashSet();
ArrayList<Float> list = new ArrayList<Float>(100);
TIntArrayList temp = new TIntArrayList();
TIntArrayList tempAdd = new TIntArrayList();
while (rs.next()) {
if (lowLevelWays != -1) {
progress.progress(1);
}
long id = rs.getLong(1);
if (visitedWays.contains(id)) {
continue;
}
visitedWays.add(id);
int level = rs.getInt(8);
int zoom = mapZooms.getLevel(level).getMaxZoom();
int minZoom = mapZooms.getLevel(level).getMinZoom();
long startNode = rs.getLong(2);
long endNode = rs.getLong(3);
namesUse.clear();
decodeNames(rs.getString(5), namesUse);
parseAndSort(typeUse, rs.getBytes(6));
parseAndSort(addtypeUse, rs.getBytes(7));
loadNodes(rs.getBytes(4), list);
ArrayList<Float> wayNodes = new ArrayList<Float>(list);
// combine startPoint with EndPoint
List<LowLevelWayCandidate> candidates = new ArrayList<LowLevelWayCandidate>();
Comparator<LowLevelWayCandidate> cmpCandidates = new Comparator<LowLevelWayCandidate>() {
@Override
public int compare(LowLevelWayCandidate o1, LowLevelWayCandidate o2) {
return -Integer.compare(o1.namesCount, o2.namesCount);
}
};
boolean combined = true;
if (minZoom >= LOW_LEVEL_ZOOM_TO_COMBINE) {
// disable combine
combined = false;
}
while (combined && wayNodes.size() < LOW_LEVEL_COMBINE_WAY_POINS_LIMIT) {
combined = false;
endStat.setLong(1, startNode);
endStat.setShort(2, (short) level);
ResultSet fs = endStat.executeQuery();
readLowLevelCandidates(fs, candidates, temp, tempAdd, visitedWays);
fs.close();
LowLevelWayCandidate cand = getCandidate(candidates, cmpCandidates);
if (cand != null) {
combined = true;
startNode = cand.otherNodeId;
visitedWays.add(cand.wayId);
loadNodes(cand.nodes, list);
ArrayList<Float> li = new ArrayList<Float>(list);
// remove first lat/lon point
wayNodes.remove(0);
wayNodes.remove(0);
li.addAll(wayNodes);
wayNodes = li;
for (MapRulType rt : new ArrayList<MapRulType>(namesUse.keySet())) {
if (!Algorithms.objectEquals(namesUse.get(rt), cand.names.get(rt)) && !checkOneLocaleHasSameName(namesUse, cand.names, rt)) {
namesUse.remove(rt);
}
}
}
}
// combined end point
combined = true;
if (minZoom >= LOW_LEVEL_ZOOM_TO_COMBINE) {
// disable combine
combined = false;
}
while (combined && wayNodes.size() < LOW_LEVEL_COMBINE_WAY_POINS_LIMIT) {
combined = false;
startStat.setLong(1, endNode);
startStat.setShort(2, (short) level);
ResultSet fs = startStat.executeQuery();
readLowLevelCandidates(fs, candidates, temp, tempAdd, visitedWays);
fs.close();
LowLevelWayCandidate cand = getCandidate(candidates, cmpCandidates);
if (cand != null) {
combined = true;
endNode = cand.otherNodeId;
visitedWays.add(cand.wayId);
loadNodes(cand.nodes, list);
for (int i = 2; i < list.size(); i++) {
wayNodes.add(list.get(i));
}
for (MapRulType rt : new ArrayList<MapRulType>(namesUse.keySet())) {
if (!Algorithms.objectEquals(namesUse.get(rt), cand.names.get(rt)) && !checkOneLocaleHasSameName(namesUse, cand.names, rt)) {
namesUse.remove(rt);
}
}
}
}
List<Node> wNodes = new ArrayList<Node>();
int wNsize = wayNodes.size();
for (int i = 0; i < wNsize; i += 2) {
wNodes.add(new Node(wayNodes.get(i), wayNodes.get(i + 1), i == 0 ? startNode : endNode));
}
boolean skip = false;
boolean cycle = startNode == endNode;
if (cycle) {
skip = checkForSmallAreas(wNodes, zoom + Math.min(zoomWaySmoothness / 2, 3), 3, 4);
} else {
// coastline
if (!typeUse.contains(renderingTypes.getCoastlineRuleType().getInternalId())) {
skip = checkForSmallAreas(wNodes, zoom + Math.min(zoomWaySmoothness / 2, 3), 2, 8);
}
}
if (!skip) {
List<Node> res = new ArrayList<Node>();
OsmMapUtils.simplifyDouglasPeucker(wNodes, zoom - 1 + 8 + zoomWaySmoothness, 3, res, false);
if (res.size() > 0) {
insertBinaryMapRenderObjectIndex(mapTree[level], res, null, namesUse, id, false, typeUse, addtypeUse, false);
}
}
// end cycle
}
}
use of net.osmand.osm.MapRenderingTypes.MapRulType in project OsmAnd-tools by osmandapp.
the class BinaryMapIndexWriter method writeMapEncodingRules.
public void writeMapEncodingRules(Map<String, MapRulType> types) throws IOException {
checkPeekState(MAP_INDEX_INIT);
ArrayList<MapRulType> out = new ArrayList<MapRulType>();
int highestTargetId = types.size();
// 1. prepare map rule type to write
for (MapRulType t : types.values()) {
if (t.getFreq() == 0 || !t.isMap()) {
t.setTargetId(highestTargetId++);
} else {
out.add(t);
}
}
// 2. sort by frequency and assign ids
Collections.sort(out, new Comparator<MapRulType>() {
@Override
public int compare(MapRulType o1, MapRulType o2) {
return o2.getFreq() - o1.getFreq();
}
});
for (int i = 0; i < out.size(); i++) {
MapEncodingRule.Builder builder = OsmandOdb.OsmAndMapIndex.MapEncodingRule.newBuilder();
MapRulType rule = out.get(i);
rule.setTargetId(i + 1);
builder.setTag(rule.getTag());
if (rule.getValue() != null) {
builder.setValue(rule.getValue());
}
builder.setMinZoom(rule.getMinzoom());
if (rule.isAdditional()) {
builder.setType(1);
} else if (rule.isText()) {
builder.setType(2);
}
MapEncodingRule rulet = builder.build();
codedOutStream.writeMessage(OsmandOdb.OsmAndMapIndex.RULES_FIELD_NUMBER, rulet);
}
}
Aggregations