21 #include "itksys/SystemTools.hxx"
39 m_Url =
"http://www.openstreetmap.org/api/0.6/map?";
70 std::ostringstream urlStream;
81 if (
m_Curl->IsCurlReturnHttpError( urlStream.str()))
83 itkExceptionMacro(<<
"The OSM Server returned an Error > =400,"
84 <<
" it means that one of server limits are crossed : node/way/relation or area requested");
95 itkExceptionMacro(<<
"The XML output FileName is empty, please set the filename via the method SetFileName");
98 if (itksys::SystemTools::GetFilenameLastExtension(
m_FileName) !=
".xml"
99 && itksys::SystemTools::GetFilenameLastExtension(
m_FileName)!=
".osm" )
101 itkExceptionMacro(<<itksys::SystemTools::GetFilenameLastExtension(
m_FileName)
102 <<
" is a wrong Extension FileName : Expected .xml or osm");
113 itkExceptionMacro(<<
"Error while deleting the file" <<
m_FileName);
124 itkExceptionMacro( <<
"Cannot open the file "<<
m_FileName );
128 TiXmlHandle hDoc(&doc);
129 TiXmlHandle root = hDoc.FirstChildElement();
131 if(!root.ToElement())
132 itkExceptionMacro(
"Invalid or corrupted XML file : The field way is not found");
141 for( TiXmlElement* node = root.FirstChild(
"node").ToElement();
142 node !=
NULL && strcmp(node->Value(),
"node")==0;
143 node = node->NextSiblingElement() )
146 double longitude = 0.;
147 double latitude = 0.;
149 if ( node->QueryIntAttribute(
"id", &
id) == TIXML_SUCCESS
150 && node->QueryDoubleAttribute(
"lat", &latitude) == TIXML_SUCCESS
151 && node->QueryDoubleAttribute(
"lon", &longitude) == TIXML_SUCCESS )
155 geoPoint[0] = longitude;
156 geoPoint[1] = latitude;
159 std::pair<int, VertexType> newEntry;
161 newEntry.second = geoPoint;
170 for( TiXmlElement* currentLayer = root.FirstChildElement(
"way").ToElement();
171 currentLayer !=
NULL && strcmp(currentLayer->Value(),
"way") ==0;
172 currentLayer = currentLayer->NextSiblingElement() )
174 bool foundKey =
false;
177 if(currentLayer->FirstChildElement(
"tag"))
182 for( TiXmlElement* currentTag = currentLayer->FirstChild(
"tag")->ToElement();
184 currentTag = currentTag->NextSiblingElement() )
186 std::string result = currentTag->Attribute(
"k");
194 std::string resultValue = currentTag->Attribute(
"v");
197 elementPair.first = result;
198 elementPair.second = resultValue;
213 for( TiXmlElement* currentNode = currentLayer->FirstChildElement(
"nd");
215 currentNode = currentNode->NextSiblingElement() )
218 if(currentNode->QueryIntAttribute(
"ref", &value) == TIXML_SUCCESS)
226 if(pointList.size() > 0)
228 vdelement.first = elementPair;
229 vdelement.second = pointList;
242 KeyMapType::iterator it =
m_KeysMap.find(key);
252 for(
unsigned int i = 0; i < currentTypes.size(); ++i)
254 if(currentTypes[i].compare(value) == 0)
260 currentTypes.push_back(value);
265 std::pair< std::string, StringVectorType > keytype;
267 keytype.second.push_back(value);
281 DataNodeType::Pointer document = DataNodeType::New();
282 DataNodeType::Pointer folder = DataNodeType::New();
287 document->SetNodeId(
"DOCUMENT");
288 folder->SetNodeId(
"FOLDER");
297 DataNodeType::Pointer currentDataNode = DataNodeType::New();
307 if(elementPair.first.compare(key) == 0)
312 if(value.empty() || elementPair.second.compare(value) == 0)
317 if(currentPointList[0].EuclideanDistanceTo(currentPointList[currentPointList.size()-1]) < 1e-10)
319 currentDataNode->SetNodeId(
"FEATURE_POLYGON");
321 PolygonType::Pointer polygon = PolygonType::New();
322 for(
unsigned int curVertexId = 0; curVertexId< currentPointList.size(); curVertexId++)
324 polygon->AddVertex(currentPointList[curVertexId]);
326 currentDataNode->SetPolygonExteriorRing(polygon);
330 LineType::Pointer currentLine = LineType::New();
331 for(
unsigned int curVertexId = 0; curVertexId< currentPointList.size(); curVertexId++)
333 currentLine->AddVertex(currentPointList[curVertexId]);
335 currentDataNode->SetNodeId(
"FEATURE_LINE");
337 currentDataNode->SetLine(currentLine);
341 currentDataNode->SetFieldAsString(
"Key", elementPair.first);
342 currentDataNode->SetFieldAsString(
"type", elementPair.second);
356 itkExceptionMacro(<<
"Requested key is empty, please set a valid one");
378 itkExceptionMacro(<<
"Requested key is empty, please set a valid one");
399 for(
unsigned int i = 0; i <
m_KeyList.size(); ++i)