Пример #1
0
 def index(self, responseFormat='html'):
     'Get tags with visible features'
     # Get responseFormat
     responseFormat = responseFormat.lower()
     if responseFormat not in ['json', 'html']:
         abort(400, 'Must specify a valid responseFormat: json, html')
     # Authenticate via personID or key
     personID = h.getPersonIDViaKey()
     # Get tags with visible features
     c.tags = Session.query(model.Tag).join(model.Tag.features).filter(model.getFeatureFilter(personID)).all()
     # If the user wants json,
     if responseFormat == 'json':
         return '\n'.join(sorted(x.text for x in c.tags))
     # If the user wants html,
     elif responseFormat == 'html':
         return render('/tags/index.mako')
Пример #2
0
 def index(self, responseFormat='html'):
     'Get tags with visible features'
     # Get responseFormat
     responseFormat = responseFormat.lower()
     if responseFormat not in ['json', 'html']:
         abort(400, 'Must specify a valid responseFormat: json, html')
     # Authenticate via personID or key
     personID = h.getPersonIDViaKey()
     # Get tags with visible features
     c.tags = Session.query(model.Tag).join(model.Tag.features).filter(
         model.getFeatureFilter(personID)).all()
     # If the user wants json,
     if responseFormat == 'json':
         return '\n'.join(sorted(x.text for x in c.tags))
     # If the user wants html,
     elif responseFormat == 'html':
         return render('/tags/index.mako')
Пример #3
0
     # Define transformation in a metric coordinate system
     simplify = lambda x: sa.func.ST_SimplifyPreserveTopology(
         geoalchemy.functions.transform(x, 3857), metersPerPixel)
 # If simplification is not desired,
 else:
     simplify = lambda x: x
 # Prepare query
 featureQuery = restrict(
     Session.query(
         model.Feature.id,
         geoalchemy.functions.wkb(
             geoalchemy.functions.transform(
                 simplify(model.Feature.geometry), srid)),
         model.Feature.properties).join(model.Feature.tags).filter(
             model.Tag.id.in_([x.id for x in tags])).filter(
                 model.getFeatureFilter(personID)))
 # Prepare map
 try:
     geojsonFeatures = [
         geojson.Feature(
             id=featureID,
             geometry=shapely.wkb.loads(str(featureWKB)),
             properties=featureProperties) for featureID,
         featureWKB, featureProperties in featureQuery
     ]
 except sa.exc.InternalError, error:
     abort(400, 'Could not execute query (%s)' % str(error))
 # Store map in cache
 cachedMap = model.Map()
 cachedMap.geojson = unicode(
     geojson.dumps(geojson.FeatureCollection(geojsonFeatures)),
Пример #4
0
                        Session.rollback()
                        y1, x1, y2, x2 = -20037508.34, -20037508.34, 20037508.34, 20037508.34
                    else:
                        y1, x1 = multiPoint.geoms[0].coords[0]
                        y2, x2 = multiPoint.geoms[1].coords[0]
                    metersPerPixel = min(abs(x2 - x1), abs(y2 - y1)) / 256.
                # If a bounding box is not specified,
                else:
                    metersPerPixel = 0.2
                # Define transformation in a metric coordinate system
                simplify = lambda x: sa.func.ST_SimplifyPreserveTopology(geoalchemy.functions.transform(x, 3857), metersPerPixel)
            # If simplification is not desired,
            else:
                simplify = lambda x: x
            # Prepare query
            featureQuery = restrict(Session.query(model.Feature.id, geoalchemy.functions.wkb(geoalchemy.functions.transform(simplify(model.Feature.geometry), srid)), model.Feature.properties).join(model.Feature.tags).filter(model.Tag.id.in_([x.id for x in tags])).filter(model.getFeatureFilter(personID)))
            # Prepare map
            try:
                geojsonFeatures = [geojson.Feature(id=featureID, geometry=shapely.wkb.loads(str(featureWKB)), properties=featureProperties) for featureID, featureWKB, featureProperties in featureQuery]
            except sa.exc.InternalError, error:
                abort(400, 'Could not execute query (%s)' % str(error))
            # Store map in cache
            cachedMap = model.Map()
            cachedMap.geojson = unicode(geojson.dumps(geojson.FeatureCollection(geojsonFeatures)), 'utf-8')
            cachedMap.query_hash = queryStringHash
            cachedMap.when_updated = datetime.datetime.utcnow()
            Session.add(cachedMap)
            Session.commit()
        # Return
        return cachedMap.geojson.encode('utf-8')