際際滷

際際滷Share a Scribd company logo
Geospatial
Visualization
GeoPandas
2
What is Geopandas?
 GeoPandas is an open-source project to make
working with geospatial data in python easier.
 GeoPandas is one of the most satisfying Python
packages to use because it produces a tangible,
visible output that is directly linked to the real world.
 Here we will be exploring the method to create a geo
map and visualize data over it, using shapefiles(.shp)
and some other Python libraries.
3
The core data structure in GeoPandas
 GeoDataFrame, a subclass of pandas.
 DataFrame, that can store geometry columns and perform
spatial operations.
 The geopandas.GeoSeries, a subclass of pandas.Series,
handles the geometries.
 Therefore, your GeoDataFrame is a combination of
pandas.Series, with traditional data (numerical, boolean, text
etc.), and geopandas.GeoSeries, with geometries (points,
polygons etc.).
 You can have as many columns with geometries as you wish;
theres no limit typical for desktop GIS software.
4
The core data structure in GeoPandas
5
The core data structure in GeoPandas
 Each GeoSeries can contain any geometry type (you can even
mix them within a single array) and has a GeoSeries.crs
attribute, which stores information about the projection (CRS
stands for Coordinate Reference System).
 Therefore, each GeoSeries in a GeoDataFrame can be in a
different projection, allowing you to have, for example,
multiple versions (different projections) of the same geometry.
 Only one GeoSeries in a GeoDataFrame is considered the
active geometry, which means that all geometric operations
applied to a GeoDataFrame operate on this active column.
6
world map projections.
 1. Mercator
 This projection was developed by Gerardus Mercator back in 1569
for navigational purposes.
 Its ability to represent lines of constant course from coast to coast
made it the perfect map for sailing the seas.
 Its popularity was so great that it became used as a geographic
teaching aid even though the projection grossly distorts countries
sizes.
 This is at its worst the closer you are to the poles. Greenland is 550%
too big, it should fit into Africa 14 times!
7
Vector Data: OpenGIS Simple Features / OCG Simple Feature Access
Used in spatial databases (Postgresql/PostGIS), GIS, 
WKT (Well known Text):
 Point, Multipoint
 LineString, MultiLineString
 Polygon, MultiPolygon
 GeometryCollection
 (TIN, Circle, Curve, Triangle, Surface, PolyhedralSurface,
)
map projections.
8
Examples
9
Examples
10
world map projections.
 1. Mercator
 This projection was developed by
Gerardus Mercator back in 1569 for
navigational purposes.
 Its ability to represent lines of constant
course from coast to coast made it the
perfect map for sailing the seas.
 Its popularity was so great that it
became used as a geographic teaching
aid even though the projection grossly
distorts countries sizes.
 This is at its worst the closer you are to
the poles. Greenland is 550% too big, it
should fit into Africa 14 times!
11
Map projections.
 2. Robinson
 This map is known as a compromise, it shows neither the shape or land
mass of countries correct.
 Arthur Robinson developed it in 1963 using a more visual trial and error
development.
 Our Classic world map uses the Robinson projection and is a contemporary
tribute to the familiar schoolroom map and is perfect for map-lovers of all
ages..
12
map projections
 3. Dymaxion Map
 This projection was released by R Buckminster Fuller in 1954 after several
decades working on it.
 The world is projected onto the surface of a icosahedron, allowing it to be
unfolded and flattened in two dimensions.
 It is said to represent the Earths continents as one island.
13
map projections
 4. Gall-Peters
 This is a cylindrical world map projection, that regains accuracy in surface
area.
 It is named after James Gall and Arno Peters. Whilst Gall, first described
the projection in 1855 it was not until 1973 when Peters, began to heavily
market the projection as the Peters World Map that it became popular.
14
map projections
5. Sinu-Mollweide
 Developed in 1953 by Allen K Philbrick, this projection fuses the
Sinusoidal projection , which was first used in the 16th Century, with Karl
Brandan Mollweide's map of 1805 and challenges our assumption of how
the flattened globe should look.
 Still an equal area projection that maintains fidelity of area, we like this
projection for its bold graphic view.
15
map projections
 6 Winkel Tripel
 A globe that is projected onto a flat surface giving it curved lines of latitude and
curved meridians.
 The projection, by Oswald Winkel in1921 was developed with the goal of minimizing
the three kinds of distortion: area, direction and distance.
 Thus it became the Tripel Projection (German for triple).
 The projection is neither equal-area nor conformal, its main feature is that all of the
parallels are curved except for the straight poles and equator.
 This gives a lovely spherical feeling to this two dimensional map.
16
Download Free Shapefile Maps
 https://www.igismap.com/download-free-shap
efile-maps/
 https://www.statsilk.com/maps/download-free-
shapefile-maps
 https://mapscaping.com/download-shapefiles-f
or-any-country/
17
GeoPandas packages:
 pandas
 shapely
 fiona
 pyproj
 packaging
 Further, matplotlib is an optional dependency,
required for plotting.
 GeoPandas using the conda package manager.
18
Reading and writing files
 Assuming you have a file containing both data and geometry
(e.g. GeoPackage, GeoJSON, Shapefile), you can read it using
geopandas.read_file(),
 which automatically detects the filetype and creates a
GeoDataFrame.
 This tutorial uses the "nybb" dataset, a map of New York
boroughs, which is available through the geodatasets package.
 Therefore, we use geodatasets.get_path() to download the
dataset and retrieve the path to the local copy.
19
Reading and writing files
 Assuming you have a file containing both data and geometry
(e.g. GeoPackage, GeoJSON, Shapefile), you can read it using
geopandas.read_file(),
 which automatically detects the filetype and creates a
GeoDataFrame.
 This tutorial uses the "nybb" dataset, a map of New York
boroughs, which is available through the geodatasets package.
 Therefore, we use geodatasets.get_path() to download the
dataset and retrieve the path to the local copy.
20
Writing files
 To write a GeoDataFrame back to file use
GeoDataFrame.to_file().
 The default file format is Shapefile, but you can
specify your own with the driver keyword.
21
Simple accessors and methods
 Now we have our GeoDataFrame and can start working with
its geometry.
 Since there was only one geometry column in the New York
Boroughs dataset, this column automatically becomes the
active geometry and spatial methods used on the
GeoDataFrame will be applied to the "geometry" column.
22
Simple accessors and methods
Measuring area
 To measure the area of each polygon (or MultiPolygon in this
specific case), access the GeoDataFrame.area attribute,
which returns a pandas.Series.
 Note that GeoDataFrame.area is just GeoSeries.area applied to
the active geometry column.
23
Simple accessors and methods
Getting polygon boundary and centroid
 To get the boundary of each polygon (LineString), access the
GeoDataFrame.boundary:
 Since we have saved boundary as a new column, we now have
two geometry columns in the same GeoDataFrame.
24
Simple accessors and methods
Getting polygon boundary and centroid
 To get the boundary of each polygon (LineString), access the
GeoDataFrame.boundary:
 Since we have saved boundary as a new column, we now have
two geometry columns in the same GeoDataFrame.
25
Simple accessors and methods
Measuring distance
 We can also measure how far each centroid is from the first centroid
location.
 Note that geopandas.GeoDataFrame is a subclass of pandas.DataFrame, so
we have all the pandas functionality available to use on the geospatial
dataset  we can even perform data manipulations with the attributes and
geometry information together.
26
Making maps
 GeoPandas can also plot maps, so we can check how the
geometries appear in space.
 To plot the active geometry, call GeoDataFrame.plot().
 To color code by another column, pass in that column as the
first argument.
 In the example below, we plot the active geometry column and
color code by the "area" column. We also want to show a
legend (legend=True).
27
Making maps
28
Making maps
 You can also explore your data interactively using
GeoDataFrame.explore(), which behaves in the same way
plot() does but returns an interactive map instead.
29
Making maps
 Switching the active geometry
(GeoDataFrame.set_geometry) to centroids, we can plot the
same data using point geometry..
30
Making maps
 And we can also layer both GeoSeries on top of each other.
We just need to use one plot as an axis for the other.
31
Step 1 : Installing GeoPandas and
Shapely
 need to install the GeoPandas and Shapely libraries in order to
plot a map, and these libraries do not come with the Anaconda
download.
 through the conda-forge channel with the following command
from your terminal
 or alternatively
 Shapely can be pip installed with the command
conda install -c conda-forge geopandas
pip install geopandas
pip install shapely
32
Importing the libraries
 Importing the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import geopandas as gpd
import shapefile as shp
from shapely.geometry import Point
sns.set_style('whitegrid')
33
Load the data
 Use india-polygon.shp shape file to plot India map
 Load the data into a GeoDataFrame as shown below.
fp = r india-polygon.shp'
map_df = gpd.read_file(fp)
map_df_copy = gpd.read_file(fp)
map_df.head()
34
Plotting the Shapefiles
 One nice thing about
downloading a
GeoDataFrame, is that
weve already got enough
info to make a basic plot.
map_df.plot()
35
Adding better data insights into the
map
df = pd.read_csv('globallandslides.csv')
pd.set_option('display.max_columns', None)df = df[df.country_name=="India"]
df["Year"] = pd.to_datetime(df["event_date"]).dt.year
df = df[df.landslide_category=="landslide"]
state_df = ls_df["admin_division_name"].value_counts()
state_df = state_df.to_frame()
state_df.reset_index(level=0, inplace=True)
state_df.columns = ['State', 'Count']state_df.at[15,"Count"] = 69
state_df.at[0,"State"] = "Jammu and Kashmir" state_df.at[20,"State"] = "Delhi"
state_df.drop(7)
36
 data of the number of
landslides that have happened
in each state over the years
37
Merge the data
 We can now merge this above state data which contains
landslide information with map_df shapefile. We will use the
State column of both the data frames for merging purposes.
#Merging the data
merged = map_df.set_index('st_nm').join(state_df.set_index('State'))
merged['Count'] = merged['Count'].replace(np.nan, 0)
merged.head()
38
Plotting the data on the Shapefile
#Create figure and axes for Matplotlib and set the title
fig, ax = plt.subplots(1, figsize=(10, 10))
ax.axis('off')ax.set_title('Number of landslides in India state-wise',
fontdict={'fontsize': '20', 'fontweight' : '10'})# Plot the figure
merged.plot(column='Count',cmap='YlOrRd', linewidth=0.8, ax=ax,
edgecolor='0',legend=True,markersize=[39.739192, -104.990337],
legend_kwds={'label': "Number of landslides"})
39
Plotting the data on the Shapefile
40
plot the latitudes and longitudes
 We can also plot the latitudes and longitudes
of the occurred landslides on the map along
with the names of states as shown below.
 For this, you will need to find the shapefile
data for Indian states and their latitudes and
longitudes.
 have to plot data points on the map..
41

More Related Content

Similar to Geospatial Visualization for datascience (20)

Geographic information system and remote sensing
Geographic information system and remote sensingGeographic information system and remote sensing
Geographic information system and remote sensing
chala hailu
remote sesing resolution for satelitte imag
remote sesing resolution for satelitte imagremote sesing resolution for satelitte imag
remote sesing resolution for satelitte imag
ARULMURUGANRAMU1
Looking into the past - feature extraction from historic maps using Python, O...
Looking into the past - feature extraction from historic maps using Python, O...Looking into the past - feature extraction from historic maps using Python, O...
Looking into the past - feature extraction from historic maps using Python, O...
James Crone
Processing Landsat 8 Multi-Spectral Images with GRASS Tools & the potential o...
Processing Landsat 8 Multi-Spectral Images with GRASS Tools & the potential o...Processing Landsat 8 Multi-Spectral Images with GRASS Tools & the potential o...
Processing Landsat 8 Multi-Spectral Images with GRASS Tools & the potential o...
Shaun Lewis
GIS_FDP_Final.pdf
GIS_FDP_Final.pdfGIS_FDP_Final.pdf
GIS_FDP_Final.pdf
SanthoshKumarP38
GIS Data Types
GIS Data TypesGIS Data Types
GIS Data Types
John Reiser
An Overview of a Cartographic Package
An Overview of a Cartographic PackageAn Overview of a Cartographic Package
An Overview of a Cartographic Package
Robert (Bob) Williams
Maperitive
MaperitiveMaperitive
Maperitive
Calvin Ng
Sfg tutorial
Sfg tutorialSfg tutorial
Sfg tutorial
TechnicalSolutions forSustainability
Principles of GIS.Lecture201511_BGTD.ppt
Principles of GIS.Lecture201511_BGTD.pptPrinciples of GIS.Lecture201511_BGTD.ppt
Principles of GIS.Lecture201511_BGTD.ppt
ShafiqullahRahmani
Opensource gis development - part 2
Opensource gis development - part 2Opensource gis development - part 2
Opensource gis development - part 2
Andrea Antonello
Mapping in Drupal using OpenLayers
Mapping in Drupal using OpenLayersMapping in Drupal using OpenLayers
Mapping in Drupal using OpenLayers
Peter Vanhee
On 2D SLAM for Large Indoor Spaces: A Polygon-Based Solution
On 2D SLAM for Large Indoor Spaces: A Polygon-Based SolutionOn 2D SLAM for Large Indoor Spaces: A Polygon-Based Solution
On 2D SLAM for Large Indoor Spaces: A Polygon-Based Solution
Noury Bouraqadi
MapInfo Professional 12.5 and Discover3D 2014 - A brief overview
MapInfo Professional 12.5 and Discover3D 2014 - A brief overviewMapInfo Professional 12.5 and Discover3D 2014 - A brief overview
MapInfo Professional 12.5 and Discover3D 2014 - A brief overview
Prakher Hajela Saxena
Opensource gis development - part 4
Opensource gis development - part 4Opensource gis development - part 4
Opensource gis development - part 4
Andrea Antonello
Terra formation control or how to move mountains
Terra formation control or how to move mountainsTerra formation control or how to move mountains
Terra formation control or how to move mountains
ijcga
The GRASS GIS software (with QGIS) - GIS Seminar
The GRASS GIS software (with QGIS) - GIS SeminarThe GRASS GIS software (with QGIS) - GIS Seminar
The GRASS GIS software (with QGIS) - GIS Seminar
Markus Neteler
Geographical Information System (GIS) Georeferencing and Digitization, Bihar ...
Geographical Information System (GIS) Georeferencing and Digitization, Bihar ...Geographical Information System (GIS) Georeferencing and Digitization, Bihar ...
Geographical Information System (GIS) Georeferencing and Digitization, Bihar ...
Kamlesh Kumar
Open@EDINA
Open@EDINAOpen@EDINA
Open@EDINA
EDINA, University of Edinburgh
Introduction and Application of GIS
Introduction and Application of GISIntroduction and Application of GIS
Introduction and Application of GIS
Satish Taji
Geographic information system and remote sensing
Geographic information system and remote sensingGeographic information system and remote sensing
Geographic information system and remote sensing
chala hailu
remote sesing resolution for satelitte imag
remote sesing resolution for satelitte imagremote sesing resolution for satelitte imag
remote sesing resolution for satelitte imag
ARULMURUGANRAMU1
Looking into the past - feature extraction from historic maps using Python, O...
Looking into the past - feature extraction from historic maps using Python, O...Looking into the past - feature extraction from historic maps using Python, O...
Looking into the past - feature extraction from historic maps using Python, O...
James Crone
Processing Landsat 8 Multi-Spectral Images with GRASS Tools & the potential o...
Processing Landsat 8 Multi-Spectral Images with GRASS Tools & the potential o...Processing Landsat 8 Multi-Spectral Images with GRASS Tools & the potential o...
Processing Landsat 8 Multi-Spectral Images with GRASS Tools & the potential o...
Shaun Lewis
GIS Data Types
GIS Data TypesGIS Data Types
GIS Data Types
John Reiser
An Overview of a Cartographic Package
An Overview of a Cartographic PackageAn Overview of a Cartographic Package
An Overview of a Cartographic Package
Robert (Bob) Williams
Maperitive
MaperitiveMaperitive
Maperitive
Calvin Ng
Principles of GIS.Lecture201511_BGTD.ppt
Principles of GIS.Lecture201511_BGTD.pptPrinciples of GIS.Lecture201511_BGTD.ppt
Principles of GIS.Lecture201511_BGTD.ppt
ShafiqullahRahmani
Opensource gis development - part 2
Opensource gis development - part 2Opensource gis development - part 2
Opensource gis development - part 2
Andrea Antonello
Mapping in Drupal using OpenLayers
Mapping in Drupal using OpenLayersMapping in Drupal using OpenLayers
Mapping in Drupal using OpenLayers
Peter Vanhee
On 2D SLAM for Large Indoor Spaces: A Polygon-Based Solution
On 2D SLAM for Large Indoor Spaces: A Polygon-Based SolutionOn 2D SLAM for Large Indoor Spaces: A Polygon-Based Solution
On 2D SLAM for Large Indoor Spaces: A Polygon-Based Solution
Noury Bouraqadi
MapInfo Professional 12.5 and Discover3D 2014 - A brief overview
MapInfo Professional 12.5 and Discover3D 2014 - A brief overviewMapInfo Professional 12.5 and Discover3D 2014 - A brief overview
MapInfo Professional 12.5 and Discover3D 2014 - A brief overview
Prakher Hajela Saxena
Opensource gis development - part 4
Opensource gis development - part 4Opensource gis development - part 4
Opensource gis development - part 4
Andrea Antonello
Terra formation control or how to move mountains
Terra formation control or how to move mountainsTerra formation control or how to move mountains
Terra formation control or how to move mountains
ijcga
The GRASS GIS software (with QGIS) - GIS Seminar
The GRASS GIS software (with QGIS) - GIS SeminarThe GRASS GIS software (with QGIS) - GIS Seminar
The GRASS GIS software (with QGIS) - GIS Seminar
Markus Neteler
Geographical Information System (GIS) Georeferencing and Digitization, Bihar ...
Geographical Information System (GIS) Georeferencing and Digitization, Bihar ...Geographical Information System (GIS) Georeferencing and Digitization, Bihar ...
Geographical Information System (GIS) Georeferencing and Digitization, Bihar ...
Kamlesh Kumar
Introduction and Application of GIS
Introduction and Application of GISIntroduction and Application of GIS
Introduction and Application of GIS
Satish Taji

More from Sivam Chinna (10)

graph theory in applied mathematics with example
graph theory in applied mathematics with examplegraph theory in applied mathematics with example
graph theory in applied mathematics with example
Sivam Chinna
Use case diagram with example of illustration
Use case diagram with example of illustrationUse case diagram with example of illustration
Use case diagram with example of illustration
Sivam Chinna
SE Roger S. Pressman - Requirement Model.ppt
SE Roger S. Pressman - Requirement Model.pptSE Roger S. Pressman - Requirement Model.ppt
SE Roger S. Pressman - Requirement Model.ppt
Sivam Chinna
Dimensionality Reduction and feature extraction.pptx
Dimensionality Reduction and feature extraction.pptxDimensionality Reduction and feature extraction.pptx
Dimensionality Reduction and feature extraction.pptx
Sivam Chinna
14078956.ppt
14078956.ppt14078956.ppt
14078956.ppt
Sivam Chinna
pythonpandas-181223110521-1(1).pptx
pythonpandas-181223110521-1(1).pptxpythonpandas-181223110521-1(1).pptx
pythonpandas-181223110521-1(1).pptx
Sivam Chinna
Pandas-(Ziad).pptx
Pandas-(Ziad).pptxPandas-(Ziad).pptx
Pandas-(Ziad).pptx
Sivam Chinna
Clustering.pptx
Clustering.pptxClustering.pptx
Clustering.pptx
Sivam Chinna
13. Anomaly.pptx
13. Anomaly.pptx13. Anomaly.pptx
13. Anomaly.pptx
Sivam Chinna
UNIT 5-ANN.ppt
UNIT 5-ANN.pptUNIT 5-ANN.ppt
UNIT 5-ANN.ppt
Sivam Chinna
graph theory in applied mathematics with example
graph theory in applied mathematics with examplegraph theory in applied mathematics with example
graph theory in applied mathematics with example
Sivam Chinna
Use case diagram with example of illustration
Use case diagram with example of illustrationUse case diagram with example of illustration
Use case diagram with example of illustration
Sivam Chinna
SE Roger S. Pressman - Requirement Model.ppt
SE Roger S. Pressman - Requirement Model.pptSE Roger S. Pressman - Requirement Model.ppt
SE Roger S. Pressman - Requirement Model.ppt
Sivam Chinna
Dimensionality Reduction and feature extraction.pptx
Dimensionality Reduction and feature extraction.pptxDimensionality Reduction and feature extraction.pptx
Dimensionality Reduction and feature extraction.pptx
Sivam Chinna
pythonpandas-181223110521-1(1).pptx
pythonpandas-181223110521-1(1).pptxpythonpandas-181223110521-1(1).pptx
pythonpandas-181223110521-1(1).pptx
Sivam Chinna
Pandas-(Ziad).pptx
Pandas-(Ziad).pptxPandas-(Ziad).pptx
Pandas-(Ziad).pptx
Sivam Chinna
Clustering.pptx
Clustering.pptxClustering.pptx
Clustering.pptx
Sivam Chinna
13. Anomaly.pptx
13. Anomaly.pptx13. Anomaly.pptx
13. Anomaly.pptx
Sivam Chinna

Recently uploaded (20)

Introduction to Microsoft Power BI is a business analytics service
Introduction to Microsoft Power BI is a business analytics serviceIntroduction to Microsoft Power BI is a business analytics service
Introduction to Microsoft Power BI is a business analytics service
Kongu Engineering College, Perundurai, Erode
IT Professional Ethics, Moral and Cu.ppt
IT Professional Ethics, Moral and Cu.pptIT Professional Ethics, Moral and Cu.ppt
IT Professional Ethics, Moral and Cu.ppt
FrancisFayiah
brightonSEO - Metehan Yesilyurt - Generative AI & GEO: the new SEO race and h...
brightonSEO - Metehan Yesilyurt - Generative AI & GEO: the new SEO race and h...brightonSEO - Metehan Yesilyurt - Generative AI & GEO: the new SEO race and h...
brightonSEO - Metehan Yesilyurt - Generative AI & GEO: the new SEO race and h...
Metehan Yeilyurt
FOOD LAWS.pptxbshdhdhdhdhdhhdhdhdhdhdhhdh
FOOD LAWS.pptxbshdhdhdhdhdhhdhdhdhdhdhhdhFOOD LAWS.pptxbshdhdhdhdhdhhdhdhdhdhdhhdh
FOOD LAWS.pptxbshdhdhdhdhdhhdhdhdhdhdhhdh
cshdhdhvfsbzdb
MeasureCamp Belgrade 2025 - Yasen Lilov - Past - Present - Prompt
MeasureCamp Belgrade 2025 - Yasen Lilov - Past - Present - PromptMeasureCamp Belgrade 2025 - Yasen Lilov - Past - Present - Prompt
MeasureCamp Belgrade 2025 - Yasen Lilov - Past - Present - Prompt
Yasen Lilov
BSEO - The Ultimate GA4 Audit - Anna Lewis - Polka Dot Data
BSEO - The Ultimate GA4 Audit - Anna Lewis - Polka Dot DataBSEO - The Ultimate GA4 Audit - Anna Lewis - Polka Dot Data
BSEO - The Ultimate GA4 Audit - Anna Lewis - Polka Dot Data
Anna Lewis
SQL-for-Data-Analytics-Top-10-Queries-Every-Analyst-Should-Know
SQL-for-Data-Analytics-Top-10-Queries-Every-Analyst-Should-KnowSQL-for-Data-Analytics-Top-10-Queries-Every-Analyst-Should-Know
SQL-for-Data-Analytics-Top-10-Queries-Every-Analyst-Should-Know
Ozias Rondon
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
berihun18
Statistics for Management - standard deviation.pptx
Statistics for Management - standard deviation.pptxStatistics for Management - standard deviation.pptx
Statistics for Management - standard deviation.pptx
Jeya Sree
PPTjhjhghhhghghghggvgfggffgftftftftftft.ppt
PPTjhjhghhhghghghggvgfggffgftftftftftft.pptPPTjhjhghhhghghghggvgfggffgftftftftftft.ppt
PPTjhjhghhhghghghggvgfggffgftftftftftft.ppt
vmanjusundertamil21
cPanel Dedicated Server Hosting at Top-Tier Data Center comes with a Premier ...
cPanel Dedicated Server Hosting at Top-Tier Data Center comes with a Premier ...cPanel Dedicated Server Hosting at Top-Tier Data Center comes with a Premier ...
cPanel Dedicated Server Hosting at Top-Tier Data Center comes with a Premier ...
soniaseo850
Respiratory failure qdhgqycfg vnqhgywuv sxbjiogucf sxbn.pptx
Respiratory failure qdhgqycfg vnqhgywuv sxbjiogucf sxbn.pptxRespiratory failure qdhgqycfg vnqhgywuv sxbjiogucf sxbn.pptx
Respiratory failure qdhgqycfg vnqhgywuv sxbjiogucf sxbn.pptx
predatorzmecet
Types_of_Data_Structures_Presentation.pptx
Types_of_Data_Structures_Presentation.pptxTypes_of_Data_Structures_Presentation.pptx
Types_of_Data_Structures_Presentation.pptx
shefalisharma776119
20-NoSQLMongoDbiig data analytics hB.pdf
20-NoSQLMongoDbiig data analytics hB.pdf20-NoSQLMongoDbiig data analytics hB.pdf
20-NoSQLMongoDbiig data analytics hB.pdf
ssuser2d043c
CPT OPT FEB 2025 TENNEY_Jamespptx university
CPT OPT FEB 2025 TENNEY_Jamespptx universityCPT OPT FEB 2025 TENNEY_Jamespptx university
CPT OPT FEB 2025 TENNEY_Jamespptx university
gobindsingh1107
This presentation detail concepts of cryptocurrency
This presentation detail concepts of cryptocurrencyThis presentation detail concepts of cryptocurrency
This presentation detail concepts of cryptocurrency
Aslbtr
BoSEU25 | Diego de J坦dar | Why User Activation is the Key to Sustainable Growth
BoSEU25 | Diego de J坦dar | Why User Activation is the Key to Sustainable GrowthBoSEU25 | Diego de J坦dar | Why User Activation is the Key to Sustainable Growth
BoSEU25 | Diego de J坦dar | Why User Activation is the Key to Sustainable Growth
Business of Software Conference
Exploratory data analysis (EDA) is used by data scientists to analyze and inv...
Exploratory data analysis (EDA) is used by data scientists to analyze and inv...Exploratory data analysis (EDA) is used by data scientists to analyze and inv...
Exploratory data analysis (EDA) is used by data scientists to analyze and inv...
jimmy841199
Threat Intelligence Platform_ The Future of Cybersecurity Defense.docx
Threat Intelligence Platform_ The Future of Cybersecurity Defense.docxThreat Intelligence Platform_ The Future of Cybersecurity Defense.docx
Threat Intelligence Platform_ The Future of Cybersecurity Defense.docx
dexposewebcast
Understanding-the-Data-Science-Lifecycle
Understanding-the-Data-Science-LifecycleUnderstanding-the-Data-Science-Lifecycle
Understanding-the-Data-Science-Lifecycle
Ozias Rondon
IT Professional Ethics, Moral and Cu.ppt
IT Professional Ethics, Moral and Cu.pptIT Professional Ethics, Moral and Cu.ppt
IT Professional Ethics, Moral and Cu.ppt
FrancisFayiah
brightonSEO - Metehan Yesilyurt - Generative AI & GEO: the new SEO race and h...
brightonSEO - Metehan Yesilyurt - Generative AI & GEO: the new SEO race and h...brightonSEO - Metehan Yesilyurt - Generative AI & GEO: the new SEO race and h...
brightonSEO - Metehan Yesilyurt - Generative AI & GEO: the new SEO race and h...
Metehan Yeilyurt
FOOD LAWS.pptxbshdhdhdhdhdhhdhdhdhdhdhhdh
FOOD LAWS.pptxbshdhdhdhdhdhhdhdhdhdhdhhdhFOOD LAWS.pptxbshdhdhdhdhdhhdhdhdhdhdhhdh
FOOD LAWS.pptxbshdhdhdhdhdhhdhdhdhdhdhhdh
cshdhdhvfsbzdb
MeasureCamp Belgrade 2025 - Yasen Lilov - Past - Present - Prompt
MeasureCamp Belgrade 2025 - Yasen Lilov - Past - Present - PromptMeasureCamp Belgrade 2025 - Yasen Lilov - Past - Present - Prompt
MeasureCamp Belgrade 2025 - Yasen Lilov - Past - Present - Prompt
Yasen Lilov
BSEO - The Ultimate GA4 Audit - Anna Lewis - Polka Dot Data
BSEO - The Ultimate GA4 Audit - Anna Lewis - Polka Dot DataBSEO - The Ultimate GA4 Audit - Anna Lewis - Polka Dot Data
BSEO - The Ultimate GA4 Audit - Anna Lewis - Polka Dot Data
Anna Lewis
SQL-for-Data-Analytics-Top-10-Queries-Every-Analyst-Should-Know
SQL-for-Data-Analytics-Top-10-Queries-Every-Analyst-Should-KnowSQL-for-Data-Analytics-Top-10-Queries-Every-Analyst-Should-Know
SQL-for-Data-Analytics-Top-10-Queries-Every-Analyst-Should-Know
Ozias Rondon
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
berihun18
Statistics for Management - standard deviation.pptx
Statistics for Management - standard deviation.pptxStatistics for Management - standard deviation.pptx
Statistics for Management - standard deviation.pptx
Jeya Sree
PPTjhjhghhhghghghggvgfggffgftftftftftft.ppt
PPTjhjhghhhghghghggvgfggffgftftftftftft.pptPPTjhjhghhhghghghggvgfggffgftftftftftft.ppt
PPTjhjhghhhghghghggvgfggffgftftftftftft.ppt
vmanjusundertamil21
cPanel Dedicated Server Hosting at Top-Tier Data Center comes with a Premier ...
cPanel Dedicated Server Hosting at Top-Tier Data Center comes with a Premier ...cPanel Dedicated Server Hosting at Top-Tier Data Center comes with a Premier ...
cPanel Dedicated Server Hosting at Top-Tier Data Center comes with a Premier ...
soniaseo850
Respiratory failure qdhgqycfg vnqhgywuv sxbjiogucf sxbn.pptx
Respiratory failure qdhgqycfg vnqhgywuv sxbjiogucf sxbn.pptxRespiratory failure qdhgqycfg vnqhgywuv sxbjiogucf sxbn.pptx
Respiratory failure qdhgqycfg vnqhgywuv sxbjiogucf sxbn.pptx
predatorzmecet
Types_of_Data_Structures_Presentation.pptx
Types_of_Data_Structures_Presentation.pptxTypes_of_Data_Structures_Presentation.pptx
Types_of_Data_Structures_Presentation.pptx
shefalisharma776119
20-NoSQLMongoDbiig data analytics hB.pdf
20-NoSQLMongoDbiig data analytics hB.pdf20-NoSQLMongoDbiig data analytics hB.pdf
20-NoSQLMongoDbiig data analytics hB.pdf
ssuser2d043c
CPT OPT FEB 2025 TENNEY_Jamespptx university
CPT OPT FEB 2025 TENNEY_Jamespptx universityCPT OPT FEB 2025 TENNEY_Jamespptx university
CPT OPT FEB 2025 TENNEY_Jamespptx university
gobindsingh1107
This presentation detail concepts of cryptocurrency
This presentation detail concepts of cryptocurrencyThis presentation detail concepts of cryptocurrency
This presentation detail concepts of cryptocurrency
Aslbtr
BoSEU25 | Diego de J坦dar | Why User Activation is the Key to Sustainable Growth
BoSEU25 | Diego de J坦dar | Why User Activation is the Key to Sustainable GrowthBoSEU25 | Diego de J坦dar | Why User Activation is the Key to Sustainable Growth
BoSEU25 | Diego de J坦dar | Why User Activation is the Key to Sustainable Growth
Business of Software Conference
Exploratory data analysis (EDA) is used by data scientists to analyze and inv...
Exploratory data analysis (EDA) is used by data scientists to analyze and inv...Exploratory data analysis (EDA) is used by data scientists to analyze and inv...
Exploratory data analysis (EDA) is used by data scientists to analyze and inv...
jimmy841199
Threat Intelligence Platform_ The Future of Cybersecurity Defense.docx
Threat Intelligence Platform_ The Future of Cybersecurity Defense.docxThreat Intelligence Platform_ The Future of Cybersecurity Defense.docx
Threat Intelligence Platform_ The Future of Cybersecurity Defense.docx
dexposewebcast
Understanding-the-Data-Science-Lifecycle
Understanding-the-Data-Science-LifecycleUnderstanding-the-Data-Science-Lifecycle
Understanding-the-Data-Science-Lifecycle
Ozias Rondon

Geospatial Visualization for datascience

  • 2. 2 What is Geopandas? GeoPandas is an open-source project to make working with geospatial data in python easier. GeoPandas is one of the most satisfying Python packages to use because it produces a tangible, visible output that is directly linked to the real world. Here we will be exploring the method to create a geo map and visualize data over it, using shapefiles(.shp) and some other Python libraries.
  • 3. 3 The core data structure in GeoPandas GeoDataFrame, a subclass of pandas. DataFrame, that can store geometry columns and perform spatial operations. The geopandas.GeoSeries, a subclass of pandas.Series, handles the geometries. Therefore, your GeoDataFrame is a combination of pandas.Series, with traditional data (numerical, boolean, text etc.), and geopandas.GeoSeries, with geometries (points, polygons etc.). You can have as many columns with geometries as you wish; theres no limit typical for desktop GIS software.
  • 4. 4 The core data structure in GeoPandas
  • 5. 5 The core data structure in GeoPandas Each GeoSeries can contain any geometry type (you can even mix them within a single array) and has a GeoSeries.crs attribute, which stores information about the projection (CRS stands for Coordinate Reference System). Therefore, each GeoSeries in a GeoDataFrame can be in a different projection, allowing you to have, for example, multiple versions (different projections) of the same geometry. Only one GeoSeries in a GeoDataFrame is considered the active geometry, which means that all geometric operations applied to a GeoDataFrame operate on this active column.
  • 6. 6 world map projections. 1. Mercator This projection was developed by Gerardus Mercator back in 1569 for navigational purposes. Its ability to represent lines of constant course from coast to coast made it the perfect map for sailing the seas. Its popularity was so great that it became used as a geographic teaching aid even though the projection grossly distorts countries sizes. This is at its worst the closer you are to the poles. Greenland is 550% too big, it should fit into Africa 14 times!
  • 7. 7 Vector Data: OpenGIS Simple Features / OCG Simple Feature Access Used in spatial databases (Postgresql/PostGIS), GIS, WKT (Well known Text): Point, Multipoint LineString, MultiLineString Polygon, MultiPolygon GeometryCollection (TIN, Circle, Curve, Triangle, Surface, PolyhedralSurface, ) map projections.
  • 10. 10 world map projections. 1. Mercator This projection was developed by Gerardus Mercator back in 1569 for navigational purposes. Its ability to represent lines of constant course from coast to coast made it the perfect map for sailing the seas. Its popularity was so great that it became used as a geographic teaching aid even though the projection grossly distorts countries sizes. This is at its worst the closer you are to the poles. Greenland is 550% too big, it should fit into Africa 14 times!
  • 11. 11 Map projections. 2. Robinson This map is known as a compromise, it shows neither the shape or land mass of countries correct. Arthur Robinson developed it in 1963 using a more visual trial and error development. Our Classic world map uses the Robinson projection and is a contemporary tribute to the familiar schoolroom map and is perfect for map-lovers of all ages..
  • 12. 12 map projections 3. Dymaxion Map This projection was released by R Buckminster Fuller in 1954 after several decades working on it. The world is projected onto the surface of a icosahedron, allowing it to be unfolded and flattened in two dimensions. It is said to represent the Earths continents as one island.
  • 13. 13 map projections 4. Gall-Peters This is a cylindrical world map projection, that regains accuracy in surface area. It is named after James Gall and Arno Peters. Whilst Gall, first described the projection in 1855 it was not until 1973 when Peters, began to heavily market the projection as the Peters World Map that it became popular.
  • 14. 14 map projections 5. Sinu-Mollweide Developed in 1953 by Allen K Philbrick, this projection fuses the Sinusoidal projection , which was first used in the 16th Century, with Karl Brandan Mollweide's map of 1805 and challenges our assumption of how the flattened globe should look. Still an equal area projection that maintains fidelity of area, we like this projection for its bold graphic view.
  • 15. 15 map projections 6 Winkel Tripel A globe that is projected onto a flat surface giving it curved lines of latitude and curved meridians. The projection, by Oswald Winkel in1921 was developed with the goal of minimizing the three kinds of distortion: area, direction and distance. Thus it became the Tripel Projection (German for triple). The projection is neither equal-area nor conformal, its main feature is that all of the parallels are curved except for the straight poles and equator. This gives a lovely spherical feeling to this two dimensional map.
  • 16. 16 Download Free Shapefile Maps https://www.igismap.com/download-free-shap efile-maps/ https://www.statsilk.com/maps/download-free- shapefile-maps https://mapscaping.com/download-shapefiles-f or-any-country/
  • 17. 17 GeoPandas packages: pandas shapely fiona pyproj packaging Further, matplotlib is an optional dependency, required for plotting. GeoPandas using the conda package manager.
  • 18. 18 Reading and writing files Assuming you have a file containing both data and geometry (e.g. GeoPackage, GeoJSON, Shapefile), you can read it using geopandas.read_file(), which automatically detects the filetype and creates a GeoDataFrame. This tutorial uses the "nybb" dataset, a map of New York boroughs, which is available through the geodatasets package. Therefore, we use geodatasets.get_path() to download the dataset and retrieve the path to the local copy.
  • 19. 19 Reading and writing files Assuming you have a file containing both data and geometry (e.g. GeoPackage, GeoJSON, Shapefile), you can read it using geopandas.read_file(), which automatically detects the filetype and creates a GeoDataFrame. This tutorial uses the "nybb" dataset, a map of New York boroughs, which is available through the geodatasets package. Therefore, we use geodatasets.get_path() to download the dataset and retrieve the path to the local copy.
  • 20. 20 Writing files To write a GeoDataFrame back to file use GeoDataFrame.to_file(). The default file format is Shapefile, but you can specify your own with the driver keyword.
  • 21. 21 Simple accessors and methods Now we have our GeoDataFrame and can start working with its geometry. Since there was only one geometry column in the New York Boroughs dataset, this column automatically becomes the active geometry and spatial methods used on the GeoDataFrame will be applied to the "geometry" column.
  • 22. 22 Simple accessors and methods Measuring area To measure the area of each polygon (or MultiPolygon in this specific case), access the GeoDataFrame.area attribute, which returns a pandas.Series. Note that GeoDataFrame.area is just GeoSeries.area applied to the active geometry column.
  • 23. 23 Simple accessors and methods Getting polygon boundary and centroid To get the boundary of each polygon (LineString), access the GeoDataFrame.boundary: Since we have saved boundary as a new column, we now have two geometry columns in the same GeoDataFrame.
  • 24. 24 Simple accessors and methods Getting polygon boundary and centroid To get the boundary of each polygon (LineString), access the GeoDataFrame.boundary: Since we have saved boundary as a new column, we now have two geometry columns in the same GeoDataFrame.
  • 25. 25 Simple accessors and methods Measuring distance We can also measure how far each centroid is from the first centroid location. Note that geopandas.GeoDataFrame is a subclass of pandas.DataFrame, so we have all the pandas functionality available to use on the geospatial dataset we can even perform data manipulations with the attributes and geometry information together.
  • 26. 26 Making maps GeoPandas can also plot maps, so we can check how the geometries appear in space. To plot the active geometry, call GeoDataFrame.plot(). To color code by another column, pass in that column as the first argument. In the example below, we plot the active geometry column and color code by the "area" column. We also want to show a legend (legend=True).
  • 28. 28 Making maps You can also explore your data interactively using GeoDataFrame.explore(), which behaves in the same way plot() does but returns an interactive map instead.
  • 29. 29 Making maps Switching the active geometry (GeoDataFrame.set_geometry) to centroids, we can plot the same data using point geometry..
  • 30. 30 Making maps And we can also layer both GeoSeries on top of each other. We just need to use one plot as an axis for the other.
  • 31. 31 Step 1 : Installing GeoPandas and Shapely need to install the GeoPandas and Shapely libraries in order to plot a map, and these libraries do not come with the Anaconda download. through the conda-forge channel with the following command from your terminal or alternatively Shapely can be pip installed with the command conda install -c conda-forge geopandas pip install geopandas pip install shapely
  • 32. 32 Importing the libraries Importing the libraries import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import geopandas as gpd import shapefile as shp from shapely.geometry import Point sns.set_style('whitegrid')
  • 33. 33 Load the data Use india-polygon.shp shape file to plot India map Load the data into a GeoDataFrame as shown below. fp = r india-polygon.shp' map_df = gpd.read_file(fp) map_df_copy = gpd.read_file(fp) map_df.head()
  • 34. 34 Plotting the Shapefiles One nice thing about downloading a GeoDataFrame, is that weve already got enough info to make a basic plot. map_df.plot()
  • 35. 35 Adding better data insights into the map df = pd.read_csv('globallandslides.csv') pd.set_option('display.max_columns', None)df = df[df.country_name=="India"] df["Year"] = pd.to_datetime(df["event_date"]).dt.year df = df[df.landslide_category=="landslide"] state_df = ls_df["admin_division_name"].value_counts() state_df = state_df.to_frame() state_df.reset_index(level=0, inplace=True) state_df.columns = ['State', 'Count']state_df.at[15,"Count"] = 69 state_df.at[0,"State"] = "Jammu and Kashmir" state_df.at[20,"State"] = "Delhi" state_df.drop(7)
  • 36. 36 data of the number of landslides that have happened in each state over the years
  • 37. 37 Merge the data We can now merge this above state data which contains landslide information with map_df shapefile. We will use the State column of both the data frames for merging purposes. #Merging the data merged = map_df.set_index('st_nm').join(state_df.set_index('State')) merged['Count'] = merged['Count'].replace(np.nan, 0) merged.head()
  • 38. 38 Plotting the data on the Shapefile #Create figure and axes for Matplotlib and set the title fig, ax = plt.subplots(1, figsize=(10, 10)) ax.axis('off')ax.set_title('Number of landslides in India state-wise', fontdict={'fontsize': '20', 'fontweight' : '10'})# Plot the figure merged.plot(column='Count',cmap='YlOrRd', linewidth=0.8, ax=ax, edgecolor='0',legend=True,markersize=[39.739192, -104.990337], legend_kwds={'label': "Number of landslides"})
  • 39. 39 Plotting the data on the Shapefile
  • 40. 40 plot the latitudes and longitudes We can also plot the latitudes and longitudes of the occurred landslides on the map along with the names of states as shown below. For this, you will need to find the shapefile data for Indian states and their latitudes and longitudes. have to plot data points on the map..
  • 41. 41