def modify_relation(uid, username, relationIn, refsIn, tagsIn): relation = pgmap.OsmRelation() relation.objId = relationIn.objId relation.metaData.version = relationIn.metaData.version + 1 relation.metaData.timestamp = int(time.time()) relation.metaData.changeset = 1000 relation.metaData.uid = uid relation.metaData.username = username relation.metaData.visible = True for k in tagsIn: relation.tags[k] = tagsIn[k] for refTypeStr, refId, refRole in refsIn: relation.refTypeStrs.append(refTypeStr) relation.refIds.append(refId) relation.refRoles.append(refRole) data = pgmap.OsmData() data.relations.append(relation) createdNodeIds = pgmap.mapi64i64() createdWayIds = pgmap.mapi64i64() createdRelationIds = pgmap.mapi64i64() errStr = pgmap.PgMapError() t = p.GetTransaction("EXCLUSIVE") ok = t.StoreObjects(data, createdNodeIds, createdWayIds, createdRelationIds, False, errStr) if not ok: t.Abort() print (errStr.errStr) return None else: t.Commit() return relation
def create_relation(uid, username, refs, changeset=1000): relation = pgmap.OsmRelation() relation.objId = -1 relation.metaData.version = 1 relation.metaData.timestamp = 0 relation.metaData.changeset = changeset relation.metaData.uid = uid relation.metaData.username = username relation.metaData.visible = True relation.tags["test"] = "moon" for refTypeStr, refId, refRole in refs: relation.refTypeStrs.append(refTypeStr) relation.refIds.append(refId) relation.refRoles.append(refRole) data = pgmap.OsmData() data.relations.append(relation) createdNodeIds = pgmap.mapi64i64() createdWayIds = pgmap.mapi64i64() createdRelationIds = pgmap.mapi64i64() errStr = pgmap.PgMapError() t = p.GetTransaction("EXCLUSIVE") ok = t.StoreObjects(data, createdNodeIds, createdWayIds, createdRelationIds, False, errStr) if not ok: t.Abort() print(errStr.errStr) return None else: t.Commit() relation.objId = createdRelationIds[-1] return relation
def delete_object(objIn, user, tIn=None, timestamp=None): if isinstance(objIn, pgmap.OsmNode): obj = pgmap.OsmNode() elif isinstance(objIn, pgmap.OsmWay): obj = pgmap.OsmWay() elif isinstance(objIn, pgmap.OsmRelation): obj = pgmap.OsmRelation() obj.objId = objIn.objId obj.metaData.version = objIn.metaData.version + 1 if timestamp is None: obj.metaData.timestamp = int(time.time()) else: obj.metaData.timestamp = int(timestamp) obj.metaData.changeset = 1000 obj.metaData.uid = user.id obj.metaData.username = user.username obj.metaData.visible = False if isinstance(objIn, pgmap.OsmNode): obj.lat = objIn.lat obj.lon = objIn.lon data = pgmap.OsmData() if isinstance(objIn, pgmap.OsmNode): data.nodes.append(obj) elif isinstance(objIn, pgmap.OsmWay): data.ways.append(obj) elif isinstance(objIn, pgmap.OsmRelation): data.relations.append(obj) createdNodeIds = pgmap.mapi64i64() createdWayIds = pgmap.mapi64i64() createdRelationIds = pgmap.mapi64i64() errStr = pgmap.PgMapError() if tIn is not None: t = tIn else: t = p.GetTransaction("EXCLUSIVE") ok = t.StoreObjects(data, createdNodeIds, createdWayIds, createdRelationIds, False, errStr) if tIn is None: if not ok: t.Abort() print(errStr.errStr) else: t.Commit() return ok
def GetObj(p, objType, objId): t = p.GetTransaction("ACCESS SHARE") osmData = pgmap.OsmData() #Watch out, this goes out of scope! t.GetObjectsById(objType, [objId], osmData) del t objs = None if objType == "node": objs = osmData.nodes if len(objs) == 0: return None return pgmap.OsmNode(objs[0]) if objType == "way": objs = osmData.ways if len(objs) == 0: return None return pgmap.OsmWay(objs[0]) if objType == "relation": objs = osmData.relations if len(objs) == 0: return None return pgmap.OsmRelation(objs[0]) return None