geotools-java

0.4.0 • Public • Published

geotools-java

Bridge API to connect node.js with geotools Java APIs

Other projects that might be helpful

  • geotools - Open source Java library that provides tools for geospatial data.
  • node-java - Bridge API to connect with existing Java APIs.

Installation

$ npm install --save geotools-java

Notes:

  • Refer to node-java for node-java installaton prerequisites

Installation Prerequisites

  • JDK 8 or newer, Apache Maven, C++ compiler, python 2.7.x, zip, unzip

GeoTools Build and Packaging

  • The npm install process clones the geotools repo to node_modules/geotools.
  • The geotools JAR files and dependencies are packaged using te Maven Shade Plugin.
  • The geotools repo is cloned and then a maven build is initiated by make-geotools.sh
  • The makegt-jar.sh script is used to generate an Uber JAR containing the dependencies:
$ ./make-geotools.sh ./geotools
$ ./makegt-jar.sh 
  • The packaged geotools dependencies are placed in geotools-java/src/gt-jar/target/node-geotools-1.x.jar

Simple Example

const geotoolsFactory = require("geotools-java");
 
(async function () {
    const className = 'org.geotools.data.shapefile.ShapefileDataStoreFactory';
    const shapeFileStorePath=__dirname + '/../geotools/modules/library/sample-data/src/main/resources/org/geotools/test-data/shapes';
    
    // Will hang on OSX without these options
    const opts = {
        vmOptions: [
            '-Djava.awt.headless=true',
            '-Dawt.toolkit=sun.awt.HToolkit'
        ]
    };
    const geotools = await geotoolsFactory.getInstance(opts);
    
    const java = geotools.getJava();
    
    const factory = geotools.createDataStoreFactoryFromClass(className);
    const params = geotools.fileToUrlParams(shapeFileStorePath);
    
    const store = factory.createDataStore(params);
    
    const names = store.getTypeNames();
    
    const typeName = 'polygontest';
    const fs = store.getFeatureSource(typeName);
    
    const features = fs.getFeatures();
            
    const fjson = geotools.createFeatureJSON();
    console.log(fjson.toString(features));
})();

Release Notes

v0.4.0

  • Revise geotools build scripts
  • Add Java VM options to eliminate hang on OSX

v0.1.0

  • Initial release

Package Sidebar

Install

npm i geotools-java

Weekly Downloads

2

Version

0.4.0

License

MIT

Unpacked Size

102 kB

Total Files

12

Last publish

Collaborators

  • jimgambale