macOS 安装 gdal java

  • Post author:
  • Post category:java




macOS 安装 gdal java



下载

下载 gdal 压缩包

https://gdal.org/download.html



安装

解压文件,之后进入根目录

cd /gdal-3.5.0

2.执行 configure

./configure --with-threads --disable-static --without-grass --with-jasper=/usr/local/lib --with-libtiff=/usr/local/lib --with-jpeg=/usr/local/lib --with-gif=/usr/local/lib --with-png=/usr/local/lib --with-geotiff=/usr/local/lib --with-pcraster=internal --with-static-proj4=/usr/local/lib --with-geos=/usr/local/lib --with-expat=/usr/local/lib --with-curl=/usr/local/lib --with-netcdf=/usr/local/lib --with-hdf5=/usr/local/lib --with-opencl --with-libz=internal --without-python --with-java=$JAVA_HOME

可能出现 proj 6 问题,直接使用 brew 安装

brew install proj

因为之前安装过 postgis,其实已经有一个版本的 gdal,但是 java 不能用,这里可能出现 geoms 问题。直接删除

--with-geos=/usr/local/lib

./configure --with-threads --disable-static --without-grass --with-jasper=/usr/local/lib --with-libtiff=/usr/local/lib --with-jpeg=/usr/local/lib --with-gif=/usr/local/lib --with-png=/usr/local/lib --with-geotiff=/usr/local/lib --with-pcraster=internal --with-static-proj4=/usr/local/lib --with-expat=/usr/local/lib --with-curl=/usr/local/lib --with-netcdf=/usr/local/lib --with-hdf5=/usr/local/lib --with-opencl --with-libz=internal --without-python --with-java=$JAVA_HOME

3.gdal-3.5.0 make

make

4.gdal-3.5.0 make install

make install

5.进入

swing/java

cd swing/java

6.修改 java.opt

#
# Java Stuff
#JAVA_HOME = "C:\Program Files\Java\jdk1.6.0_16"
#JAVA_HOME = /usr/lib/jvm/java-6-openjdk/
JAVA_HOME = /Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
JAVADOC=$(JAVA_HOME)/bin/javadoc
JAVAC=$(JAVA_HOME)/bin/javac
JAVA=$(JAVA_HOME)/bin/java
JAR=$(JAVA_HOME)/bin/jar
JAVA_INCLUDE=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin


JAVA_HOME

使用系统 java 安装路径,注意

JAVA_INCLUDE

因系统不同需要

-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux

或者

-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin

,macOS 使用

-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin

7.swing/java make

make

8.swing/java make install

make install

执行之后在

swing/java

目录下找到

libgdalalljni.31.dylib



libgdalalljni.dylib

,拷贝至

/Library/Java/Extensions

cp libgdalalljni.31.dylib /Library/Java/Extensions
cp libgdalalljni.dylib /Library/Java/Extensions

如果出现文件权限问题,使用 777 权限

sudo chmod -R 777 /Library/Java/Extensions



PS

执行过程中遇到的

commond not found

,可以使用

brew

直接

install



项目引用

maven 项目其实可以直接引用中央仓库的源,不需要使用自己本地

make

编译的 jar 包

				<dependency>
            <groupId>org.gdal</groupId>
            <artifactId>gdal</artifactId>
            <version>3.5.0</version>
        </dependency>



测试

可以运行以下代码测试是否可以正常使用

import org.gdal.gdal.gdal;
import org.gdal.ogr.ogr;

public class GdalTest {

    public static void main(String[] args) {
        gdal.AllRegister();
        int count = ogr.GetDriverCount();
        for (int i = 0; i < count; i++) {
            String driverName = ogr.GetDriver(i).getName();
            System.out.print(driverName + "\t");
        }
        gdal.GDALDestroyDriverManager();
    }
}

输出结果

ESRIC	FITS	PCIDSK	netCDF	PDS4	VICAR	JP2OpenJPEG	PDF	BAG	EEDA	OGCAPI	ESRI Shapefile	MapInfo File	UK .NTF	LVBAG	OGR_SDTS	S57	DGN	OGR_VRT	Memory	CSV	NAS	GML	GPX	KML	GeoJSON	GeoJSONSeq	ESRIJSON	TopoJSON	Interlis 1	Interlis 2	OGR_GMT	ODBC	WAsP	PGeo	MSSQLSpatial	PostgreSQL	OpenFileGDB	DXF	CAD	FlatGeobuf	Geoconcept	GeoRSS	PGDUMP	GPSBabel	OGR_PDS	WFS	OAPIF	EDIGEO	SVG	Idrisi	XLS	ODS	XLSX	Elasticsearch	Carto	AmigoCloud	SXF	Selafin	JML	PLSCENES	CSW	VDV	GMLAS	MVT	NGW	MapML	TIGER	AVCBin	AVCE00	HTTP



版权声明:本文为weixin_43955726原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。