How to Use spatial in MAC

1. To download package management tools


2. Install macPort and check whether the installation is successful

lqdeMacBook-Pro:~ lq$ port
MacPorts 2.3.1
Entering interactive mode... ("help" for help, "quit" to quit)
[Users/lq] > port
lqdeMacBook-Pro:~ lq$ port selfupdate
--->  Updating MacPorts base sources using rsync
Error: can't create directory "/opt/local/var/macports/sources/": permission denied
Please run `port -v selfupdate' for details.
Error: /opt/local/bin/port: port selfupdate failed: can't create directory "/opt/local/var/macports/sources/": permission denied
lqdeMacBook-Pro:~ lq$ sudo port selfupdate
Sorry, try again.
--->  Updating MacPorts base sources using rsync
MacPorts base version 2.3.1 installed,
MacPorts base version 2.3.1 downloaded.
--->  Updating the ports tree
--->  MacPorts base is already the latest version

The ports tree has been updated. To upgrade your installed ports, you should run
  port upgrade outdated

3. Check if the package exists

You can go to the following website to check whether the package exists or not

4. Install the spatialite

lqdeMacBook-Pro:~ lq$ port intall spatialite
Error: Unrecognized action "port intall"
lqdeMacBook-Pro:~ lq$ port install spatialite
Error: Insufficient privileges to write to MacPorts install prefix.
lqdeMacBook-Pro:~ lq$ sudo port install spatialite  ———Note: You need to add sudo to get system privileges.
Warning: The Xcode Command Line Tools don't appear to be installed; most ports will likely fail to build.
Warning: Install them by running `xcode-select --install'.
--->  Computing dependencies for spatialite
--->  Dependencies to be installed: geos libxml2 libiconv xz gettext expat ncurses zlib proj sqlite3 libedit
--->  Fetching archive for geos
--->  Attempting to fetch geos-3.4.2_0.darwin_13.x86_64.tbz2 from
--->  Attempting to fetch geos-3.4.2_0.darwin_13.x86_64.tbz2.rmd160 from
--->  Installing geos @3.4.2_0
--->  Activating geos @3.4.2_0
--->  Cleaning geos
--->  Fetching archive for libiconv
--->  Attempting to fetch libiconv-1.14_0.darwin_13.x86_64.tbz2 from
--->  Attempting to fetch libiconv-1.14_0.darwin_13.x86_64.tbz2.rmd160 from
--->  Installing libiconv @1.14_0
--->  Activating libiconv @1.14_0
--->  Cleaning libiconv
--->  Fetching archive for expat
--->  Attempting to fetch expat-2.1.0_0.darwin_13.x86_64.tbz2 from
--->  Attempting to fetch expat-2.1.0_0.darwin_13.x86_64.tbz2.rmd160 from
--->  Installing expat @2.1.0_0
--->  Activating expat @2.1.0_0
--->  Cleaning expat
--->  Fetching archive for ncurses
--->  Attempting to fetch ncurses-5.9_2.darwin_13.x86_64.tbz2 from
--->  Attempting to fetch ncurses-5.9_2.darwin_13.x86_64.tbz2.rmd160 from
--->  Installing ncurses @5.9_2
--->  Activating ncurses @5.9_2
--->  Cleaning ncurses
--->  Fetching archive for gettext
--->  Attempting to fetch gettext-0.19.1_1.darwin_13.x86_64.tbz2 from
--->  Attempting to fetch gettext-0.19.1_1.darwin_13.x86_64.tbz2.rmd160 from
--->  Installing gettext @0.19.1_1
--->  Activating gettext @0.19.1_1
--->  Cleaning gettext
--->  Fetching archive for xz
--->  Attempting to fetch xz-5.0.5_0.darwin_13.x86_64.tbz2 from
--->  Attempting to fetch xz-5.0.5_0.darwin_13.x86_64.tbz2.rmd160 from
--->  Installing xz @5.0.5_0
--->  Activating xz @5.0.5_0
--->  Cleaning xz
--->  Fetching archive for zlib
--->  Attempting to fetch zlib-1.2.8_0.darwin_13.x86_64.tbz2 from
--->  Attempting to fetch zlib-1.2.8_0.darwin_13.x86_64.tbz2.rmd160 from
--->  Installing zlib @1.2.8_0
--->  Activating zlib @1.2.8_0
--->  Cleaning zlib
--->  Fetching archive for libxml2
--->  Attempting to fetch libxml2-2.9.1_0.darwin_13.x86_64.tbz2 from
--->  Attempting to fetch libxml2-2.9.1_0.darwin_13.x86_64.tbz2.rmd160 from
--->  Installing libxml2 @2.9.1_0
--->  Activating libxml2 @2.9.1_0
--->  Cleaning libxml2
--->  Fetching archive for proj
--->  Attempting to fetch proj-4.8.0_0.darwin_13.x86_64.tbz2 from
--->  Attempting to fetch proj-4.8.0_0.darwin_13.x86_64.tbz2.rmd160 from
--->  Installing proj @4.8.0_0
--->  Activating proj @4.8.0_0
--->  Cleaning proj
--->  Fetching archive for libedit
--->  Attempting to fetch libedit-20121213-3.0_0.darwin_13.x86_64.tbz2 from
--->  Attempting to fetch libedit-20121213-3.0_0.darwin_13.x86_64.tbz2.rmd160 from
--->  Installing libedit @20121213-3.0_0
--->  Activating libedit @20121213-3.0_0
--->  Cleaning libedit
--->  Fetching archive for sqlite3
--->  Attempting to fetch sqlite3- from
--->  Attempting to fetch sqlite3- from
--->  Installing sqlite3 @
--->  Activating sqlite3 @
--->  Cleaning sqlite3
--->  Fetching archive for spatialite
--->  Attempting to fetch spatialite-4.1.1_0.darwin_13.x86_64.tbz2 from
--->  Attempting to fetch spatialite-4.1.1_0.darwin_13.x86_64.tbz2.rmd160 from
--->  Installing spatialite @4.1.1_0
--->  Activating spatialite @4.1.1_0
--->  Cleaning spatialite
--->  Updating database of binaries
--->  Scanning binaries for linking errors               
--->  No broken files found.

5. Test whether the installation is successful

lqdeMacBook-Pro:~ lq$ sqlite3
SQLite version 2014-04-03 16:53:12
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> select load_extension('libspatialite')
   ...> ;
Error: dlopen(libspatialite.dylib, 10): image not found
sqlite> select load_extension('libspatialite-5');
Error: dlopen(libspatialite-5.dylib, 10): image not found
sqlite> select load_extension('libspatialite.5');
Error: dlopen(libspatialite.5.dylib, 10): image not found
sqlite> select load_extension('/opt/local/lib/libspatialite.5’); // Note: This is the compile path automatically generated by the system after downloading, it must be full path or it may not be read successfully.

sqlite> select geomfromtext('POINT ( 23 56 )', 4326)
   ...> ;
sqlite>select astext(geomfromtext('POINT ( 23 56 )', 4326));
POINT(23 56)


Read More: