Example #1
0
def test_creating_multiple_crs_without_file_limit():
    """
    This test checks for two things:
    1. Ensure database connection is closed for file limit
       https://github.com/pyproj4/pyproj/issues/374
    2. Ensure core-dumping does not occur when many objects are created
       https://github.com/pyproj4/pyproj/issues/678
    """
    codes = get_codes("EPSG", PJType.PROJECTED_CRS, False)
    assert [CRS.from_epsg(code) for code in codes]
Example #2
0
# Before adding a new WMS version, it should be checked if every consumer supports it!
supported_wms_versions = ["1.3.0", "1.1.1", "1.1.0", "1.0.0"]

epsg_3857_alias = set([
    "EPSG:{}".format(epsg)
    for epsg in [900913, 3587, 54004, 41001, 102113, 102100, 3785]
])

# List of not deprecated EPSG codes
valid_epsgs = set(["CRS:84"])
for pj_type in pyproj.enums.PJType:
    valid_epsgs.update(
        map(
            lambda x: "EPSG:{}".format(x),
            pyproj.get_codes("EPSG", pj_type, allow_deprecated=False),
        ))

# EPSG:3857 alias are valid if server does not support EPSG:3857
valid_epsgs.update(epsg_3857_alias)


def parse_eli_geometry(geometry):
    """ELI currently uses a geometry encoding not compatible with geojson.
    Create valid geometries from this format."""
    _geom = shape(geometry)
    geoms = [Polygon(_geom.exterior.coords)]
    for ring in _geom.interiors:
        geoms.append(Polygon(ring.coords))
    return cascaded_union(geoms)
def main():
    ''' 
    Create a csv file of datumshift maxima for ever grid cell of dimensions GRIDDEGREES
    within:
        LNGMIN, LNGMAX, LATMIN, LATMAX
    
    Invoke without parameters as:
       python datumshiftproj.py >> destfile.csv
    '''
    # Increment cells from LATMIN to LATMAX within LNGMIN to LNGMAX
    for x in frange(LNGMIN, LNGMAX, GRIDDEGREES):
        for y in frange(LATMIN, LATMAX, GRIDDEGREES):
            # Create the cell with a diff of 0 and the coordinates of the SW corner of
            # the cell
            griddiffs.append(0)
            gridpoints.append(Point(x, y))
    # Prepare variables for maximum shift searches
    # maxdiff - the overall biggest datum shift
    # maxdiffpoint - the coordinates of the SW corner of the cell with the biggest
    # datum shift
    # maxcrs - the coordinate reference system  of the SW corner of the cell with the
    # biggest datum shift
    maxdiff = 0
    maxdiffpoint = None
    maxcrs = None
    # Cycle through all EPSG code for which the type is a geographic coordinate system
    # and calculate datum shift for those that, like WGS84, use the Greenwich Meridian.
    for code in pyproj.get_codes('EPSG', PJType.GEOGRAPHIC_CRS):
        crs = CRS.from_user_input('epsg:%s' % code)
        if crs.prime_meridian.name == 'Greenwich':
            i = 0
            t = Transformer.from_crs("epsg:%s" % code,
                                     'epsg:4326',
                                     always_xy=True)
            ops = t.operations
            # For each grid cell in the current coordinate reference system, find the
            # transformed corner coordinate in WGS84
            for lng in frange(LNGMIN, LNGMAX, GRIDDEGREES):
                for lat in frange(LATMIN, LATMAX, GRIDDEGREES):
                    p = Point(float(lng), float(lat))
                    x, y = t.transform(lng, lat)
                    p_wgs84 = Point(x, y)
                    try:
                        # Find the haversine distance between the point in the current
                        # coordinate reference system and the location with the same
                        # coordinate in WGS84
                        diff = p.haversine_distance(p_wgs84)
                        # If the datum shift for the current coordinate reference system
                        # is greater than any other for the same location so far, store it
                        if diff > griddiffs[i]:
                            griddiffs[i] = round(diff)
                        # If the datum shift for the current coordinate reference system
                        # is greater than any other so far, store it, along with the
                        # EPSG code for the coordinate reference system
                        if diff > maxdiff:
                            maxdiff = diff
                            maxdiffpoint = p
                            maxdiffwgs84 = Point(x, y)
                            maxcrs = crs
                    except ValueError:
                        pass
                    i += 1


#    print(griddiffs)
#    print("maxcrs: %s op:%s %.0fm at %s: WGS84: %s" % (maxcrs.to_wkt(), ops, maxdiff, maxdiffpoint, maxdiffwgs84))
#    printvallnglat()
# print only the datum shifts for each cell
    printdiffsonly()
Example #4
0
def test_get_codes__invalid_code():
    with pytest.raises(ValueError):
        get_codes("ITRF", "frank")
Example #5
0
def test_get_codes__invalid_auth():
    with pytest.raises(TypeError):
        get_codes(123, PJType.BOUND_CRS)
Example #6
0
def test_get_codes__empty(auth, pj_type):
    assert not get_codes(auth, pj_type)
Example #7
0
def test_get_codes(auth, pj_type, deprecated):
    assert get_codes(auth, pj_type, deprecated)