{"id":86771,"date":"2023-02-23T09:00:59","date_gmt":"2023-02-23T03:30:59","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=86771"},"modified":"2023-02-23T09:00:59","modified_gmt":"2023-02-23T03:30:59","slug":"geographic-maps-and-their-mapping-in-python","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/","title":{"rendered":"Geographic maps and their Mapping in Python"},"content":{"rendered":"<p><span style=\"font-weight: 400\">Have you ever wondered how those stunning maps of the world are made? The interactive data visualisations on Our World in Data cover a wide range of topics, including population growth, violence, political power, education, culture, and many other issues that are important to us. These representations aid in our comprehension of the causes and effects of recent global change. This quantity of knowledge piqued my interest and gave me the desire to learn more.<\/span><\/p>\n<p><span style=\"font-weight: 400\">When defining a physical object&#8217;s position or that of any other entity, such as a town, a city, a street, a structure, etc, We refer to this type of data as &#8220;spatial data,&#8221; also known as geospatial data, GIS data, or geodata, since it uses a geographic coordinate system. Using spatial data, you may ascertain an object&#8217;s length, size, area, and shape in addition to its location. The GeoPandas and GeoPlot libraries are required to interact with geographical data in Python.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Of course, when we talk about geographic data, we think of a data point&#8217;s coordinates, which are its longitude and latitude. They are merely the X and Y coordinates for a particular location on the map, which is correct. Other geographic data types, such as polygon and line data, do exist. Here, a map&#8217;s point data will be the primary subject of attention. With TechVidvan let&#8217;s start and learn about Mapping Geographic Data in Python.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">What is Spatial Data?<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Any piece of information that, either directly or indirectly, refers to a specific geographic region or location is referred to as &#8220;spatial data.&#8221; Spatial data is a numerical representation of a physical object in a geographical coordinate system. Although there are many other kinds of spatial data, geometric and geographic data are the most prevalent. Let&#8217;s attempt to comprehend these two types of facts.<\/span><\/p>\n<h4><span style=\"font-weight: 400\">1. Geometric Data:<\/span><\/h4>\n<p><span style=\"font-weight: 400\">A two-dimensional flat surface represents geometric data, a type of spatial data. For instance, floor plans require geometric data. Geometric information is used by Google Maps, a navigation app, to produce accurate directions.<\/span><\/p>\n<h4><span style=\"font-weight: 400\">2. Geographic Data:<\/span><\/h4>\n<p><span style=\"font-weight: 400\">Information that has been plotted around a sphere is referred to as &#8220;geographical data.&#8221; The globe is typically Earth in most cases. Geographical information highlights the connection between latitude and longitude to a certain object or region. A well-known example of geographic data is the Global Positioning System (GPS).<\/span><\/p>\n<h3>Prerequisites for Mapping Geographic Data in Python<\/h3>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Numpy<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Pandas (version 0.24 or later)\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Shapely (interface to GEOS)\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Fiona (interface to GDAL)\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Pyproj (interface to PROJ; +2.2.0v)<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400\">Installation:<\/span><\/h3>\n<p><b>Anaconda can be used for installation:<\/b><\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">conda install geopandas\nconda install geoplot\n<\/pre>\n<p><span style=\"font-weight: 400\">A community project called conda-forge offers conda packages for a variety of software. In addition to the &#8220;defaults&#8221; channel that Anaconda offers, it provides the conda-forge package channel for conda from which packages can be installed.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Examining a Shapefile:<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Using the variable &#8220;world data,&#8221; we will first import the GeoPandas library before reading our shapefile. Using the command: Geopandas can read nearly any vector-based spatial data format, including ESRI shapefiles, GeoJSON files, and more.<\/span><\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import geopandas as gpds\n  \n# Reading the data\nworlds_data = gpds.read_file(r'worlds.shp')\n  \nworlds_data\n<\/pre>\n<h3><span style=\"font-weight: 400\">Steps involved in Mapping Geographic Data in Python :<\/span><\/h3>\n<p><span style=\"font-weight: 400\">An open-source project called GeoPandas aims to simplify the handling of geographical data in Python. GeoPandas adds support for spatial operations on geometric types to the Pandas data types. Shapely geometric processes are carried out. Geopandas also use Matplotlib for charting and Fiona for file access. A sizable stack of open-source geospatial libraries is what GeoPandas rely on for its spatial capability (GEOS, GDAL, and PROJ).<\/span><\/p>\n<p><b>Step 1: Libraries and data are being loaded:<\/b><\/p>\n<p>Let&#8217;s begin by loading the libraries first.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy\nimport pandas\nimport matplotlib\n\npyplot as plty\n<\/pre>\n<p><b>Step 2: dataset is loaded<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">df = pd.read_csv(\u2018C:\/.. \u2026\/DataSet.txt\u2019)\n\ndf.head()\n<\/pre>\n<p><b>Step 3: Establish the Bounding Box<\/b><\/p>\n<p><span style=\"font-weight: 400\">The Bounding Box must now be defined. The area that will encompass all spatial points is known as the Bounding Box, and it is specified by two longitudes and two latitudes.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">BBox = ((df.longitude.min(),   df.longitude.max(),df.latitude.min(), df.latitude.max())\n&gt; (46.5691,46.8398, 24.6128, 24.8256)\n<\/pre>\n<p><b>Step 4: Find Your Map<\/b><\/p>\n<p><span style=\"font-weight: 400\">Enter the bounding box information before exporting the desired map as an image.\u00a0<\/span><\/p>\n<p><b>Step 5: Plotting geographic data in python<\/b><\/p>\n<p><span style=\"font-weight: 400\">Finally, create scatter points on the &#8216;ruh m&#8217; map picture using the &#8216;df.longitude&#8217; and &#8216;df.latitude&#8217; values. Keep in mind that the X-axis and Y-axis must be set up according to the bounding box, or &#8220;BBox.&#8221;<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fig, ax = plt.subplots(figsize = (8,7))\nax.scatter(df.longitude, df.latitude, zorder=1, alpha= 0.2, c='b', s=10)\nax.set_title('Plotting Spatial Data on Riyadh Map')\nax.set_xlim(BBox[0],BBox[1])\nax.set_ylim(BBox[2],BBox[3])\nax.imshow(ruh_m, zorder=0, extent = BBox, aspect= 'equal')\n<\/pre>\n<h3><span style=\"font-weight: 400\">Other methods to graph geograph data:<\/span><\/h3>\n<h4>1. Reference System for Coordinates:<\/h4>\n<p><span style=\"font-weight: 400\">Geopandas&#8217; CRS, or Coordinates Reference System, allows us to examine the coordinate system we are currently using. Additionally, we may transform it into a system for project coordination\u2014the pyproj.CRS object represents the Coordinate Reference System (CRS). We can use the following syntax to check the current CRS.<\/span><\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">GeoDataFrame.crs<\/pre>\n<p><span style=\"font-weight: 400\">The to_crs() method converts geometry to a different coordinate reference system. Change the system of coordinates used to reference all of the geometries in a geometry column that is active. The series at hand must have the CRS attribute configured. One of two output formats, CRS or ePSG, may be used. All points in all objects will be altered using this technique. It doesn&#8217;t have any idea about projecting whole geometries.<\/span><\/p>\n<p><span style=\"font-weight: 400\"> In the current projection, all segment joining points\u2014not geodesics\u2014are taken to be lined up. Crossing the dateline (or another projection barrier) will cause objects to act in an unfavorable manner.<\/span><\/p>\n<h4>2. Inserting a legend<\/h4>\n<p><span style=\"font-weight: 400\">Next, we will convert the area into square kilometers by dividing it by 106 (i.e. (1000000). The &#8220;world data&#8221; variable in the variable explorer displays the output.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Using plot() parameters, we can add a legend and a label to our global map.<\/span><\/p>\n<p><span style=\"font-weight: 400\">name: bool (default False). Set up a legend, ignored if no column or color is specified<\/span><\/p>\n<p><span style=\"font-weight: 400\">dict legend kwds (default None). Matplotlib.pyplot.legend() and Matplotlib.pyplot.colorbar keyword arguments (). Additional words that are acceptable when a scheme is specified:<\/span><\/p>\n<p><span style=\"font-weight: 400\">string, format: a formatting guideline for the classes&#8217; bin borders in the legend. For instance, do not use decimals: {\u201cfmt\u201d: \u201c{:.0f}\u201d}.<\/span><\/p>\n<h4>3. Geoplot&#8217;s Sankey<\/h4>\n<p><span style=\"font-weight: 400\">An information network&#8217;s information flow is shown on a Sankey diagram. It helps see the volumes of data that are being processed by a system. The Sankey diagram is given a geospatial context in this picture, which makes it useful for tracking, for instance, travel volumes between airports or traffic loads on a road network. <\/span><\/p>\n<p><span style=\"font-weight: 400\">A GeoDataFrame with line strings or multipoint geometries is necessary for a basic Sankey. Hue gives the map a gradation of color. To control the colormap, use matplotlib&#8217;s cmap function. Indicate the color scheme for a category colormap. A legend turns a story on or off. Here, Mollweide projection is being used.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Conclusion:<\/span><\/h3>\n<p><span style=\"font-weight: 400\">We learned about Various data visualization tools, including Matplotlib, Pandas, Plotly, Seaborn, Bokeh, etc., that can be used to accomplish Mapping Geographic Data in Python. These tools are all frequently used with tabular data. Similarly, we can use a Python module called GeoPandas to visualize geospatial data or draw a map of any geographic place and show some of the noteworthy information. Geospatial data manipulation and graphing are the only uses for this package. In this essay, we will talk about the following issues in contrast to GeoPandas:<\/span><\/p>\n<p><span style=\"font-weight: 400\">We have examined spatial data and its corresponding properties in this article. Later, we talked about how GeoPandas, which is entirely based on Pandas, may be used to manage geospatial data. We have expertly produced the satellite view of our map by analyzing the map from the internet using contextual data and coordinates from GeoPandas.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever wondered how those stunning maps of the world are made? The interactive data visualisations on Our World in Data cover a wide range of topics, including population growth, violence, political power,&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":87216,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1053],"tags":[4842],"class_list":["post-86771","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-mapping-geographic-data-in-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Geographic maps and their Mapping in Python - TechVidvan<\/title>\n<meta name=\"description\" content=\"See Various data visualization tools like Matplotlib, Pandas, Plotly, Seaborn, Bokeh, etc. for Mapping Geographic Data in Python.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Geographic maps and their Mapping in Python - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"See Various data visualization tools like Matplotlib, Pandas, Plotly, Seaborn, Bokeh, etc. for Mapping Geographic Data in Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-23T03:30:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/02\/python-geographic-maps.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Geographic maps and their Mapping in Python - TechVidvan","description":"See Various data visualization tools like Matplotlib, Pandas, Plotly, Seaborn, Bokeh, etc. for Mapping Geographic Data in Python.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Geographic maps and their Mapping in Python - TechVidvan","og_description":"See Various data visualization tools like Matplotlib, Pandas, Plotly, Seaborn, Bokeh, etc. for Mapping Geographic Data in Python.","og_url":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2023-02-23T03:30:59+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/02\/python-geographic-maps.webp","type":"image\/webp"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Geographic maps and their Mapping in Python","datePublished":"2023-02-23T03:30:59+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/"},"wordCount":1221,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/02\/python-geographic-maps.webp","keywords":["Mapping Geographic Data in Python"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/","url":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/","name":"Geographic maps and their Mapping in Python - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/02\/python-geographic-maps.webp","datePublished":"2023-02-23T03:30:59+00:00","description":"See Various data visualization tools like Matplotlib, Pandas, Plotly, Seaborn, Bokeh, etc. for Mapping Geographic Data in Python.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/02\/python-geographic-maps.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/02\/python-geographic-maps.webp","width":1200,"height":628,"caption":"python geographic data maping"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/geographic-maps-and-their-mapping-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Geographic maps and their Mapping in Python"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/86771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=86771"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/86771\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/87216"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=86771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=86771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=86771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}