def ways_for_node(request, objType, objId): t = p.GetTransaction("ACCESS SHARE") #Check reference object exists osmData = pgmap.OsmData() t.GetObjectsById(objType, pgmap.seti64([int(objId)]), osmData) # From the 0.6 spec: "There is no error if the element does not exist." osmData = pgmap.OsmData() t.GetWaysForNodes([int(objId)], osmData) sio = io.BytesIO() enc = pgmap.PyOsmXmlEncode(sio, common.xmlAttribs) osmData.StreamTo(enc) return HttpResponse(sio.getvalue(), content_type='text/xml')
def element(request, objType, objId): if request.method == 'GET': osmData = pgmap.OsmData() t = p.GetTransaction("ACCESS SHARE") t.GetObjectsById(objType.encode("UTF-8"), pgmap.seti64([int(objId)]), osmData) if len(osmData.nodes) + len(osmData.ways) + len( osmData.relations) == 0: return HttpResponseNotFound("{} {} not found".format( objType, objId)) sio = io.BytesIO() enc = pgmap.PyOsmXmlEncode(sio, common.xmlAttribs) osmData.StreamTo(enc) return HttpResponse(sio.getvalue(), content_type='text/xml') if request.method in ['PUT', 'DELETE']: t = p.GetTransaction("EXCLUSIVE") action = None if request.method == "PUT": action = "modify" if request.method == "DELETE": action = "delete" obj = None if objType == "node": obj = request.data.nodes[0] if objType == "way": obj = request.data.ways[0] if objType == "relation": obj = request.data.relations[0] if obj.objId != objId: return HttpResponseBadRequest("Object has wrong ID") ret = upload_single_object(action, request, obj, objType, t) if ret != True: return ret return HttpResponse("", content_type='text/plain')
settings["dbname"], settings["dbuser"], settings["dbpass"], settings["dbhost"]), settings["dbtableprefix"], settings["dbtabletestprefix"]) print("Connected to database", p.Ready()) t = p.GetTransaction(b"ACCESS SHARE") if 0: sio = io.BytesIO() #enc = pgmap.PyO5mEncode(sio) enc = pgmap.PyOsmXmlEncode(sio) print( t.MapQuery((-1.1473846, 50.7360206, -0.9901428, 50.8649113), 0, enc)) data = sio.getvalue() print(len(data), "bytes") if 1: osmData = pgmap.OsmData() objectIds = [1000594005591, 1000595178493, 1000594446551] t.GetObjectsById("node", pgmap.seti64(objectIds), osmData) print(len(osmData.nodes)) for i in range(len(osmData.nodes)): node = osmData.nodes[i] print(type(node)) print(node.objId, node.lat, node.lon) t.Commit()