Ejemplo n.º 1
0
void OsmXmlEncodeBase::StoreRelation(int64_t objId, const class MetaData &metaData, const TagMap &tags, 
	const std::vector<std::string> &refTypeStrs, const std::vector<int64_t> &refIds,
	const std::vector<std::string> &refRoles)
{
	if(refTypeStrs.size() != refIds.size() || refTypeStrs.size() != refRoles.size())
		throw std::invalid_argument("Length of ref vectors must be equal");

	stringstream ss;
	ss << "  <relation id=\""<<objId<<"\"";
	this->EncodeMetaData(metaData, ss);
	if(tags.size() == 0 && refTypeStrs.size() == 0)
		ss <<" />" << endl;
	else
	{
		ss <<">" << endl;

		//Write node IDs
		for(size_t i=0; i<refTypeStrs.size(); i++)
			ss << "    <member type=\""<<escapexml(refTypeStrs[i])<<"\" ref=\""<<refIds[i]<<"\" role=\""<<escapexml(refRoles[i])<<"\" />" << endl;

		//Write tags
		for(TagMap::const_iterator it=tags.begin(); it!=tags.end(); it++)
			ss << "    <tag k=\""<<escapexml(it->first)<<"\" v=\""<<escapexml(it->second)<<"\" />" << endl;

		ss << "  </relation>" << endl;
	}
	*this << ss.str();
}
Ejemplo n.º 2
0
Archivo: o5m.cpp Proyecto: TimSC/cppo5m
void PrintTagMap(const TagMap &tagMap)
{
	for(TagMap::const_iterator it = tagMap.begin(); it != tagMap.end(); it++)
	{
		std::cout << it->first << "=" << it->second << std::endl;
	}
}
Ejemplo n.º 3
0
Archivo: o5m.cpp Proyecto: TimSC/cppo5m
void O5mEncodeBase::StoreNode(int64_t objId, const class MetaData &metaData, 
		const TagMap &tags, double latIn, double lonIn)
{
	this->write("\x10",1);

	//Object ID
	std::stringstream tmpStream;
	int64_t deltaId = objId - this->lastObjId;
	tmpStream << EncodeZigzag(deltaId);
	this->lastObjId = objId;

	this->EncodeMetaData(metaData, tmpStream);

	//Position
	int64_t lon = round(lonIn * 1e7);
	int64_t deltaLon = lon - this->lastLon;
	tmpStream << EncodeZigzag(deltaLon);
	this->lastLon = lon;
	int64_t lat = round(latIn * 1e7);
	int64_t deltaLat = lat - this->lastLat;
	tmpStream << EncodeZigzag(deltaLat);
	this->lastLat = lat;

	for (TagMap::const_iterator it=tags.begin(); it != tags.end(); it++)
		this->WriteStringPair(it->first, it->second, tmpStream);

	std::string binData = tmpStream.str();
	std::string len = EncodeVarint(binData.size());
	*this << len;
	*this << binData;
}
Ejemplo n.º 4
0
void OsmXmlEncodeBase::WriteStart(const TagMap &customAttribs)
{
	*this << "<?xml version='1.0' encoding='UTF-8'?>\n";
	*this << "<osm";
	TagMap::const_iterator it = customAttribs.find("version");
	if(it != customAttribs.end())
	{
		*this << " version=\""; 
		*this << escapexml(it->second);
		*this << "\"";
	}
	else
		*this << " version=\"0.6\"";

	it = customAttribs.find("generator");
	if(it != customAttribs.end())
	{
		*this << " generator=\"";
		*this << escapexml(it->second);
		*this << "\"";
	}
	else
		*this << " generator=\"cppo5m\"";

	for(it = customAttribs.begin(); it != customAttribs.end(); it++)
	{
		if(it->first == "version" || it->first == "generator")
			continue;
		if(it->second.length() == 0)
			continue;
		*this << " ";
		*this << escapexml(it->first);
		*this <<"=\"";
		*this << escapexml(it->second);
		*this <<"\"";
	}

	*this << ">\n";
}
Ejemplo n.º 5
0
void OsmXmlEncodeBase::StoreNode(int64_t objId, const class MetaData &metaData, 
	const TagMap &tags, double lat, double lon)
{
	stringstream ss;
	ss.precision(9);
	ss << "  <node id=\""<<objId<<"\"";
	this->EncodeMetaData(metaData, ss);
	ss << fixed << " lat=\""<<lat<<"\" lon=\""<<lon<<"\"";
	if(tags.size() == 0)
		ss <<" />" << endl;
	else
	{
		ss <<">" << endl;

		//Write tags
		for(TagMap::const_iterator it=tags.begin(); it!=tags.end(); it++)
		{
			ss << "    <tag k=\""<<escapexml(it->first)<<"\" v=\""<<escapexml(it->second)<<"\" />" << endl;
		}
		ss << "  </node>" << endl;
	}
	*this << ss.str();
}
Ejemplo n.º 6
0
void OsmXmlEncodeBase::StoreWay(int64_t objId, const class MetaData &metaData, 
	const TagMap &tags, const std::vector<int64_t> &refs)
{
	stringstream ss;
	ss << "  <way id=\""<<objId<<"\"";
	this->EncodeMetaData(metaData, ss);
	if(tags.size() == 0 && refs.size() == 0)
		ss <<" />" << endl;
	else
	{
		ss <<">" << endl;

		//Write node IDs
		for(size_t i=0; i<refs.size(); i++)
			ss << "    <nd ref=\""<<refs[i]<<"\" />" << endl;

		//Write tags
		for(TagMap::const_iterator it=tags.begin(); it!=tags.end(); it++)
			ss << "    <tag k=\""<<escapexml(it->first)<<"\" v=\""<<escapexml(it->second)<<"\" />" << endl;

		ss << "  </way>" << endl;
	}
	*this << ss.str();
}
Ejemplo n.º 7
0
Archivo: o5m.cpp Proyecto: TimSC/cppo5m
void O5mEncodeBase::StoreWay(int64_t objId, const class MetaData &metaData, 
		const TagMap &tags, const std::vector<int64_t> &refs)
{
	this->write("\x11", 1);

	//Object ID
	std::stringstream tmpStream;
	int64_t deltaId = objId - this->lastObjId;
	tmpStream << EncodeZigzag(deltaId);
	this->lastObjId = objId;

	//Store meta data
	this->EncodeMetaData(metaData, tmpStream);

	//Store nodes
	std::stringstream refStream;
	for(size_t i=0; i< refs.size(); i++)
	{
		int64_t ref = refs[i]; 
		int64_t deltaRef = ref - this->lastRefNode;
		refStream << EncodeZigzag(deltaRef);
		this->lastRefNode = ref;
	}

	std::string encRefs = refStream.str();
	tmpStream << EncodeVarint(encRefs.size());
	tmpStream << encRefs;

	//Write tags
	for (TagMap::const_iterator it=tags.begin(); it != tags.end(); it++)
		this->WriteStringPair(it->first, it->second, tmpStream);

	std::string binData = tmpStream.str();
	*this << EncodeVarint(binData.size());
	*this << binData;
}
Ejemplo n.º 8
0
Archivo: o5m.cpp Proyecto: TimSC/cppo5m
void O5mEncodeBase::StoreRelation(int64_t objId, const class MetaData &metaData, const TagMap &tags, 
		const std::vector<std::string> &refTypeStrs, const std::vector<int64_t> &refIds, 
		const std::vector<std::string> &refRoles)
{
	if(refTypeStrs.size() != refIds.size() || refTypeStrs.size() != refRoles.size())
		throw std::invalid_argument("Length of ref vectors must be equal");

	this->write("\x12", 1);

	//Object ID
	std::stringstream tmpStream;
	int64_t deltaId = objId - this->lastObjId;
	tmpStream << EncodeZigzag(deltaId);
	this->lastObjId = objId;

	//Store meta data
	this->EncodeMetaData(metaData, tmpStream);

	//Store referenced children
	std::stringstream refStream;
	for(size_t i=0; i<refTypeStrs.size(); i++)
	{
		const std::string &typeStr = refTypeStrs[i];
		int64_t refId = refIds[i];
		const std::string &role = refRoles[i];
		char typeCode[2] = "0";
		int64_t deltaRef = 0;
		if(typeStr == "node")
		{
			typeCode[0] = '0';
			deltaRef = refId - this->lastRefNode;
			this->lastRefNode = refId;
		}
		if(typeStr == "way")
		{
			typeCode[0] = '1';
			deltaRef = refId - this->lastRefWay;
			this->lastRefWay = refId;
		}
		if(typeStr == "relation")
		{
			typeCode[0] = '2';
			deltaRef = refId - this->lastRefRelation;
			this->lastRefRelation = refId;
		}

		refStream << EncodeZigzag(deltaRef);

		std::string typeCodeAndRole(typeCode);
		typeCodeAndRole.append(role);

		bool indexFound = false;
		size_t refIndex = this->FindStringPairsIndex(typeCodeAndRole, indexFound);
		if(indexFound)
		{
			refStream << EncodeVarint(refIndex);
		}
		else
		{
			refStream.write("\x00", 1); //String start byte
			refStream << typeCodeAndRole;
			refStream.write("\x00", 1); //String end byte
			if(typeCodeAndRole.size() <= this->refTableLengthThreshold)
				this->AddToRefTable(typeCodeAndRole);
		}
	}
	
	std::string encRefs = refStream.str();
	tmpStream << EncodeVarint(encRefs.size());
	tmpStream << encRefs;

	//Write tags
	for (TagMap::const_iterator it=tags.begin(); it != tags.end(); it++)
		this->WriteStringPair(it->first, it->second, tmpStream);

	std::string binData = tmpStream.str();
	*this << EncodeVarint(binData.size());
	*this << binData;

}