Search in sources :

Example 1 with Relation

use of net.osmand.osm.edit.Relation in project OsmAnd-tools by osmandapp.

the class IndexCreator method indexRelations.

private void indexRelations(OsmDbAccessor accessor, IProgress progress) throws SQLException, InterruptedException {
    if (indexAddress || indexMap || indexRouting || indexPOI || indexTransport) {
        // $NON-NLS-1$
        setGeneralProgress(progress, "[30 / 100]");
        // $NON-NLS-1$
        progress.startTask(Messages.getString("IndexCreator.PREINDEX_BOUNDARIES_RELATIONS"), accessor.getAllRelations());
        accessor.iterateOverEntities(progress, EntityType.RELATION, new OsmDbVisitor() {

            @Override
            public void iterateEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
                if (indexAddress) {
                    // indexAddressCreator.indexAddressRelation((Relation) e, ctx); streets needs loaded boundaries !!!
                    indexAddressCreator.indexBoundariesRelation(e, ctx);
                }
                if (indexMap) {
                    indexMapCreator.indexMapRelationsAndMultiPolygons(e, ctx);
                }
                if (indexRouting) {
                    indexRouteCreator.indexRelations(e, ctx);
                }
                if (indexPOI) {
                    indexPoiCreator.iterateRelation((Relation) e, ctx);
                }
                if (indexTransport) {
                    indexTransportCreator.indexRelations((Relation) e, ctx);
                }
            }
        });
        if (indexMap) {
            indexMapCreator.createMapIndexTableIndexes(mapConnection);
        }
        if (indexAddress) {
            // $NON-NLS-1$
            setGeneralProgress(progress, "[40 / 100]");
            // $NON-NLS-1$
            progress.startTask(Messages.getString("IndexCreator.PREINDEX_BOUNDARIES_WAYS"), accessor.getAllWays());
            accessor.iterateOverEntities(progress, EntityType.WAY_BOUNDARY, new OsmDbVisitor() {

                @Override
                public void iterateEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
                    indexAddressCreator.indexBoundariesRelation(e, ctx);
                }
            });
            // $NON-NLS-1$
            setGeneralProgress(progress, "[42 / 100]");
            // $NON-NLS-1$
            progress.startTask(Messages.getString("IndexCreator.BIND_CITIES_AND_BOUNDARIES"), 100);
            // finish up the boundaries and cities
            indexAddressCreator.tryToAssignBoundaryToFreeCities(progress);
            // $NON-NLS-1$
            setGeneralProgress(progress, "[45 / 100]");
            // $NON-NLS-1$
            progress.startTask(Messages.getString("IndexCreator.PREINDEX_ADRESS_MAP"), accessor.getAllRelations());
            accessor.iterateOverEntities(progress, EntityType.RELATION, new OsmDbVisitor() {

                @Override
                public void iterateEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
                    indexAddressCreator.indexAddressRelation((Relation) e, ctx);
                }
            });
            indexAddressCreator.commitToPutAllCities();
        }
    }
}
Also used : Entity(net.osmand.osm.edit.Entity) Relation(net.osmand.osm.edit.Relation) SQLException(java.sql.SQLException) OsmDbVisitor(net.osmand.data.preparation.OsmDbAccessor.OsmDbVisitor)

Example 2 with Relation

use of net.osmand.osm.edit.Relation in project OsmAnd-tools by osmandapp.

the class IndexPoiCreator method iterateRelation.

public void iterateRelation(Relation e, OsmDbAccessorContext ctx) throws SQLException {
    Map<String, String> tags = renderingTypes.transformTags(e.getTags(), EntityType.RELATION, EntityConvertApplyType.POI);
    for (String t : tags.keySet()) {
        boolean index = poiTypes.parseAmenity(t, tags.get(t), true, tags) != null;
        if (index) {
            ctx.loadEntityRelation(e);
            for (RelationMember id : ((Relation) e).getMembers()) {
                tagsTransform.registerPropogatedTag(id.getEntityId(), t, tags.get(t));
            }
        }
    }
    tagsTransform.handleRelationPropogatedTags(e, renderingTypes, ctx, EntityConvertApplyType.POI);
}
Also used : Relation(net.osmand.osm.edit.Relation) RelationMember(net.osmand.osm.edit.Relation.RelationMember)

Example 3 with Relation

use of net.osmand.osm.edit.Relation in project OsmAnd-tools by osmandapp.

the class IndexRouteCreator method indexRelations.

public void indexRelations(Entity e, OsmDbAccessorContext ctx) throws SQLException {
    indexHighwayRestrictions(e, ctx);
    if (e instanceof Relation) {
        tagsTransformer.handleRelationPropogatedTags((Relation) e, renderingTypes, ctx, EntityConvertApplyType.ROUTING);
        Map<String, String> tags = renderingTypes.transformTags(e.getTags(), EntityType.RELATION, EntityConvertApplyType.ROUTING);
        if ("enforcement".equals(tags.get("type")) && "maxspeed".equals(tags.get("enforcement"))) {
            ctx.loadEntityRelation((Relation) e);
            Iterator<RelationMember> from = ((Relation) e).getMembers("from").iterator();
            // mark as speed cameras
            while (from.hasNext()) {
                Entity n = from.next().getEntity();
                if (n instanceof Node) {
                    tagsTransformer.registerPropogatedTag(new EntityId(EntityType.NODE, n.getId()), "highway", "speed_camera");
                }
            }
        }
    }
}
Also used : EntityId(net.osmand.osm.edit.Entity.EntityId) Entity(net.osmand.osm.edit.Entity) Relation(net.osmand.osm.edit.Relation) RelationMember(net.osmand.osm.edit.Relation.RelationMember) Node(net.osmand.osm.edit.Node)

Example 4 with Relation

use of net.osmand.osm.edit.Relation in project OsmAnd-tools by osmandapp.

the class IndexTransportCreator method iterateMainEntity.

public void iterateMainEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
    if (e instanceof Relation && e.getTag(OSMTagKey.ROUTE) != null) {
        ctx.loadEntityRelation((Relation) e);
        List<TransportRoute> troutes = new ArrayList<>();
        indexTransportRoute((Relation) e, troutes);
        for (TransportRoute route : troutes) {
            insertTransportIntoIndex(route);
        }
    }
}
Also used : Relation(net.osmand.osm.edit.Relation) TransportRoute(net.osmand.data.TransportRoute) ArrayList(java.util.ArrayList)

Example 5 with Relation

use of net.osmand.osm.edit.Relation in project OsmAnd-tools by osmandapp.

the class IndexTransportCreator method indexTransportRoute.

private void indexTransportRoute(Relation rel, List<TransportRoute> troutes) {
    String ref = rel.getTag(OSMTagKey.REF);
    String route = rel.getTag(OSMTagKey.ROUTE);
    String operator = rel.getTag(OSMTagKey.OPERATOR);
    String color = rel.getTag(OSMTagKey.COLOUR);
    Relation master = masterRoutes.get(rel.getId());
    if (master != null) {
        if (ref == null) {
            ref = master.getTag(OSMTagKey.REF);
        }
        if (route == null) {
            route = master.getTag(OSMTagKey.ROUTE);
        }
        if (operator == null) {
            operator = master.getTag(OSMTagKey.OPERATOR);
        }
        if (color == null) {
            color = master.getTag(OSMTagKey.COLOUR);
        }
    }
    if (route == null || ref == null) {
        return;
    }
    if (!acceptedRoutes.contains(route)) {
        return;
    }
    if (color != null) {
        String tmp = MapRenderingTypesEncoder.formatColorToPalette(color, false).replaceAll("_", "");
        color = "subwayText" + tmp.substring(0, 1).toUpperCase() + tmp.substring(1) + "Color";
    }
    TransportRoute directRoute = EntityParser.parserRoute(rel, ref);
    directRoute.setOperator(operator);
    directRoute.setColor(color);
    directRoute.setType(route);
    directRoute.setRef(ref);
    directRoute.setId(directRoute.getId() << 1);
    if (processTransportRelationV2(rel, directRoute)) {
        // try new transport relations first
        troutes.add(directRoute);
    } else {
        TransportRoute backwardRoute = EntityParser.parserRoute(rel, ref);
        backwardRoute.setOperator(operator);
        backwardRoute.setColor(color);
        backwardRoute.setType(route);
        backwardRoute.setRef(ref);
        backwardRoute.setName(reverseName(ref, backwardRoute.getName()));
        if (!Algorithms.isEmpty(backwardRoute.getEnName(false))) {
            backwardRoute.setEnName(reverseName(ref, backwardRoute.getEnName(false)));
        }
        if (processTransportRelationV1(rel, directRoute, backwardRoute)) {
            // old relation style otherwise
            backwardRoute.setId((backwardRoute.getId() << 1) + 1);
            troutes.add(directRoute);
            troutes.add(backwardRoute);
        }
    }
}
Also used : Relation(net.osmand.osm.edit.Relation) TransportRoute(net.osmand.data.TransportRoute)

Aggregations

Relation (net.osmand.osm.edit.Relation)30 Way (net.osmand.osm.edit.Way)17 RelationMember (net.osmand.osm.edit.Relation.RelationMember)16 Entity (net.osmand.osm.edit.Entity)15 Node (net.osmand.osm.edit.Node)14 EntityId (net.osmand.osm.edit.Entity.EntityId)11 ArrayList (java.util.ArrayList)8 LinkedHashMap (java.util.LinkedHashMap)7 TLongArrayList (gnu.trove.list.array.TLongArrayList)4 IOException (java.io.IOException)4 LinkedHashSet (java.util.LinkedHashSet)4 EntityInfo (net.osmand.osm.edit.EntityInfo)4 File (java.io.File)3 SQLException (java.sql.SQLException)3 HashMap (java.util.HashMap)3 LatLon (net.osmand.data.LatLon)3 EntityType (net.osmand.osm.edit.Entity.EntityType)3 FileOutputStream (java.io.FileOutputStream)2 ResultSet (java.sql.ResultSet)2 List (java.util.List)2