use of net.osmand.data.Street in project Osmand by osmandapp.
the class QuickSearchListFragment method showOnMap.
private void showOnMap(SearchResult searchResult) {
if (searchResult.location != null) {
SampleApplication app = getMyApplication();
String lang = searchResult.requiredSearchPhrase.getSettings().getLang();
boolean transliterate = searchResult.requiredSearchPhrase.getSettings().isTransliterate();
PointDescription pointDescription = null;
Object object = searchResult.object;
switch(searchResult.objectType) {
case POI:
Amenity a = (Amenity) object;
String poiSimpleFormat = SampleFormatter.getPoiStringWithoutType(a, lang, transliterate);
pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(a));
break;
case HOUSE:
String typeNameHouse = null;
String name = searchResult.localeName;
if (searchResult.relatedObject instanceof City) {
name = ((City) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true) + " " + name;
} else if (searchResult.relatedObject instanceof Street) {
String s = ((Street) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
typeNameHouse = ((Street) searchResult.relatedObject).getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
name = s + " " + name;
} else if (searchResult.localeRelatedObjectName != null) {
name = searchResult.localeRelatedObjectName + " " + name;
}
pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameHouse, name);
pointDescription.setIconName("ic_action_building");
break;
case LOCATION:
pointDescription = new PointDescription(searchResult.location.getLatitude(), searchResult.location.getLongitude());
pointDescription.setIconName("ic_action_world_globe");
break;
case STREET_INTERSECTION:
String typeNameIntersection = QuickSearchListItem.getTypeName(app, searchResult);
if (Algorithms.isEmpty(typeNameIntersection)) {
typeNameIntersection = null;
}
pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameIntersection, QuickSearchListItem.getName(app, searchResult));
pointDescription.setIconName("ic_action_intersection");
break;
}
dialogFragment.hideToolbar();
dialogFragment.hide();
getMainActivity().showOnMap(searchResult.location, searchResult.preferredZoom);
getMainActivity().getContextMenu().show(searchResult.location, pointDescription, object);
}
}
use of net.osmand.data.Street in project OsmAnd-tools by osmandapp.
the class BinaryMapIndexWriter method createStreetAndBuildings.
protected StreetIndex createStreetAndBuildings(Street street, int cx, int cy, String postcodeFilter, Map<Long, Set<Street>> mapNodeToStreet, Map<Street, List<Node>> wayNodes, Map<String, Integer> tagRules) throws IOException {
checkPeekState(CITY_INDEX_INIT);
StreetIndex.Builder streetBuilder = OsmandOdb.StreetIndex.newBuilder();
streetBuilder.setName(street.getName());
if (checkEnNameToWrite(street)) {
streetBuilder.setNameEn(street.getEnName(false));
}
Iterator<Entry<String, String>> it = street.getNamesMap(false).entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> next = it.next();
Integer intg = tagRules.get("name:" + next.getKey());
if (intg != null) {
streetBuilder.addAttributeTagIds(intg);
streetBuilder.addAttributeValues(next.getValue());
}
}
streetBuilder.setId(street.getId());
int sx = MapUtils.get31TileNumberX(street.getLocation().getLongitude());
int sy = MapUtils.get31TileNumberY(street.getLocation().getLatitude());
streetBuilder.setX((sx - cx) >> 7);
streetBuilder.setY((sy - cy) >> 7);
street.sortBuildings();
for (Building b : street.getBuildings()) {
if (postcodeFilter != null && !postcodeFilter.equalsIgnoreCase(b.getPostcode())) {
continue;
}
OsmandOdb.BuildingIndex.Builder bbuilder = OsmandOdb.BuildingIndex.newBuilder();
int bx = MapUtils.get31TileNumberX(b.getLocation().getLongitude());
int by = MapUtils.get31TileNumberY(b.getLocation().getLatitude());
bbuilder.setX((bx - sx) >> 7);
bbuilder.setY((by - sy) >> 7);
String number2 = b.getName2();
if (!Algorithms.isEmpty(number2)) {
LatLon loc = b.getLatLon2();
if (loc == null) {
bbuilder.setX((bx - sx) >> 7);
bbuilder.setY((by - sy) >> 7);
} else {
int bcx = MapUtils.get31TileNumberX(loc.getLongitude());
int bcy = MapUtils.get31TileNumberY(loc.getLatitude());
bbuilder.setX2((bcx - sx) >> 7);
bbuilder.setY2((bcy - sy) >> 7);
}
bbuilder.setName2(number2);
if (b.getInterpolationType() != null) {
bbuilder.setInterpolation(b.getInterpolationType().getValue());
} else if (b.getInterpolationInterval() > 0) {
bbuilder.setInterpolation(b.getInterpolationInterval());
} else {
bbuilder.setInterpolation(1);
}
}
// bbuilder.setId(b.getId());
bbuilder.setName(b.getName());
if (b.getPostcode() != null) {
bbuilder.setPostcode(b.getPostcode());
}
it = b.getNamesMap(false).entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> next = it.next();
Integer intg = tagRules.get("name:" + next.getKey());
if (intg != null) {
bbuilder.addAttributeTagIds(intg);
bbuilder.addAttributeValues(next.getValue());
}
}
if (checkEnNameToWrite(b)) {
bbuilder.setNameEn(b.getEnName(false));
}
if (postcodeFilter == null && b.getPostcode() != null) {
bbuilder.setPostcode(b.getPostcode());
}
streetBuilder.addBuildings(bbuilder.build());
}
if (wayNodes != null) {
Set<Street> checkedStreets = new TreeSet<Street>();
for (Node intersection : wayNodes.get(street)) {
for (Street streetJ : mapNodeToStreet.get(intersection.getId())) {
if (checkedStreets.contains(streetJ) || streetJ.getId().longValue() == street.getId().longValue()) {
continue;
}
checkedStreets.add(streetJ);
StreetIntersection.Builder builder = OsmandOdb.StreetIntersection.newBuilder();
int ix = MapUtils.get31TileNumberX(intersection.getLongitude());
int iy = MapUtils.get31TileNumberY(intersection.getLatitude());
builder.setIntersectedX((ix - sx) >> 7);
builder.setIntersectedY((iy - sy) >> 7);
builder.setName(streetJ.getName());
if (checkEnNameToWrite(streetJ)) {
builder.setNameEn(streetJ.getEnName(false));
}
it = streetJ.getNamesMap(false).entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> next = it.next();
Integer intg = tagRules.get("name:" + next.getKey());
if (intg != null) {
builder.addAttributeTagIds(intg);
builder.addAttributeValues(next.getValue());
}
}
streetBuilder.addIntersections(builder.build());
}
}
}
return streetBuilder.build();
}
use of net.osmand.data.Street in project OsmAnd-tools by osmandapp.
the class BinaryMapIndexWriter method writeCityIndex.
public void writeCityIndex(City cityOrPostcode, List<Street> streets, Map<Street, List<Node>> wayNodes, BinaryFileReference ref, Map<String, Integer> tagRules) throws IOException {
checkPeekState(CITY_INDEX_INIT);
codedOutStream.writeTag(CitiesIndex.BLOCKS_FIELD_NUMBER, FieldType.MESSAGE.getWireType());
codedOutStream.flush();
long startMessage = getFilePointer();
long startCityBlock = ref.getStartPointer();
ref.writeReference(raf, startMessage);
CityBlockIndex.Builder cityInd = OsmandOdb.CityBlockIndex.newBuilder();
cityInd.setShiftToCityIndex((int) (startMessage - startCityBlock));
long currentPointer = startMessage + 4 + CodedOutputStream.computeTagSize(CityBlockIndex.SHIFTTOCITYINDEX_FIELD_NUMBER);
int cx = MapUtils.get31TileNumberX(cityOrPostcode.getLocation().getLongitude());
int cy = MapUtils.get31TileNumberY(cityOrPostcode.getLocation().getLatitude());
Map<Long, Set<Street>> mapNodeToStreet = new LinkedHashMap<Long, Set<Street>>();
if (wayNodes != null) {
for (int i = 0; i < streets.size(); i++) {
for (Node n : wayNodes.get(streets.get(i))) {
if (!mapNodeToStreet.containsKey(n.getId())) {
mapNodeToStreet.put(n.getId(), new LinkedHashSet<Street>(3));
}
mapNodeToStreet.get(n.getId()).add(streets.get(i));
}
}
}
String postcodeFilter = cityOrPostcode.isPostcode() ? cityOrPostcode.getName() : null;
for (Street s : streets) {
StreetIndex streetInd = createStreetAndBuildings(s, cx, cy, postcodeFilter, mapNodeToStreet, wayNodes, tagRules);
currentPointer += CodedOutputStream.computeTagSize(CityBlockIndex.STREETS_FIELD_NUMBER);
if (currentPointer > Integer.MAX_VALUE) {
throw new IllegalArgumentException("File offset > 2 GB.");
}
s.setFileOffset((int) currentPointer);
currentPointer += CodedOutputStream.computeMessageSizeNoTag(streetInd);
cityInd.addStreets(streetInd);
}
CityBlockIndex block = cityInd.build();
int size = CodedOutputStream.computeRawVarint32Size(block.getSerializedSize());
codedOutStream.writeMessageNoTag(block);
for (Street s : streets) {
s.setFileOffset(s.getFileOffset() + size);
}
}
use of net.osmand.data.Street in project OsmAnd-tools by osmandapp.
the class MapAddressLayer method searchAddressDetailedInfo.
private void searchAddressDetailedInfo(BinaryMapIndexReader index, double lat, double lon, List<Entity> results) throws IOException {
Map<String, List<Street>> streets = new LinkedHashMap<String, List<Street>>();
log.info("Searching region ");
int[] cityType = new int[] { BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE, BinaryMapAddressReaderAdapter.POSTCODES_TYPE, BinaryMapAddressReaderAdapter.VILLAGES_TYPE };
for (int j = 0; j < cityType.length; j++) {
int type = cityType[j];
for (City c : index.getCities(null, type)) {
if (MapUtils.getDistance(c.getLocation(), lat, lon) < distance) {
log.info("Searching city " + c.getName());
index.preloadStreets(c, null);
for (Street t : c.getStreets()) {
Long id = t.getId();
if (!streets.containsKey(t.getName())) {
streets.put(t.getName(), new ArrayList<Street>());
}
streets.get(t.getName()).add(t);
// index.preloadBuildings(t, null);
// List<Street> streets = t.getIntersectedStreets();
// if (streets != null && !streets.isEmpty()) {
// for (Street s : streets) {
// // TODO
// }
// }
}
}
}
}
for (List<Street> l : streets.values()) {
while (l.size() > 0) {
Street s = l.remove(l.size() - 1);
String cityName = s.getCity().getName();
LatLon loc = s.getLocation();
Node n = new Node(loc.getLatitude(), loc.getLongitude(), -1);
for (int k = 0; k < l.size(); ) {
if (MapUtils.getDistance(l.get(k).getLocation(), loc) < 50) {
Street ks = l.remove(k);
cityName += ";" + ks.getCity().getName();
} else {
k++;
}
}
n.putTag(OSMTagKey.NAME.getValue(), s.getName() + "\n" + cityName);
results.add(n);
}
}
}
use of net.osmand.data.Street in project OsmAnd-tools by osmandapp.
the class IndexAddressCreator method readStreetsAndBuildingsForCity.
private void readStreetsAndBuildingsForCity(PreparedStatement streetBuildingsStat, City city, PreparedStatement waynodesStat, Map<Street, List<Node>> streetNodes, TLongObjectHashMap<Street> visitedStreets, Map<String, List<Street>> uniqueNames) throws SQLException {
streetBuildingsStat.setLong(1, city.getId());
ResultSet set = streetBuildingsStat.executeQuery();
while (set.next()) {
long streetId = set.getLong(1);
if (!visitedStreets.containsKey(streetId)) {
String streetName = set.getString(2);
Map<String, String> names = Algorithms.decodeMap(set.getString(3));
double lat = set.getDouble(4);
double lon = set.getDouble(5);
// load the street nodes
List<Node> thisWayNodes = loadStreetNodes(streetId, waynodesStat);
if (!uniqueNames.containsKey(streetName)) {
uniqueNames.put(streetName, new ArrayList<Street>());
}
Street street = new Street(city);
uniqueNames.get(streetName).add(street);
street.setLocation(lat, lon);
street.setId(streetId);
// If there are more streets with same name in different districts.
// Add district name to all other names. If sorting is right, the first street was the one in the city
String district = set.getString(12);
String cityPart = district == null || district.equals(city.getName()) ? "" : " (" + district + ")";
street.setName(streetName + cityPart);
for (String lang : names.keySet()) {
street.setName(lang, names.get(lang) + cityPart);
}
streetNodes.put(street, thisWayNodes);
city.registerStreet(street);
// mark the street as visited
visitedStreets.put(streetId, street);
}
if (set.getObject(6) != null) {
Street s = visitedStreets.get(streetId);
Building b = new Building();
b.setId(set.getLong(6));
b.copyNames(set.getString(7), null, Algorithms.decodeMap(set.getString(8)));
b.setLocation(set.getDouble(9), set.getDouble(10));
b.setPostcode(set.getString(11));
b.setName2(set.getString(13));
// no en name2 for now
b.setName2(set.getString(14));
double lat2 = set.getDouble(15);
double lon2 = set.getDouble(16);
if (lat2 != 0 || lon2 != 0) {
b.setLatLon2(new LatLon(lat2, lon2));
}
b.setInterpolationInterval(set.getInt(17));
String type = set.getString(18);
if (type != null) {
b.setInterpolationType(BuildingInterpolation.valueOf(type));
}
s.addBuildingCheckById(b);
}
}
set.close();
}
Aggregations