fix issue 146

git-svn-id: https://osmand.googlecode.com/svn/trunk@663 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-11-12 20:31:35 +00:00
parent 2bbe41fa7d
commit a2dbdbd399
4 changed files with 85 additions and 75 deletions

View file

@ -1,6 +1,7 @@
package net.osmand.data; package net.osmand.data;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import net.osmand.osm.Entity; import net.osmand.osm.Entity;
import net.osmand.osm.MapRenderingTypes; import net.osmand.osm.MapRenderingTypes;
@ -17,11 +18,12 @@ public class Amenity extends MapObject {
private String phone; private String phone;
private String site; private String site;
public Amenity(Entity entity){ public Amenity(Entity entity, AmenityType type, String subtype){
super(entity); super(entity);
// manipulate with id to distinguish way and nodes // manipulate with id to distinguish way and nodes
this.id = entity.getId() << 1 + ((entity instanceof Node)? 0 : 1); this.id = entity.getId() << 1 + ((entity instanceof Node)? 0 : 1);
initTypeSubtype(entity, this); this.type = type;
this.subType = subtype;
this.openingHours = entity.getTag(OSMTagKey.OPENING_HOURS); this.openingHours = entity.getTag(OSMTagKey.OPENING_HOURS);
this.phone = entity.getTag(OSMTagKey.PHONE); this.phone = entity.getTag(OSMTagKey.PHONE);
if (this.phone == null) { if (this.phone == null) {
@ -51,32 +53,6 @@ public class Amenity extends MapObject {
public Amenity(){ public Amenity(){
} }
private static AmenityType initTypeSubtype(Entity entity, Amenity init) {
Collection<String> keySet = entity.getTagKeySet();
if (!keySet.isEmpty()) {
for (String t : keySet) {
AmenityType type = MapRenderingTypes.getAmenityType(t, entity.getTag(t));
if (type != null) {
if (init != null) {
init.type = type;
init.subType = MapRenderingTypes.getAmenitySubtype(t, entity.getTag(t));
}
return type;
}
}
for (String t : keySet) {
AmenityType type = MapRenderingTypes.getAmenityType(t, null);
if (type != null) {
if (init != null) {
init.type = type;
init.subType = MapRenderingTypes.getAmenitySubtype(t, entity.getTag(t));
}
return type;
}
}
}
return null;
}
public AmenityType getType(){ public AmenityType getType(){
return type; return type;
} }
@ -93,12 +69,33 @@ public class Amenity extends MapObject {
this.subType = subType; this.subType = subType;
} }
public static boolean isAmenity(Entity n){ public static List<Amenity> parseAmenities(Entity entity, List<Amenity> amenitiesList){
if(n instanceof Relation){ if(entity instanceof Relation){
// it could be collection of amenities // it could be collection of amenities
return false; return amenitiesList;
} }
return initTypeSubtype(n, null) != null;
Collection<String> keySet = entity.getTagKeySet();
if (!keySet.isEmpty()) {
int shift = 0;
for (String t : keySet) {
AmenityType type = MapRenderingTypes.getAmenityType(t, entity.getTag(t));
if (type != null) {
String subtype = MapRenderingTypes.getAmenitySubtype(t, entity.getTag(t));
amenitiesList.add(shift, new Amenity(entity, type, subtype));
shift++;
} else {
type = MapRenderingTypes.getAmenityType(t, null);
if (type != null) {
String subtype = MapRenderingTypes.getAmenitySubtype(t, entity.getTag(t));
// add amenity to the end
amenitiesList.add(new Amenity(entity, type, subtype));
}
}
}
}
return amenitiesList;
} }
public String getOpeningHours() { public String getOpeningHours() {

View file

@ -1109,12 +1109,18 @@ public class IndexCreator {
return foundId; return foundId;
} }
private List<Amenity> tempAmenityList = new ArrayList<Amenity>();
private void iterateEntity(Entity e, int step) throws SQLException { private void iterateEntity(Entity e, int step) throws SQLException {
if (step == STEP_MAIN) { if (step == STEP_MAIN) {
if (indexPOI && Amenity.isAmenity(e)) { if (indexPOI) {
tempAmenityList.clear();
tempAmenityList = Amenity.parseAmenities(e, tempAmenityList);
if(!tempAmenityList.isEmpty() && poiPreparedStatement != null){
// load data for way (location etc...)
loadEntityData(e, false); loadEntityData(e, false);
if (poiPreparedStatement != null) { for (Amenity a : tempAmenityList) {
Amenity a = new Amenity(e); a.setEntity(e);
if (a.getLocation() != null) { if (a.getLocation() != null) {
// do not convert english name // do not convert english name
// convertEnglishName(a); // convertEnglishName(a);
@ -1122,6 +1128,7 @@ public class IndexCreator {
} }
} }
} }
}
if (indexTransport) { if (indexTransport) {
if (e instanceof Relation && e.getTag(OSMTagKey.ROUTE) != null) { if (e instanceof Relation && e.getTag(OSMTagKey.ROUTE) != null) {
loadEntityData(e, true); loadEntityData(e, true);
@ -2494,18 +2501,16 @@ public class IndexCreator {
public static void main(String[] args) throws IOException, SAXException, SQLException { public static void main(String[] args) throws IOException, SAXException, SQLException {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
IndexCreator creator = new IndexCreator(new File("e:/Information/OSM maps/osmand/")); IndexCreator creator = new IndexCreator(new File("e:/Information/OSM maps/osmand/"));
creator.setIndexMap(true); // creator.setIndexMap(true);
creator.setIndexAddress(true); // creator.setIndexAddress(true);
creator.setSaveAddressWays(true);
creator.setNormalizeStreets(true);
creator.setIndexPOI(true); creator.setIndexPOI(true);
creator.setIndexTransport(true); // creator.setIndexTransport(true);
creator.recreateOnlyBinaryFile = false; creator.recreateOnlyBinaryFile = false;
creator.deleteDatabaseIndexes = false; creator.deleteDatabaseIndexes = false;
// creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/minsk.tmp.odb")); creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/minsk.tmp.odb"));
// creator.generateIndexes(new File("e:/Information/OSM maps/belarus osm/minsk.osm"), new ConsoleProgressImplementation(3), null); creator.generateIndexes(new File("e:/Information/OSM maps/belarus osm/minsk.osm"), new ConsoleProgressImplementation(3), null);
// creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/belarus_nodes.tmp.odb")); // creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/belarus_nodes.tmp.odb"));
// creator.generateIndexes(new File("e:/Information/OSM maps/belarus osm/belarus.osm.bz2"), new ConsoleProgressImplementation(3), null); // creator.generateIndexes(new File("e:/Information/OSM maps/belarus osm/belarus.osm.bz2"), new ConsoleProgressImplementation(3), null);
@ -2521,8 +2526,8 @@ public class IndexCreator {
// creator.generateIndexes(new File("e:/Information/OSM maps/osm_map/forest_complex.osm"), new ConsoleProgressImplementation(25), null); // creator.generateIndexes(new File("e:/Information/OSM maps/osm_map/forest_complex.osm"), new ConsoleProgressImplementation(25), null);
creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/luxembourg.tmp.odb")); // creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/luxembourg.tmp.odb"));
creator.generateIndexes(new File("e:/Information/OSM maps/osm_map/luxembourg.osm.pbf"), new ConsoleProgressImplementation(15), null); // creator.generateIndexes(new File("e:/Information/OSM maps/osm_map/luxembourg.osm.pbf"), new ConsoleProgressImplementation(15), null);
System.out.println("WHOLE GENERATION TIME : " + (System.currentTimeMillis() - time)); System.out.println("WHOLE GENERATION TIME : " + (System.currentTimeMillis() - time));
System.out.println("COORDINATES_SIZE " + BinaryMapIndexWriter.COORDINATES_SIZE + " count " + BinaryMapIndexWriter.COORDINATES_COUNT); System.out.println("COORDINATES_SIZE " + BinaryMapIndexWriter.COORDINATES_SIZE + " count " + BinaryMapIndexWriter.COORDINATES_COUNT);

View file

@ -7,7 +7,9 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.AmenityType; import net.osmand.data.AmenityType;
@ -110,7 +112,7 @@ public class AmenityIndexRepository extends BaseLocationIndexRepository<Amenity>
return true; return true;
} }
public boolean deleteAmenity(long id){ public boolean deleteAmenities(long id){
db.execSQL("DELETE FROM " + IndexConstants.POI_TABLE+ " WHERE id="+id); //$NON-NLS-1$ //$NON-NLS-2$ db.execSQL("DELETE FROM " + IndexConstants.POI_TABLE+ " WHERE id="+id); //$NON-NLS-1$ //$NON-NLS-2$
return true; return true;
} }
@ -215,12 +217,17 @@ public class AmenityIndexRepository extends BaseLocationIndexRepository<Amenity>
log.info("Start loading poi : " + u); //$NON-NLS-1$ log.info("Start loading poi : " + u); //$NON-NLS-1$
InputStream is = url.openStream(); InputStream is = url.openStream();
OsmBaseStorage st = new OsmBaseStorage(); OsmBaseStorage st = new OsmBaseStorage();
final List<Entity> amen = new ArrayList<Entity>(); final Map<Amenity, Entity> amen = new LinkedHashMap<Amenity, Entity>();
final List<Amenity> tempList = new ArrayList<Amenity>();
st.getFilters().add(new IOsmStorageFilter(){ st.getFilters().add(new IOsmStorageFilter(){
@Override @Override
public boolean acceptEntityToLoad(OsmBaseStorage storage, Entity.EntityId id, Entity entity) { public boolean acceptEntityToLoad(OsmBaseStorage storage, Entity.EntityId id, Entity entity) {
if(Amenity.isAmenity(entity)){ Amenity.parseAmenities(entity, tempList);
amen.add(entity); if(!tempList.isEmpty()){
for(Amenity a : tempList){
amen.put(a, entity);
}
tempList.clear();
return true; return true;
} }
// to // to
@ -228,8 +235,9 @@ public class AmenityIndexRepository extends BaseLocationIndexRepository<Amenity>
} }
}); });
st.parseOSM(is, null, null, false); st.parseOSM(is, null, null, false);
for (Entity e : amen) { for (Amenity am : amen.keySet()) {
Amenity am = new Amenity(e); // update location (when all nodes of way are loaded)
am.setEntity(amen.get(am));
if(am.getEnName().length() == 0){ if(am.getEnName().length() == 0){
am.setEnName(Junidecode.unidecode(am.getName())); am.setEnName(Junidecode.unidecode(am.getName()));
} }

View file

@ -111,7 +111,7 @@ public class EditingPOIActivity {
if(n != null){ if(n != null){
dlg = new Dialog(ctx); dlg = new Dialog(ctx);
dlg.setTitle(R.string.poi_edit_title); dlg.setTitle(R.string.poi_edit_title);
showDialog(n); showDialog(n, a.getType(), a.getSubType());
} else { } else {
Toast.makeText(ctx, ctx.getString(R.string.poi_error_poi_not_found), Toast.LENGTH_SHORT).show(); Toast.makeText(ctx, ctx.getString(R.string.poi_error_poi_not_found), Toast.LENGTH_SHORT).show();
} }
@ -123,7 +123,7 @@ public class EditingPOIActivity {
n.putTag(OSMTagKey.AMENITY.getValue(), ""); //$NON-NLS-1$ n.putTag(OSMTagKey.AMENITY.getValue(), ""); //$NON-NLS-1$
n.putTag(OSMTagKey.OPENING_HOURS.getValue(), ""); //$NON-NLS-1$ n.putTag(OSMTagKey.OPENING_HOURS.getValue(), ""); //$NON-NLS-1$
dlg.setTitle(R.string.poi_create_title); dlg.setTitle(R.string.poi_create_title);
showDialog(n); showDialog(n, null, null);
} }
public void showDeleteDialog(Amenity a){ public void showDeleteDialog(Amenity a){
@ -157,8 +157,8 @@ public class EditingPOIActivity {
builder.show(); builder.show();
} }
private void showDialog(final Node n){ private void showDialog(final Node n, AmenityType type, String subtype){
final Amenity a = new Amenity(n); final Amenity a = new Amenity(n, type, subtype);
dlg.setContentView(R.layout.editing_poi); dlg.setContentView(R.layout.editing_poi);
nameText =((EditText)dlg.findViewById(R.id.Name)); nameText =((EditText)dlg.findViewById(R.id.Name));
nameText.setText(a.getName()); nameText.setText(a.getName());
@ -564,25 +564,25 @@ public class EditingPOIActivity {
ser.endTag(null, "node"); //$NON-NLS-1$ ser.endTag(null, "node"); //$NON-NLS-1$
} }
private void updateNodeInIndexes(String action, Node n){ private void updateNodeInIndexes(String action, Node n) {
List<AmenityIndexRepository> repos = app.getResourceManager().searchAmenityRepositories(n.getLatitude(), n.getLongitude()); List<AmenityIndexRepository> repos = app.getResourceManager().searchAmenityRepositories(n.getLatitude(), n.getLongitude());
if(DELETE_ACTION.equals(action)){ // delete all amenities with same id
for(AmenityIndexRepository r: repos){ if (DELETE_ACTION.equals(action) || MODIFY_ACTION.equals(action)) {
r.deleteAmenity(n.getId()); for (AmenityIndexRepository r : repos) {
r.deleteAmenities(n.getId() << 1);
r.clearCache(); r.clearCache();
} }
} else { }
boolean changed = MODIFY_ACTION.equals(action); // add amenities
Amenity a = new Amenity(n); if (!DELETE_ACTION.equals(action)) {
for(AmenityIndexRepository r: repos){ List<Amenity> ams = Amenity.parseAmenities(n, new ArrayList<Amenity>());
if(changed){ for (Amenity a : ams) {
r.updateAmenity(a); for (AmenityIndexRepository r : repos) {
} else {
r.addAmenity(a); r.addAmenity(a);
}
r.clearCache(); r.clearCache();
} }
} }
}
} }