[Featureserver] Query using pattern matching

Tom A. Cox tomc at hot.rr.com
Wed Aug 26 14:34:27 EDT 2009


I need to be able to retrieve a set of features from a PostGIS database using 
a pattern match.  For example, a column contains full street address 
information and I want to be able to retrieve all addresses for "Ave A".  I 
have a temporary hack in PostGIS.py for doing this using POSIX expressions.  
Does anyone have any thoughts on a better, more permanent solution?

Here's what I have right now.  The user indicates they want a pattern match by 
prefacing the data with a tilde.  "~Ave A".  The PostGIS.py code is modified 
as follows.

if action.attributes:
    match = Feature(props = action.attributes)
    filters = self.feature_predicates(match)
    attrs = action.attributes
    
    # TAC new pattern matchine code.
    for i in range(0, len(filters)):
        fields = filters[i].split()

        if attrs[fields[0]][0] == '~':
            # Strip the '~' from the input value, "~hwy" for example.
            attrs[fields[0]] = attrs[fields[0]][1:]

            # Eg. replace "container_type = %(container_type)s" with
            #             "container_type ~* %(container_type)s"
            # which performs a POSIX case insensitve match using 'hwy'
            filters[i] = "%s ~* %s" % (fields[0], fields[2])

-- 
Tom A. Cox
IntelliSystems
Systems Analyst and Consultant
Office: 254-848-5598  Email: Tom Cox <tomc at hot.rr.com>



More information about the Featureserver mailing list