Dados Geoespaciais¶
Instalando o Ambiente¶
In [1]:
Copied!
!pip install geopandas shapely mapclassify libpysal splot esda pysal contextily
!pip install --upgrade pyshp
!pip install --upgrade descartes
!pip install --upgrade fiona
!pip install geopandas shapely mapclassify libpysal splot esda pysal contextily
!pip install --upgrade pyshp
!pip install --upgrade descartes
!pip install --upgrade fiona
Requirement already satisfied: geopandas in /usr/local/lib/python3.10/dist-packages (0.13.2) Requirement already satisfied: shapely in /usr/local/lib/python3.10/dist-packages (2.0.3) Collecting mapclassify Downloading mapclassify-2.6.1-py3-none-any.whl (38 kB) Collecting libpysal Downloading libpysal-4.10-py3-none-any.whl (2.8 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.8/2.8 MB 16.3 MB/s eta 0:00:00 Collecting splot Downloading splot-1.1.5.post1-py3-none-any.whl (39 kB) Collecting esda Downloading esda-2.5.1-py3-none-any.whl (132 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 132.4/132.4 kB 14.3 MB/s eta 0:00:00 Collecting pysal Downloading pysal-24.1-py3-none-any.whl (17 kB) Collecting contextily Downloading contextily-1.6.0-py3-none-any.whl (17 kB) Requirement already satisfied: fiona>=1.8.19 in /usr/local/lib/python3.10/dist-packages (from geopandas) (1.9.6) Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from geopandas) (24.0) Requirement already satisfied: pandas>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from geopandas) (1.5.3) Requirement already satisfied: pyproj>=3.0.1 in /usr/local/lib/python3.10/dist-packages (from geopandas) (3.6.1) Requirement already satisfied: numpy<2,>=1.14 in /usr/local/lib/python3.10/dist-packages (from shapely) (1.25.2) Requirement already satisfied: networkx>=2.7 in /usr/local/lib/python3.10/dist-packages (from mapclassify) (3.2.1) Requirement already satisfied: scikit-learn>=1.0 in /usr/local/lib/python3.10/dist-packages (from mapclassify) (1.2.2) Requirement already satisfied: scipy>=1.8 in /usr/local/lib/python3.10/dist-packages (from mapclassify) (1.11.4) Requirement already satisfied: beautifulsoup4>=4.10 in /usr/local/lib/python3.10/dist-packages (from libpysal) (4.12.3) Requirement already satisfied: platformdirs>=2.0.2 in /usr/local/lib/python3.10/dist-packages (from libpysal) (4.2.0) Requirement already satisfied: requests>=2.27 in /usr/local/lib/python3.10/dist-packages (from libpysal) (2.31.0) Collecting giddy (from splot) Downloading giddy-2.3.5-py3-none-any.whl (61 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.1/61.1 kB 5.0 MB/s eta 0:00:00 Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from splot) (3.7.1) Requirement already satisfied: seaborn in /usr/local/lib/python3.10/dist-packages (from splot) (0.13.1) Collecting spreg (from splot) Downloading spreg-1.4.2-py3-none-any.whl (331 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 331.8/331.8 kB 19.0 MB/s eta 0:00:00 Collecting access>=1.1.8 (from pysal) Downloading access-1.1.9-py3-none-any.whl (21 kB) Collecting inequality>=1.0.0 (from pysal) Downloading inequality-1.0.1-py3-none-any.whl (15 kB) Collecting pointpats>=2.2.0 (from pysal) Downloading pointpats-2.4.0-py3-none-any.whl (58 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.4/58.4 kB 3.6 MB/s eta 0:00:00 Collecting segregation>=2.3.1 (from pysal) Downloading segregation-2.5-py3-none-any.whl (141 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 141.3/141.3 kB 14.5 MB/s eta 0:00:00 Collecting spaghetti>=1.6.6 (from pysal) Downloading spaghetti-1.7.5.post1-py3-none-any.whl (54 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.1/54.1 kB 3.9 MB/s eta 0:00:00 Collecting mgwr>=2.1.2 (from pysal) Downloading mgwr-2.2.1-py3-none-any.whl (47 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 47.9/47.9 kB 3.2 MB/s eta 0:00:00 Collecting momepy>=0.5.3 (from pysal) Downloading momepy-0.7.0-py3-none-any.whl (277 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 277.8/277.8 kB 14.6 MB/s eta 0:00:00 Collecting spglm>=1.0.8 (from pysal) Downloading spglm-1.1.0-py3-none-any.whl (41 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.4/41.4 kB 2.7 MB/s eta 0:00:00 Collecting spint>=1.0.7 (from pysal) Downloading spint-1.0.7.tar.gz (28 kB) Preparing metadata (setup.py) ... done Collecting spvcm>=0.3.0 (from pysal) Downloading spvcm-0.3.0.tar.gz (5.7 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.7/5.7 MB 27.9 MB/s eta 0:00:00 Preparing metadata (setup.py) ... done Collecting tobler>=0.8.2 (from pysal) Downloading tobler-0.11.2-py3-none-any.whl (34 kB) Collecting spopt>=0.4.1 (from pysal) Downloading spopt-0.6.0-py3-none-any.whl (244 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 244.5/244.5 kB 10.9 MB/s eta 0:00:00 Requirement already satisfied: geopy in /usr/local/lib/python3.10/dist-packages (from contextily) (2.3.0) Collecting mercantile (from contextily) Downloading mercantile-1.2.1-py3-none-any.whl (14 kB) Requirement already satisfied: pillow in /usr/local/lib/python3.10/dist-packages (from contextily) (9.4.0) Collecting rasterio (from contextily) Downloading rasterio-1.3.9-cp310-cp310-manylinux2014_x86_64.whl (20.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 20.6/20.6 MB 13.9 MB/s eta 0:00:00 Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from contextily) (1.3.2) Requirement already satisfied: xyzservices in /usr/local/lib/python3.10/dist-packages (from contextily) (2023.10.1) Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.10/dist-packages (from beautifulsoup4>=4.10->libpysal) (2.5) Requirement already satisfied: attrs>=19.2.0 in /usr/local/lib/python3.10/dist-packages (from fiona>=1.8.19->geopandas) (23.2.0) Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from fiona>=1.8.19->geopandas) (2024.2.2) Requirement already satisfied: click~=8.0 in /usr/local/lib/python3.10/dist-packages (from fiona>=1.8.19->geopandas) (8.1.7) Requirement already satisfied: click-plugins>=1.0 in /usr/local/lib/python3.10/dist-packages (from fiona>=1.8.19->geopandas) (1.1.1) Requirement already satisfied: cligj>=0.5 in /usr/local/lib/python3.10/dist-packages (from fiona>=1.8.19->geopandas) (0.7.2) Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from fiona>=1.8.19->geopandas) (1.16.0) Collecting quantecon>=0.4.7 (from giddy->splot) Downloading quantecon-0.7.2-py3-none-any.whl (215 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 215.4/215.4 kB 13.9 MB/s eta 0:00:00 Requirement already satisfied: tqdm>=4.63.0 in /usr/local/lib/python3.10/dist-packages (from momepy>=0.5.3->pysal) (4.66.2) Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=1.1.0->geopandas) (2.8.2) Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=1.1.0->geopandas) (2023.4) Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.27->libpysal) (3.3.2) Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.27->libpysal) (3.6) Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.27->libpysal) (2.0.7) Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn>=1.0->mapclassify) (3.3.0) Collecting deprecation (from segregation>=2.3.1->pysal) Downloading deprecation-2.1.0-py2.py3-none-any.whl (11 kB) Requirement already satisfied: numba in /usr/local/lib/python3.10/dist-packages (from segregation>=2.3.1->pysal) (0.58.1) Collecting rtree>=1.0 (from spaghetti>=1.6.6->pysal) Downloading Rtree-1.2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (535 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 535.2/535.2 kB 16.8 MB/s eta 0:00:00 Collecting pulp>=2.7 (from spopt>=0.4.1->pysal) Downloading PuLP-2.8.0-py3-none-any.whl (17.7 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.7/17.7 MB 19.1 MB/s eta 0:00:00 Requirement already satisfied: statsmodels in /usr/local/lib/python3.10/dist-packages (from tobler>=0.8.2->pysal) (0.14.1) Collecting rasterstats (from tobler>=0.8.2->pysal) Downloading rasterstats-0.19.0-py3-none-any.whl (16 kB) Requirement already satisfied: geographiclib<3,>=1.52 in /usr/local/lib/python3.10/dist-packages (from geopy->contextily) (2.0) Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->splot) (1.2.0) Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib->splot) (0.12.1) Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->splot) (4.50.0) Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->splot) (1.4.5) Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->splot) (3.1.2) Collecting affine (from rasterio->contextily) Downloading affine-2.4.0-py3-none-any.whl (15 kB) Collecting snuggs>=1.4.1 (from rasterio->contextily) Downloading snuggs-1.4.7-py3-none-any.whl (5.4 kB) Requirement already satisfied: setuptools in /usr/local/lib/python3.10/dist-packages (from rasterio->contextily) (67.7.2) Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from quantecon>=0.4.7->giddy->splot) (1.12) Requirement already satisfied: llvmlite<0.42,>=0.41.0dev0 in /usr/local/lib/python3.10/dist-packages (from numba->segregation>=2.3.1->pysal) (0.41.1) Collecting simplejson (from rasterstats->tobler>=0.8.2->pysal) Downloading simplejson-3.19.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (137 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 137.9/137.9 kB 3.4 MB/s eta 0:00:00 Requirement already satisfied: patsy>=0.5.4 in /usr/local/lib/python3.10/dist-packages (from statsmodels->tobler>=0.8.2->pysal) (0.5.6) Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy->quantecon>=0.4.7->giddy->splot) (1.3.0) Building wheels for collected packages: spint, spvcm Building wheel for spint (setup.py) ... done Created wheel for spint: filename=spint-1.0.7-py3-none-any.whl size=31360 sha256=7731d2437343c4fc3f448873c4488c9042f63c76e26c87d472cda6a5adf88d91 Stored in directory: /root/.cache/pip/wheels/f6/1d/ab/81b0c9d17a778a97ec078147cb11901afdab420c4894dcfbc5 Building wheel for spvcm (setup.py) ... done Created wheel for spvcm: filename=spvcm-0.3.0-py3-none-any.whl size=5777184 sha256=54cd8526b7feebaefd0d056446b387657794f5d3e372f4df4947fd0aa5d30b68 Stored in directory: /root/.cache/pip/wheels/1c/58/6f/debcb62c0a142a6615a65f23217209b543b478d309edfa4e2b Successfully built spint spvcm Installing collected packages: snuggs, simplejson, rtree, pulp, mercantile, deprecation, affine, rasterio, quantecon, rasterstats, mapclassify, contextily, libpysal, access, tobler, spreg, segregation, pointpats, momepy, inequality, esda, spvcm, spglm, spaghetti, giddy, spopt, splot, spint, mgwr, pysal Successfully installed access-1.1.9 affine-2.4.0 contextily-1.6.0 deprecation-2.1.0 esda-2.5.1 giddy-2.3.5 inequality-1.0.1 libpysal-4.10 mapclassify-2.6.1 mercantile-1.2.1 mgwr-2.2.1 momepy-0.7.0 pointpats-2.4.0 pulp-2.8.0 pysal-24.1 quantecon-0.7.2 rasterio-1.3.9 rasterstats-0.19.0 rtree-1.2.0 segregation-2.5 simplejson-3.19.2 snuggs-1.4.7 spaghetti-1.7.5.post1 spglm-1.1.0 spint-1.0.7 splot-1.1.5.post1 spopt-0.6.0 spreg-1.4.2 spvcm-0.3.0 tobler-0.11.2 Requirement already satisfied: pyshp in /usr/local/lib/python3.10/dist-packages (2.3.1) Collecting descartes Downloading descartes-1.1.0-py3-none-any.whl (5.8 kB) Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from descartes) (3.7.1) Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->descartes) (1.2.0) Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib->descartes) (0.12.1) Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->descartes) (4.50.0) Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->descartes) (1.4.5) Requirement already satisfied: numpy>=1.20 in /usr/local/lib/python3.10/dist-packages (from matplotlib->descartes) (1.25.2) Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->descartes) (24.0) Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->descartes) (9.4.0) Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->descartes) (3.1.2) Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib->descartes) (2.8.2) Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib->descartes) (1.16.0) Installing collected packages: descartes Successfully installed descartes-1.1.0 Requirement already satisfied: fiona in /usr/local/lib/python3.10/dist-packages (1.9.6) Requirement already satisfied: attrs>=19.2.0 in /usr/local/lib/python3.10/dist-packages (from fiona) (23.2.0) Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from fiona) (2024.2.2) Requirement already satisfied: click~=8.0 in /usr/local/lib/python3.10/dist-packages (from fiona) (8.1.7) Requirement already satisfied: click-plugins>=1.0 in /usr/local/lib/python3.10/dist-packages (from fiona) (1.1.1) Requirement already satisfied: cligj>=0.5 in /usr/local/lib/python3.10/dist-packages (from fiona) (0.7.2) Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from fiona) (1.16.0)
Sobre os dados¶
Baixados em https://www.ibge.gov.br/estatisticas/downloads-estatisticas.html
Dicionário de dados para Agregados preliminares por setores censitários:
Importando pacotes¶
In [2]:
Copied!
import pandas as pd
import numpy as np
import zipfile
# para gráficos
import matplotlib.pyplot as plt
import seaborn as sns
# para a análise de dados espaciais
import geopandas as gp
import mapclassify as mc
import contextily as cx
import pandas as pd
import numpy as np
import zipfile
# para gráficos
import matplotlib.pyplot as plt
import seaborn as sns
# para a análise de dados espaciais
import geopandas as gp
import mapclassify as mc
import contextily as cx
Baixando Arquivos¶
In [3]:
Copied!
!wget https://255ribeiro.github.io/curso_python_gis/geo_py/BA_Malha_Preliminar_2022.zip
!wget https://255ribeiro.github.io/curso_python_gis/geo_py/BA_Malha_Preliminar_2022.zip
--2024-03-27 13:35:54-- https://255ribeiro.github.io/curso_python_gis/geo_py/BA_Malha_Preliminar_2022.zip Resolving 255ribeiro.github.io (255ribeiro.github.io)... 185.199.108.153, 185.199.109.153, 185.199.110.153, ... Connecting to 255ribeiro.github.io (255ribeiro.github.io)|185.199.108.153|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 62263048 (59M) [application/zip] Saving to: ‘BA_Malha_Preliminar_2022.zip’ BA_Malha_Preliminar 100%[===================>] 59.38M 86.3MB/s in 0.7s 2024-03-27 13:35:54 (86.3 MB/s) - ‘BA_Malha_Preliminar_2022.zip’ saved [62263048/62263048]
Extraindo do arquivo zip¶
In [4]:
Copied!
with zipfile.ZipFile("BA_Malha_Preliminar_2022.zip", 'r') as zip_ref:
zip_ref.extractall("./BA_Malha_Preliminar_2022")
with zipfile.ZipFile("BA_Malha_Preliminar_2022.zip", 'r') as zip_ref:
zip_ref.extractall("./BA_Malha_Preliminar_2022")
Carregando GeoJson¶
In [5]:
Copied!
df_geo = gp.read_file("./BA_Malha_Preliminar_2022/BA_Malha_Preliminar_2022.json")
df_geo = gp.read_file("./BA_Malha_Preliminar_2022/BA_Malha_Preliminar_2022.json")
Informações do arquivo¶
In [6]:
Copied!
df_geo.shape
df_geo.shape
Out[6]:
(30642, 30)
In [7]:
Copied!
df_geo.info()
df_geo.info()
<class 'geopandas.geodataframe.GeoDataFrame'> RangeIndex: 30642 entries, 0 to 30641 Data columns (total 30 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 CD_SETOR 30642 non-null object 1 AREA_KM2 30642 non-null float64 2 CD_REGIAO 30642 non-null object 3 NM_REGIAO 30642 non-null object 4 CD_UF 30642 non-null object 5 NM_UF 30642 non-null object 6 CD_MUN 30642 non-null object 7 NM_MUN 30642 non-null object 8 CD_DIST 30642 non-null object 9 NM_DIST 30642 non-null object 10 CD_SUBDIST 30642 non-null object 11 NM_SUBDIST 5491 non-null object 12 CD_MICRO 30642 non-null object 13 NM_MICRO 30642 non-null object 14 CD_MESO 30642 non-null object 15 NM_MESO 30642 non-null object 16 CD_RGI 30642 non-null object 17 NM_RGI 30642 non-null object 18 CD_RGINT 30642 non-null object 19 NM_RGINT 30642 non-null object 20 CD_CONCURB 11112 non-null object 21 NM_CONCURB 11112 non-null object 22 v0001 30642 non-null object 23 v0002 30642 non-null object 24 v0003 30642 non-null object 25 v0004 30642 non-null object 26 v0005 30642 non-null object 27 v0006 30642 non-null object 28 v0007 30642 non-null object 29 geometry 30642 non-null geometry dtypes: float64(1), geometry(1), object(28) memory usage: 7.0+ MB
In [8]:
Copied!
df_geo.describe()
df_geo.describe()
Out[8]:
AREA_KM2 | |
---|---|
count | 30642.000000 |
mean | 18.430926 |
std | 54.460159 |
min | 0.001235 |
25% | 0.061144 |
50% | 0.254225 |
75% | 8.604529 |
max | 1484.628804 |
In [9]:
Copied!
df_geo.head()
df_geo.head()
Out[9]:
CD_SETOR | AREA_KM2 | CD_REGIAO | NM_REGIAO | CD_UF | NM_UF | CD_MUN | NM_MUN | CD_DIST | NM_DIST | ... | CD_CONCURB | NM_CONCURB | v0001 | v0002 | v0003 | v0004 | v0005 | v0006 | v0007 | geometry | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 290010805000001P | 1.252312 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | ... | None | None | 807 | 421 | 419 | 2 | 2.668919 | 0.000000 | 296 | POLYGON ((-41.65404 -13.25992, -41.65423 -13.2... |
1 | 290010805000002P | 0.258089 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | ... | None | None | 416 | 234 | 234 | 0 | 2.461538 | 11.834320 | 169 | POLYGON ((-41.66355 -13.25025, -41.66425 -13.2... |
2 | 290010805000003P | 0.636238 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | ... | None | None | 681 | 392 | 392 | 0 | 2.522222 | 5.185185 | 270 | POLYGON ((-41.66645 -13.25044, -41.66702 -13.2... |
3 | 290010805000004P | 1.395440 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | ... | None | None | 626 | 344 | 344 | 0 | 2.608333 | 2.083333 | 240 | POLYGON ((-41.66355 -13.25025, -41.66345 -13.2... |
4 | 290010805000005P | 1.130747 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | ... | None | None | 276 | 159 | 159 | 0 | 2.732673 | 0.990099 | 101 | POLYGON ((-41.65110 -13.25848, -41.65082 -13.2... |
5 rows × 30 columns
In [10]:
Copied!
pd.set_option('display.max_columns', None)
df_geo.head()
pd.set_option('display.max_columns', None)
df_geo.head()
Out[10]:
CD_SETOR | AREA_KM2 | CD_REGIAO | NM_REGIAO | CD_UF | NM_UF | CD_MUN | NM_MUN | CD_DIST | NM_DIST | CD_SUBDIST | NM_SUBDIST | CD_MICRO | NM_MICRO | CD_MESO | NM_MESO | CD_RGI | NM_RGI | CD_RGINT | NM_RGINT | CD_CONCURB | NM_CONCURB | v0001 | v0002 | v0003 | v0004 | v0005 | v0006 | v0007 | geometry | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 290010805000001P | 1.252312 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | 29001080500 | None | 29023 | Seabra | 2906 | Centro Sul Baiano | 290013 | Brumado | 2904 | Vitória da Conquista | None | None | 807 | 421 | 419 | 2 | 2.668919 | 0.000000 | 296 | POLYGON ((-41.65404 -13.25992, -41.65423 -13.2... |
1 | 290010805000002P | 0.258089 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | 29001080500 | None | 29023 | Seabra | 2906 | Centro Sul Baiano | 290013 | Brumado | 2904 | Vitória da Conquista | None | None | 416 | 234 | 234 | 0 | 2.461538 | 11.834320 | 169 | POLYGON ((-41.66355 -13.25025, -41.66425 -13.2... |
2 | 290010805000003P | 0.636238 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | 29001080500 | None | 29023 | Seabra | 2906 | Centro Sul Baiano | 290013 | Brumado | 2904 | Vitória da Conquista | None | None | 681 | 392 | 392 | 0 | 2.522222 | 5.185185 | 270 | POLYGON ((-41.66645 -13.25044, -41.66702 -13.2... |
3 | 290010805000004P | 1.395440 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | 29001080500 | None | 29023 | Seabra | 2906 | Centro Sul Baiano | 290013 | Brumado | 2904 | Vitória da Conquista | None | None | 626 | 344 | 344 | 0 | 2.608333 | 2.083333 | 240 | POLYGON ((-41.66355 -13.25025, -41.66345 -13.2... |
4 | 290010805000005P | 1.130747 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | 29001080500 | None | 29023 | Seabra | 2906 | Centro Sul Baiano | 290013 | Brumado | 2904 | Vitória da Conquista | None | None | 276 | 159 | 159 | 0 | 2.732673 | 0.990099 | 101 | POLYGON ((-41.65110 -13.25848, -41.65082 -13.2... |
Plotagem com o geopandas¶
https://geopandas.org/en/stable/docs/user_guide/mapping.html
In [11]:
Copied!
df_geo.plot()
df_geo.plot()
Out[11]:
<Axes: >
In [12]:
Copied!
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "v0001")
fig.show()
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "v0001")
fig.show()
In [13]:
Copied!
df_geo.boundary.plot(figsize=(10,10), edgecolor="black")
df_geo.boundary.plot(figsize=(10,10), edgecolor="black")
Out[13]:
<Axes: >
In [14]:
Copied!
df_geo.boundary.plot(figsize=(10,10), edgecolor="black", lw=.5)
df_geo.boundary.plot(figsize=(10,10), edgecolor="black", lw=.5)
Out[14]:
<Axes: >
Tratando dados¶
In [15]:
Copied!
df_geo["v0001"] = df_geo["v0001"].astype(float)
df_geo["v0002"] = df_geo["v0002"].astype(float)
df_geo["v0003"] = df_geo["v0003"].astype(float)
df_geo["v0004"] = df_geo["v0004"].astype(float)
df_geo["v0005"] = df_geo["v0005"].astype(float)
df_geo["v0006"] = df_geo["v0006"].astype(float)
df_geo["v0007"] = df_geo["v0007"].astype(float)
# criado novas colunas
df_geo["desnidade_pop"] = df_geo["v0001"]/df_geo["AREA_KM2"]
df_geo["v0001"] = df_geo["v0001"].astype(float)
df_geo["v0002"] = df_geo["v0002"].astype(float)
df_geo["v0003"] = df_geo["v0003"].astype(float)
df_geo["v0004"] = df_geo["v0004"].astype(float)
df_geo["v0005"] = df_geo["v0005"].astype(float)
df_geo["v0006"] = df_geo["v0006"].astype(float)
df_geo["v0007"] = df_geo["v0007"].astype(float)
# criado novas colunas
df_geo["desnidade_pop"] = df_geo["v0001"]/df_geo["AREA_KM2"]
In [16]:
Copied!
df_geo.info()
df_geo.info()
<class 'geopandas.geodataframe.GeoDataFrame'> RangeIndex: 30642 entries, 0 to 30641 Data columns (total 31 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 CD_SETOR 30642 non-null object 1 AREA_KM2 30642 non-null float64 2 CD_REGIAO 30642 non-null object 3 NM_REGIAO 30642 non-null object 4 CD_UF 30642 non-null object 5 NM_UF 30642 non-null object 6 CD_MUN 30642 non-null object 7 NM_MUN 30642 non-null object 8 CD_DIST 30642 non-null object 9 NM_DIST 30642 non-null object 10 CD_SUBDIST 30642 non-null object 11 NM_SUBDIST 5491 non-null object 12 CD_MICRO 30642 non-null object 13 NM_MICRO 30642 non-null object 14 CD_MESO 30642 non-null object 15 NM_MESO 30642 non-null object 16 CD_RGI 30642 non-null object 17 NM_RGI 30642 non-null object 18 CD_RGINT 30642 non-null object 19 NM_RGINT 30642 non-null object 20 CD_CONCURB 11112 non-null object 21 NM_CONCURB 11112 non-null object 22 v0001 30642 non-null float64 23 v0002 30642 non-null float64 24 v0003 30642 non-null float64 25 v0004 30642 non-null float64 26 v0005 30642 non-null float64 27 v0006 30642 non-null float64 28 v0007 30642 non-null float64 29 geometry 30642 non-null geometry 30 desnidade_pop 30642 non-null float64 dtypes: float64(9), geometry(1), object(21) memory usage: 7.2+ MB
In [17]:
Copied!
df_geo.describe()
df_geo.describe()
Out[17]:
AREA_KM2 | v0001 | v0002 | v0003 | v0004 | v0005 | v0006 | v0007 | desnidade_pop | |
---|---|---|---|---|---|---|---|---|---|
count | 30642.000000 | 30642.000000 | 30642.000000 | 30642.000000 | 30642.000000 | 30642.000000 | 30642.000000 | 30642.000000 | 30642.000000 |
mean | 18.430926 | 461.511194 | 224.417173 | 224.164447 | 0.252725 | 2.745468 | 2.032173 | 166.266497 | 6241.302646 |
std | 54.460159 | 289.645276 | 131.152737 | 131.035016 | 1.539796 | 0.455014 | 3.254504 | 102.624350 | 10243.991791 |
min | 0.001235 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 |
25% | 0.061144 | 248.000000 | 133.000000 | 133.000000 | 0.000000 | 2.571429 | 0.000000 | 90.000000 | 24.972272 |
50% | 0.254225 | 440.000000 | 216.000000 | 216.000000 | 0.000000 | 2.760000 | 0.921659 | 160.000000 | 1692.239809 |
75% | 8.604529 | 629.000000 | 298.000000 | 298.000000 | 0.000000 | 2.956522 | 3.225806 | 228.000000 | 8179.894673 |
max | 1484.628804 | 4253.000000 | 2170.000000 | 2170.000000 | 102.000000 | 8.000000 | 100.000000 | 1397.000000 | 171696.149844 |
In [19]:
Copied!
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
legend_kwds={"title": "Habitantes por km²"}
)
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
legend_kwds={"title": "Habitantes por km²"}
)
Ajustes de color maps¶
color maps padrão https://matplotlib.org/stable/users/explain/colors/colormaps.html
In [20]:
Copied!
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
cmap='viridis',
legend=True,
legend_kwds={"title": "Habitantes por km²"}
)
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
cmap='viridis',
legend=True,
legend_kwds={"title": "Habitantes por km²"}
)
Cmaps customizados¶
https://matplotlib.org/stable/gallery/color/named_colors.html
In [21]:
Copied!
from matplotlib import colors as mcolors
c_list = ["darkred","red","orangered", "salmon","mistyrose"]
c_map = mcolors.ListedColormap(c_list)
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
cmap=c_map,
legend=True,
legend_kwds={"title": "Habitantes por km²"}
)
from matplotlib import colors as mcolors
c_list = ["darkred","red","orangered", "salmon","mistyrose"]
c_map = mcolors.ListedColormap(c_list)
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
cmap=c_map,
legend=True,
legend_kwds={"title": "Habitantes por km²"}
)
usando seletores de cores da web https://coolors.co/
In [22]:
Copied!
c_list = ["#271f30","#6c5a49","#c8ad55","#9bc59d","#d0fcb3"]
#c_list.reverse()
# for i in range(len(c_list)):
# if c_list[i][0]!= "#":
# c_list[i] = "#" + c_list[i]
print(c_list)
c_map = mcolors.ListedColormap(c_list)
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
cmap=c_map,
legend=True,
legend_kwds={"title": "Habitantes por km²"}
)
c_list = ["#271f30","#6c5a49","#c8ad55","#9bc59d","#d0fcb3"]
#c_list.reverse()
# for i in range(len(c_list)):
# if c_list[i][0]!= "#":
# c_list[i] = "#" + c_list[i]
print(c_list)
c_map = mcolors.ListedColormap(c_list)
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
cmap=c_map,
legend=True,
legend_kwds={"title": "Habitantes por km²"}
)
['#271f30', '#6c5a49', '#c8ad55', '#9bc59d', '#d0fcb3']
Filtrando mapa por valor de coluna¶
In [23]:
Copied!
fltr = df_geo["NM_MUN"] == "Salvador"
df_geo_ssa = df_geo[fltr]
df_geo_ssa.shape, df_geo.shape
fltr = df_geo["NM_MUN"] == "Salvador"
df_geo_ssa = df_geo[fltr]
df_geo_ssa.shape, df_geo.shape
Out[23]:
((4552, 31), (30642, 31))
In [24]:
Copied!
df_geo_ssa.info()
df_geo_ssa.info()
<class 'geopandas.geodataframe.GeoDataFrame'> Int64Index: 4552 entries, 20719 to 25270 Data columns (total 31 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 CD_SETOR 4552 non-null object 1 AREA_KM2 4552 non-null float64 2 CD_REGIAO 4552 non-null object 3 NM_REGIAO 4552 non-null object 4 CD_UF 4552 non-null object 5 NM_UF 4552 non-null object 6 CD_MUN 4552 non-null object 7 NM_MUN 4552 non-null object 8 CD_DIST 4552 non-null object 9 NM_DIST 4552 non-null object 10 CD_SUBDIST 4552 non-null object 11 NM_SUBDIST 4552 non-null object 12 CD_MICRO 4552 non-null object 13 NM_MICRO 4552 non-null object 14 CD_MESO 4552 non-null object 15 NM_MESO 4552 non-null object 16 CD_RGI 4552 non-null object 17 NM_RGI 4552 non-null object 18 CD_RGINT 4552 non-null object 19 NM_RGINT 4552 non-null object 20 CD_CONCURB 4552 non-null object 21 NM_CONCURB 4552 non-null object 22 v0001 4552 non-null float64 23 v0002 4552 non-null float64 24 v0003 4552 non-null float64 25 v0004 4552 non-null float64 26 v0005 4552 non-null float64 27 v0006 4552 non-null float64 28 v0007 4552 non-null float64 29 geometry 4552 non-null geometry 30 desnidade_pop 4552 non-null float64 dtypes: float64(9), geometry(1), object(21) memory usage: 1.1+ MB
In [25]:
Copied!
df_geo_ssa.plot()
df_geo_ssa.plot()
Out[25]:
<Axes: >
In [26]:
Copied!
df_geo_ssa.crs
df_geo_ssa.crs
Out[26]:
<Geographic 2D CRS: EPSG:4326> Name: WGS 84 Axis Info [ellipsoidal]: - Lat[north]: Geodetic latitude (degree) - Lon[east]: Geodetic longitude (degree) Area of Use: - name: World. - bounds: (-180.0, -90.0, 180.0, 90.0) Datum: World Geodetic System 1984 ensemble - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
In [27]:
Copied!
df_geo_ssa = df_geo_ssa.to_crs("31984")
df_geo_ssa.crs
df_geo_ssa = df_geo_ssa.to_crs("31984")
df_geo_ssa.crs
Out[27]:
<Projected CRS: EPSG:31984> Name: SIRGAS 2000 / UTM zone 24S Axis Info [cartesian]: - E[east]: Easting (metre) - N[north]: Northing (metre) Area of Use: - name: Brazil - between 42°W and 36°W, northern and southern hemispheres, onshore and offshore. - bounds: (-42.0, -26.35, -36.0, 0.74) Coordinate Operation: - name: UTM zone 24S - method: Transverse Mercator Datum: Sistema de Referencia Geocentrico para las AmericaS 2000 - Ellipsoid: GRS 1980 - Prime Meridian: Greenwich
Gravando Geojson¶
In [28]:
Copied!
with open("SSA_BA_Malha_Preliminar_2022.json" , 'w') as file:
file.write(df_geo_ssa.to_json())
with open("SSA_BA_Malha_Preliminar_2022.json" , 'w') as file:
file.write(df_geo_ssa.to_json())
Abrindo GeoJson¶
In [29]:
Copied!
df_2 = gp.read_file("SSA_BA_Malha_Preliminar_2022.json")
df_2.info()
df_2 = gp.read_file("SSA_BA_Malha_Preliminar_2022.json")
df_2.info()
<class 'geopandas.geodataframe.GeoDataFrame'> RangeIndex: 4552 entries, 0 to 4551 Data columns (total 32 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 id 4552 non-null object 1 CD_SETOR 4552 non-null object 2 AREA_KM2 4552 non-null float64 3 CD_REGIAO 4552 non-null object 4 NM_REGIAO 4552 non-null object 5 CD_UF 4552 non-null object 6 NM_UF 4552 non-null object 7 CD_MUN 4552 non-null object 8 NM_MUN 4552 non-null object 9 CD_DIST 4552 non-null object 10 NM_DIST 4552 non-null object 11 CD_SUBDIST 4552 non-null object 12 NM_SUBDIST 4552 non-null object 13 CD_MICRO 4552 non-null object 14 NM_MICRO 4552 non-null object 15 CD_MESO 4552 non-null object 16 NM_MESO 4552 non-null object 17 CD_RGI 4552 non-null object 18 NM_RGI 4552 non-null object 19 CD_RGINT 4552 non-null object 20 NM_RGINT 4552 non-null object 21 CD_CONCURB 4552 non-null object 22 NM_CONCURB 4552 non-null object 23 v0001 4552 non-null float64 24 v0002 4552 non-null float64 25 v0003 4552 non-null float64 26 v0004 4552 non-null float64 27 v0005 4552 non-null float64 28 v0006 4552 non-null float64 29 v0007 4552 non-null float64 30 desnidade_pop 4552 non-null float64 31 geometry 4552 non-null geometry dtypes: float64(9), geometry(1), object(22) memory usage: 1.1+ MB
In [30]:
Copied!
df_2.plot()
df_2.plot()
Out[30]:
<Axes: >
Eliminando feição indesejada¶
Identificando feição indesejada -método 1¶
In [31]:
Copied!
df_2['coords'] = df_2['geometry'].apply(lambda x: x.representative_point().coords[0])
df_2['coords'] = df_2['geometry'].apply(lambda x: x.representative_point().coords[0])
In [32]:
Copied!
df_2['coords']
df_2['coords']
Out[32]:
0 (555517.6892997203, 8561162.794243902) 1 (555869.385196075, 8561221.765203156) 2 (555561.692228948, 8561448.0105288) 3 (555666.401386929, 8561893.694598991) 4 (555818.1373583635, 8561625.594414245) ... 4547 (554137.1694208445, 8563500.747517455) 4548 (551078.8695353717, 8562426.471542083) 4549 (551215.1880186847, 8562493.736728266) 4550 (552074.8722883032, 8564677.217530191) 4551 (551955.4441563855, 8564454.894890044) Name: coords, Length: 4552, dtype: object
In [33]:
Copied!
df_2.plot()
for idx, row in df_2.iterrows():
plt.annotate(text=row['id'], xy=row['coords'],
horizontalalignment='center')
df_2.plot()
for idx, row in df_2.iterrows():
plt.annotate(text=row['id'], xy=row['coords'],
horizontalalignment='center')
Identificando feição indesejada - médodo 2¶
In [34]:
Copied!
df_2['AREA_KM2'].max()
df_2['AREA_KM2'].max()
Out[34]:
386.114232
In [35]:
Copied!
fltr = df_2['AREA_KM2'] == df_2['AREA_KM2'].max()
df_2[fltr].plot()
df_2[fltr].shape, df_2[fltr]["id"].values
fltr = df_2['AREA_KM2'] == df_2['AREA_KM2'].max()
df_2[fltr].plot()
df_2[fltr].shape, df_2[fltr]["id"].values
Out[35]:
((1, 33), array(['21881'], dtype=object))
Eliminado feição indesejada¶
In [36]:
Copied!
fltr = df_2["id"] != "21881"
df_2 = df_2[fltr]
fltr = df_2["id"] != "21881"
df_2 = df_2[fltr]
Gerando mapa
In [37]:
Copied!
fig, ax = plt.subplots(1)
df_2.plot(ax = ax, column="NM_SUBDIST" ,cmap="cubehelix", legend=True, legend_kwds={'bbox_to_anchor': (1.5, 1)})
fig, ax = plt.subplots(1)
df_2.plot(ax = ax, column="NM_SUBDIST" ,cmap="cubehelix", legend=True, legend_kwds={'bbox_to_anchor': (1.5, 1)})
Out[37]:
<Axes: >
Agregando com dissolve¶
https://geopandas.org/en/stable/docs/user_guide/aggregation_with_dissolve.html
In [38]:
Copied!
df_3 = df_2[['NM_SUBDIST', "v0001",'v0005', "geometry"]]
df_3 = df_3.dissolve(by='NM_SUBDIST', aggfunc='sum', as_index=False)
df_3.head()
df_3 = df_2[['NM_SUBDIST', "v0001",'v0005', "geometry"]]
df_3 = df_3.dissolve(by='NM_SUBDIST', aggfunc='sum', as_index=False)
df_3.head()
Out[38]:
NM_SUBDIST | geometry | v0001 | v0005 | |
---|---|---|---|---|
0 | Amaralina | POLYGON ((555768.884 8561020.182, 555765.446 8... | 254133.0 | 1138.743352 |
1 | Brotas | POLYGON ((554383.205 8563533.513, 554358.146 8... | 178577.0 | 900.154859 |
2 | Conceição da Praia | POLYGON ((552582.398 8565306.142, 552579.429 8... | 416.0 | 4.270202 |
3 | Itapoã | POLYGON ((563322.057 8565454.801, 563258.583 8... | 191205.0 | 805.219044 |
4 | Mares | POLYGON ((553634.123 8569419.347, 553605.637 8... | 3314.0 | 37.887135 |
In [39]:
Copied!
fig, ax = plt.subplots(1)
df_3.plot(ax = ax,column="NM_SUBDIST", cmap="cubehelix", legend=True, legend_kwds={'bbox_to_anchor': (1.5, 1)})
plt.xticks(rotation=90)
fig, ax = plt.subplots(1)
df_3.plot(ax = ax,column="NM_SUBDIST", cmap="cubehelix", legend=True, legend_kwds={'bbox_to_anchor': (1.5, 1)})
plt.xticks(rotation=90)
Out[39]:
(array([535000., 540000., 545000., 550000., 555000., 560000., 565000., 570000., 575000., 580000.]), [Text(535000.0, 0, '535000'), Text(540000.0, 0, '540000'), Text(545000.0, 0, '545000'), Text(550000.0, 0, '550000'), Text(555000.0, 0, '555000'), Text(560000.0, 0, '560000'), Text(565000.0, 0, '565000'), Text(570000.0, 0, '570000'), Text(575000.0, 0, '575000'), Text(580000.0, 0, '580000')])
In [59]:
Copied!
fig, ax = plt.subplots(1, figsize=(10,10))
df_2.plot(ax = ax, column="v0001", cmap='flare',legend=True )
cx.add_basemap(ax=ax, crs=df_2.crs)
fig, ax = plt.subplots(1, figsize=(10,10))
df_2.plot(ax = ax, column="v0001", cmap='flare',legend=True )
cx.add_basemap(ax=ax, crs=df_2.crs)
In [ ]:
Copied!
# Listas de provedores de mapas online
cx.providers
# Listas de provedores de mapas online
cx.providers
In [76]:
Copied!
fig, ax = plt.subplots(1, figsize=(10,10))
df_2.plot(ax = ax, column="v0001", cmap='flare',legend=True )
cx.add_basemap(ax=ax, source=cx.providers.CartoDB.Voyager , crs=df_2.crs)
fig, ax = plt.subplots(1, figsize=(10,10))
df_2.plot(ax = ax, column="v0001", cmap='flare',legend=True )
cx.add_basemap(ax=ax, source=cx.providers.CartoDB.Voyager , crs=df_2.crs)
In [41]:
Copied!
fig, ax = plt.subplots(1, figsize=(10,10))
df_2.plot(ax = ax, column="v0001", cmap='OrRd',legend=True )
cx.add_basemap(ax, source=cx.providers.CartoDB.PositronNoLabels, zoom=12, crs=df_2.crs)
cx.add_basemap(ax, source=cx.providers.CartoDB.PositronOnlyLabels, zoom=15, crs=df_2.crs)
fig, ax = plt.subplots(1, figsize=(10,10))
df_2.plot(ax = ax, column="v0001", cmap='OrRd',legend=True )
cx.add_basemap(ax, source=cx.providers.CartoDB.PositronNoLabels, zoom=12, crs=df_2.crs)
cx.add_basemap(ax, source=cx.providers.CartoDB.PositronOnlyLabels, zoom=15, crs=df_2.crs)
Marcando um ponto por corrdenadas¶
In [44]:
Copied!
from shapely.geometry import Point
# substitua os valores de latitue e longitude pelos valores do seu ponto
# use pontos para separar os decimais
lat = 0
lon = 0
pt_terreno = Point(lon, lat)
from shapely.geometry import Point
# substitua os valores de latitue e longitude pelos valores do seu ponto
# use pontos para separar os decimais
lat = 0
lon = 0
pt_terreno = Point(lon, lat)
aplicando sistema de coordenads
In [45]:
Copied!
loc_terreno= gp.GeoDataFrame([1], geometry=[pt_terreno], crs="EPSG:4326")
loc_terreno= gp.GeoDataFrame([1], geometry=[pt_terreno], crs="EPSG:4326")
In [46]:
Copied!
loc_terreno.head()
loc_terreno.head()
Out[46]:
0 | geometry | |
---|---|---|
0 | 1 | POINT (-38.43202 -12.97391) |
In [47]:
Copied!
loc_terreno = loc_terreno.to_crs(df_2.crs)
loc_terreno = loc_terreno.to_crs(df_2.crs)
In [48]:
Copied!
fig, ax = plt.subplots()
df_2.plot(ax=ax, cmap="Oranges")
loc_terreno.plot(ax=ax)
plt.xticks(rotation=90)
fig, ax = plt.subplots()
df_2.plot(ax=ax, cmap="Oranges")
loc_terreno.plot(ax=ax)
plt.xticks(rotation=90)
Out[48]:
(array([535000., 540000., 545000., 550000., 555000., 560000., 565000., 570000., 575000., 580000.]), [Text(535000.0, 0, '535000'), Text(540000.0, 0, '540000'), Text(545000.0, 0, '545000'), Text(550000.0, 0, '550000'), Text(555000.0, 0, '555000'), Text(560000.0, 0, '560000'), Text(565000.0, 0, '565000'), Text(570000.0, 0, '570000'), Text(575000.0, 0, '575000'), Text(580000.0, 0, '580000')])
In [49]:
Copied!
entorno = loc_terreno.buffer(1000)
entorno = loc_terreno.buffer(1000)
In [77]:
Copied!
fig, ax = plt.subplots()
plt.grid(alpha = .2)
df_2.plot(ax=ax, cmap="Oranges")
entorno.plot(ax=ax)
plt.xticks(rotation=90)
fig.show()
fig, ax = plt.subplots()
plt.grid(alpha = .2)
df_2.plot(ax=ax, cmap="Oranges")
entorno.plot(ax=ax)
plt.xticks(rotation=90)
fig.show()
In [54]:
Copied!
fltr = df_2.intersects(entorno[0])
df_4 = df_2[fltr]
fltr = df_2.intersects(entorno[0])
df_4 = df_2[fltr]
In [57]:
Copied!
fig, ax = plt.subplots()
df_4.plot(ax=ax, cmap="Oranges")
loc_terreno.plot(ax=ax, marker='o', color='teal', markersize=100)
ax.annotate("Terreno", xy= (loc_terreno.geometry.x, loc_terreno.geometry.y), xytext=(3, 3), textcoords="offset points")
plt.xticks(rotation=90)
ax.ticklabel_format(style='plain')
#salvando figura
fig.savefig('./entorno.svg')
fig.show()
fig, ax = plt.subplots()
df_4.plot(ax=ax, cmap="Oranges")
loc_terreno.plot(ax=ax, marker='o', color='teal', markersize=100)
ax.annotate("Terreno", xy= (loc_terreno.geometry.x, loc_terreno.geometry.y), xytext=(3, 3), textcoords="offset points")
plt.xticks(rotation=90)
ax.ticklabel_format(style='plain')
#salvando figura
fig.savefig('./entorno.svg')
fig.show()