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;
import java.util.Collection;
import java.util.List;
import net.osmand.osm.Entity;
import net.osmand.osm.MapRenderingTypes;
@ -17,11 +18,12 @@ public class Amenity extends MapObject {
private String phone;
private String site;
public Amenity(Entity entity){
public Amenity(Entity entity, AmenityType type, String subtype){
super(entity);
// manipulate with id to distinguish way and nodes
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.phone = entity.getTag(OSMTagKey.PHONE);
if (this.phone == null) {
@ -51,32 +53,6 @@ public class Amenity extends MapObject {
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(){
return type;
}
@ -93,12 +69,33 @@ public class Amenity extends MapObject {
this.subType = subType;
}
public static boolean isAmenity(Entity n){
if(n instanceof Relation){
public static List<Amenity> parseAmenities(Entity entity, List<Amenity> amenitiesList){
if(entity instanceof Relation){
// 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() {

View file

@ -1109,12 +1109,18 @@ public class IndexCreator {
return foundId;
}
private List<Amenity> tempAmenityList = new ArrayList<Amenity>();
private void iterateEntity(Entity e, int step) throws SQLException {
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);
if (poiPreparedStatement != null) {
Amenity a = new Amenity(e);
for (Amenity a : tempAmenityList) {
a.setEntity(e);
if (a.getLocation() != null) {
// do not convert english name
// convertEnglishName(a);
@ -1122,6 +1128,7 @@ public class IndexCreator {
}
}
}
}
if (indexTransport) {
if (e instanceof Relation && e.getTag(OSMTagKey.ROUTE) != null) {
loadEntityData(e, true);
@ -2494,18 +2501,16 @@ public class IndexCreator {
public static void main(String[] args) throws IOException, SAXException, SQLException {
long time = System.currentTimeMillis();
IndexCreator creator = new IndexCreator(new File("e:/Information/OSM maps/osmand/"));
creator.setIndexMap(true);
creator.setIndexAddress(true);
creator.setSaveAddressWays(true);
creator.setNormalizeStreets(true);
// creator.setIndexMap(true);
// creator.setIndexAddress(true);
creator.setIndexPOI(true);
creator.setIndexTransport(true);
// creator.setIndexTransport(true);
creator.recreateOnlyBinaryFile = false;
creator.deleteDatabaseIndexes = false;
// 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.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.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);
@ -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.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.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);
System.out.println("WHOLE GENERATION TIME : " + (System.currentTimeMillis() - time));
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.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.osmand.data.Amenity;
import net.osmand.data.AmenityType;
@ -110,7 +112,7 @@ public class AmenityIndexRepository extends BaseLocationIndexRepository<Amenity>
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$
return true;
}
@ -215,12 +217,17 @@ public class AmenityIndexRepository extends BaseLocationIndexRepository<Amenity>
log.info("Start loading poi : " + u); //$NON-NLS-1$
InputStream is = url.openStream();
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(){
@Override
public boolean acceptEntityToLoad(OsmBaseStorage storage, Entity.EntityId id, Entity entity) {
if(Amenity.isAmenity(entity)){
amen.add(entity);
Amenity.parseAmenities(entity, tempList);
if(!tempList.isEmpty()){
for(Amenity a : tempList){
amen.put(a, entity);
}
tempList.clear();
return true;
}
// to
@ -228,8 +235,9 @@ public class AmenityIndexRepository extends BaseLocationIndexRepository<Amenity>
}
});
st.parseOSM(is, null, null, false);
for (Entity e : amen) {
Amenity am = new Amenity(e);
for (Amenity am : amen.keySet()) {
// update location (when all nodes of way are loaded)
am.setEntity(amen.get(am));
if(am.getEnName().length() == 0){
am.setEnName(Junidecode.unidecode(am.getName()));
}

View file

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