Changeset 19880 in osm for applications/editors/josm


Ignore:
Timestamp:
2010-02-05T14:31:42+01:00 (14 years ago)
Author:
guggis
Message:

compiled xpaths, more efficient processing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/haiti_earthquake/hospitals/HospitalChunkCheck.groovy

    r19879 r19880  
    4040        }
    4141       
     42        def exprHospitalsInProximity = xpath.compile("count(//tag[@k = 'amenity'][@v = 'hospital']/..)")       
    4243        def int countHospitalsInProximity(node) {
    4344                def bbox = buildQueryBbox(node)
    4445                def queryUrl = "http://xapi.openstreetmap.org/api/0.6/*[amenity=hospital][${bbox}]"
    4546                def xapiResponse = DOMBuilder.parse(new InputStreamReader(new URL(queryUrl).openStream(), "UTF-8"))
    46                 def int  count = xpath.evaluate("count(//tag[@k = 'amenity'][@v = 'hospital']/..)", xapiResponse, XPathConstants.NUMBER)
     47                def int  count = exprHospitalsInProximity.evaluate(xapiResponse, XPathConstants.NUMBER)
    4748                return count
    4849        }
    4950       
     51        def exprHealthFacilitiesInProximity = xpath.compile("count(//tag[@k = 'health_facility:paho_id']/..)") 
    5052        def int countHealthFacilitiesInProximity(node) {
    5153                def bbox = buildQueryBbox(node)
    5254                def queryUrl = "http://xapi.openstreetmap.org/api/0.6/*[health_facility:paho_id=*][${bbox}]"
    5355                def xapiResponse = DOMBuilder.parse(new InputStreamReader(new URL(queryUrl).openStream(), "UTF-8"))
    54                 def int count = xpath.evaluate("count(//tag[@k = 'health_facility:paho_id']/..)", xapiResponse, XPathConstants.NUMBER)
     56                def int count = exprHealthFacilitiesInProximity.evaluate(xapiResponse, XPathConstants.NUMBER)
    5557                return count
    5658        }
     
    5961                def id = getHealthFacilityId(node)
    6062                def queryUrl = "http://xapi.openstreetmap.org/api/0.6/*[health_facility:paho_id=${id}]"
     63                //def queryUrl = "http://osmxapi.hypercube.telascience.org/api/0.6/*[health_facility:paho_id=${id}]"
    6164                def xapiResponse = DOMBuilder.parse(new InputStreamReader(new URL(queryUrl).openStream(), "UTF-8"))
    62                 def int count = xpath.evaluate("count(//tag[@k = 'health_facility:paho_id'][@v ='${id}'])", xapiResponse, XPathConstants.NUMBER)
     65                def int count = xpath.evaluate("count(//tag[@k = 'health_facility:paho_id'][@v =${id}])", xapiResponse, XPathConstants.NUMBER)
    6366                return count > 0
    6467        }
    6568       
     69        def exprHealthFacilityId = xpath.compile("./tag[@k = 'health_facility:paho_id']/@v")
    6670        def getHealthFacilityId(node) {
    67                 return xpath.evaluate("./tag[@k = 'health_facility:paho_id']/@v", node)
     71                return exprHealthFacilityId.evaluate(node)
    6872        }
    6973       
     74        def exprName = xpath.compile("./tag[@k = 'name']/@v")
    7075        def getName(node) {
    71                 return xpath.evaluate("./tag[@k = 'name']/@v", node)           
     76                return exprName.evaluate(node)         
    7277        }
    7378       
     79        def exprId = xpath.compile("./@id")
    7480        def getNodeId(node) {
    75                 return xpath.evaluate("./@id", node)           
     81                return exprId.evaluate(node)           
    7682        }
    7783       
Note: See TracChangeset for help on using the changeset viewer.