How to use the svgis.projection function in svgis

To help you get started, we’ve selected a few svgis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fitnr / svgis / tests / test_projection.py View on Github external
def testUtm(self):
        assert projection.utm_proj4(-21, 42) == '+proj=utm +zone=27 +north +datum=WGS84 +units=m +no_defs'

        assert projection.utm_proj4(-21, -42) == '+proj=utm +zone=27 +south +datum=WGS84 +units=m +no_defs'

        with self.assertRaises(ValueError):
            projection.utm_proj4(-200, 100)
github fitnr / svgis / tests / test_projection.py View on Github external
def testUtm(self):
        assert projection.utm_proj4(-21, 42) == '+proj=utm +zone=27 +north +datum=WGS84 +units=m +no_defs'

        assert projection.utm_proj4(-21, -42) == '+proj=utm +zone=27 +south +datum=WGS84 +units=m +no_defs'

        with self.assertRaises(ValueError):
            projection.utm_proj4(-200, 100)
github fitnr / svgis / svgis / svgis.py View on Github external
self.files = [files]
        elif isinstance(files, Iterable):
            self.files = files
        else:
            raise ValueError("'files' must be a file name or list of file names")

        self.log.info('starting SVGIS, files: %s', ', '.join(self.files))

        if bounding.check(bounds):
            self._unprojected_bounds = bounds
        elif bounds:
            self.log.warning("ignoring invalid bounds: %s", bounds)

        # This may return a keyword, which will require more updating.
        # If so, will update when files are open.
        self._out_crs = projection.pick(crs)

        self.scalar = kwargs.pop('scalar', 1) or 1

        self.style = STYLE + (kwargs.pop('style', '') or '')

        self.padding = kwargs.pop('padding', 0) or 0

        self.precision = kwargs.pop('precision', None)

        self.clip = kwargs.pop('clip', True)

        simple = kwargs.pop('simplify', None)

        if simple:
            self.simplifier = transform.simplifier(simple)
            self.log.debug('Simplifying with a factor of %d', simple)
github fitnr / svgis / svgis / graticule.py View on Github external
'''
    Draw graticules.

    Args:
        bounds (tuple): In WGS84 coordinates.
        step (int): Distance between graticule lines, in the output projection.
        crs_or_method (str): A projection specification.

    Returns:
        A generator that yields GeoJSON-like dicts of graticule features.
    '''
    if crs_or_method == 'file':
        raise ValueError("'file' is not a valid option for projecting graticules.")

    if crs_or_method:
        out_crs = projection.pick(crs_or_method, bounds=bounds, file_crs=utils.DEFAULT_GEOID)

        bounds = bounding.transform(utils.DEFAULT_GEOID, out_crs, bounds)
        unproject = partial(fiona.transform.transform, out_crs, utils.DEFAULT_GEOID)

    else:
        def unproject(x, y):
            return x, y

    minx, miny, maxx, maxy = bounds

    minx, miny = utils.modfloor(minx, step), utils.modfloor(miny, step)
    maxx, maxy = utils.modceil(maxx, step), utils.modceil(maxy, step)

    frange = partial(utils.frange, cover=True)

    for i, X in enumerate(frange(minx, maxx + step, step), 1):
github fitnr / svgis / svgis / svgis.py View on Github external
def set_out_crs(self, bounds):
        '''Set the output CRS, if not yet set.'''
        if self.out_crs:
            return

        # Determine projection transformation:
        # either use something passed in, a non latlong layer projection,
        # the local UTM, or customize local TM
        self.log.debug('Picking a projection:')
        self.log.debug('    out crs: %s', self._out_crs)
        self.log.debug('    in crs: %s', projection.fake_to_string(self.in_crs))
        self.log.debug('    bounds: %s', bounds)
        self._out_crs = projection.pick(self._out_crs, bounds, self.in_crs)
        self.log.debug('Set output crs to %s', projection.fake_to_string(self.out_crs))
github fitnr / svgis / svgis / cli.py View on Github external
def project(bounds, method, crs):
    '''Get a local Transverse Mercator or UTM projection for a bounding box. Expects WGS84 coordinates.'''
    if crs in projection.METHODS:
        click.echo('CRS must be an EPSG code, a Proj4 string, or file containing a Proj4 string.', err=1)
        return

    if len(bounds) == 2:
        bounds = bounds + bounds

    if len(bounds) != 4:
        click.echo('Either two or four bounds required', err=True)
        return

    result = fiona.crs.to_string(projection.pick(method, file_crs=crs, bounds=bounds))
    click.echo(result.encode('utf-8'))
github fitnr / svgis / svgis / cli.py View on Github external
def bounds(layer, crs, latlon=False):
    '''
    Return the bounds for a given layer, optionally projected.
    '''
    meta = meta_complete(layer)

    # If crs==file, these will basically be no ops.
    out_crs = projection.pick(crs, meta['bounds'], file_crs=meta['crs'])
    result = bounding.transform(meta['crs'], out_crs, meta['bounds'])

    if latlon:
        fmt = '{0[1]} {0[0]} {0[3]} {0[2]}'
    else:
        fmt = '{0[0]} {0[1]} {0[2]} {0[3]}'

    click.echo(fmt.format(result), file=sys.stdout)
github fitnr / svgis / svgis / cli / actions.py View on Github external
def proj(_, minx, miny, maxx, maxy, project=None):
    '''Return a transverse mercator projection for the given bounds'''
    prj = projection.generatecrs(minx, miny, maxx, maxy, project)
    return prj + '\n'
github fitnr / svgis / svgis / osm.py View on Github external
def make_projection(osm, out_crs=None):
    if out_crs is None:
        coords = [(float(n.get('lon')), float(n.get('lat'))) for n in osm.findall('node')]
        lons, lats = zip(*coords)

        midx = (max(lons) + min(lons)) / 2
        midy = (max(lats) + min(lats)) / 2

        out_crs = projection.utm_proj4(midx, midy)

    return out_crs