use of net.osmand.data.Street 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();
}
}
}
use of net.osmand.data.Street in project OsmAnd-tools by osmandapp.
the class BinaryMapIndexWriter method writeAddressNameIndex.
public void writeAddressNameIndex(Map<String, List<MapObject>> namesIndex) throws IOException {
checkPeekState(ADDRESS_INDEX_INIT);
codedOutStream.writeTag(OsmAndAddressIndex.NAMEINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
preserveInt32Size();
Map<String, BinaryFileReference> res = writeIndexedTable(OsmAndAddressNameIndexData.TABLE_FIELD_NUMBER, namesIndex.keySet());
for (Entry<String, List<MapObject>> entry : namesIndex.entrySet()) {
BinaryFileReference ref = res.get(entry.getKey());
codedOutStream.writeTag(OsmAndAddressNameIndexData.ATOM_FIELD_NUMBER, FieldType.MESSAGE.getWireType());
codedOutStream.flush();
long pointer = getFilePointer();
if (ref != null) {
ref.writeReference(raf, getFilePointer());
}
AddressNameIndexData.Builder builder = AddressNameIndexData.newBuilder();
// collapse same name ?
for (MapObject o : entry.getValue()) {
AddressNameIndexDataAtom.Builder atom = AddressNameIndexDataAtom.newBuilder();
// this is optional
// atom.setName(o.getName());
// if(checkEnNameToWrite(o)){
// atom.setNameEn(o.getEnName());
// }
int type = 1;
if (o instanceof City) {
if (((City) o).isPostcode()) {
type = 2;
} else {
CityType ct = ((City) o).getType();
if (ct != CityType.CITY && ct != CityType.TOWN) {
type = 3;
}
}
} else if (o instanceof Street) {
type = 4;
}
atom.setType(type);
LatLon ll = o.getLocation();
int x = (int) MapUtils.getTileNumberX(16, ll.getLongitude());
int y = (int) MapUtils.getTileNumberY(16, ll.getLatitude());
atom.addXy16((x << 16) + y);
atom.addShiftToIndex((int) (pointer - o.getFileOffset()));
if (o instanceof Street) {
atom.addShiftToCityIndex((int) (pointer - ((Street) o).getCity().getFileOffset()));
}
builder.addAtom(atom.build());
}
codedOutStream.writeMessageNoTag(builder.build());
}
int len = writeInt32Size();
log.info("ADDRESS NAME INDEX SIZE : " + len);
}
use of net.osmand.data.Street in project OsmAnd-tools by osmandapp.
the class IndexAddressCreator method readStreetsBuildings.
private List<Street> readStreetsBuildings(PreparedStatement streetBuildingsStat, City city, PreparedStatement waynodesStat, Map<Street, List<Node>> streetNodes, List<City> citySuburbs) throws SQLException {
TLongObjectHashMap<Street> visitedStreets = new TLongObjectHashMap<Street>();
Map<String, List<Street>> uniqueNames = new TreeMap<String, List<Street>>(OsmAndCollator.primaryCollator());
// read streets for city
readStreetsAndBuildingsForCity(streetBuildingsStat, city, waynodesStat, streetNodes, visitedStreets, uniqueNames);
// read streets for suburbs of the city
if (citySuburbs != null) {
for (City suburb : citySuburbs) {
readStreetsAndBuildingsForCity(streetBuildingsStat, suburb, waynodesStat, streetNodes, visitedStreets, uniqueNames);
}
}
mergeStreetsWithSameNames(streetNodes, uniqueNames);
return new ArrayList<Street>(streetNodes.keySet());
}
use of net.osmand.data.Street in project OsmAnd-tools by osmandapp.
the class IndexAddressCreator method writeCityBlockIndex.
private void writeCityBlockIndex(BinaryMapIndexWriter writer, int type, PreparedStatement streetstat, PreparedStatement waynodesStat, List<City> suburbs, List<City> cities, Map<String, City> postcodes, Map<String, List<MapObject>> namesIndex, Map<String, Integer> tagRules, IProgress progress) throws IOException, SQLException {
List<BinaryFileReference> refs = new ArrayList<BinaryFileReference>();
// 1. write cities
writer.startCityBlockIndex(type);
for (City c : cities) {
refs.add(writer.writeCityHeader(c, c.getType().ordinal(), tagRules));
}
for (int i = 0; i < cities.size(); i++) {
City city = cities.get(i);
BinaryFileReference ref = refs.get(i);
putNamedMapObject(namesIndex, city, ref.getStartPointer());
if (type == CITIES_TYPE) {
progress.progress(1);
} else {
if ((cities.size() - i) % 100 == 0) {
progress.progress(1);
}
}
Map<Street, List<Node>> streetNodes = new LinkedHashMap<Street, List<Node>>();
List<City> listSuburbs = null;
if (suburbs != null) {
for (City suburb : suburbs) {
if (suburb.getIsInValue().toLowerCase().contains(city.getName().toLowerCase())) {
if (listSuburbs == null) {
listSuburbs = new ArrayList<City>();
}
listSuburbs.add(suburb);
}
}
}
long time = System.currentTimeMillis();
List<Street> streets = readStreetsBuildings(streetstat, city, waynodesStat, streetNodes, listSuburbs);
long f = System.currentTimeMillis() - time;
writer.writeCityIndex(city, streets, streetNodes, ref, tagRules);
int bCount = 0;
// register postcodes and name index
for (Street s : streets) {
putNamedMapObject(namesIndex, s, s.getFileOffset());
for (Building b : s.getBuildings()) {
bCount++;
if (city.getPostcode() != null && b.getPostcode() == null) {
b.setPostcode(city.getPostcode());
}
if (b.getPostcode() != null) {
if (!postcodes.containsKey(b.getPostcode())) {
City p = City.createPostcode(b.getPostcode());
p.setLocation(b.getLocation().getLatitude(), b.getLocation().getLongitude());
postcodes.put(b.getPostcode(), p);
}
City post = postcodes.get(b.getPostcode());
Street newS = post.getStreetByName(s.getName());
if (newS == null) {
newS = new Street(post);
newS.copyNames(s);
newS.setLocation(s.getLocation().getLatitude(), s.getLocation().getLongitude());
// newS.getWayNodes().addAll(s.getWayNodes());
newS.setId(s.getId());
post.registerStreet(newS);
}
newS.addBuildingCheckById(b);
}
}
}
if (f > 500) {
if (logMapDataWarn != null) {
logMapDataWarn.info("! " + city.getName() + " ! " + f + " ms " + streets.size() + " streets " + bCount + " buildings");
} else {
log.info("! " + city.getName() + " ! " + f + " ms " + streets.size() + " streets " + bCount + " buildings");
}
}
}
writer.endCityBlockIndex();
}
use of net.osmand.data.Street in project OsmAnd-tools by osmandapp.
the class IndexAddressCreator method mergeStreets.
private void mergeStreets(List<Street> streets, Map<Street, List<Node>> streetNodes) {
// Merge streets to streets with biggest amount of intersections.
// Streets, that were extracted from addr:street tag has no intersections at all.
Collections.sort(streets, new Comparator<Street>() {
@Override
public int compare(Street s0, Street s1) {
return Algorithms.compare(s0.getIntersectedStreets().size(), s1.getIntersectedStreets().size());
}
});
for (int i = 0; i < streets.size() - 1; ) {
Street s = streets.get(i);
boolean merged = false;
for (int j = i + 1; j < streets.size(); ) {
Street candidate = streets.get(j);
if (getDistance(s, candidate, streetNodes) <= 900) {
merged = true;
// logMapDataWarn.info("City : " + s.getCity() +
// " combine 2 district streets '" + s.getName() + "' with '" + candidate.getName() + "'");
s.mergeWith(candidate);
candidate.getCity().unregisterStreet(candidate);
List<Node> old = streetNodes.remove(candidate);
streetNodes.get(s).addAll(old);
streets.remove(j);
} else {
j++;
}
}
if (!merged) {
i++;
}
}
}
Aggregations