示例#1
0
def filterMaps(mapSets, propName,operator,value):
        """Return a new set of maps whose property propName satisfies the given operator/value.
        The operators can be ==,!=, <,>,<=,>=, match, !match"""
        from ucar.visad import ShapefileAdapter
        from ucar.unidata.util import StringUtil
	goodOnes = java.util.ArrayList();
	sets = mapSets.getSets();
        for mapIdx in xrange(len(sets)):
		mapValue =  getMapProperty(sets[mapIdx],propName);
		if(mapValue is None):
			continue;
		if(operator== '==' and mapValue == value):
			goodOnes.add(sets[mapIdx]);
		elif(operator== '!=' and mapValue != value):
			goodOnes.add(sets[mapIdx]);
		elif(operator== '<' and mapValue < value):
			goodOnes.add(sets[mapIdx]);
		elif(operator== '<=' and mapValue <= value):
			goodOnes.add(sets[mapIdx]);
		elif(operator== '>' and mapValue > value):
			goodOnes.add(sets[mapIdx]);
		elif(operator== '>=' and mapValue >= value):
			goodOnes.add(sets[mapIdx]);
		elif(operator== 'match' and StringUtil.stringMatch(str(mapValue), value)):
			goodOnes.add(sets[mapIdx]);
		elif(operator== '!match' and not StringUtil.stringMatch(str(mapValue), value)):
			print "not match: " + mapValue;
			goodOnes.add(sets[mapIdx]);

	return ShapefileAdapter.makeSet(goodOnes);