コード例 #1
0
def _get_flowline_lonlat(gdir):
    """Quick n dirty solution to write the flowlines as a shapefile"""

    cls = gdir.read_pickle('inversion_flowlines')
    olist = []
    for j, cl in enumerate(cls[::-1]):
        mm = 1 if j == 0 else 0
        gs = gpd.GeoSeries()
        gs['RGIID'] = gdir.rgi_id
        gs['LE_SEGMENT'] = np.rint(np.max(cl.dis_on_line) * gdir.grid.dx)
        gs['MAIN'] = mm
        tra_func = partial(gdir.grid.ij_to_crs, crs=wgs84)
        gs['geometry'] = shp_trafo(tra_func, cl.line)
        olist.append(gs)

    return olist
コード例 #2
0
ファイル: utils.py プロジェクト: fmaussion/oggm
def _get_centerline_lonlat(gdir):
    """Quick n dirty solution to write the centerlines as a shapefile"""

    olist = []
    for i in gdir.divide_ids:
        cls = gdir.read_pickle("centerlines", div_id=i)
        for i, cl in enumerate(cls):
            mm = 1 if i == 0 else 0
            gs = gpd.GeoSeries()
            gs["RGIID"] = gdir.rgi_id
            gs["DIVIDE"] = i
            gs["LE_SEGMENT"] = np.rint(np.max(cl.dis_on_line) * gdir.grid.dx)
            gs["MAIN"] = mm
            tra_func = partial(gdir.grid.ij_to_crs, crs=wgs84)
            gs["geometry"] = shp_trafo(tra_func, cl.line)
            olist.append(gs)

    return olist
コード例 #3
0
def _get_centerline_lonlat(gdir):
    """Quick n dirty solution to write the centerlines as a shapefile"""

    olist = []
    for i in gdir.divide_ids:
        cls = gdir.read_pickle('centerlines', div_id=i)
        for i, cl in enumerate(cls):
            mm = 1 if i == 0 else 0
            gs = gpd.GeoSeries()
            gs['RGIID'] = gdir.rgi_id
            gs['DIVIDE'] = i
            gs['LE_SEGMENT'] = np.rint(np.max(cl.dis_on_line) * gdir.grid.dx)
            gs['MAIN'] = mm
            tra_func = partial(gdir.grid.ij_to_crs, crs=wgs84)
            gs['geometry'] = shp_trafo(tra_func, cl.line)
            olist.append(gs)

    return olist
コード例 #4
0
def _get_catchment_widths_lonlat(gdir):
    """Quick n dirty solution to write the flowlines catchment widths
     as a shapefile"""
    cls = gdir.read_pickle('inversion_flowlines')
    olist = []
    for j, cl in enumerate(cls[::-1]):
        for wi, cur, (n1, n2) in zip(cl.widths, cl.line.coords, cl.normals):
            _l = shpg.LineString([
                shpg.Point(cur + wi / 2. * n1),
                shpg.Point(cur + wi / 2. * n2)
            ])

            mm = 1 if j == 0 else 0
            gs = gpd.GeoSeries()
            gs['RGIID'] = gdir.rgi_id
            gs['LE_SEGMENT'] = np.rint(np.max(cl.dis_on_line) * gdir.grid.dx)
            gs['MAIN'] = mm
            tra_func = partial(gdir.grid.ij_to_crs, crs=wgs84)
            gs['geometry'] = shp_trafo(tra_func, _l)
            olist.append(gs)

    return olist
コード例 #5
0
    def _reproject_and_write_shapefile(self, entity, filesuffix=''):

        # Make a local glacier map
        params = dict(name='tmerc',
                      lat_0=0.,
                      lon_0=self.cenlon,
                      k=0.9996,
                      x_0=0,
                      y_0=0,
                      datum='WGS84')
        proj4_str = "+proj={name} +lat_0={lat_0} +lon_0={lon_0} +k={k} " \
                    "+x_0={x_0} +y_0={y_0} +datum={datum}".format(**params)

        # Reproject
        proj_in = pyproj.Proj("epsg:4326", preserve_units=True)
        proj_out = pyproj.Proj(proj4_str, preserve_units=True)

        # transform geometry to map
        project = partial(transform_proj, proj_in, proj_out)
        geometry = shp_trafo(project, entity['geometry'])
        geometry = multipolygon_to_polygon(geometry, gdir=self)

        # Save transformed geometry to disk
        entity = entity.copy()
        entity['geometry'] = geometry

        # Do we want to use the RGI area or ours?
        if not cfg.PARAMS['use_rgi_area']:
            # Update Area
            area = geometry.area * 1e-6
            entity['Area'] = area

        # Avoid fiona bug: https://github.com/Toblerity/Fiona/issues/365
        for k, s in entity.iteritems():
            if type(s) in [np.int32, np.int64]:
                entity[k] = int(s)
        towrite = gpd.GeoDataFrame(entity).T
        towrite.crs = proj4_str

        # Write shapefile
        self.write_shapefile(towrite, 'outlines', filesuffix=filesuffix)

        # Also transform the intersects if necessary
        gdf = cfg.PARAMS['intersects_gdf']
        if len(gdf) > 0:
            gdf = gdf.loc[((gdf.RGIId_1 == self.rgi_id) |
                           (gdf.RGIId_2 == self.rgi_id))]
            if len(gdf) > 0:
                gdf = salem.transform_geopandas(gdf, to_crs=proj_out)
                if hasattr(gdf.crs, 'srs'):
                    # salem uses pyproj
                    gdf.crs = gdf.crs.srs
                self.write_shapefile(gdf, 'intersects')
        else:
            # Sanity check
            if cfg.PARAMS['use_intersects']:
                raise InvalidParamsError(
                    'You seem to have forgotten to set the '
                    'intersects file for this run. OGGM '
                    'works better with such a file. If you '
                    'know what your are doing, set '
                    "cfg.PARAMS['use_intersects'] = False to "
                    "suppress this error.")
コード例 #6
0
# plot the results
graphics.plot_centerlines(gdir, figsize=(8, 7), use_flowlines=True, add_downstream=True)

# the glacier directories now have more files in them. Let's look
import os
print(os.listdir(gdir.dir))


# export centerlines to shapefiles
test = gdir.read_pickle('centerlines')
olist = []
for j, cl in enumerate(test[::-1]):
        mm = 1 if j == 0 else 0
        gs = gpd.GeoSeries()
        gs['RGIID'] = gdir.rgi_id
        gs['LE_SEGMENT'] = np.rint(np.max(cl.dis_on_line) * gdir.grid.dx)
        gs['MAIN'] = mm
        tra_func = partial(gdir.grid.ij_to_crs, crs=wgs84)
        gs['geometry'] = shp_trafo(tra_func, cl.line)
        olist.append(gs)

# centerlines GeoDataFrame
cl_gdf = gpd.GeoDataFrame()

# assign linestrings from GeoSeries to GeoDataFrame
for i in olist:
    cl_gdf.append(i, ignore_index=True)

# write GeoDataFrame to Shapefile
cl_gdf.to_file('centerlines.shp', driver='ESRI Shapefile')