Search in sources :

Example 11 with EntityId

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

the class ObfDiffGenerator method compareRouteData.

private void compareRouteData(ObfFileInMemory fStart, ObfFileInMemory fEnd, boolean print, Set<EntityId> modifiedObjIds) {
    RouteRegion ri = fEnd.getRouteIndex();
    int deleteId = ri.searchRouteEncodingRule(OSMAND_CHANGE_TAG, OSMAND_CHANGE_VALUE);
    if (deleteId == -1) {
        deleteId = ri.routeEncodingRules.size();
        if (deleteId == 0) {
            deleteId = 1;
        }
        ri.initRouteEncodingRule(deleteId, OSMAND_CHANGE_TAG, OSMAND_CHANGE_VALUE);
    }
    TLongObjectHashMap<RouteDataObject> startData = fStart.getRoutingData();
    TLongObjectHashMap<RouteDataObject> endData = fEnd.getRoutingData();
    if (endData == null) {
        return;
    }
    for (Long idx : startData.keys()) {
        RouteDataObject objE = endData.get(idx);
        RouteDataObject objS = startData.get(idx);
        if (print) {
            if (objE == null) {
                System.out.println("Route " + idx + " is missing in (2): " + objS);
            } else {
                if (!objE.compareRoute(objS)) {
                    System.out.println("Route " + idx + " is not equal: " + objS + " != " + objE);
                }
                endData.remove(idx);
            }
        } else {
            if (objE == null) {
                EntityId wayId = new EntityId(EntityType.WAY, idx >> (BinaryInspector.SHIFT_ID));
                if (modifiedObjIds == null || modifiedObjIds.contains(wayId)) {
                    RouteDataObject rdo = generateDeletedRouteObject(ri, deleteId, objS);
                    endData.put(idx, rdo);
                }
            } else if (objE.compareRoute(objS)) {
                endData.remove(idx);
            }
        }
    }
    if (print) {
        for (RouteDataObject e : endData.valueCollection()) {
            System.out.println("Route " + e.getId() + " is missing in (1): " + e);
        }
    }
}
Also used : EntityId(net.osmand.osm.edit.Entity.EntityId) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) RouteDataObject(net.osmand.binary.RouteDataObject)

Example 12 with EntityId

use of net.osmand.osm.edit.Entity.EntityId 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;
}
Also used : EntityId(net.osmand.osm.edit.Entity.EntityId) Relation(net.osmand.osm.edit.Relation) RelationMember(net.osmand.osm.edit.Relation.RelationMember) Way(net.osmand.osm.edit.Way)

Example 13 with EntityId

use of net.osmand.osm.edit.Entity.EntityId in project Osmand by osmandapp.

the class OpenstreetmapRemoteUtil method loadNode.

public EntityInfo loadNode(Node n) {
    // >> 1;
    long nodeId = n.getId();
    try {
        String res = sendRequest(getSiteApi() + "api/0.6/node/" + nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, // $NON-NLS-1$ //$NON-NLS-2$
        false);
        if (res != null) {
            OsmBaseStorage st = new OsmBaseStorage();
            st.setConvertTagsToLC(false);
            // $NON-NLS-1$
            st.parseOSM(new ByteArrayInputStream(res.getBytes("UTF-8")), null, null, true);
            EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
            Node entity = (Node) st.getRegisteredEntities().get(id);
            // merge non existing tags
            Map<String, String> updatedTags = new HashMap<>();
            for (String tagKey : entity.getTagKeySet()) {
                if (tagKey != null && !deletedTag(n, tagKey)) {
                    addIfNotNull(tagKey, entity.getTag(tagKey), updatedTags);
                }
            }
            if (n.getChangedTags() != null) {
                for (String tagKey : n.getChangedTags()) {
                    if (tagKey != null) {
                        addIfNotNull(tagKey, n.getTag(tagKey), updatedTags);
                    }
                }
            }
            n.replaceTags(updatedTags);
            if (MapUtils.getDistance(n.getLatLon(), entity.getLatLon()) < 10) {
                // avoid shifting due to round error
                n.setLatitude(entity.getLatitude());
                n.setLongitude(entity.getLongitude());
            }
            entityInfo = st.getRegisteredEntityInfo().get(id);
            entityInfoId = id;
            return entityInfo;
        }
    } catch (IOException | XmlPullParserException e) {
        // $NON-NLS-1$
        log.error("Loading node failed " + nodeId, e);
        Toast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error), Toast.LENGTH_LONG).show();
    }
    return null;
}
Also used : EntityId(net.osmand.osm.edit.Entity.EntityId) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OsmBaseStorage(net.osmand.osm.io.OsmBaseStorage) Node(net.osmand.osm.edit.Node) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 14 with EntityId

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

the class IndexTransportCreator method processTransportRelationV2.

private boolean processTransportRelationV2(Relation rel, TransportRoute route) {
    // first, verify we can accept this relation as new transport relation
    // accepted roles restricted to: <empty>, stop, platform, ^(stop|platform)_(entry|exit)_only$
    String version = rel.getTag("public_transport:version");
    try {
        if (Algorithms.isEmpty(version) || Integer.parseInt(version) < 2) {
            for (RelationMember entry : rel.getMembers()) {
                // ignore ways (cause with even with new relations there could be a mix of forward/backward ways)
                if (entry.getEntity() instanceof Way) {
                    continue;
                }
                String role = entry.getRole();
                if (role.isEmpty() || "stop".equals(role) || "platform".equals(role)) {
                    // accepted roles
                    continue;
                }
                stopPlatformMatcher.reset(role);
                if (stopPlatformMatcher.matches()) {
                    continue;
                }
                // there is wrong role in the relation, exit
                return false;
            }
        }
    } catch (NumberFormatException e) {
        return false;
    }
    List<Entity> platformsAndStops = new ArrayList<Entity>();
    List<Entity> platforms = new ArrayList<Entity>();
    List<Entity> stops = new ArrayList<Entity>();
    Map<EntityId, Entity> platformNames = new LinkedHashMap<>();
    for (RelationMember entry : rel.getMembers()) {
        String role = entry.getRole();
        if (entry.getEntity() == null || entry.getEntity().getLatLon() == null) {
            continue;
        }
        if (role.startsWith("platform")) {
            platformsAndStops.add(entry.getEntity());
            platforms.add(entry.getEntity());
        } else if (role.startsWith("stop")) {
            platformsAndStops.add(entry.getEntity());
            stops.add(entry.getEntity());
        } else {
            if (entry.getEntity() instanceof Way) {
                route.addWay((Way) entry.getEntity());
            }
        }
    }
    mergePlatformsStops(platformsAndStops, platforms, stops, platformNames);
    if (platformsAndStops.isEmpty()) {
        // nothing to get from this relation - there is no stop
        return true;
    }
    for (Entity s : platformsAndStops) {
        TransportStop stop = EntityParser.parseTransportStop(s);
        Relation stopArea = stopAreas.get(EntityId.valueOf(s));
        // verify name tag, not stop.getName because it may contain unnecessary refs, etc
        Entity genericStopName = null;
        if (stopArea != null && !Algorithms.isEmpty(stopArea.getTag(OSMTagKey.NAME))) {
            genericStopName = stopArea;
        } else if (platformNames.containsKey(EntityId.valueOf(s))) {
            genericStopName = platformNames.get(EntityId.valueOf(s));
        }
        if (genericStopName != null) {
            stop.copyNames(genericStopName.getTag(OSMTagKey.NAME), genericStopName.getTag(OSMTagKey.NAME_EN), genericStopName.getNameTags(), true);
        }
        route.getForwardStops().add(stop);
    }
    return true;
}
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) ArrayList(java.util.ArrayList) TransportStop(net.osmand.data.TransportStop) Way(net.osmand.osm.edit.Way) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with EntityId

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

the class IndexVectorMapCreator method iterateMainEntity.

public void iterateMainEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
    if (e instanceof Way || e instanceof Node) {
        tagsTransformer.addPropogatedTags(e);
        // manipulate what kind of way to load
        long originalId = e.getId();
        long assignedId = e.getId();
        List<Map<String, String>> splitTags = renderingTypes.splitTags(e.getTags(), EntityType.valueOf(e));
        Map<String, String> tags = splitTags == null ? e.getModifiableTags() : splitTags.get(0);
        for (int level = 0; level < mapZooms.size(); level++) {
            processMainEntity(e, originalId, assignedId, level, tags);
        }
        if (splitTags != null) {
            EntityId eid = EntityId.valueOf(e);
            for (int i = 1; i < splitTags.size(); i++) {
                assignedId = assignIdBasedOnOriginalSplit(eid);
                Map<String, String> stags = splitTags.get(i);
                for (int level = 0; level < mapZooms.size(); level++) {
                    processMainEntity(e, originalId, assignedId, level, stags);
                }
            }
        }
    }
}
Also used : EntityId(net.osmand.osm.edit.Entity.EntityId) Node(net.osmand.osm.edit.Node) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TreeMap(java.util.TreeMap) Way(net.osmand.osm.edit.Way)

Aggregations

EntityId (net.osmand.osm.edit.Entity.EntityId)25 Entity (net.osmand.osm.edit.Entity)15 Node (net.osmand.osm.edit.Node)15 Way (net.osmand.osm.edit.Way)15 Relation (net.osmand.osm.edit.Relation)11 LinkedHashMap (java.util.LinkedHashMap)10 HashMap (java.util.HashMap)8 RelationMember (net.osmand.osm.edit.Relation.RelationMember)7 OsmBaseStorage (net.osmand.osm.io.OsmBaseStorage)7 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)5 OsmStorageWriter (net.osmand.osm.io.OsmStorageWriter)5 IOException (java.io.IOException)4 Map (java.util.Map)4 EntityInfo (net.osmand.osm.edit.EntityInfo)4 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)3 ArrayList (java.util.ArrayList)3 LinkedHashSet (java.util.LinkedHashSet)3 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2