Пример #1
0
def test_proj4(flowmachine_connect):
    """Test that correct proj4 strings are returned."""
    wsg84 = "+proj=longlat +datum=WGS84 +no_defs"
    haiti = "+proj=lcc +lat_1=35.46666666666667 +lat_2=34.03333333333333 +lat_0=33.5 +lon_0=-118 +x_0=2000000 +y_0=500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
    assert proj4string(flowmachine_connect) == wsg84  # Default
    assert proj4string(flowmachine_connect, wsg84) == wsg84
    assert proj4string(flowmachine_connect, 2770) == haiti  # Known proj4
Пример #2
0
def test_geojson_caching_off():
    """Test that switching off caching clears the cache, and doesn't add to it."""
    dl = daily_location("2016-01-01", "2016-01-02",
                        level="lat-lon").aggregate()
    js = dl.to_geojson(crs=2770)  # OSGB36
    dl.turn_off_caching()  # Check caching for geojson switches off
    with pytest.raises(KeyError):
        dl._geojson[proj4string(dl.connection, 2770)]
    js = dl.to_geojson(crs=2770)  # OSGB36
    with pytest.raises(KeyError):
        dl._geojson[proj4string(dl.connection, 2770)]
Пример #3
0
def test_geojson_caching_off():
    """Test that switching off caching clears the cache, and doesn't add to it."""
    dl = daily_location("2016-01-01",
                        "2016-01-02",
                        spatial_unit=make_spatial_unit("lon-lat")).aggregate()
    js = dl.to_geojson(crs=2770)  # OSGB36
    dl.turn_off_caching()  # Check caching for geojson switches off
    with pytest.raises(KeyError):
        dl._geojson[proj4string(get_db(), 2770)]
    js = dl.to_geojson(crs=2770)  # OSGB36
    with pytest.raises(KeyError):
        dl._geojson[proj4string(get_db(), 2770)]
Пример #4
0
def test_geojson_cache():
    """
    Test geojson is cached locally.
    """
    dl = daily_location("2016-01-01", "2016-01-02",
                        level="lat-lon").aggregate()
    js = dl.to_geojson(crs=2770)  # OSGB36
    assert js == dl._geojson[proj4string(dl.connection, 2770)]
Пример #5
0
def test_geojson_cache():
    """
    Test geojson is cached locally.
    """
    dl = daily_location("2016-01-01",
                        "2016-01-02",
                        spatial_unit=make_spatial_unit("lon-lat")).aggregate()
    js = dl.to_geojson(crs=2770)  # OSGB36
    assert js == dl._geojson[proj4string(get_db(), 2770)]
Пример #6
0
def test_reprojection():
    """
    Test that in db reprojection works.

    """
    dl = daily_location("2016-01-01",
                        "2016-01-02",
                        spatial_unit=make_spatial_unit("lon-lat")).aggregate()
    js = dl.to_geojson(crs=2770)  # OSGB36
    assert js["features"][0]["geometry"]["coordinates"] == pytest.approx(
        [-8094697.52, 9465052.88])
    assert js["properties"]["crs"] == proj4string(get_db(), 2770)
Пример #7
0
def test_reprojection():
    """
    Test that in db reprojection works.

    """
    dl = daily_location("2016-01-01", "2016-01-02",
                        level="lat-lon").aggregate()
    js = dl.to_geojson(crs=2770)  # OSGB36
    assert js["features"][0]["geometry"]["coordinates"] == [
        -8094697.51781301,
        9465052.88370377,
    ]
    assert js["properties"]["crs"] == proj4string(dl.connection, 2770)
Пример #8
0
 def to_geojson(self, crs=None):
     """
     Parameters
     ----------
     crs : int or str
         Optionally give an integer srid, or valid proj4 string to transform output to
     
     Returns
     -------
     dict
         This query as a GeoJson FeatureCollection in dict form.
     """
     proj4_string = proj4string(self.connection, crs)
     try:
         js = self._geojson.get(proj4_string, self._get_geojson(proj4_string))
     except AttributeError:
         self._geojson = {}
         js = self._get_geojson(proj4_string)
     if self._cache:
         self._geojson[proj4_string] = js
     return js.copy()
Пример #9
0
def test_proj4_errors(flowmachine_connect):
    """Test that appropriate errors are raised for bad inputs."""
    with pytest.raises(ValueError):
        proj4string(flowmachine_connect, ("foo", ))
    with pytest.raises(ValueError):
        proj4string(flowmachine_connect, 1)