map2loop.m2l_utils

map2loop.m2l_utils.clip_shp(shp, clip_obj)

Clip points, lines, or polygon geometries to the clip_obj extent. Both layers must be in the same Coordinate Reference System (CRS) and will be clipped to the full extent of the clip object. If there are multiple polygons in clip_obj, data from shp will be clipped to the total boundary of all polygons in clip_obj. Parameters ———- shp : GeoDataFrame

Vector layer (point, line, polygon) to be clipped to clip_obj.

clip_objGeoDataFrame

Polygon vector layer used to clip shp. The clip_obj’s geometry is dissolved into one geometric feature and intersected with shp.

Returns

GeoDataFrame

Vector data (points, lines, polygons) from shp clipped to polygon boundary from clip_obj.

Examples

Clipping points (glacier locations in the state of Colorado) with a polygon (the boundary of Rocky Mountain National Park):

>>> import geopandas as gpd
>>> import earthpy.clip as cl
>>> from earthpy.io import path_to_example
>>> rmnp = gpd.read_file(path_to_example('rmnp.shp'))
>>> glaciers = gpd.read_file(path_to_example('colorado-glaciers.geojson'))
>>> glaciers.shape
(134, 2)
>>> rmnp_glaciers = cl.clip_shp(glaciers, rmnp)
>>> rmnp_glaciers.shape
(36, 2)

Clipping a line (the Continental Divide Trail) with a polygon (the boundary of Rocky Mountain National Park):

>>> cdt = gpd.read_file(path_to_example('continental-div-trail.geojson'))
>>> rmnp_cdt_section = cl.clip_shp(cdt, rmnp)
>>> cdt['geometry'].length > rmnp_cdt_section['geometry'].length
0    True
dtype: bool

Clipping a polygon (Colorado counties) with another polygon (the boundary of Rocky Mountain National Park):

>>> counties = gpd.read_file(path_to_example('colorado-counties.geojson'))
>>> counties.shape
(64, 13)
>>> rmnp_counties = cl.clip_shp(counties, rmnp)
>>> rmnp_counties.shape
(4, 13)
map2loop.m2l_utils.floatstohex(rgb)

Takes an RGB tuple or list and returns a hex RGB string.

map2loop.m2l_utils.hextofloats(h)

Takes a hex rgb string (e.g. #ffffff) and returns an RGB tuple (float, float, float).

map2loop.m2l_utils.hextoints(h)

Takes a hex rgb string (e.g. #ffffff) and returns an RGB tuple (float, float, float).

map2loop.m2l_utils.intstohex(rgb)

Takes an RGB tuple or list and returns a hex RGB string.