use of net.osmand.osm.edit.Relation in project OsmAnd-tools by osmandapp.
the class AugmentedDiffsInspector method writeFile.
private File writeFile(File targetDir, String prefix, Map<EntityId, Entity> octx, Set<EntityId> oset, Map<EntityId, Entity> nctx, Set<EntityId> nset, long lastModified) throws XMLStreamException, IOException, FileNotFoundException {
List<Node> nodes = new ArrayList<Node>();
List<Way> ways = new ArrayList<Way>();
List<Relation> relations = new ArrayList<Relation>();
groupObjects(octx, oset, nodes, ways, relations);
groupObjects(nctx, nset, nodes, ways, relations);
File f = new File(targetDir, prefix + ".osm.gz");
FileOutputStream fous = new FileOutputStream(f);
GZIPOutputStream gz = new GZIPOutputStream(fous);
new OsmStorageWriter().writeOSM(gz, new HashMap<Entity.EntityId, EntityInfo>(), nodes, ways, relations, true);
gz.close();
fous.close();
f.setLastModified(lastModified);
return f;
}
use of net.osmand.osm.edit.Relation in project OsmAnd-tools by osmandapp.
the class MultipolygonFileTest method buildPolygon.
private Multipolygon buildPolygon(OsmBaseStorage st, long id) {
Relation r = (Relation) st.getRegisteredEntities().get(new EntityId(EntityType.RELATION, id));
Iterator<RelationMember> it = r.getMembers().iterator();
MultipolygonBuilder bld = new MultipolygonBuilder();
while (it.hasNext()) {
RelationMember e = it.next();
if (e.getRole().equals("outer")) {
bld.addOuterWay((Way) e.getEntity());
} else if (e.getRole().equals("inner")) {
bld.addInnerWay((Way) e.getEntity());
}
}
Multipolygon polygon = bld.build();
return polygon;
}
use of net.osmand.osm.edit.Relation in project OsmAnd-tools by osmandapp.
the class IndexCreator method generateBasemapIndex.
public void generateBasemapIndex(IProgress progress, IOsmStorageFilter addFilter, MapZooms mapZooms, MapRenderingTypesEncoder renderingTypes, Log logMapDataWarn, String regionName, File... readFiles) throws IOException, SQLException, InterruptedException, XmlPullParserException {
if (logMapDataWarn == null) {
logMapDataWarn = log;
}
if (renderingTypes == null) {
renderingTypes = new MapRenderingTypesEncoder("basemap");
}
if (mapZooms == null) {
mapZooms = MapZooms.getDefault();
}
// clear previous results and setting variables
try {
final BasemapProcessor processor = new BasemapProcessor(logMapDataWarn, mapZooms, renderingTypes, zoomWaySmoothness);
final IndexPoiCreator poiCreator = indexPOI ? new IndexPoiCreator(renderingTypes, false) : null;
if (indexPOI) {
poiCreator.createDatabaseStructure(getPoiFile());
}
OsmDbAccessor accessor = initDbAccessor(readFiles, progress, addFilter, true, false, true);
// 2. Create index connections and index structure
setGeneralProgress(progress, "[50 / 100]");
progress.startTask(Messages.getString("IndexCreator.PROCESS_OSM_NODES"), accessor.getAllNodes());
accessor.iterateOverEntities(progress, EntityType.NODE, new OsmDbVisitor() {
@Override
public void iterateEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
processor.processEntity(e);
if (indexPOI) {
poiCreator.iterateEntity(e, ctx, true);
}
}
});
setGeneralProgress(progress, "[70 / 100]");
progress.startTask(Messages.getString("IndexCreator.PROCESS_OSM_WAYS"), accessor.getAllWays());
accessor.iterateOverEntities(progress, EntityType.WAY, new OsmDbVisitor() {
@Override
public void iterateEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
processor.processEntity(e);
if (indexPOI) {
poiCreator.iterateEntity(e, ctx, true);
}
}
});
setGeneralProgress(progress, "[90 / 100]");
progress.startTask(Messages.getString("IndexCreator.PROCESS_OSM_REL"), accessor.getAllRelations());
accessor.iterateOverEntities(progress, EntityType.RELATION, new OsmDbVisitor() {
@Override
public void iterateEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
ctx.loadEntityRelation((Relation) e);
processor.processEntity(e);
}
});
accessor.closeReadingConnection();
mapFile = new File(workingDir, getMapFileName());
// to save space
mapFile.getParentFile().mkdirs();
if (mapFile.exists()) {
mapFile.delete();
}
mapRAFile = new RandomAccessFile(mapFile, "rw");
BinaryMapIndexWriter writer = new BinaryMapIndexWriter(mapRAFile, lastModifiedDate == null ? System.currentTimeMillis() : lastModifiedDate.longValue());
setGeneralProgress(progress, "[95 of 100]");
progress.startTask("Writing map index to binary file...", -1);
processor.writeBasemapFile(writer, regionName);
if (indexPOI) {
poiCreator.writeBinaryPoiIndex(writer, regionName, progress);
}
progress.finishTask();
writer.close();
mapRAFile.close();
// $NON-NLS-1$
log.info("Finish writing binary file");
} catch (RuntimeException e) {
// $NON-NLS-1$
log.error("Log exception", e);
throw e;
} catch (SQLException e) {
// $NON-NLS-1$
log.error("Log exception", e);
throw e;
} catch (IOException e) {
// $NON-NLS-1$
log.error("Log exception", e);
throw e;
} catch (XmlPullParserException e) {
// $NON-NLS-1$
log.error("Log exception", e);
throw e;
}
}
use of net.osmand.osm.edit.Relation in project OsmAnd-tools by osmandapp.
the class IndexPoiCreator method iterateEntity.
public void iterateEntity(Entity e, OsmDbAccessorContext ctx, boolean basemap) throws SQLException {
tempAmenityList.clear();
tagsTransform.addPropogatedTags(e);
Map<String, String> tags = e.getTags();
Map<String, String> etags = renderingTypes.transformTags(tags, EntityType.valueOf(e), EntityConvertApplyType.POI);
boolean privateReg = "private".equals(e.getTag("access"));
tempAmenityList = EntityParser.parseAmenities(poiTypes, e, etags, tempAmenityList);
if (!tempAmenityList.isEmpty() && poiPreparedStatement != null) {
if (e instanceof Relation) {
ctx.loadEntityRelation((Relation) e);
}
boolean first = true;
long id = e.getId();
if (basemap) {
id = GENERATE_OBJ_ID--;
} else if (e instanceof Relation) {
// id = GENERATE_OBJ_ID--;
id = assignIdForMultipolygon((Relation) e);
} else if (id > 0) {
// keep backward compatibility for ids (osm editing)
id = e.getId() >> (OsmDbCreator.SHIFT_ID - 1);
if (id % 2 != (e.getId() % 2)) {
id ^= 1;
}
}
for (Amenity a : tempAmenityList) {
if (a.getType().getKeyName().equals("entertainment") && privateReg) {
// don't index private swimming pools
continue;
}
if (basemap) {
PoiType st = a.getType().getPoiTypeByKeyName(a.getSubType());
if (st == null || !a.getType().containsBasemapPoi(st)) {
continue;
}
}
// do not add that check because it is too much printing for batch creation
// by statistic < 1% creates maps manually
// checkEntity(e);
EntityParser.parseMapObject(a, e, etags);
a.setId(id);
if (a.getLocation() != null) {
// convertEnglishName(a);
if (overwriteIds && first) {
if (!ids.add(a.getId())) {
poiPreparedStatement.executeBatch();
poiDeleteStatement.setString(1, a.getId() + "");
poiDeleteStatement.execute();
first = false;
}
}
insertAmenityIntoPoi(a);
}
}
}
}
use of net.osmand.osm.edit.Relation in project OsmAnd-tools by osmandapp.
the class IndexRouteCreator method indexHighwayRestrictions.
private void indexHighwayRestrictions(Entity e, OsmDbAccessorContext ctx) throws SQLException {
if (e instanceof Relation && "restriction".equals(e.getTag(OSMTagKey.TYPE))) {
// $NON-NLS-1$
// $NON-NLS-1$
String val = e.getTag("restriction");
if (val != null) {
if ("no_u_turn".equalsIgnoreCase(val) && Algorithms.objectEquals(e.getTag("from"), e.getTag("to"))) {
// don't index such roads - can't go through issue https://www.openstreetmap.org/way/338099991#map=17/46.86699/-0.20473
return;
}
byte type = -1;
if ("no_right_turn".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_NO_RIGHT_TURN;
} else if ("no_left_turn".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_NO_LEFT_TURN;
} else if ("no_u_turn".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_NO_U_TURN;
} else if ("no_straight_on".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_NO_STRAIGHT_ON;
} else if ("only_right_turn".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_ONLY_RIGHT_TURN;
} else if ("only_left_turn".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_ONLY_LEFT_TURN;
} else if ("only_straight_on".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_ONLY_STRAIGHT_ON;
}
if (type != -1) {
ctx.loadEntityRelation((Relation) e);
// $NON-NLS-1$
Collection<RelationMember> fromL = ((Relation) e).getMembers("from");
// $NON-NLS-1$
Collection<RelationMember> toL = ((Relation) e).getMembers("to");
if (!fromL.isEmpty() && !toL.isEmpty()) {
RelationMember from = fromL.iterator().next();
RelationMember to = toL.iterator().next();
if (from.getEntityId().getType() == EntityType.WAY) {
if (!highwayRestrictions.containsKey(from.getEntityId().getId())) {
highwayRestrictions.put(from.getEntityId().getId(), new TLongArrayList());
}
highwayRestrictions.get(from.getEntityId().getId()).add((to.getEntityId().getId() << 3) | (long) type);
}
}
}
}
}
}
Aggregations