Search in sources :

Example 1 with RelationMember

use of net.osmand.osm.edit.Relation.RelationMember 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 2 with RelationMember

use of net.osmand.osm.edit.Relation.RelationMember 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 3 with RelationMember

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

the class IndexVectorMapCreator method createMultipolygonBuilder.

private MultipolygonBuilder createMultipolygonBuilder(Entity e, OsmDbAccessorContext ctx) throws SQLException {
    ctx.loadEntityRelation((Relation) e);
    // create a multipolygon object for this
    MultipolygonBuilder original = new MultipolygonBuilder();
    original.setId(e.getId());
    // fill the multipolygon with all ways from the Relation
    for (RelationMember es : ((Relation) e).getMembers()) {
        if (es.getEntity() instanceof Way) {
            // $NON-NLS-1$
            boolean inner = "inner".equals(es.getRole());
            if (inner) {
                original.addInnerWay((Way) es.getEntity());
            } else if ("outer".equals(es.getRole())) {
                original.addOuterWay((Way) es.getEntity());
            }
        }
    }
    return original;
}
Also used : Relation(net.osmand.osm.edit.Relation) RelationMember(net.osmand.osm.edit.Relation.RelationMember) Way(net.osmand.osm.edit.Way) MultipolygonBuilder(net.osmand.data.MultipolygonBuilder)

Example 4 with RelationMember

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

the class BasemapProcessor method processEntity.

public void processEntity(Entity e) {
    if (e instanceof Way) {
        if ("reverse_coastline".equals(((Way) e).getModifiableTags().get("natural"))) {
            ((Way) e).putTag("natural", "coastline");
            Collections.reverse(((Way) e).getNodes());
            ((Way) e).getNodeIds().reverse();
        }
    }
    long refId = -Math.abs(e.getId());
    for (int level = 0; level < mapZooms.getLevels().size(); level++) {
        boolean mostDetailed = level == 0;
        MapZoomPair zoomPair = mapZooms.getLevel(level);
        int zoomToEncode = mostDetailed ? Math.max(MOST_DETAILED_APPROXIMATION, zoomPair.getMinZoom() + 1) : zoomPair.getMaxZoom();
        if (mostDetailed && zoomPair.getMaxZoom() < 10) {
            throw new IllegalStateException("Zoom pair is not detailed " + zoomPair);
        }
        renderingTypes.encodeEntityWithType(e, zoomToEncode, typeUse, addtypeUse, namesUse, tempNameUse);
        if (typeUse.isEmpty()) {
            continue;
        }
        if (e instanceof Relation) {
            Relation r = (Relation) e;
            Iterator<RelationMember> it = r.getMembers().iterator();
            List<Node> outer = null;
            List<List<Node>> inner = new ArrayList<List<Node>>();
            while (it.hasNext()) {
                RelationMember n = it.next();
                if (n.getRole().equals("outer")) {
                    if (outer != null) {
                        throw new IllegalStateException("2 outer lines for relation = " + e.getId());
                    }
                    outer = ((Way) n.getEntity()).getNodes();
                } else if (n.getRole().equals("inner")) {
                    inner.add(((Way) n.getEntity()).getNodes());
                }
            }
            if (OsmMapUtils.polygonAreaPixels(outer, zoomToEncode) < PIXELS_THRESHOLD_AREA) {
                continue;
            }
            addObject(refId, level, zoomPair, zoomToEncode, outer, inner);
        } else if (e instanceof Way) {
            if (((Way) e).getNodes().size() < 2) {
                continue;
            }
            double dist = OsmMapUtils.getDistance(((Way) e).getFirstNode(), ((Way) e).getLastNode());
            boolean polygon = dist < 100;
            if ("coastline".equals(e.getTag("natural"))) {
                if (polygon && !mostDetailed) {
                    if (OsmMapUtils.polygonAreaPixels(((Way) e).getNodes(), zoomToEncode) < PIXELS_THRESHOLD_AREA) {
                        continue;
                    }
                }
                splitContinuousWay(((Way) e).getNodes(), typeUse.toArray(), !addtypeUse.isEmpty() ? addtypeUse.toArray() : null, zoomPair, zoomToEncode, quadTrees[level], refId);
            } else {
                List<Node> ns = ((Way) e).getNodes();
                if (!polygon) {
                    QuadRect qr = ((Way) e).getLatLonBBox();
                    if (qr == null) {
                        continue;
                    }
                    double mult = 1 / MapUtils.getPowZoom(Math.max(31 - (zoomToEncode + 8), 0));
                    int rx = MapUtils.get31TileNumberX(qr.right);
                    int lx = MapUtils.get31TileNumberX(qr.left);
                    int by = MapUtils.get31TileNumberY(qr.bottom);
                    int ty = MapUtils.get31TileNumberY(qr.top);
                    if (mult * (rx - lx) < PIXELS_THRESHOLD_AREA && mult * (by - ty) < PIXELS_THRESHOLD_AREA) {
                        continue;
                    }
                } else {
                    if (OsmMapUtils.polygonAreaPixels(ns, zoomToEncode) < PIXELS_THRESHOLD_AREA) {
                        continue;
                    }
                }
                addObject(refId, level, zoomPair, zoomToEncode, ns, null);
            }
        } else {
            int z = getViewZoom(zoomPair.getMinZoom(), zoomToEncode);
            int tilex = (int) MapUtils.getTileNumberX(z, ((Node) e).getLongitude());
            int tiley = (int) MapUtils.getTileNumberY(z, ((Node) e).getLatitude());
            addRawData(Collections.singletonList((Node) e), null, typeUse.toArray(), !addtypeUse.isEmpty() ? addtypeUse.toArray() : null, zoomPair, quadTrees[level], z, tilex, tiley, namesUse.isEmpty() ? null : new LinkedHashMap<MapRulType, String>(namesUse), refId);
        }
    }
}
Also used : Node(net.osmand.osm.edit.Node) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect) Way(net.osmand.osm.edit.Way) MapRulType(net.osmand.osm.MapRenderingTypes.MapRulType) MapZoomPair(net.osmand.binary.MapZooms.MapZoomPair) Relation(net.osmand.osm.edit.Relation) RelationMember(net.osmand.osm.edit.Relation.RelationMember) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 5 with RelationMember

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

the class OsmStorageWriter method writeOSM.

public void writeOSM(OutputStream output, Map<EntityId, EntityInfo> entityInfo, Collection<Node> nodes, Collection<Way> ways, Collection<Relation> relations, boolean skipMissingMembers) throws FactoryConfigurationError, XMLStreamException {
    // transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    // String indent = "{http://xml.apache.org/xslt}indent-amount";
    // transformer.setOutputProperty(indent, "4");
    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    XMLStreamWriter streamWriter = xof.createXMLStreamWriter(new OutputStreamWriter(output));
    streamWriter.writeStartDocument();
    Set<EntityId> nd = new HashSet<Entity.EntityId>();
    writeStartElement(streamWriter, ELEM_OSM, "");
    streamWriter.writeAttribute(ATTR_VERSION, "0.6");
    for (Node n : nodes) {
        writeStartElement(streamWriter, ELEM_NODE, INDENT);
        streamWriter.writeAttribute(ATTR_LAT, String.valueOf(n.getLatitude()));
        streamWriter.writeAttribute(ATTR_LON, String.valueOf(n.getLongitude()));
        streamWriter.writeAttribute(ATTR_ID, String.valueOf(n.getId()));
        writeEntityAttributes(streamWriter, n, entityInfo.get(EntityId.valueOf(n)));
        writeTags(streamWriter, n);
        writeEndElement(streamWriter, INDENT);
        if (skipMissingMembers) {
            nd.add(EntityId.valueOf(n));
        }
    }
    for (Way w : ways) {
        writeStartElement(streamWriter, ELEM_WAY, INDENT);
        streamWriter.writeAttribute(ATTR_ID, String.valueOf(w.getId()));
        writeEntityAttributes(streamWriter, w, entityInfo.get(EntityId.valueOf(w)));
        TLongArrayList ids = w.getNodeIds();
        for (int i = 0; i < ids.size(); i++) {
            writeStartElement(streamWriter, ELEM_ND, INDENT2);
            streamWriter.writeAttribute(ATTR_REF, String.valueOf(ids.get(i)));
            writeEndElement(streamWriter, INDENT2);
        }
        writeTags(streamWriter, w);
        writeEndElement(streamWriter, INDENT);
        if (skipMissingMembers) {
            nd.add(EntityId.valueOf(w));
        }
    }
    for (Relation r : relations) {
        if (skipMissingMembers) {
            nd.add(EntityId.valueOf(r));
        }
        writeStartElement(streamWriter, ELEM_RELATION, INDENT);
        streamWriter.writeAttribute(ATTR_ID, String.valueOf(r.getId()));
        writeEntityAttributes(streamWriter, r, entityInfo.get(EntityId.valueOf(r)));
        for (RelationMember e : r.getMembers()) {
            if (skipMissingMembers && !nd.contains(e.getEntityId())) {
                continue;
            }
            writeStartElement(streamWriter, ELEM_MEMBER, INDENT2);
            streamWriter.writeAttribute(ATTR_REF, String.valueOf(e.getEntityId().getId()));
            String s = e.getRole();
            if (s == null) {
                s = "";
            }
            streamWriter.writeAttribute(ATTR_ROLE, s);
            streamWriter.writeAttribute(ATTR_TYPE, e.getEntityId().getType().toString().toLowerCase());
            writeEndElement(streamWriter, INDENT2);
        }
        writeTags(streamWriter, r);
        writeEndElement(streamWriter, INDENT);
    }
    // osm
    writeEndElement(streamWriter, "");
    streamWriter.writeEndDocument();
    streamWriter.flush();
}
Also used : Entity(net.osmand.osm.edit.Entity) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) TLongArrayList(gnu.trove.list.array.TLongArrayList) Node(net.osmand.osm.edit.Node) Way(net.osmand.osm.edit.Way) EntityId(net.osmand.osm.edit.Entity.EntityId) Relation(net.osmand.osm.edit.Relation) RelationMember(net.osmand.osm.edit.Relation.RelationMember) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Relation (net.osmand.osm.edit.Relation)16 RelationMember (net.osmand.osm.edit.Relation.RelationMember)16 Way (net.osmand.osm.edit.Way)11 Node (net.osmand.osm.edit.Node)9 Entity (net.osmand.osm.edit.Entity)7 EntityId (net.osmand.osm.edit.Entity.EntityId)7 LinkedHashMap (java.util.LinkedHashMap)5 TLongArrayList (gnu.trove.list.array.TLongArrayList)3 ArrayList (java.util.ArrayList)3 LinkedHashSet (java.util.LinkedHashSet)3 MultipolygonBuilder (net.osmand.data.MultipolygonBuilder)2 TransportStop (net.osmand.data.TransportStop)2 MapRulType (net.osmand.osm.MapRenderingTypes.MapRulType)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1