Python Create Maps with GeoPandas

Поділитися
Вставка
  • Опубліковано 14 жов 2024
  • In this python tutorial, we will go over how to make maps with GeoPandas.
    GeoPandas Jupyter Notebooks: github.com/gro...
    Topics Covered: geopandas, geodataframes, geoseries, geopandas map layers, convert pandas dataframe to geodataframe, geopandas plots, geopandas subplots, geopandas plot points, geopandas choropleth map, geopandas grouping, geopandas add background map using contextily, geopandas filter geodataframes, geopandas centroids, geopandas distance between centroids, geopandas area, geopandas buffer, geopandas boundary, geopandas intersects, geopandas with folium, geopandas with geojson, geopandas crs, geopandas convert crs, geopandas with cartopy, geopandas with geoplot, geodataframe to excel, geodataframe to geojson, geodataframe to shapefile, geopandas geocode, using geopandas with QGIS
    NOTES:
    *Install instructions - see my tutorial titled: Python Create Package Environments with Anaconda Navigator (example uses geopandas). Extra packages will need to be installed along with geopandas to run the examples.
    *Tricky/complex parts are (crs, projections, epsg) and converting measurements into desired units
    *Map projections and coordinate reference systems is a complex topic. When working with projections and coordinate reference systems, I often have to do a lot of research and sometimes I still can’t find what I am looking for. In the end, I usually try to make sure what I have chosen works well for the task at hand or analysis I am trying to complete and the map I am creating.
    *Map projections try to portray the surface of the earth, or a portion of the earth, on a flat piece of paper or computer screen. In layman’s terms, map projections try to transform the earth from its spherical shape (3D) to a planar shape (2D). A coordinate reference system (CRS) then defines how the two-dimensional, projected map in your GIS relates to real places on the earth. The decision of which map projection and CRS to use depends on the regional extent of the area you want to work in, on the analysis you want to do, and often on the availability of data. Source: QGIS Documentation
    *See Plotting polygons with Folium section in GeoPandas documentation for example of going from projected crs to geographic and back to projected
    *Sources for shapefiles - United States Geological Survey (USGS), US Census Bureau, Natural Earth, GADM, ArcGIS Hub and ESRI (Environmental Systems Research Institute), Local University / College websites often have shapefiles available
    *Not exactly sure what the natural earth GDP numbers are showing
    *GeoDataFrames can have more than one column with geometry but only one default active geometry column at a time
    *When using fig, axs = plt.subplots(2,3), axs is typically used for plural axes (multiple subplots)
    *For the grouping - aggregation with dissolve example, grouped variable name used but a better variable name should be used because nothing is actually grouped yet here
    *In the folium geojson example the Indiana counties are already in a geographic projection but we do show how to convert the crs if needed. If you use the Boroughs of New York City example in the geopandas documentation, the crs starts as projected.
    *When I first looked at the numbers returned for certain measurements like area and distance, I had to do some research. For information on the crs, use gdf.crs or by using epsg.org, you can search for a certain EPSG code and then look for the unit of measure (UoM) and you will usually see something like feet, meter, or degree, etc. You can also see if an EPSG is Projected vs Geographic (geopandas will throw error message if trying to find area, distances when using Geographic). Error Message: UserWarning: Geometry is in a geographic CRS. Results from 'area' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.
    *I just updated to geopandas 0.10.2 and there is an option to use explore() with a geodataframe to create leaflet maps and overlay other map layers. Below is and example of the code:
    path_to_data = gpd.datasets.get_path('nybb')
    gdf = gpd.read_file(path_to_data)
    gdf['area'] = gdf.area
    gdf.explore('area', legend=False)

КОМЕНТАРІ • 17

  • @yuakai1995
    @yuakai1995 Рік тому +1

    hi ryan! thank you so much for this insightful video!! very helpful

  • @espua72
    @espua72 2 роки тому

    great introductory to GeoPandas, very useful

  • @toowel20010
    @toowel20010 2 роки тому

    Great video, @Ryan. I just have an issue plotting my point on my shape. I am using ax=ax for both, but it seems the shapes are larger than the points, so I end up with a map with the point and name in different positions. Please, what can I do to plot them on the same scale? Thank you in advance.

    • @RyanNoonan
      @RyanNoonan  2 роки тому +1

      Can you share the code and/or a specific example?

    • @toowel20010
      @toowel20010 2 роки тому

      @@RyanNoonan I sent you an invite to my share folder. - Thank you for your time and consideration.

    • @RyanNoonan
      @RyanNoonan  2 роки тому +1

      From a quick look - it looks like the 2 geodataframes are using different units. When looking at the numbers on the x an y axis - one is using longitude and latitude and the other is using numbers from 100000 to 600000. Projections and coordinate reference systems (crs) can be tricky but I would start there. Use geodataframe.crs to see what you are working with and geodataframe.to_crs(epsg=xxxx) to change the crs, etc.

    • @toowel20010
      @toowel20010 2 роки тому

      Hey @@RyanNoonan it worked. Thank you so much buddy.

  • @hafeesogunfowora6866
    @hafeesogunfowora6866 2 роки тому

    Hello, for a cholopleth map, my column has negative values, but it would not show in the comments.

  • @montonibass5013
    @montonibass5013 2 роки тому

    Everytime I see someone plotting states inside a country, they plot one country only, and then they plot subdivisions inside. Is it possible to plot a world map that I can also see subdivisions inside a country? e.g. 50 United States states or Brazil's 27 states etc.

    • @RyanNoonan
      @RyanNoonan  2 роки тому +1

      Yes. Use ax. See example below:
      fig, ax = plt.subplots(figsize=(15, 10))
      us_states.plot(ax=ax)
      brazil.plot(ax=ax)
      world.plot(ax=ax, color='green', alpha=0.5);
      us_states, brazil, world are geodataframes. For Brazil, find a shapefile and convert to geodataframe. Shapefiles can be found on Natural Earth and GADM (GADM requires permission for some uses).

    • @montonibass5013
      @montonibass5013 2 роки тому +1

      @@RyanNoonan Thank you very much!

  • @abdelkaderfassifihri7985
    @abdelkaderfassifihri7985 2 роки тому

    Hello, where can i find the file indiana_counties.shp please

    • @RyanNoonan
      @RyanNoonan  2 роки тому

      I have some map layers (shapefiles, geojson) on my GitHub in the map layers folder or do a google search for indiana maps layer gallery (edu site, demographics, census). GADM is also a good site for map layers (shapefiles).

  • @afroomedia5
    @afroomedia5 2 роки тому

    how do you add hover information on a map?

    • @RyanNoonan
      @RyanNoonan  2 роки тому

      There are some hover/pop-up options when using geopandas geojson with folium and by using gdf.explore(). gdf.explore() is a newer option available with the most recent geopandas version. There are some options to use geopandas geodataframes with plotly which offers hover information.