{ "cells": [ { "cell_type": "markdown", "id": "d4a0b595", "metadata": {}, "source": [ "(e_attributes)=\n", " \n", "\n", "----------------\n", "\n", "```{admonition} Learning Objectives\n", "* Create and manipulate vector attributes\n", "* Subset data\n", "* Plot lat lon as points\n", "* Subset points by location\n", "```\n", "```{admonition} Review\n", "* [Vector Data](c_vectors.md)\n", "```\n", "----------------\n", "\n", "\n", "# Attributes & Indexing for Vector Data\n", "\n", "```{figure} ../_static/c_data_types/dataframe.svg\n", ":name: vector properties \n", "Structure of a `GeoDataFrame` extends the functionality of a Pandas `DataFrame`\n", "```\n", "\n", "Each `GeoSeries` can contain any geometry type (e.g. points, lines, polygon) and has a `GeoSeries.crs` attribute, which stores information on 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 of the same geometry, just in a different CRS.\n", "\n", "\n", "```{tip} Becuase GeoPandas are so intertwined spend the time to learn more about here [Pandas User Guide](https://pandas.pydata.org/pandas-docs/stable/user_guide/index.html)\n", "```\n", "\n", "## Create New Attributes\n", "\n", "One of the most basic operations is creating new attributes. Let's say for instance we want to look at the world population in millions. We can start with an existing column of data `pop_est`. Let's start by looking at the column names:" ] }, { "cell_type": "code", "execution_count": 1, "id": "c29f501d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['pop_est', 'continent', 'name', 'iso_a3', 'gdp_md_est', 'geometry'], dtype='object')" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import geopandas\n", "world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))\n", "world.columns" ] }, { "cell_type": "markdown", "id": "0babd195", "metadata": {}, "source": [ "We can then do basic operations on the basis of column names. Here we create a new column `m_pop_est`:" ] }, { "cell_type": "code", "execution_count": 2, "id": "337fb249", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | pop_est | \n", "continent | \n", "name | \n", "iso_a3 | \n", "gdp_md_est | \n", "geometry | \n", "m_pop_est | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "889953.0 | \n", "Oceania | \n", "Fiji | \n", "FJI | \n", "5496 | \n", "MULTIPOLYGON (((180.00000 -16.06713, 180.00000... | \n", "0.889953 | \n", "
1 | \n", "58005463.0 | \n", "Africa | \n", "Tanzania | \n", "TZA | \n", "63177 | \n", "POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... | \n", "58.005463 | \n", "