Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method ProcessGeocodeResponse (HTTPInterface httpinterface) 
 | 
{ 
 | 
  #keys: '1[105690.0.469397562]' 
 | 
  Description: 'Process the HTTP response (in XML form) to store it in result NamedValueTree' 
 | 
  TextBody: 
 | 
  [* 
 | 
    // boon kiat Nov-7-2013 (created) 
 | 
    ticks := OS::PrecisionCounter(); 
 | 
     
 | 
    library := this.LibOSM_OSMGISLibrary(); 
 | 
    utils := library.LibOSM_Utils(); 
 | 
    result := library.Result(); 
 | 
    resultroot := result.Root(); 
 | 
     
 | 
    xmldomimplementation := XMLDOMImplementation::Create(); 
 | 
    geocoderesponse := xmldomimplementation.CreateDocumentFromBinaryInput( httpinterface.BinaryResult(), httpinterface.Encoding() ); 
 | 
    utils.DebugDump( "geocode_response.xml", geocoderesponse ); 
 | 
    utils.DebugEndTrace( "Dumping the geocode response", ticks ); 
 | 
     
 | 
    ticks := OS::PrecisionCounter(); 
 | 
     
 | 
    arguments := library.Arguments(); 
 | 
    maxresultshandle := arguments.GetHandle( "maxresults" ); 
 | 
    targetsrswkthandle := arguments.GetHandle( "targetsrswkt" ); 
 | 
    argumentsroot := arguments.Root(); 
 | 
    maxresults := argumentsroot.Child( maxresultshandle ).GetValueAsNumber(); 
 | 
     
 | 
    geocodedaddresshandle := result.GetHandle( "geocodedaddress" ); 
 | 
    countryhandle := result.GetHandle( "country" ); 
 | 
    statehandle := result.GetHandle( "state" ); 
 | 
    cityhandle := result.GetHandle( "city" ); 
 | 
    streethandle := result.GetHandle( "street" ); 
 | 
    housenumberhandle := result.GetHandle( "housenumber" ); 
 | 
    postcodehandle := result.GetHandle( "postcode" ); 
 | 
    matchhandle := result.GetHandle( "match" ); 
 | 
    xhandle := result.GetHandle( "x" ); 
 | 
    yhandle := result.GetHandle( "y" ); 
 | 
    srswkthandle := result.GetHandle( "srswkt" ); 
 | 
     
 | 
    if( this.Endpoint() = 'OSM-NOMINATIM' ) 
 | 
    { 
 | 
      resultaddresses := geocoderesponse.GetElementsByTagName( "place" ); 
 | 
     
 | 
      // Assuming fault when there is no result - QP #1459 
 | 
      if( resultaddresses.Size() = 0 ) 
 | 
      { 
 | 
        utils.HandleFault_Nominatim( "Geocode", httpinterface.ASyncCallId() ); 
 | 
      } 
 | 
      else 
 | 
      { 
 | 
        size := Number::Min( resultaddresses.Size(), maxresults ); 
 | 
     
 | 
        coordformatsetting := utils.GetOrCorrectCoordFormatSetting(); 
 | 
        coordformatwkt := LibOSM_Utils::GetCoordFormatWKT( coordformatsetting ); 
 | 
        desiredcoordformatwkt := argumentsroot.ChildOrDefault( targetsrswkthandle ).GetValueAsString( "" ); 
 | 
        stringtorealconverter := StringToReal::ISOConverter(); 
 | 
        for ( idx := 0; idx < size; idx++ ) 
 | 
        { 
 | 
          resultaddress := resultaddresses.Element( idx ); 
 | 
          geocodedaddress := resultroot.AddChild( geocodedaddresshandle ); 
 | 
          //Special static methods are created to retrieve the required node value, sets to default value if not present in response 
 | 
          geocodedaddress.AddChild( countryhandle, LibOSM_GeocodingServer::GetNodeOrDefaultValue( resultaddress, "country_code", "" ) ); 
 | 
          geocodedaddress.AddChild( statehandle, LibOSM_GeocodingServer::GetNodeOrDefaultValue( resultaddress, "state", "" ) ); 
 | 
          geocodedaddress.AddChild( cityhandle, LibOSM_GeocodingServer::GetNodeOrDefaultValue( resultaddress, "city", "" ) ); 
 | 
          geocodedaddress.AddChild( streethandle, LibOSM_GeocodingServer::GetNodeOrDefaultValue( resultaddress, "road", "" ) ); 
 | 
          geocodedaddress.AddChild( housenumberhandle, LibOSM_GeocodingServer::GetNodeOrDefaultValue( resultaddress, "house_number", "" ) ); 
 | 
          geocodedaddress.AddChild( postcodehandle, LibOSM_GeocodingServer::GetNodeOrDefaultValue( resultaddress, "postcode", "" ) ); 
 | 
          geocodedaddress.AddChild( matchhandle, LibOSM_GeocodingServer::ImportanceScoreAsMatchValue_Nominatim( stringtorealconverter.Convert( resultaddress.GetAttribute( "importance" ).NodeValue() ) ) ); 
 | 
          //lon - x, lat - y 
 | 
          x := stringtorealconverter.Convert( resultaddress.GetAttribute( "lon" ).NodeValue() ); 
 | 
          y := stringtorealconverter.Convert( resultaddress.GetAttribute( "lat" ).NodeValue() ); 
 | 
          if ( desiredcoordformatwkt.Length() > 0 and coordformatwkt <> desiredcoordformatwkt ) 
 | 
          { 
 | 
            convertedx := x; 
 | 
            convertedy := y; 
 | 
            LibOSM_Utils::Convert( coordformatwkt, x, y, desiredcoordformatwkt, convertedx, convertedy ); 
 | 
            geocodedaddress.AddChild( xhandle, convertedx ); 
 | 
            geocodedaddress.AddChild( yhandle, convertedy ); 
 | 
            geocodedaddress.AddChild( srswkthandle, desiredcoordformatwkt ); 
 | 
          } 
 | 
          else 
 | 
          { 
 | 
            geocodedaddress.AddChild( xhandle, x ); 
 | 
            geocodedaddress.AddChild( yhandle, y ); 
 | 
            geocodedaddress.AddChild( srswkthandle, coordformatwkt ); 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    else 
 | 
    { 
 | 
      resultinfo := geocoderesponse.GetElementByTagName( "info", 0 ); 
 | 
      statuscode := resultinfo.GetElementByTagName( "statusCode", 0 ).TextContent(); 
 | 
     
 | 
      // Assuming fault when statuscode is not 0 - QP #1459 
 | 
      if( statuscode <> '0' ) 
 | 
      { 
 | 
        utils.HandleFault_MapQuest( "Geocode", httpinterface.ASyncCallId(), resultinfo ); 
 | 
      } 
 | 
      else 
 | 
      { 
 | 
        resultaddresses := geocoderesponse.GetElementsByTagName( "location" ); 
 | 
        size := Number::Min( resultaddresses.Size(), maxresults ); 
 | 
     
 | 
        coordformatsetting := utils.GetOrCorrectCoordFormatSetting(); 
 | 
        coordformatwkt := LibOSM_Utils::GetCoordFormatWKT( coordformatsetting ); 
 | 
        desiredcoordformatwkt := argumentsroot.ChildOrDefault( targetsrswkthandle ).GetValueAsString( "" ); 
 | 
        stringtorealconverter := StringToReal::ISOConverter(); 
 | 
        for ( idx := 0; idx < size; idx++ ) 
 | 
        { 
 | 
          resultaddress := resultaddresses.Element( idx ); 
 | 
          geocodedaddress := resultroot.AddChild( geocodedaddresshandle ); 
 | 
          geocodedaddress.AddChild( countryhandle, resultaddress.GetElementByTagName( "adminArea1", 0 ).TextContent() ); //country 
 | 
          geocodedaddress.AddChild( statehandle, resultaddress.GetElementByTagName( "adminArea3", 0 ).TextContent() );   //state 
 | 
          geocodedaddress.AddChild( cityhandle, resultaddress.GetElementByTagName( "adminArea5", 0 ).TextContent() );    //city 
 | 
          geocodedaddress.AddChild( streethandle, resultaddress.GetElementByTagName( "street", 0 ).TextContent() ); 
 | 
          //TODO - should the house number be an optional result node? 
 | 
          geocodedaddress.AddChild( housenumberhandle, "" ); 
 | 
          geocodedaddress.AddChild( postcodehandle, resultaddress.GetElementByTagName( "postalCode", 0 ).TextContent() ); 
 | 
          geocodedaddress.AddChild( matchhandle, LibOSM_GeocodingServer::GeocodeQualityAsMatchValue_MapQuest( resultaddress.GetElementByTagName( "geocodeQuality", 0 ).TextContent() ) ); 
 | 
          //lng - x, lat - y 
 | 
          //TODO - or use displayLatLng instead? 
 | 
          x := stringtorealconverter.Convert( resultaddress.GetElementByTagName( "lng", 1 ).TextContent() ); 
 | 
          y := stringtorealconverter.Convert( resultaddress.GetElementByTagName( "lat", 1 ).TextContent() ); 
 | 
          if ( desiredcoordformatwkt.Length() > 0 and coordformatwkt <> desiredcoordformatwkt ) 
 | 
          { 
 | 
            convertedx := x; 
 | 
            convertedy := y; 
 | 
            LibOSM_Utils::Convert( coordformatwkt, x, y, desiredcoordformatwkt, convertedx, convertedy ); 
 | 
            geocodedaddress.AddChild( xhandle, convertedx ); 
 | 
            geocodedaddress.AddChild( yhandle, convertedy ); 
 | 
            geocodedaddress.AddChild( srswkthandle, desiredcoordformatwkt ); 
 | 
          } 
 | 
          else 
 | 
          { 
 | 
            geocodedaddress.AddChild( xhandle, x ); 
 | 
            geocodedaddress.AddChild( yhandle, y ); 
 | 
            geocodedaddress.AddChild( srswkthandle, coordformatwkt ); 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
     
 | 
    utils.DebugEndTrace( "GeocodingServer.ProcessGeocodeResponse", ticks ); 
 | 
     
 | 
    utils.DebugDump( "geocode_result.txt", resultroot ); 
 | 
     
 | 
    library.Done(); 
 | 
  *] 
 | 
} 
 |