def modify_way(wayIn, refsIn, tagsIn, user, timestamp = None): way = pgmap.OsmWay() way.objId = wayIn.objId way.metaData.version = wayIn.metaData.version + 1 if timestamp is None: way.metaData.timestamp = int(time.time()) else: way.metaData.timestamp = int(timestamp) way.metaData.changeset = 1000 way.metaData.uid = user.id way.metaData.username = user.username way.metaData.visible = True for k in tagsIn: way.tags[k] = tagsIn[k] for ref in refsIn: way.refs.append(ref) data = pgmap.OsmData() data.ways.append(way) 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) else: t.Commit() return ok, way
def create_way(uid, username, refs, changeset = 1000, timestamp = None): way = pgmap.OsmWay() way.objId = -1 way.metaData.version = 1 if timestamp is None: way.metaData.timestamp = int(time.time()) else: way.metaData.timestamp = int(timestamp) way.metaData.changeset = changeset way.metaData.uid = uid way.metaData.username = username way.metaData.visible = True way.tags["test"] = "spring" for ref in refs: way.refs.append(ref) data = pgmap.OsmData() data.ways.append(way) 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() way.objId = createdWayIds[-1] return way
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