jpndistrict is a convenient R package for plotting administrative districts in Japan. I was advised that it would be convenient, so I decided to use it, but it was quite difficult to install. In the end, the installation was successful and I realized that it was a useful tool, so I will write an article so that I can help with the installation when I recommend it to others.
The usage of jpndistrict itself is not explained. Please refer to the Official Page for details.
CentOS 7 R version 3.6.0
First, simply try installing jpndistrict on R. If it is not CentOS 7 such as ubuntu, this will probably work (see below).
If you get the following error during installation, install the requested package and try again.
configure: error: -------------------------------------------------------------------------------- Configuration failed because libudunits2.so was not found. Try installing: * deb: libudunits2-dev (Debian, Ubuntu, ...) * rpm: udunits2-devel (Fedora, EPEL, ...) * brew: udunits (OSX) If udunits2 is already installed in a non-standard location, use: --configure-args='--with-udunits2-lib=/usr/local/lib' if the library was not found, and/or: --configure-args='--with-udunits2-include=/usr/include/udunits2' if the header was not found, replacing paths with appropriate values. You can alternatively set UDUNITS2_INCLUDE and UDUNITS2_LIBS manually. --------------------------------------------------------------------------------
Since my OS is CentOS 7, install udunits2-devel and try again. But it failed.
install.packages("jpndistrict") (Omitted) * installing *source* package ‘sf’ ... **Successfully unzipped package ‘sf’ and verified MD5 thumb ** using staged installation configure: CC: gcc -m64 -std=gnu99 configure: CXX: g++ -m64 -std=gnu++11 checking for gdal-config... no configure: error: gdal-config not found or not executable. ERROR: configuration failed for package ‘sf’
checking for gdal-config... no
I was told that I installed GDAL by referring to here, but
configure: GDAL: 1.11.4 checking GDAL version >= 2.0.1... no configure: error: sf is not compatible with GDAL versions below 2.0.1 ERROR: configuration failed for package ‘sf’
I have been told that the version of GDAL is old.
yum info gdal name: gdal architecture: x86_64 version: 1.11.4 release: 3.el7 capacity: 276 k Repository: epel/x86_64 wrap up: GIS file format library URL : http://www.gdal.org license: MIT Explanation: Geospatial Data Abstraction Library (GDAL/OGR) is a cross : platform C++ translator library for raster and vector : geospatial data formats. As a library, it presents a single : abstract data model to the calling application for all : supported formats. It also comes with a variety of useful : commandline utilities for data translation and processing. : : It provides the primary data access engine for many : applications. GDAL/OGR is the most widely used geospatial data : access library.
The latest version that can be installed with yum (using EPEL repository) is 1.11.4
apt info gdal-bin Package: gdal-bin Version: 3.0.4+dfsg-1build3 Priority: optional Section: universe/science Source: gdal Origin: Ubuntu Maintainer: Ubuntu Developers <[email protected]> Original-Maintainer: Debian GIS Project <[email protected]> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 1369 kB Depends: python3-gdal (= 3.0.4+dfsg-1build3), python3-numpy (>= 1:1.16.0~rc1), python3-numpy-abi9, python3:any, libc6 (>= 2.15), libgcc-s1 (>= 3.0), libgdal26 (>= 3.0.0), libstdc++6 (>= 5.2) Suggests: libgdal-grass Breaks: gdal-bin (<< 1.10.0-0~), python-gdal (<< 2.4.3~) Replaces: python-gdal (<< 2.4.3~) Homepage: http://www.gdal.org/ Download-Size: 256 kB APT-Sources: http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages Description: Geospatial Data Abstraction Library - Utility programs
The GDAL that can be installed with apt (ubuntu) was 3.0.4.
So, if the version of the package registered in the repository is an older CentOS 7, If you want to install jpndistrict (sf package required by) ** You need to build from source and install GDAL without using yum **. Furthermore, if you install PROJ, which is necessary to run GDAL, from yum, the version is old.
yum info proj name: proj architecture: x86_64 version: 4.8.0 release: 4.el7 capacity: 181 k Repository: epel/x86_64 wrap up: Cartographic projection software (PROJ.4) URL : http://proj.osgeo.org license: MIT Explanation: Proj and invproj perform respective forward and inverse : transformation of cartographic data to or from cartesian data : with a wide range of selectable projection functions.
You can install with yum 4.8.0 and now you need 6.0.0 or above
In short, you need to install "** PROJ " to install " GDAL " to install " sf " to install " jpndistrict **" .. Depressed.
At least the required version GDAL >= 2.0.1 PROJ >= 6.0.0 GEOS >= 3.4.0
The latest version that can be installed with yum GDAL : 1.11.4 PROJ : 4.8.0 GEOS : 3.4.2
After trying various things, when installing sf on CentOS 7
It worked well if I installed it first.
** GDAL ** has the latest version as of the time of article creation (2020/11/18).
When ** PROJ ** tried to install the latest version 7.2.0, it was necessary to upgrade SQLite3 additionally, and it would be a part of yum's system, so I gave up thinking that it was a high risk. However, even if I installed 6.0.0, which is the oldest version that can be used and does not require an upgrade of SQLite, the subsequent installation of the tool failed probably because the versions of GDAL and PROJ are too far apart. After trying various versions, the installation was successful with 6.1.1. reference [How to update SQLite3] https://qiita.com/kai_kou/items/c18b68a7916251231f6d The link destination is Amazon Linux 2, but I heard that OS base is like RHEL 7 / CentOS 7, so it's helpful. I made it.
** GEOS ** seems to be okay with a version that can be installed with yum, but I thought that it would be a problem if the version is too far from GDAL like PROJ and an error occurs, so I installed the latest version.
Install in the order of PROJ → GEOS → GDAL
For both installation methods, unzip the downloaded file and
./configure make make install
Installation is successful if the above three commands are passed
After installation, start R
Type jpndistrict installation (sf is also installed).
Load the package,
library("jpndistrict") This package provide map data is based on the Digital Map 25000 (Map Image) published by Geospatial Information Authority of Japan (Approval No.603FY2017 information usage <https://www.gsi.go.jp>)
If it appears, the installation is successful.
Occurs when configuring PROJ
checking for SQLITE3... configure: error: Package requirements (sqlite3 >= 3.7) were not met: No package 'sqlite3' found
I confirmed it, but it's there
sqlite3 --version 3.7.17
Solution: Install sqlite-devel
yum install sqlite-devel
Occurs during sf installation
checking GDAL: /usr/local/share/gdal/pcs.csv readable... no
I checked the location of the path, but pcs.csv did not exist.
Solution: Search on the net and install under "/ usr / local / share / gdal /" https://trac.osgeo.org/gdal/browser/trunk/gdal/data/pcs.csv
Occurs during sf installation
checking GDAL: checking whether PROJ is available fur running:... ./gdal_proj: error while loading shared libraries: libgdal.so.28: cannot open shared object file: No such file or directory no configure: error: OGRCoordinateTransformation() does not return a coord.trans: PROJ not available? ERROR: configuration failed for package ‘sf’
Solution: Exit R and then go to /etc/ld.so.conf.d/libgdal-x86_64.conf
Addition (If libgdal-x86_64.conf does not exist, create a new one and write the above contents).
After executing, start R and try the installation again.
When you hit
ERROR while rich displaying an object: Error in loadNamespace(name): there is no package called ‘geojsonio’
If you get an error, install geojsonio.
If no error occurs, the jpndistrict usage environment is complete.
As an operation test, let's display the location of the government office in Hokkaido.
pref01 = jpn_pref(admin_name = "Hokkaido") # Hokkaidoの地形データ df_office01 = jpn_admins(1) #Location of the government office in Hokkaido #Creating a canvas ggplot() + #Draw terrain geom_sf(data = pref01, aes(fill = city)) + #Plot points geom_sf(data = df_office01, color = "white", size=0.8) + theme(legend.position = 'none')
Visualizing the coordinates made it possible to predict the mountains from the location of the government office, which was an interesting result.
The old packages that can be installed with yum made me messed up. It's been a year since CentOS 8 was released, and maybe it's time to upgrade.