def validateSRID(srid): 'Make sure we have a valid SRID' if not srid: raise GeoRegistryError('Must specify spatial reference srid') try: srid = int(srid) except ValueError: raise GeoRegistryError('Could not parse srid=%s as an integer' % srid) result = Session.execute('SELECT proj4text FROM spatial_ref_sys WHERE srid=:srid', dict(srid=srid)).fetchone() if not result: raise GeoRegistryError('Could not recognize srid=%s' % srid) return result[0]
def getTags(string, addMissing=False): 'Return corresponding tags' # Load tagTexts and discard empty lines tagTexts = filter(lambda x: x, (x.strip() for x in string.splitlines())) if not tagTexts: raise GeoRegistryError('Must specify at least one tag in tags') # Check whether tagTexts are too long longTagTexts = filter(lambda x: len(x) > parameter.TAG_LENGTH_MAXIMUM, tagTexts) if longTagTexts: raise GeoRegistryError('Cannot add the following tags because they are too long:\n%s' % '\n'.join(longTagTexts)) # Check whether tags exist missingTagTexts = list(set(tagTexts).difference(tag.text for tag in Session.query(Tag).filter(Tag.text.in_(tagTexts)))) if missingTagTexts: # If we are not supposed to add missing tags, if not addMissing: raise GeoRegistryError('Cannot match the following tags: %s' % missingTagTexts) # Add tags that don't exist Session.execute(tags_table.insert(), [{ 'text': x, } for x in missingTagTexts]) # Commit Session.commit() # Return return Session.query(Tag).filter(Tag.text.in_(tagTexts)).all()