Esempio n. 1
0
def get_document():
  r = request.GET.get("f")
  entity = db['documents'].find()

  # this returns a list of individual features
  # devs responsibility to build wrap in a
  # FeatureCollection
  # Sending ESRI JSON to be used in
  # Backbone kind of blows
  # Format doesn't play nice with Backbone Collection/Model
  features = map(lambda x: x, entity)
  featurecoll = {}
  featurecoll["features"] = features
  featurecoll["type"] = "FeatureCollection"
  if not entity:
    abort(404, 'No documents with id %s' % id)
  if (r and r.lower() == 'esri'):
    response = geo_to_esri(featurecoll)
    for feat in response["features"]:
      feat["_id"] = feat["attributes"]["_id"]

    response = json.dumps(response["features"])
  else:
    response = featurecoll
  return response
Esempio n. 2
0
def put_esrijs():
  data = request.body.readline()
  if not data:
    abort(400, 'No data received')
  entity = json.loads(data)

  result = geo_to_esri(entity)

  return result
Esempio n. 3
0
def get_document(id):
  r = request.GET.get("f")
  entity = db['documents'].find_one({'_id':id})
  if not entity:
    abort(404, 'No documents with id %s' % id)
  if (r and r.lower() == 'esri'):
    response = geo_to_esri(entity)
  else:
    response = entity
  return response
Esempio n. 4
0
def convert_geojson2esri():
  data = request.body.readline()
  print data
  if not data:
    abort(400, 'No data received')

  entity = json.loads(data)

  # remember, in this case
  # entity is just geojson
  result = geo_to_esri(entity)

  return result
Esempio n. 5
0
def post_documentgeojson():
  data = request.body.readline()
  print data
  if not data:
    abort(400, 'No data received')
  
  entity = json.loads(data)
  if not entity.has_key('_id'):
    abort(400, 'No _id specified')

  # remember, in this case
  # entity is just geojson
  try:
    db['documents'].save(entity)
  except ValidationError as ve:
    abort(400, str(ve))
  result = geo_to_esri(entity["features"])

  return result
Esempio n. 6
0
def put_documentesri():
  data = request.body.readline()
  print data
  if not data:
    abort(400, 'No data received')
  
  entity = json.loads(data)
  if not entity.has_key('_id'):
    abort(400, 'No _id specified')

  geojs = esri_to_geo(entity)
  geojs["_id"] = entity["_id"]

  try:
    db['documents'].save(geojs)
  except ValidationError as ve:
    abort(400, str(ve))
  result = geo_to_esri(geojs["features"])

  return result