Skip to content

Instantly share code, notes, and snippets.

@JosiahParry
Created August 2, 2022 13:10
Show Gist options
  • Save JosiahParry/d0fcbb883188a443f5642c8b98d2338e to your computer and use it in GitHub Desktop.
Save JosiahParry/d0fcbb883188a443f5642c8b98d2338e to your computer and use it in GitHub Desktop.
```{r}
fp <- "https://raw.githubusercontent.com/gdsbook/book/master/data/tokyo/tokyo_clean.csv"
user <- readr::read_csv(fp) |>
dplyr::filter(user_id == "95795770@N00") |>
sf::st_as_sf(coords = c("x", "y"))
hull <- sf::st_geometry(user) |>
geos::geos_make_collection() |>
geos::geos_concave_hull(ratio = 1)
```
```{r}
reticulate::use_condaenv("geo")
```
```{python}
import numpy
import pandas
import geopandas
import pysal
import seaborn
from pointpats import centrography
db = pandas.read_csv("https://raw.githubusercontent.com/gdsbook/book/master/data/tokyo/tokyo_clean.csv")
user = db.query('user_id == "95795770@N00"')
coordinates = user[['x','y']].values
convex_hull_vertices = centrography.hull(coordinates)
```
```{r}
library(reticulate)
pysal_convex <- sfheaders::sf_polygon(py$convex_hull_vertices)
plot(sf::st_geometry(pysal_convex), border = "red")
plot(sf::st_geometry(sf::st_as_sf(hull)), lty = 3, lwd = 3, add = TRUE)
```
@JosiahParry
Copy link
Author

My environment.yml

name: geo
channels:
  - conda-forge
dependencies:
  - attrs=21.4.0=pyhd8ed1ab_0
  - blosc=1.21.0=h9f76cd9_0
  - boost-cpp=1.74.0=h3afdda6_7
  - brotli=1.0.9=h3422bc3_6
  - brotli-bin=1.0.9=h3422bc3_6
  - bzip2=1.0.8=h3422bc3_4
  - c-ares=1.18.1=h3422bc3_0
  - ca-certificates=2022.6.15=h4653dfc_0
  - cairo=1.16.0=h933af38_1010
  - certifi=2022.6.15=py38h10201cd_0
  - cfitsio=4.0.0=h99351b2_0
  - click=8.0.3=py38h10201cd_1
  - click-plugins=1.1.1=py_0
  - cligj=0.7.2=pyhd8ed1ab_1
  - colorama=0.4.4=pyh9f0ad1d_0
  - curl=7.81.0=h8d07098_0
  - cycler=0.11.0=pyhd8ed1ab_0
  - deprecated=1.2.13=pyh6c4a22f_0
  - descartes=1.1.0=py_4
  - esda=2.4.1=pyhd8ed1ab_0
  - expat=2.4.4=hbdafb3b_0
  - fiona=1.8.21=py38hce3cb01_0
  - font-ttf-dejavu-sans-mono=2.37=hab24e00_0
  - font-ttf-inconsolata=3.000=h77eed37_0
  - font-ttf-source-code-pro=2.038=h77eed37_0
  - font-ttf-ubuntu=0.83=hab24e00_0
  - fontconfig=2.13.96=heb65262_0
  - fonts-conda-ecosystem=1=0
  - fonts-conda-forge=1=0
  - fonttools=4.29.1=py38hea4295b_0
  - freetype=2.10.4=h17b34a0_1
  - freexl=1.0.6=h27ca646_0
  - fribidi=1.0.10=h27ca646_0
  - gdal=3.4.1=py38hd9ac394_2
  - geopandas=0.9.0=pyhd8ed1ab_1
  - geopandas-base=0.9.0=pyhd8ed1ab_1
  - geos=3.10.2=hbdafb3b_0
  - geotiff=1.7.0=h0dc1598_6
  - gettext=0.19.8.1=h049c9fb_1008
  - giflib=5.2.1=h27ca646_2
  - hdf4=4.2.15=h0ef36ac_3
  - hdf5=1.12.1=nompi_h829dc4f_103
  - icu=69.1=hbdafb3b_0
  - jbig=2.1=h3422bc3_2003
  - joblib=1.1.0=pyhd8ed1ab_0
  - jpeg=9e=h3422bc3_0
  - json-c=0.15=hc6a1b29_0
  - kealib=1.4.14=h8a8d77f_3
  - kiwisolver=1.3.2=py38h1670459_1
  - krb5=1.19.2=hfff258c_3
  - lcms2=2.12=had6a04f_0
  - lerc=3.0=hbdafb3b_0
  - libblas=3.9.0=13_osxarm64_openblas
  - libbrotlicommon=1.0.9=h3422bc3_6
  - libbrotlidec=1.0.9=h3422bc3_6
  - libbrotlienc=1.0.9=h3422bc3_6
  - libcblas=3.9.0=13_osxarm64_openblas
  - libcurl=7.81.0=h8d07098_0
  - libcxx=12.0.1=h168391b_1
  - libdap4=3.20.6=h8510809_2
  - libdeflate=1.8=h3422bc3_0
  - libedit=3.1.20191231=hc8eb9b7_2
  - libev=4.33=h642e427_1
  - libffi=3.4.2=h3422bc3_5
  - libgdal=3.4.1=hd607cb8_2
  - libgfortran=5.0.0.dev0=11_0_1_hf114ba7_23
  - libgfortran5=11.0.1.dev0=hf114ba7_23
  - libglib=2.70.2=h67e64d8_2
  - libiconv=1.16=h642e427_0
  - libkml=1.3.0=h893ab4d_1014
  - liblapack=3.9.0=13_osxarm64_openblas
  - libnetcdf=4.8.1=nompi_h96a3436_101
  - libnghttp2=1.46.0=h62a264d_0
  - libopenblas=0.3.18=openmp_h5dd58f0_0
  - libpng=1.6.37=hf7e6567_2
  - libpq=14.1=h2f670be_1
  - libpysal=4.1.1=py_0
  - librttopo=1.1.0=h56e3e6d_9
  - libspatialindex=1.9.3=hbdafb3b_4
  - libspatialite=5.0.1=hde20a99_14
  - libssh2=1.10.0=h7a5bd25_2
  - libtiff=4.3.0=h74060c4_2
  - libwebp=1.2.2=h0d20362_0
  - libwebp-base=1.2.2=h3422bc3_1
  - libxcb=1.13=h9b22ae9_1004
  - libxml2=2.9.12=hedbfbf4_1
  - libzip=1.8.0=hc06522b_1
  - libzlib=1.2.11=hee7b306_1013
  - llvm-openmp=12.0.1=hf3c4609_1
  - lz4-c=1.9.3=hbdafb3b_1
  - mapclassify=2.4.3=pyhd8ed1ab_0
  - matplotlib=3.5.1=py38h150bfb4_0
  - matplotlib-base=3.5.1=py38hb140015_0
  - munch=2.5.0=py_0
  - munkres=1.1.4=pyh9f0ad1d_0
  - ncurses=6.3=hc470f4d_0
  - networkx=2.6.3=pyhd8ed1ab_1
  - nspr=4.32=hbdafb3b_1
  - nss=3.74=h353d031_0
  - numpy=1.22.2=py38h9d822b3_0
  - openjpeg=2.4.0=h062765e_1
  - openssl=3.0.5=h7aea29f_1
  - packaging=21.3=pyhd8ed1ab_0
  - palettable=3.3.0=py_0
  - pandas=1.4.0=py38h3777fb4_0
  - patsy=0.5.2=pyhd8ed1ab_0
  - pcre=8.45=hbdafb3b_0
  - pillow=9.0.1=py38he7148d4_0
  - pip=22.0.3=pyhd8ed1ab_0
  - pixman=0.40.0=h27ca646_0
  - pointpats=2.2.0=pyhd8ed1ab_1
  - poppler=21.11.0=hb0dbcdf_0
  - poppler-data=0.4.11=hd8ed1ab_0
  - postgresql=14.1=h9a9b6fe_1
  - proj=8.2.1=h2d984c1_0
  - pthread-stubs=0.4=h27ca646_1001
  - pyparsing=3.0.7=pyhd8ed1ab_0
  - pyproj=3.3.0=py38h4b69435_1
  - pysal=2.1.0=py_0
  - python=3.8.12=hd949e87_3_cpython
  - python-dateutil=2.8.2=pyhd8ed1ab_0
  - python_abi=3.8=2_cp38
  - pytz=2021.3=pyhd8ed1ab_0
  - readline=8.1=hedafd6a_0
  - rtree=0.9.7=py38hb34dff0_3
  - scikit-learn=1.0.2=py38h2cd4032_0
  - scipy=1.8.0=py38hd0c9ec0_0
  - seaborn=0.11.2=hd8ed1ab_0
  - seaborn-base=0.11.2=pyhd8ed1ab_0
  - setuptools=60.8.1=py38h10201cd_0
  - shapely=1.8.0=py38hf23740d_5
  - six=1.16.0=pyh6c4a22f_0
  - sqlite=3.37.0=h72a2b83_0
  - statsmodels=0.13.1=py38h691f20f_0
  - threadpoolctl=3.1.0=pyh8a188c0_0
  - tiledb=2.6.2=h42267fc_1
  - tk=8.6.11=he1e0b03_1
  - tornado=6.1=py38hea4295b_2
  - tqdm=4.62.3=pyhd8ed1ab_0
  - tzcode=2021e=h3422bc3_0
  - tzdata=2021e=he74cb21_0
  - unicodedata2=14.0.0=py38hea4295b_0
  - wheel=0.37.1=pyhd8ed1ab_0
  - wrapt=1.13.3=py38hea4295b_1
  - xerces-c=3.2.3=hff64b9e_4
  - xorg-libxau=1.0.9=h27ca646_0
  - xorg-libxdmcp=1.1.3=h27ca646_0
  - xz=5.2.5=h642e427_1
  - zlib=1.2.11=hee7b306_1013
  - zstd=1.5.2=h861e0a7_0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment