Search in sources :

Example 1 with RouteActivityType

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

the class IndexRouteRelationCreator method processRouteRelation.

private void processRouteRelation(Relation e, OsmDbAccessorContext ctx, IndexCreationContext icc) throws SQLException {
    Map<String, String> tags = renderingTypes.transformTags(e.getTags(), EntityType.RELATION, EntityConvertApplyType.MAP);
    String rt = e.getTag(OSMTagKey.ROUTE);
    boolean publicTransport = IndexTransportCreator.acceptedPublicTransportRoute(rt);
    boolean road = "road".equals(rt);
    boolean railway = "railway".equals(rt);
    boolean infra = "power".equals(rt) || "pipeline".equals(rt);
    if (rt != null && !publicTransport && !road && !railway && !infra) {
        ctx.loadEntityRelation(e);
        List<Way> ways = new ArrayList<Way>();
        List<RelationMember> ms = e.getMembers();
        tags = new LinkedHashMap<>(tags);
        RouteActivityType activityType = RouteActivityType.getTypeFromOSMTags(tags);
        for (RelationMember rm : ms) {
            if (rm.getEntity() instanceof Way) {
                Way w = (Way) rm.getEntity();
                // Way newWay = new Way(-e.getId(), w.getNodes()); // duplicates
                Way newWay = new Way(GENERATE_OBJ_ID--, w.getNodes());
                newWay.replaceTags(tags);
                ways.add(newWay);
            }
        }
        TransportRoute.mergeRouteWays(ways);
        for (Way w : ways) {
            addRouteRelationTags(e, w, tags, activityType, icc);
            if (settings.addRegionTag) {
                icc.calcRegionTag(e, true);
            }
            w.replaceTags(tags);
            icc.translitJapaneseNames(e, settings.addRegionTag);
            for (int level = 0; level < mapZooms.size(); level++) {
                icc.getIndexMapCreator().processMainEntity(w, w.getId(), w.getId(), level, tags);
            }
            if (settings.indexPOI) {
                icc.getIndexPoiCreator().iterateEntityInternal(w, ctx, icc);
            }
        }
        String routeKey = activityType == null ? rt : activityType.getName();
        Integer c = indexRouteRelationTypes.get(routeKey);
        indexRouteRelationTypes.put(rt, (c == null ? 0 : c) + 1);
    }
}
Also used : RelationMember(net.osmand.osm.edit.Relation.RelationMember) RouteActivityType(net.osmand.osm.RouteActivityType) ArrayList(java.util.ArrayList) Way(net.osmand.osm.edit.Way)

Example 2 with RouteActivityType

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

the class DownloadOsmGPX method queryGPXForBBOX.

protected void queryGPXForBBOX(QueryParams qp) throws SQLException, IOException, FactoryConfigurationError, XMLStreamException, InterruptedException, XmlPullParserException {
    String conditions = "";
    if (!Algorithms.isEmpty(qp.user)) {
        conditions += " and t.\"user\" = '" + qp.user + "'";
    }
    if (!Algorithms.isEmpty(qp.tag)) {
        // conditions += " and '" + qp.tag + "' = ANY(t.tags)";
        String[] tagsAnd = qp.tag.split(",");
        for (String tagAnd : tagsAnd) {
            conditions += " and (";
            String[] tagsOr = tagAnd.split("\\;");
            boolean t = false;
            for (String tagOr : tagsOr) {
                if (t) {
                    conditions += " or ";
                }
                conditions += " lower('^'||array_to_string(t.tags,'^','')||'^') like '%^" + tagOr.trim().toLowerCase() + "^%'";
                t = true;
            }
            conditions += ")";
        }
    }
    if (!Algorithms.isEmpty(qp.datestart)) {
        conditions += " and t.date >= '" + qp.datestart + "'";
    }
    if (!Algorithms.isEmpty(qp.dateend)) {
        conditions += " and t.date <= '" + qp.dateend + "'";
    }
    if (qp.minlat != OsmGpxFile.ERROR_NUMBER) {
        conditions += " and t.maxlat >= " + qp.minlat;
        conditions += " and t.minlat <= " + qp.maxlat;
        conditions += " and t.maxlon >= " + qp.minlon;
        conditions += " and t.minlon <= " + qp.maxlon;
    }
    String query = "SELECT t.id, s.data, t.name, t.description, t.\"user\", t.date, t.tags from " + GPX_METADATA_TABLE_NAME + " t join " + GPX_FILES_TABLE_NAME + " s on s.id = t.id " + " where 1 = 1 " + conditions + " order by t.date asc";
    if (qp.limit != -1) {
        query += " limit " + qp.limit;
    }
    System.out.println(query);
    ResultSet rs = dbConn.createStatement().executeQuery(query);
    OsmGpxWriteContext ctx = new OsmGpxWriteContext(qp);
    ctx.startDocument();
    Date lastTimestamp = null;
    while (rs.next()) {
        if ((ctx.tracks + 1) % 1000 == 0) {
            System.out.println(String.format("Fetched %d tracks %d segments - last %s (now %s)", ctx.tracks + 1, ctx.segments, lastTimestamp, new Date()));
        }
        OsmGpxFile gpxInfo = new OsmGpxFile();
        gpxInfo.id = rs.getLong(1);
        byte[] cont = rs.getBytes(2);
        if (cont == null) {
            continue;
        }
        gpxInfo.name = rs.getString(3);
        gpxInfo.description = rs.getString(4);
        gpxInfo.user = rs.getString(5);
        gpxInfo.timestamp = new Date(rs.getDate(6).getTime());
        lastTimestamp = gpxInfo.timestamp;
        Array tags = rs.getArray(7);
        List<String> trackTags = new ArrayList<>();
        if (tags != null) {
            ResultSet rsar = tags.getResultSet();
            while (rsar.next()) {
                String tg = rsar.getString(2);
                if (tg != null) {
                    trackTags.add(tg.toLowerCase());
                }
            }
        }
        gpxInfo.tags = trackTags.toArray(new String[0]);
        if (qp.activityTypes != null) {
            RouteActivityType rat = RouteActivityType.getTypeFromTags(gpxInfo.tags);
            if (rat == null || !qp.activityTypes.contains(rat)) {
                continue;
            }
        }
        ByteArrayInputStream is = new ByteArrayInputStream(Algorithms.gzipToString(cont).getBytes());
        GPXFile gpxFile = GPXUtilities.loadGPXFile(is);
        GPXTrackAnalysis analysis = gpxFile.getAnalysis(gpxInfo.timestamp.getTime());
        ctx.writeTrack(gpxInfo, null, gpxFile, analysis, "OG");
    }
    ctx.endDocument();
    System.out.println(String.format("Fetched %d tracks %d segments", ctx.tracks, ctx.segments));
    generateObfFile(qp);
}
Also used : GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) OsmGpxWriteContext(net.osmand.obf.OsmGpxWriteContext) Array(java.sql.Array) RouteActivityType(net.osmand.osm.RouteActivityType) ByteArrayInputStream(java.io.ByteArrayInputStream) ResultSet(java.sql.ResultSet) GPXFile(net.osmand.GPXUtilities.GPXFile)

Example 3 with RouteActivityType

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

the class OsmGpxWriteContext method addGpxInfoTags.

private void addGpxInfoTags(Map<String, String> gpxTrackTags, OsmGpxFile gpxInfo, String routeIdPrefix) {
    if (gpxInfo != null) {
        gpxTrackTags.put("route_id", routeIdPrefix + gpxInfo.id);
        gpxTrackTags.put("ref", gpxInfo.id % 1000 + "");
        gpxTrackTags.put("name", gpxInfo.name);
        gpxTrackTags.put("route_name", gpxInfo.name);
        gpxTrackTags.put("user", gpxInfo.user);
        gpxTrackTags.put("date", gpxInfo.timestamp.toString());
        gpxTrackTags.put("description", gpxInfo.description);
        RouteActivityType activityType = RouteActivityType.getTypeFromTags(gpxInfo.tags);
        for (String tg : gpxInfo.tags) {
            gpxTrackTags.put("tag_" + tg, tg);
        }
        if (activityType != null) {
            // red, blue, green, orange, yellow
            // gpxTrackTags.put("gpx_icon", "");
            gpxTrackTags.put("gpx_bg", activityType.getColor() + "_hexagon_3_road_shield");
            gpxTrackTags.put("color", activityType.getColor());
            gpxTrackTags.put("route_activity_type", activityType.getName().toLowerCase());
        }
    }
}
Also used : RouteActivityType(net.osmand.osm.RouteActivityType)

Aggregations

RouteActivityType (net.osmand.osm.RouteActivityType)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Array (java.sql.Array)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 GPXFile (net.osmand.GPXUtilities.GPXFile)1 GPXTrackAnalysis (net.osmand.GPXUtilities.GPXTrackAnalysis)1 OsmGpxWriteContext (net.osmand.obf.OsmGpxWriteContext)1 RelationMember (net.osmand.osm.edit.Relation.RelationMember)1 Way (net.osmand.osm.edit.Way)1