Search in sources :

Example 1 with Amenity

use of net.osmand.data.Amenity in project OsmAnd-tools by osmandapp.

the class OsmExtractionUI method updateSearchResult.

private void updateSearchResult(final JTextField statusField, SearchResultCollection res, boolean addMore) {
    popup.setVisible(false);
    popup.removeAll();
    if (res.getCurrentSearchResults().size() > 0 || addMore) {
        int count = 30;
        if (addMore) {
            JMenuItem mi = new JMenuItem();
            mi.setText("Results " + res.getCurrentSearchResults().size() + ", radius " + res.getPhrase().getRadiusLevel() + " (show more...)");
            mi.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    SearchSettings settings = searchUICore.getPhrase().getSettings();
                    searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1));
                    SearchResultCollection collection = searchUICore.search(statusField.getText(), true, null);
                    updateSearchResult(statusField, collection, false);
                }
            });
            popup.add(mi);
        }
        for (final SearchResult sr : res.getCurrentSearchResults()) {
            count--;
            if (count == 0) {
            // break;
            }
            JMenuItem mi = new JMenuItem();
            LatLon location = res.getPhrase().getLastTokenLocation();
            String locationString = "";
            if (sr.location != null) {
                locationString = ((int) MapUtils.getDistance(location, sr.location)) / 1000.f + " km";
            }
            if (!Algorithms.isEmpty(sr.localeRelatedObjectName)) {
                locationString += " " + sr.localeRelatedObjectName;
                if (sr.distRelatedObjectName != 0) {
                    locationString += " " + (int) (sr.distRelatedObjectName / 1000.f) + " km";
                }
            }
            if (sr.objectType == ObjectType.HOUSE) {
                if (sr.relatedObject instanceof Street) {
                    locationString += " " + ((Street) sr.relatedObject).getCity().getName();
                }
            }
            if (sr.objectType == ObjectType.LOCATION) {
                locationString += " " + osmandRegions.getCountryName(sr.location);
            }
            if (sr.object instanceof Amenity) {
                locationString += " " + ((Amenity) sr.object).getSubType();
                if (((Amenity) sr.object).isClosed()) {
                    locationString += " (CLOSED)";
                }
            }
            mi.setText(sr.localeName + " [" + sr.getFoundWordCount() + ", " + sr.objectType + "] " + locationString);
            mi.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    mapPanel.setStatusField(null);
                    if (sr.location != null) {
                        mapPanel.setLatLon(sr.location.getLatitude(), sr.location.getLongitude());
                        mapPanel.setZoom(sr.preferredZoom);
                    }
                    searchUICore.selectSearchResult(sr);
                    String txt = searchUICore.getPhrase().getText(true);
                    statusField.setText(txt);
                    searchUICore.search(txt, false, null);
                    statusField.requestFocus();
                // statusField.setCaretPosition(statusField.getText().length());
                }
            });
            popup.add(mi);
        }
        // .getCaret().getMagicCaretPosition();
        Point p = statusField.getLocation();
        if (popup.isVisible()) {
            popup.setVisible(true);
        } else {
            popup.show(statusField.getParent(), p.x, p.y + statusField.getHeight() + 4);
        // popup.show();
        }
    }
}
Also used : Amenity(net.osmand.data.Amenity) ActionEvent(java.awt.event.ActionEvent) SearchResult(net.osmand.search.core.SearchResult) Point(java.awt.Point) Point(java.awt.Point) LatLon(net.osmand.data.LatLon) ActionListener(java.awt.event.ActionListener) SearchSettings(net.osmand.search.core.SearchSettings) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) Street(net.osmand.data.Street) JMenuItem(javax.swing.JMenuItem)

Example 2 with Amenity

use of net.osmand.data.Amenity in project OsmAnd-tools by osmandapp.

the class ObfDiffGenerator method comparePOI.

private void comparePOI(ObfFileInMemory fStart, ObfFileInMemory fEnd, boolean print, Set<EntityId> modifiedObjIds) {
    TLongObjectHashMap<Map<String, Amenity>> startPoiSource = fStart.getPoiObjects();
    TLongObjectHashMap<Map<String, Amenity>> endPoiSource = fEnd.getPoiObjects();
    if (endPoiSource == null) {
        return;
    }
    Map<String, Amenity> startPoi = buildPoiMap(startPoiSource);
    Map<String, Amenity> endPoi = buildPoiMap(endPoiSource);
    if (print) {
        System.out.println("Compare POI");
    }
    for (String idx : startPoi.keySet()) {
        Amenity objE = endPoi.get(idx);
        Amenity objS = startPoi.get(idx);
        EntityId aid = getAmenityId(objS);
        if (print) {
            if (objE == null) {
                System.out.println("POI " + idx + " is missing in (2): " + objS);
            } else {
                if (!objS.comparePoi(objE)) {
                    System.out.println("POI " + idx + " is not equal: " + objS + " != " + objE);
                }
                endPoi.remove(idx);
            }
        } else {
            if (objE == null) {
                if (modifiedObjIds == null || modifiedObjIds.contains(aid) || aid == null) {
                    objS.setAdditionalInfo(OSMAND_CHANGE_TAG, OSMAND_CHANGE_VALUE);
                    endPoi.put(idx, objS);
                    if (endPoiSource.get(objS.getId()) == null) {
                        endPoiSource.put(objS.getId(), new TreeMap<String, Amenity>());
                    }
                    endPoiSource.get(objS.getId()).put(objS.getType().getKeyName(), objS);
                }
            } else {
                if (objS.comparePoi(objE)) {
                    endPoi.remove(idx);
                    endPoiSource.get(objS.getId()).remove(objS.getType().getKeyName());
                }
            }
        }
    }
    if (print) {
        Iterator<Entry<String, Amenity>> it = endPoi.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, Amenity> e = it.next();
            System.out.println("POI " + e.getKey() + " is missing in (1): " + e.getValue());
        }
    }
}
Also used : EntityId(net.osmand.osm.edit.Entity.EntityId) Amenity(net.osmand.data.Amenity) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) Map(java.util.Map) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TreeMap(java.util.TreeMap)

Example 3 with Amenity

use of net.osmand.data.Amenity in project OsmAnd-tools by osmandapp.

the class ObfFileInMemory method writeFile.

public void writeFile(File targetFile, boolean doNotSimplifyObjects) throws IOException, RTreeException, SQLException {
    boolean gzip = targetFile.getName().endsWith(".gz");
    File nonGzip = targetFile;
    if (gzip) {
        nonGzip = new File(targetFile.getParentFile(), targetFile.getName().substring(0, targetFile.getName().length() - 3));
    }
    final RandomAccessFile raf = new RandomAccessFile(nonGzip, "rw");
    // write files
    CodedOutputStream ous = CodedOutputStream.newInstance(new OutputStream() {

        @Override
        public void write(int b) throws IOException {
            raf.write(b);
        }

        @Override
        public void write(byte[] b) throws IOException {
            raf.write(b);
        }

        @Override
        public void write(byte[] b, int off, int len) throws IOException {
            raf.write(b, off, len);
        }
    });
    timestamp = timestamp == 0 ? System.currentTimeMillis() : timestamp;
    int version = IndexConstants.BINARY_MAP_VERSION;
    ous.writeInt32(OsmandOdb.OsmAndStructure.VERSION_FIELD_NUMBER, version);
    ous.writeInt64(OsmandOdb.OsmAndStructure.DATECREATED_FIELD_NUMBER, timestamp);
    BinaryMapIndexWriter writer = new BinaryMapIndexWriter(raf, ous);
    String defName = targetFile.getName().substring(0, targetFile.getName().indexOf('.'));
    if (mapObjects.size() > 0) {
        String name = mapIndex.getName();
        if (Algorithms.isEmpty(name)) {
            name = defName;
        }
        writer.startWriteMapIndex(Algorithms.capitalizeFirstLetter(name));
        writer.writeMapEncodingRules(mapIndex.decodingRules);
        Iterator<Entry<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>>> it = mapObjects.entrySet().iterator();
        while (it.hasNext()) {
            Entry<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>> n = it.next();
            writeMapData(writer, n.getKey(), n.getValue(), targetFile, doNotSimplifyObjects);
        }
        writer.endWriteMapIndex();
    }
    if (routeObjects.size() > 0) {
        String name = mapIndex.getName();
        if (Algorithms.isEmpty(name)) {
            name = defName;
        }
        writer.startWriteRouteIndex(name);
        writer.writeRouteRawEncodingRules(routeIndex.routeEncodingRules);
        writeRouteData(writer, routeObjects, targetFile);
        writer.endWriteRouteIndex();
    }
    if (poiObjects.size() > 0) {
        String name = "";
        boolean overwriteIds = false;
        if (Algorithms.isEmpty(name)) {
            name = defName;
        }
        MapRenderingTypesEncoder renderingTypes = new MapRenderingTypesEncoder(null, name);
        final IndexPoiCreator indexPoiCreator = new IndexPoiCreator(renderingTypes, overwriteIds);
        File poiFile = new File(targetFile.getParentFile(), IndexCreator.getPoiFileName(name));
        indexPoiCreator.createDatabaseStructure(poiFile);
        for (Map<String, Amenity> mp : poiObjects.valueCollection()) {
            for (Amenity a : mp.values()) {
                indexPoiCreator.insertAmenityIntoPoi(a);
            }
        }
        indexPoiCreator.writeBinaryPoiIndex(writer, name, null);
        indexPoiCreator.commitAndClosePoiFile(System.currentTimeMillis());
        indexPoiCreator.removePoiFile();
    }
    // TODO Write Transport
    ous.writeInt32(OsmandOdb.OsmAndStructure.VERSIONCONFIRM_FIELD_NUMBER, version);
    ous.flush();
    raf.close();
    if (gzip) {
        nonGzip.setLastModified(timestamp);
        FileInputStream fis = new FileInputStream(nonGzip);
        GZIPOutputStream gzout = new GZIPOutputStream(new FileOutputStream(targetFile));
        Algorithms.streamCopy(fis, gzout);
        fis.close();
        gzout.close();
        nonGzip.delete();
    }
    targetFile.setLastModified(timestamp);
}
Also used : Amenity(net.osmand.data.Amenity) CodedOutputStream(com.google.protobuf.CodedOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) CodedOutputStream(com.google.protobuf.CodedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) IOException(java.io.IOException) IndexPoiCreator(net.osmand.data.preparation.IndexPoiCreator) FileInputStream(java.io.FileInputStream) Entry(java.util.Map.Entry) MapZoomPair(net.osmand.binary.MapZooms.MapZoomPair) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) RandomAccessFile(java.io.RandomAccessFile) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) BinaryMapIndexWriter(net.osmand.data.preparation.BinaryMapIndexWriter) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 4 with Amenity

use of net.osmand.data.Amenity in project OsmAnd-tools by osmandapp.

the class ObfRegionSplitter method split.

private void split(String[] args) throws IOException {
    File worldObf = new File(args[0]);
    File ocbfFile = new File(args[2]);
    File dir = new File(args[1]);
    String subFolder = args.length > 3 ? args[3] : "";
    String fileSuffix = args.length > 4 ? args[4] : "";
    if (!worldObf.exists() || !ocbfFile.exists()) {
        System.out.println("Incorrect file!");
        System.exit(1);
    }
    if (!dir.exists()) {
        dir.mkdir();
    }
    try {
        ObfFileInMemory fl = new ObfFileInMemory();
        fl.readObfFiles(Collections.singletonList(worldObf));
        OsmandRegions osmandRegions = new OsmandRegions();
        osmandRegions.prepareFile(ocbfFile.getAbsolutePath());
        osmandRegions.cacheAllCountries();
        Map<String, Map<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>>> regionsMapData = splitRegionMapData(fl, osmandRegions);
        Map<String, TLongObjectHashMap<RouteDataObject>> regionsRouteData = splitRegionRouteData(fl, osmandRegions);
        Map<String, TLongObjectHashMap<Map<String, Amenity>>> regionsPoiData = splitRegionPoiData(fl, osmandRegions);
        TreeSet<String> regionNames = new TreeSet<>();
        regionNames.addAll(regionsMapData.keySet());
        regionNames.addAll(regionsRouteData.keySet());
        for (String regionName : regionNames) {
            File folder = new File(dir, regionName);
            if (!Algorithms.isEmpty(subFolder)) {
                folder = new File(folder, subFolder);
            }
            folder.mkdirs();
            File result = new File(folder, Algorithms.capitalizeFirstLetter(regionName) + fileSuffix + ".obf.gz");
            ObfFileInMemory obf = new ObfFileInMemory();
            Map<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>> mp = regionsMapData.get(regionName);
            if (mp != null) {
                for (MapZoomPair mzPair : mp.keySet()) {
                    obf.putMapObjects(mzPair, mp.get(mzPair).valueCollection(), true);
                }
            }
            TLongObjectHashMap<RouteDataObject> ro = regionsRouteData.get(regionName);
            if (ro != null) {
                obf.putRoutingData(ro, true);
            }
            TLongObjectHashMap<Map<String, Amenity>> poi = regionsPoiData.get(regionName);
            if (poi != null) {
                obf.putPoiData(poi, true);
            }
            // TODO split Transport
            obf.updateTimestamp(fl.getTimestamp());
            obf.writeFile(result, true);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : Amenity(net.osmand.data.Amenity) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) IOException(java.io.IOException) MapZoomPair(net.osmand.binary.MapZooms.MapZoomPair) OsmandRegions(net.osmand.map.OsmandRegions) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) TreeSet(java.util.TreeSet) RouteDataObject(net.osmand.binary.RouteDataObject) File(java.io.File) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) Map(java.util.Map)

Example 5 with Amenity

use of net.osmand.data.Amenity in project OsmAnd-tools by osmandapp.

the class ObfRegionSplitter method splitRegionPoiData.

private Map<String, TLongObjectHashMap<Map<String, Amenity>>> splitRegionPoiData(ObfFileInMemory fl, OsmandRegions osmandRegions) throws IOException {
    Map<String, TLongObjectHashMap<Map<String, Amenity>>> result = new HashMap<>();
    TLongObjectHashMap<Map<String, Amenity>> poiData = fl.getPoiObjects();
    for (Map<String, Amenity> objMap : poiData.valueCollection()) {
        Amenity obj = objMap.values().iterator().next();
        int x = MapUtils.get31TileNumberX(obj.getLocation().getLongitude());
        int y = MapUtils.get31TileNumberY(obj.getLocation().getLatitude());
        List<BinaryMapDataObject> l = osmandRegions.query(x, y);
        for (BinaryMapDataObject b : l) {
            if (osmandRegions.contain(b, x, y)) {
                String dw = osmandRegions.getDownloadName(b);
                WorldRegion wr = osmandRegions.getRegionDataByDownloadName(dw);
                if (dw == null || wr == null) {
                    continue;
                }
                if (!Algorithms.isEmpty(dw) && wr.isRegionMapDownload()) {
                    TLongObjectHashMap<Map<String, Amenity>> mp = result.get(dw);
                    if (mp == null) {
                        mp = new TLongObjectHashMap<>();
                        result.put(dw, mp);
                    }
                    mp.put(obj.getId(), objMap);
                }
            }
        }
    }
    return result;
}
Also used : Amenity(net.osmand.data.Amenity) WorldRegion(net.osmand.map.WorldRegion) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) Map(java.util.Map)

Aggregations

Amenity (net.osmand.data.Amenity)53 LatLon (net.osmand.data.LatLon)17 ArrayList (java.util.ArrayList)11 PoiCategory (net.osmand.osm.PoiCategory)9 AbstractPoiType (net.osmand.osm.AbstractPoiType)8 PoiType (net.osmand.osm.PoiType)8 PointDescription (net.osmand.data.PointDescription)7 Paint (android.graphics.Paint)6 View (android.view.View)6 ImageView (android.widget.ImageView)6 HashMap (java.util.HashMap)6 FavouritePoint (net.osmand.data.FavouritePoint)6 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)5 File (java.io.File)5 Map (java.util.Map)5 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)5 QuadRect (net.osmand.data.QuadRect)5 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 LinearLayout (android.widget.LinearLayout)4