How to use the geopandas.read_file function in geopandas

To help you get started, we’ve selected a few geopandas 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 martinfleis / momepy / tests / test_dimension.py View on Github external
def setup_method(self):

        test_file_path = mm.datasets.get_path("bubenec")
        self.df_buildings = gpd.read_file(test_file_path, layer="buildings")
        self.df_streets = gpd.read_file(test_file_path, layer="streets")
        self.df_tessellation = gpd.read_file(test_file_path, layer="tessellation")
        self.df_buildings["height"] = np.linspace(10.0, 30.0, 144)
github CosmiQ / solaris / tests / test_tile / test_tile.py View on Github external
f))
            expected = skimage.io.imread(
                os.path.join(data_dir, 'rastertile_test_expected', f))
            assert np.array_equal(result, expected)
            os.remove(os.path.join(data_dir, 'rastertile_test_result', f))
        os.rmdir(os.path.join(data_dir, 'rastertile_test_result'))
        vector_tiler = VectorTiler(os.path.join(data_dir,
                                                'vectortile_test_result'))
        vector_tiler.tile(os.path.join(data_dir, 'geotiff_labels.geojson'),
                          raster_tiler.tile_bounds)
        vector_tiling_result_files = os.listdir(os.path.join(
            data_dir, 'vectortile_test_result'))
        assert len(vector_tiling_result_files) == len(os.listdir(os.path.join(
            data_dir, 'vectortile_test_expected')))
        for f in vector_tiling_result_files:
            result = gpd.read_file(os.path.join(data_dir,
                                                'vectortile_test_result',
                                                f))
            expected = gpd.read_file(os.path.join(data_dir,
                                                  'vectortile_test_expected',
                                                  f))
            if len(result) == 0:
                assert len(expected) == 0
            else:
                result = cascaded_union(result.geometry)
                expected = cascaded_union(expected.geometry)
                assert result.intersection(expected).area/result.area > 0.99999
            os.remove(os.path.join(data_dir, 'vectortile_test_result', f))
        os.rmdir(os.path.join(data_dir, 'vectortile_test_result'))
github scottyhq / dinoSARaws / bin / prep_topsApp.py View on Github external
def load_inventory(vectorFile):
    '''
    load merged inventory. easy!
    '''
    gf = gpd.read_file(vectorFile)
    gf['timeStamp'] = gpd.pd.to_datetime(gf.sceneDate, format='%Y-%m-%d %H:%M:%S')
    gf['sceneDateString'] = gf.timeStamp.apply(lambda x: x.strftime('%Y-%m-%d'))
    gf['dateStamp'] = gpd.pd.to_datetime(gf.sceneDateString)
    gf['utc'] = gf.timeStamp.apply(lambda x: x.strftime('%H:%M:%S'))
    gf['orbitCode'] = gf.relativeOrbit.astype('category').cat.codes
    return gf
github ResidentMario / geoplot / examples / plot_minard_napoleon_russia.py View on Github external
This plot demonstrates building and using a custom ``matplotlib`` colormap. To learn more refer to
`the matplotlib documentation
`_.

`Click here `_ to see an 
interactive scrolly-panny version of this webmap built with ``mplleaflet``. To learn more about
``mplleaflet``, refer to `the mplleaflet GitHub repo `_.
"""

import geopandas as gpd
import geoplot as gplt
import matplotlib.pyplot as plt
import mplleaflet
from matplotlib.colors import LinearSegmentedColormap

napoleon_troop_movements = gpd.read_file(gplt.datasets.get_path('napoleon_troop_movements'))

colors = [(215/255, 193/255, 126/255), (37/255, 37/255, 37/255)]
cm = LinearSegmentedColormap.from_list('minard', colors)

gplt.sankey(
    napoleon_troop_movements,
    scale='survivors', limits=(0.5, 45),
    hue='direction',
    cmap=cm
)
fig = plt.gcf()
plt.savefig("minard-napoelon-russia.png", bbox_inches='tight', pad_inches=0.1)
github earthlab / earthpy / examples / plot_rgb.py View on Github external
# Plot Boundary Over Composite Image
# -----------------------------------
# .. note::
#       If you are on windows, you may need to add the crs issue discussed above
#       here!
#
# You can overlay a polygon boundary on top of an RGB plot created with EarthPy.
# To begin, the raster data and the boundary need to be in the same
# Coordinate Reference System (CRS). You can reproject the boundary layer to
# match the CRS of the image by getting the CRS of the image from the Rasterio
# profile object and passing that CRS to the ``to_crs`` method from GeoPandas.

os.chdir(os.path.join(et.io.HOME, "earth-analytics"))

# Open polygon boundary using GeoPandas
bound = gpd.read_file(
    "data/vignette-landsat/vector_layers/fire-boundary-geomac/co_cold_springs_20160711_2200_dd83.shp"
)

# Reproject boundary to match CRS of the Landsat images
with rio.open(stack_band_paths[0]) as raster_crs:
    raster_profile = raster_crs.profile
    bound_utm13N = bound.to_crs(raster_profile["crs"])

################################################################################
# Create a Plot With the Boundary overlayed on the RGB Image 
# ----------------------------------------------------------
# You can plot a polygon boundary over an image by creating a raster extent
# for the plot using the ``plotting_extent`` function from ``rasterio.plot``.
# The function needs the Rasterio profile of the image and a single layer of a
# numpy array, which can be specified with ``arr_str[0]``. The function also
# needs the spatial transformation for the Rasterio object, which can be acquired
github ESA-PhiLab / OpenSarToolkit / ost / helpers / vector.py View on Github external
def exterior(infile, outfile, buffer=None):

    gdf = gpd.read_file(infile, crs={'init': 'EPSG:4326'})
    gdf.geometry = gdf.geometry.apply(lambda row: Polygon(row.exterior))
    gdf_clean = gdf[gdf.geometry.area >= 1.0e-6]
    gdf_clean.geometry = gdf_clean.geometry.buffer(-0.0018)
    #if buffer:
    #    gdf.geometry = gdf.geometry.apply(
     #           lambda row: Polygon(row.buffer(-0.0018)))
    gdf_clean.to_file(outfile)
github jkibele / OpticalRS / OpticalRS / GeoDFUtils.py View on Github external
def __init__(self, rds, shp, gdf_query=None):
        if type(rds).__name__ == 'RasterDS':
            self.rds = rds
        else:
            self.rds = RasterDS(rds)

        if type(shp).__name__ == 'GeoDataFrame':
            self.gdf = shp
        else:
            self.gdf = gpd.read_file(shp)
github USEPA / StreamCat / MakeWatersheds.py View on Github external
temp_ws['COMID'] = temp_ws.index
#            temp_ws['SITE_ID'] = lakes_df.loc[lakes_df.index[i],'SITE_ID']
        out_ws = out_ws.append(temp_ws, ignore_index=True)
    i+=1
    print("--- %s seconds ---" % (time.time() - start_time2)) 
    #world.to_file(filename=temp_shp,driver='ESRI Shapefile',crs_wkt=prj)
    print '------------------------------------'

out_ws = out_ws[['COMID','geometry']]  
out_ws = out_ws.merge(lakes_df, how='left') 
out_ws = out_ws[['SITE_ID','COMID','geometry']]     
out_ws.to_file('L:/Priv/CORFiles/Geospatial_Library_Projects/NLA/NLA2017LandscapeMetrics/Off_Network_Lakes/Off_Network_InNHD_NLA17Lakes.shp', driver = 'ESRI Shapefile')
off_net_inNHD = out_ws

# Combind on and off network lakes with standard columns
off_net = gpd.read_file('L:/Priv/CORFiles/Geospatial_Library_Projects/NLA/NLA2017LandscapeMetrics/Off_Network_Lakes/Off_Network_NLA17Lakes.shp')
on_net = gpd.read_file('L:/Priv/CORFiles/Geospatial_Library_Projects/NLA/NLA2017LandscapeMetrics/On_Network_Lakes/OnNetLakes.shp')

off_net = off_net[['comid','geometry']]
off_net.columns = ['COMID','geometry']
off_net = off_net.merge(lakes_df, how='left')
off_net[['COMID']] = off_net[['COMID']].astype(int)
off_net = off_net[['SITE_ID','COMID','geometry']]
on_net = on_net[['SITE_ID','COMID','geometry']]

lake_wats = on_net.append(off_net, ignore_index=True)

# and then the InNHD off-network
lake_wats = lake_wats.append(off_net_inNHD, ignore_index=True)
lake_wats.to_file('L:/Priv/CORFiles/Geospatial_Library_Projects/NLA/NLA2017LandscapeMetrics/NLA17_Watersheds.shp', driver = 'ESRI Shapefile')
github scottyhq / dinoSARaws / bin / get_inventory_asf.py View on Github external
def ogr2snwe(args):
    gf = gpd.read_file(args.input)
    gf.to_crs(epsg=4326, inplace=True)
    poly = gf.geometry.convex_hull
    if args.buffer:
        poly = poly.buffer(args.buffer)
    W,S,E,N = poly.bounds.values[0]
    args.roi = [S,N,W,E]