コード例 #1
0
def modify_node(nodeIn, nodeCurrentVer, user, timestamp = None):
	node = pgmap.OsmNode()
	node.objId = nodeIn.objId
	node.metaData.version = nodeCurrentVer + 1
	if timestamp is None:
		node.metaData.timestamp = int(time.time())
	else:
		node.metaData.timestamp = int(timestamp)
	node.metaData.changeset = 1000
	node.metaData.uid = user.id
	node.metaData.username = user.username
	node.metaData.visible = True
	node.tags["test"] = "winter"
	node.lat = nodeIn.lat + 0.1
	node.lon = nodeIn.lon + 0.2

	data = pgmap.OsmData()
	data.nodes.append(node)

	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, node
コード例 #2
0
ファイル: tests.py プロジェクト: aaj013/pycrocosm
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
コード例 #3
0
ファイル: tests.py プロジェクト: aaj013/pycrocosm
def create_node(uid,
                username,
                nearbyNode=None,
                changeset=1000,
                timestamp=None):
    node = pgmap.OsmNode()
    node.objId = -1
    node.metaData.version = 1
    if timestamp is None:
        node.metaData.timestamp = int(time.time())
    else:
        node.metaData.timestamp = int(timestamp)
    node.metaData.changeset = changeset
    node.metaData.uid = uid
    node.metaData.username = username
    node.metaData.visible = True
    node.tags["test"] = "autumn"
    if nearbyNode is None:
        node.lat = 43.0 + random.uniform(-1.0, 1.0)
        node.lon = -70.3 + random.uniform(-1.0, 1.0)
    else:
        node.lat = nearbyNode.lat + random.uniform(-0.00015, 0.00015)
        node.lon = nearbyNode.lon + random.uniform(-0.00015, 0.00015)

    data = pgmap.OsmData()
    data.nodes.append(node)

    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()
    node.objId = createdNodeIds[-1]
    return node
コード例 #4
0
ファイル: tests.py プロジェクト: guyarad/pycrocosm
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