Skip to main content
corrected spelling, improved formatting
Source Link
nmtoken
  • 13.6k
  • 5
  • 38
  • 89

How to import a background image for overlay with geopandasGeoPandas

I recently downloaded the shapefiles fromfor San Francisco from Mapzen. Now Now I am able to display the streets, but I would like to have a real map as a background image, such that it is easier to make the link between the real roads from San Francisco and the ones shown by GeopandasGeoPandas.

Here is the code to show the streets with GeopandasGeoPandas:

  1. First Downloaddownload the shaepfileshapefile from Mapzen: https://s3.amazonaws.com/metro-extracts.mapzen.com/san-francisco_california.imposm-shapefiles.zip

  2. Open a Python notebook and add those lines:

    #Useful starting lines %matplotlib inline import numpy as np import matplotlib.pyplot as plt %load_ext autoreload %autoreload 2

      #Useful starting lines
      %matplotlib inline
      import numpy as np
      import matplotlib.pyplot as plt
      %load_ext autoreload
      %autoreload 2
    
  3. Load the street map:

    shapefile_dir = 'the path to your directory where you store the shapefile'

    shapefile_name ='san-francisco_california_osm_roads_gen0.shp'

    shapefile_roads = os.path.join(shapefile_dir, shapefile_name)

     shapefile_name ='san-francisco_california_osm_roads_gen0.shp'
     shapefile_roads = os.path.join(shapefile_dir, shapefile_name)
    
  4. Import as a geopandas dataframe:

    import os

    import geopandas as gpd

    df = gpd.GeoDataFrame.from_file(shapefile_roads)

    import os
    import geopandas as gpd
    
    df = gpd.GeoDataFrame.from_file(shapefile_roads)
    
  5. Simply plot the street network:

    df.plot();

     df.plot();
    

The output should be:

enter image description here

Now I would like to have a real map (Color map) as a background. How can I do it  ?

How to import a background image for overlay with geopandas

I recently downloaded the shapefiles from San Francisco from Mapzen. Now I am able to display the streets, but I would like to have a real map as a background image, such that it is easier to make the link between the real roads from San Francisco and the ones shown by Geopandas.

Here is the code to show the streets with Geopandas:

  1. First Download the shaepfile from Mapzen: https://s3.amazonaws.com/metro-extracts.mapzen.com/san-francisco_california.imposm-shapefiles.zip

  2. Open a Python notebook and add those lines:

    #Useful starting lines %matplotlib inline import numpy as np import matplotlib.pyplot as plt %load_ext autoreload %autoreload 2

  3. Load the street map:

    shapefile_dir = 'the path to your directory where you store the shapefile'

    shapefile_name ='san-francisco_california_osm_roads_gen0.shp'

    shapefile_roads = os.path.join(shapefile_dir, shapefile_name)

  4. Import as a geopandas dataframe:

    import os

    import geopandas as gpd

    df = gpd.GeoDataFrame.from_file(shapefile_roads)

  5. Simply plot the street network:

    df.plot();

The output should be:

enter image description here

Now I would like to have a real map (Color map) as a background. How can I do it  ?

How to import a background image for overlay with GeoPandas

I recently downloaded the shapefiles for San Francisco from Mapzen. Now I am able to display the streets, but I would like to have a real map as a background image, such that it is easier to make the link between the real roads from San Francisco and the ones shown by GeoPandas.

Here is the code to show the streets with GeoPandas:

  1. First download the shapefile from Mapzen: https://s3.amazonaws.com/metro-extracts.mapzen.com/san-francisco_california.imposm-shapefiles.zip

  2. Open a Python notebook and add those lines:

      #Useful starting lines
      %matplotlib inline
      import numpy as np
      import matplotlib.pyplot as plt
      %load_ext autoreload
      %autoreload 2
    
  3. Load the street map:

    shapefile_dir = 'the path to your directory where you store the shapefile'

     shapefile_name ='san-francisco_california_osm_roads_gen0.shp'
     shapefile_roads = os.path.join(shapefile_dir, shapefile_name)
    
  4. Import as a geopandas dataframe:

    import os
    import geopandas as gpd
    
    df = gpd.GeoDataFrame.from_file(shapefile_roads)
    
  5. Simply plot the street network:

     df.plot();
    

The output should be:

enter image description here

Now I would like to have a real map (Color map) as a background. How can I do it?

Source Link
james
  • 103
  • 1
  • 3

How to import a background image for overlay with geopandas

I recently downloaded the shapefiles from San Francisco from Mapzen. Now I am able to display the streets, but I would like to have a real map as a background image, such that it is easier to make the link between the real roads from San Francisco and the ones shown by Geopandas.

Here is the code to show the streets with Geopandas:

  1. First Download the shaepfile from Mapzen: https://s3.amazonaws.com/metro-extracts.mapzen.com/san-francisco_california.imposm-shapefiles.zip

  2. Open a Python notebook and add those lines:

    #Useful starting lines %matplotlib inline import numpy as np import matplotlib.pyplot as plt %load_ext autoreload %autoreload 2

  3. Load the street map:

    shapefile_dir = 'the path to your directory where you store the shapefile'

    shapefile_name ='san-francisco_california_osm_roads_gen0.shp'

    shapefile_roads = os.path.join(shapefile_dir, shapefile_name)

  4. Import as a geopandas dataframe:

    import os

    import geopandas as gpd

    df = gpd.GeoDataFrame.from_file(shapefile_roads)

  5. Simply plot the street network:

    df.plot();

The output should be:

enter image description here

Now I would like to have a real map (Color map) as a background. How can I do it ?