Search in sources :

Example 6 with TagValuePair

use of net.osmand.binary.BinaryMapIndexReader.TagValuePair in project Osmand by osmandapp.

the class OsmandRegions method getSearchIndex.

private String getSearchIndex(BinaryMapDataObject object) {
    MapIndex mi = object.getMapIndex();
    TIntObjectIterator<String> it = object.getObjectNames().iterator();
    StringBuilder ind = new StringBuilder();
    while (it.hasNext()) {
        it.advance();
        TagValuePair tp = mi.decodeType(it.key());
        if (tp.tag.startsWith("name") || tp.tag.equals("key_name")) {
            final String vl = it.value().toLowerCase();
            // if (!CollatorStringMatcher.ccontains(clt, ind.toString(), vl)) {
            if (ind.indexOf(vl) == -1) {
                ind.append(" ").append(vl);
            }
        }
    }
    return ind.toString();
}
Also used : MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair)

Example 7 with TagValuePair

use of net.osmand.binary.BinaryMapIndexReader.TagValuePair in project Osmand by osmandapp.

the class BinaryInspector method printOsmMapDetails.

private void printOsmMapDetails(BinaryMapDataObject obj, StringBuilder b) {
    boolean multipolygon = obj.getPolygonInnerCoordinates() != null && obj.getPolygonInnerCoordinates().length > 0;
    boolean point = obj.getPointsLength() == 1;
    StringBuilder tags = new StringBuilder();
    int[] types = obj.getTypes();
    for (int j = 0; j < types.length; j++) {
        TagValuePair pair = obj.getMapIndex().decodeType(types[j]);
        if (pair == null) {
            throw new NullPointerException("Type " + types[j] + "was not found");
        }
        tags.append("\t<tag k='").append(pair.tag).append("' v='").append(quoteName(pair.value)).append("' />\n");
    }
    if (obj.getAdditionalTypes() != null && obj.getAdditionalTypes().length > 0) {
        for (int j = 0; j < obj.getAdditionalTypes().length; j++) {
            int addtype = obj.getAdditionalTypes()[j];
            TagValuePair pair = obj.getMapIndex().decodeType(addtype);
            if (pair == null) {
                throw new NullPointerException("Type " + obj.getAdditionalTypes()[j] + "was not found");
            }
            tags.append("\t<tag k='").append(pair.tag).append("' v='").append(quoteName(pair.value)).append("' />\n");
        }
    }
    TIntObjectHashMap<String> names = obj.getObjectNames();
    if (names != null && !names.isEmpty()) {
        int[] keys = names.keys();
        for (int j = 0; j < keys.length; j++) {
            TagValuePair pair = obj.getMapIndex().decodeType(keys[j]);
            if (pair == null) {
                throw new NullPointerException("Type " + keys[j] + "was not found");
            }
            String name = names.get(keys[j]);
            name = quoteName(name);
            tags.append("\t<tag k='").append(pair.tag).append("' v='").append(name).append("' />\n");
        }
    }
    tags.append("\t<tag k=\'").append("original_id").append("' v='").append(obj.getId() >> (SHIFT_ID + 1)).append("'/>\n");
    tags.append("\t<tag k=\'").append("osmand_id").append("' v='").append(obj.getId()).append("'/>\n");
    if (point) {
        float lon = (float) MapUtils.get31LongitudeX(obj.getPoint31XTile(0));
        float lat = (float) MapUtils.get31LatitudeY(obj.getPoint31YTile(0));
        b.append("<node id = '" + OSM_ID++ + "' version='1' lat='" + lat + "' lon='" + lon + "' >\n");
        b.append(tags);
        b.append("</node>\n");
    } else {
        TLongArrayList innerIds = new TLongArrayList();
        TLongArrayList ids = new TLongArrayList();
        for (int i = 0; i < obj.getPointsLength(); i++) {
            float lon = (float) MapUtils.get31LongitudeX(obj.getPoint31XTile(i));
            float lat = (float) MapUtils.get31LatitudeY(obj.getPoint31YTile(i));
            int id = OSM_ID++;
            b.append("\t<node id = '" + id + "' version='1' lat='" + lat + "' lon='" + lon + "' />\n");
            ids.add(id);
        }
        long outerId = printWay(ids, b, multipolygon ? null : tags);
        if (multipolygon) {
            int[][] polygonInnerCoordinates = obj.getPolygonInnerCoordinates();
            for (int j = 0; j < polygonInnerCoordinates.length; j++) {
                ids.clear();
                for (int i = 0; i < polygonInnerCoordinates[j].length; i += 2) {
                    float lon = (float) MapUtils.get31LongitudeX(polygonInnerCoordinates[j][i]);
                    float lat = (float) MapUtils.get31LatitudeY(polygonInnerCoordinates[j][i + 1]);
                    int id = OSM_ID++;
                    b.append("<node id = '" + id + "' version='1' lat='" + lat + "' lon='" + lon + "' />\n");
                    ids.add(id);
                }
                innerIds.add(printWay(ids, b, null));
            }
            int id = OSM_ID++;
            b.append("<relation id = '" + id + "' version='1'>\n");
            b.append(tags);
            b.append("\t<member type='way' role='outer' ref= '" + outerId + "'/>\n");
            TLongIterator it = innerIds.iterator();
            while (it.hasNext()) {
                long ref = it.next();
                b.append("<member type='way' role='inner' ref= '" + ref + "'/>\n");
            }
            b.append("</relation>\n");
        }
    }
}
Also used : TLongArrayList(gnu.trove.list.array.TLongArrayList) TLongIterator(gnu.trove.iterator.TLongIterator) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair)

Example 8 with TagValuePair

use of net.osmand.binary.BinaryMapIndexReader.TagValuePair in project Osmand by osmandapp.

the class BinaryMapIndexFilter method process.

private Stat process(final int zoom) throws IOException {
    final Stat stat = new Stat();
    final Map<TagValuePair, Integer> map = new HashMap<TagValuePair, Integer>();
    SearchFilter sf = new SearchFilter() {

        @Override
        public boolean accept(TIntArrayList types, MapIndex index) {
            boolean polygon = false;
            boolean polyline = false;
            for (int j = 0; j < types.size(); j++) {
                int wholeType = types.get(j);
                TagValuePair pair = index.decodeType(wholeType);
                if (pair != null) {
                    int t = wholeType & 3;
                    if (t == RenderingRulesStorage.POINT_RULES) {
                        stat.pointCount++;
                    } else if (t == RenderingRulesStorage.LINE_RULES) {
                        stat.wayCount++;
                        polyline = true;
                    } else {
                        polygon = true;
                        stat.polygonCount++;
                        if (!map.containsKey(pair)) {
                            map.put(pair, 0);
                        }
                        map.put(pair, map.get(pair) + 1);
                    }
                }
            }
            stat.totalCount++;
            return polyline;
        }
    };
    ResultMatcher<BinaryMapDataObject> matcher = new ResultMatcher<BinaryMapDataObject>() {

        TIntHashSet set = new TIntHashSet();

        @Override
        public boolean isCancelled() {
            return false;
        }

        @Override
        public boolean publish(BinaryMapDataObject object) {
            // double area = calculateArea(object, zoom);
            double len = calculateLength(object, zoom);
            if (/*tilesCovers(object, zoom, set) >= 2  && */
            len > 100) {
                stat.polygonBigSize++;
                if (stat.polygonBigSize % 10000 == 0) {
                    return true;
                }
            }
            return false;
        }
    };
    SearchRequest<BinaryMapDataObject> req = BinaryMapIndexReader.buildSearchRequest(0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, zoom, sf, matcher);
    List<BinaryMapDataObject> result = reader.searchMapIndex(req);
    ArrayList<TagValuePair> list = new ArrayList<TagValuePair>(map.keySet());
    Collections.sort(list, new Comparator<TagValuePair>() {

        @Override
        public int compare(TagValuePair o1, TagValuePair o2) {
            return -map.get(o1) + map.get(o2);
        }
    });
    for (TagValuePair tp : list) {
        Integer i = map.get(tp);
        if (i > 10) {
        // System.out.println(tp.toString() + " " + i);
        }
    }
    for (BinaryMapDataObject obj : result) {
        System.out.println("id " + (obj.getId() >> 3) + " " + calculateArea(obj, zoom));
    }
    return stat;
}
Also used : HashMap(java.util.HashMap) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) SearchFilter(net.osmand.binary.BinaryMapIndexReader.SearchFilter) ResultMatcher(net.osmand.ResultMatcher) TIntArrayList(gnu.trove.list.array.TIntArrayList) TIntHashSet(gnu.trove.set.hash.TIntHashSet) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair) MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex)

Example 9 with TagValuePair

use of net.osmand.binary.BinaryMapIndexReader.TagValuePair in project Osmand by osmandapp.

the class OsmandRegions method prepareFile.

public BinaryMapIndexReader prepareFile(String fileName) throws IOException {
    reader = new BinaryMapIndexReader(new RandomAccessFile(fileName, "r"), new File(fileName));
    // final Collator clt = OsmAndCollator.primaryCollator();
    final Map<String, String> parentRelations = new LinkedHashMap<String, String>();
    final ResultMatcher<BinaryMapDataObject> resultMatcher = new ResultMatcher<BinaryMapDataObject>() {

        @Override
        public boolean publish(BinaryMapDataObject object) {
            initTypes(object);
            int[] types = object.getTypes();
            for (int i = 0; i < types.length; i++) {
                TagValuePair tp = object.getMapIndex().decodeType(types[i]);
                if ("boundary".equals(tp.value)) {
                    return false;
                }
            }
            WorldRegion rd = initRegionData(parentRelations, object);
            if (rd == null) {
                return false;
            }
            if (rd.regionDownloadName != null) {
                downloadNamesToFullNames.put(rd.regionDownloadName, rd.regionFullName);
            }
            fullNamesToRegionData.put(rd.regionFullName, rd);
            return false;
        }

        @Override
        public boolean isCancelled() {
            return false;
        }
    };
    iterateOverAllObjects(resultMatcher);
    // post process download names
    for (Map.Entry<String, String> e : parentRelations.entrySet()) {
        String fullName = e.getKey();
        String parentFullName = e.getValue();
        // String parentParentFulName = parentRelations.get(parentFullName); // could be used for japan/russia
        WorldRegion rd = fullNamesToRegionData.get(fullName);
        WorldRegion parent = fullNamesToRegionData.get(parentFullName);
        if (parent != null && rd != null) {
            parent.addSubregion(rd);
        }
    }
    structureWorldRegions(new ArrayList<WorldRegion>(fullNamesToRegionData.values()));
    return reader;
}
Also used : BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) ResultMatcher(net.osmand.ResultMatcher) LinkedHashMap(java.util.LinkedHashMap) RandomAccessFile(java.io.RandomAccessFile) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 10 with TagValuePair

use of net.osmand.binary.BinaryMapIndexReader.TagValuePair in project Osmand by osmandapp.

the class OsmandRegions method findBinaryMapDataObject.

public BinaryMapDataObject findBinaryMapDataObject(LatLon latLon) throws IOException {
    int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
    int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
    BinaryMapDataObject res = null;
    List<BinaryMapDataObject> mapDataObjects;
    try {
        mapDataObjects = queryBbox(point31x, point31x, point31y, point31y);
    } catch (IOException e) {
        throw new IOException("Error while calling queryBbox");
    }
    if (mapDataObjects != null) {
        Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
        while (it.hasNext()) {
            BinaryMapDataObject o = it.next();
            if (o.getTypes() != null) {
                boolean isRegion = true;
                for (int i = 0; i < o.getTypes().length; i++) {
                    TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
                    if ("boundary".equals(tp.value)) {
                        isRegion = false;
                        break;
                    }
                }
                WorldRegion downloadRegion = getRegionData(getFullName(o));
                if (!isRegion || downloadRegion == null || !downloadRegion.isRegionMapDownload() || !contain(o, point31x, point31y)) {
                    it.remove();
                }
            }
        }
        double smallestArea = -1;
        for (BinaryMapDataObject o : mapDataObjects) {
            double area = OsmandRegions.getArea(o);
            if (smallestArea == -1) {
                smallestArea = area;
                res = o;
            } else if (area < smallestArea) {
                smallestArea = area;
                res = o;
            }
        }
    }
    return res;
}
Also used : BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) IOException(java.io.IOException) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair)

Aggregations

TagValuePair (net.osmand.binary.BinaryMapIndexReader.TagValuePair)13 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)8 TIntArrayList (gnu.trove.list.array.TIntArrayList)4 ArrayList (java.util.ArrayList)4 Paint (android.graphics.Paint)3 IOException (java.io.IOException)3 MapIndex (net.osmand.binary.BinaryMapIndexReader.MapIndex)3 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 ResultMatcher (net.osmand.ResultMatcher)2 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)2 OsmandRegions (net.osmand.map.OsmandRegions)2 WorldRegion (net.osmand.map.WorldRegion)2 IndexItem (net.osmand.plus.download.IndexItem)2 SpannableString (android.text.SpannableString)1 TextPaint (android.text.TextPaint)1 TLongIterator (gnu.trove.iterator.TLongIterator)1 TIntHashSet (gnu.trove.set.hash.TIntHashSet)1 File (java.io.File)1