Beispiel #1
0
 def test_should_create_location_geojson_for_unknown_location(self):
     expected_geojson = '{"type": "FeatureCollection", "features": []}'
     entity1 = Entity(self.dbm,
                      entity_type="Water Point",
                      location=["India", "MH", "Pune"],
                      short_code="WP002")
     entity_list = [entity1]
     self.assertEqual(expected_geojson,
                      helper.create_location_geojson(entity_list))
Beispiel #2
0
def map_entities(request):
    dbm = get_database_manager(request.user)
    project = Project.load(dbm.database, request.GET['project_id'])
    if project.is_activity_report():
        entity_list = [
            get_by_short_code(dbm, short_code, ["reporter"])
            for short_code in project.data_senders
        ]
    else:
        entity_list = get_entities_by_type(dbm, request.GET['id'])
    location_geojson = helper.create_location_geojson(entity_list)
    return HttpResponse(location_geojson)
Beispiel #3
0
 def test_should_not_raise_exception_if_coordinates_is_empty(self):
     expected_geojson = '{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [3, 1]}, "type": "Feature"}]}'
     entity1 = Entity(self.dbm,
                      entity_type="Water Point",
                      location=["India", "MH", "Pune"],
                      short_code="WP002",
                      geometry={
                          'type': 'Point',
                          'coordinates': []
                      })
     entity2 = Entity(self.dbm,
                      entity_type="Water Point",
                      location=["India", "MH", "Pune"],
                      short_code="WP002",
                      geometry={
                          'type': 'Point',
                          'coordinates': [1, 3]
                      })
     entity_list = [entity1, entity2]
     self.assertEqual(expected_geojson,
                      helper.create_location_geojson(entity_list))
Beispiel #4
0
 def test_should_resolve_location_to_centriod(self):
     expected_geojson = '{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [48.41586788688786, -17.814011993472985]}, "type": "Feature"}, {"geometry": {"type": "Point", "coordinates": [3, 1]}, "type": "Feature"}]}'
     entity1 = Entity(self.dbm,
                      entity_type="Water Point",
                      location=[
                          'Madagascar', 'TOAMASINA', 'ALAOTRA MANGORO',
                          'AMBATONDRAZAKA', 'AMBATONDRAZAKA'
                      ],
                      short_code="WP002",
                      geometry={})
     entity2 = Entity(self.dbm,
                      entity_type="Water Point",
                      location=["India", "MH", "Pune"],
                      short_code="WP002",
                      geometry={
                          'type': 'Point',
                          'coordinates': [1, 3]
                      })
     entity_list = [entity1, entity2]
     self.assertEqual(expected_geojson,
                      helper.create_location_geojson(entity_list))
Beispiel #5
0
 def test_should_not_raise_exception_if_no_location_or_geo_code_specified(
         self):
     entity = Entity(self.dbm,
                     entity_type="Water Point",
                     short_code="WP002")
     helper.create_location_geojson(entity_list=[entity])