├── .github └── workflows │ └── build.yml ├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .travis.yml ├── README.md ├── bin ├── geoscript-js ├── geoscript-js-dev └── geoscript-js.cmd ├── doc ├── api │ ├── feature.rst │ ├── feature │ │ ├── feature.rst │ │ ├── featurecollection.rst │ │ ├── field.rst │ │ └── schema.rst │ ├── filter.rst │ ├── filter │ │ ├── expression.rst │ │ └── filter.rst │ ├── geom.rst │ ├── geom │ │ ├── bounds.rst │ │ ├── circularstring.rst │ │ ├── compoundcurve.rst │ │ ├── geometry.rst │ │ ├── geometrycollection.rst │ │ ├── linestring.rst │ │ ├── multilinestring.rst │ │ ├── multipoint.rst │ │ ├── multipolygon.rst │ │ ├── point.rst │ │ └── polygon.rst │ ├── index.rst │ ├── index │ │ ├── quadtree.rst │ │ └── strtree.rst │ ├── io │ │ ├── json.rst │ │ └── wkt.rst │ ├── layer.rst │ ├── map.rst │ ├── object.rst │ ├── process.rst │ ├── proj.rst │ ├── proj │ │ └── projection.rst │ ├── raster.rst │ ├── style.rst │ ├── style │ │ ├── brush.rst │ │ ├── color.rst │ │ ├── fill.rst │ │ ├── icon.rst │ │ ├── label.rst │ │ ├── shape.rst │ │ ├── stroke.rst │ │ ├── style.rst │ │ └── symbolizer.rst │ ├── types.rst │ ├── workspace.rst │ └── workspace │ │ ├── directory.rst │ │ ├── flatgeobuf.rst │ │ ├── geobuf.rst │ │ ├── geopackage.rst │ │ ├── h2.rst │ │ ├── memory.rst │ │ ├── mysql.rst │ │ ├── postgis.rst │ │ └── workspace.rst ├── download.rst ├── index.rst └── quickstart.rst ├── examples ├── README.md ├── centroids-layer.js ├── geometry │ ├── delaunayTriangle.js │ └── voronoiDigram.js ├── process │ └── buffer.js ├── raster │ ├── raster.pgw │ ├── raster.png │ ├── raster.prj │ ├── raster.tif │ └── readRaster.js ├── setup.js ├── style │ └── gradient.js ├── update.js └── wms │ ├── README.md │ ├── actions.js │ ├── main.js │ ├── static │ └── favicon.ico │ └── templates │ └── index.html ├── lib ├── ringo-core.jar └── ringo-modules.jar ├── license.txt ├── mvnw ├── mvnw.cmd ├── package.json ├── pom.xml └── src ├── main ├── assembly │ └── all.xml ├── java │ └── org │ │ └── geoscript │ │ └── js │ │ ├── GeoObject.java │ │ ├── GeoScriptModules.java │ │ ├── GeoScriptShell.java │ │ ├── feature │ │ ├── Feature.java │ │ ├── FeatureCollection.java │ │ ├── Field.java │ │ ├── Iterator.java │ │ ├── Module.java │ │ └── Schema.java │ │ ├── filter │ │ ├── Expression.java │ │ ├── Filter.java │ │ └── Module.java │ │ ├── geom │ │ ├── Bounds.java │ │ ├── CircularString.java │ │ ├── CompoundCurve.java │ │ ├── Geometry.java │ │ ├── GeometryCollection.java │ │ ├── GeometryWrapper.java │ │ ├── LineString.java │ │ ├── Module.java │ │ ├── MultiLineString.java │ │ ├── MultiPoint.java │ │ ├── MultiPolygon.java │ │ ├── Point.java │ │ └── Polygon.java │ │ ├── index │ │ ├── Module.java │ │ ├── Quadtree.java │ │ ├── STRtree.java │ │ └── SpatialIndex.java │ │ ├── io │ │ ├── JSON.java │ │ └── WKT.java │ │ ├── process │ │ ├── MetaProcess.java │ │ ├── Module.java │ │ └── Process.java │ │ ├── proj │ │ ├── Module.java │ │ └── Projection.java │ │ └── raster │ │ ├── Band.java │ │ ├── Format.java │ │ ├── Module.java │ │ └── Raster.java └── resources │ ├── Messages.properties │ └── org │ └── geoscript │ └── js │ └── lib │ ├── geoscript.js │ └── geoscript │ ├── factory.js │ ├── feature.js │ ├── filter.js │ ├── filter │ ├── expression.js │ ├── filter.js │ └── util.js │ ├── geom.js │ ├── geom │ └── io │ │ └── json.js │ ├── index.js │ ├── io │ ├── json.js │ └── wkt.js │ ├── layer.js │ ├── map.js │ ├── object.js │ ├── process.js │ ├── proj.js │ ├── raster.js │ ├── registry.js │ ├── style.js │ ├── style │ ├── brush.js │ ├── color.js │ ├── fill.js │ ├── icon.js │ ├── label.js │ ├── shape.js │ ├── stroke.js │ ├── style.js │ ├── symbolizer.js │ └── util.js │ ├── util.js │ ├── viewer.js │ ├── workspace.js │ └── workspace │ ├── directory.js │ ├── flatgeobuf.js │ ├── geobuf.js │ ├── geopackage.js │ ├── h2.js │ ├── memory.js │ ├── mysql.js │ ├── postgis.js │ ├── spatialite.js │ ├── util.js │ └── workspace.js └── test ├── java └── org │ └── geoscript │ └── js │ ├── DocParser.java │ ├── DoctestsTest.java │ └── RingoTest.java └── resources └── org └── geoscript └── js └── tests ├── admin.js ├── all.js ├── data ├── geopkg.zip ├── h2.zip ├── raster.tif └── states.shp.zip ├── geoscript ├── feature │ ├── test_collection.js │ ├── test_feature.js │ ├── test_field.js │ └── test_schema.js ├── filter │ ├── test_expression.js │ └── test_filter.js ├── geom │ ├── io │ │ ├── test_json.js │ │ └── test_wkt.js │ ├── test_bounds.js │ ├── test_circularstring.js │ ├── test_collection.js │ ├── test_compoundcurve.js │ ├── test_io.js │ ├── test_linestring.js │ ├── test_multilinestring.js │ ├── test_point.js │ └── test_polygon.js ├── io │ └── test_json.js ├── layer │ ├── common.js │ ├── test_h2.js │ ├── test_memory.js │ ├── test_postgis.js │ └── test_shapefile.js ├── raster │ ├── test_format.js │ └── test_raster.js ├── style │ ├── test_color.js │ ├── test_fill.js │ ├── test_shape.js │ ├── test_stroke.js │ ├── test_style.js │ └── test_symbolizer.js ├── test_feature.js ├── test_filter.js ├── test_geom.js ├── test_index.js ├── test_io.js ├── test_layer.js ├── test_map.js ├── test_process.js ├── test_proj.js ├── test_raster.js ├── test_style.js ├── test_util.js ├── test_workspace.js └── workspace │ ├── test_directory.js │ ├── test_flatgeobuf.js │ ├── test_geobuf.js │ ├── test_geopackage.js │ ├── test_h2.js │ ├── test_memory.js │ └── test_postgis.js └── test_geoscript.js /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Maven Build 2 | on: 3 | push: 4 | branches: [ master ] 5 | pull_request: 6 | branches: [ master ] 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Set up JDK 1.8 13 | uses: actions/setup-java@v1 14 | with: 15 | java-version: 1.8 16 | - name: Build with Maven 17 | run: mvn -B package --file pom.xml 18 | - name: Upload geoscript-js.zip 19 | uses: actions/upload-artifact@v2 20 | with: 21 | name: geoscript-js.zip 22 | path: target/geoscript-js-*.zip 23 | - name: Upload geoscript-js-app.jar 24 | uses: actions/upload-artifact@v2 25 | with: 26 | name: geoscript-js-app 27 | path: target/geoscript-js-*-app.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings/ 4 | /target/ 5 | /data/ 6 | .idea 7 | *.iml -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geoscript/geoscript-js/baf658cb6880aa70e419a58e41824a2facdec294/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | 3 | language: java 4 | 5 | jdk: 6 | - oraclejdk8 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Current Status](https://secure.travis-ci.org/geoscript/geoscript-js.png?branch=master)](https://travis-ci.org/geoscript/geoscript-js) 2 | 3 | [![Build Status](https://github.com/geoscript/geoscript-js/workflows/Maven%20Build/badge.svg)](https://github.com/geoscript/geoscript-js/actions) 4 | 5 | # geoscript.js 6 | 7 | ## GeoScript in JavaScript 8 | 9 | Copyright (c) 2009-2013 Tim Schaub 10 | 11 | Released under the MIT license. Please see the license.txt for full detail. 12 | 13 | ### Download and Installation 14 | 15 | The latest release of GeoScript JS can be found on the [downloads page](http://geoscript.net/js/download.html). To install, extract the zip archive somewhere onto your filesystem. In the `bin` folder you'll find a `geoscript` executable. Adding this `bin` folder to your path makes for easy launching of GeoScript from anywhere. 16 | 17 | ### Running GeoScript JS 18 | 19 | Change into the directory where you extracted the GeoScript JS download. From there, you can launch the GeoScript JS shell. 20 | 21 | ./bin/geoscript-js 22 | 23 | Once running the shell, you can pull in GeoScript modules with `require`. 24 | 25 | js> var geom = require("geoscript/geom") 26 | js> var p = new geom.Point([1, 2]) 27 | js> p.buffer(10) 28 | 29 | 30 | When you're done in the shell, exit with `quit()`. 31 | 32 | js> quit() 33 | 34 | To run a script that uses the GeoScript JS modules, include the path to your script. 35 | 36 | ./bin/geoscript-js yourscript.js 37 | 38 | ### Learning GeoScript JS 39 | 40 | See the [GeoScript JS website](http://geoscript.net/js/) for details on getting started using GeoScript JS. 41 | 42 | ### Getting set up for development 43 | 44 | If you'd like to contribute to GeoScript JS development, clone the repository and then use Maven to pull in dependencies and run tests. 45 | 46 | git clone git://github.com/tschaub/geoscript-js.git 47 | cd geoscript-js 48 | mvn install 49 | 50 | After pulling down the dependencies, you can launch the shell and use GeoScript JS modules as described above - with one exception: use the `geoscript-dev` script in the `bin` directory. 51 | 52 | ### Generating a release 53 | 54 | Update version numbers in the main pom.xml file. Generate an archive with all dependencies included: 55 | 56 | mvn assembly:single 57 | 58 | Deploy both the stand-alone archive and a jar with just the GeoScript JS modules (that depends on GeoTools): 59 | 60 | mvn deploy 61 | 62 | -------------------------------------------------------------------------------- /bin/geoscript-js: -------------------------------------------------------------------------------- 1 | 2 | # parse options 3 | DEBUG= 4 | JARS= 5 | MODULES= 6 | while getopts 'dj:m:' OPTION; do 7 | case $OPTION in 8 | d) DEBUG=1;; 9 | j) JARS="$OPTARG";; 10 | m) MODULES="$OPTARG";; 11 | esac 12 | done 13 | shift $(($OPTIND -1)) 14 | 15 | # find home 16 | if [ -z "$0" ]; then 17 | # as a last recourse, use the present working directory 18 | GEOSCRIPT_HOME=$(pwd) 19 | else 20 | # get the absolute path of the executable 21 | SELF_PATH=$( 22 | cd -P -- "$(dirname -- "$0")" \ 23 | && pwd -P 24 | ) && SELF_PATH=$SELF_PATH/$(basename -- "$0") 25 | 26 | # resolve symlinks 27 | while [ -h "$SELF_PATH" ]; do 28 | DIR=$(dirname -- "$SELF_PATH") 29 | SYM=$(readlink -- "$SELF_PATH") 30 | SELF_PATH=$(cd -- "$DIR" && cd -- $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM") 31 | done 32 | 33 | GEOSCRIPT_HOME=$(dirname -- "$(dirname -- "$SELF_PATH")") 34 | fi 35 | 36 | if [ ! "$JARS" ]; then 37 | JARS=$GEOSCRIPT_HOME/jars 38 | fi 39 | 40 | # put GeoTools jars on the classpath 41 | CP="" 42 | for x in `ls $JARS/*.jar`; do 43 | CP=$CP:$x 44 | done 45 | 46 | if [ "$DEBUG" ]; then 47 | CLASS=org.mozilla.javascript.tools.debugger.Main 48 | else 49 | CLASS=org.geoscript.js.GeoScriptShell 50 | fi 51 | 52 | ARGS= 53 | if [ "$MODULES" ]; then 54 | ARGS="-Dgeoscript.modules=$MODULES" 55 | fi 56 | 57 | if [ $# -eq 1 ]; then 58 | # resolve absolute path to main module 59 | MAIN_PATH=$( 60 | cd -P -- "$(dirname -- "$1")" \ 61 | && pwd -P 62 | ) && MAIN_PATH=$MAIN_PATH/$(basename -- "$1") 63 | 64 | java -cp $CP $ARGS $CLASS $MAIN_PATH 65 | else 66 | java -cp $CP $ARGS $CLASS 67 | fi 68 | -------------------------------------------------------------------------------- /bin/geoscript-js-dev: -------------------------------------------------------------------------------- 1 | # find home 2 | if [ -z "$0" ]; then 3 | # as a last recourse, use the present working directory 4 | GEOSCRIPT_HOME=$(pwd) 5 | else 6 | # get the absolute path of the executable 7 | SELF_PATH=$( 8 | cd -P -- "$(dirname -- "$0")" \ 9 | && pwd -P 10 | ) && SELF_PATH=$SELF_PATH/$(basename -- "$0") 11 | 12 | # resolve symlinks 13 | while [ -h "$SELF_PATH" ]; do 14 | DIR=$(dirname -- "$SELF_PATH") 15 | SYM=$(readlink -- "$SELF_PATH") 16 | SELF_PATH=$(cd -- "$DIR" && cd -- $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM") 17 | done 18 | 19 | GEOSCRIPT_HOME=$(dirname -- "$(dirname -- "$SELF_PATH")") 20 | fi 21 | 22 | $GEOSCRIPT_HOME/bin/geoscript-js -j $GEOSCRIPT_HOME/target/jars -m $GEOSCRIPT_HOME/src/main/resources/org/geoscript/js/lib "$@" 23 | -------------------------------------------------------------------------------- /bin/geoscript-js.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | :: GEOSCRIPT_HOME is the parent of the bin directory 5 | set GEOSCRIPT_HOME=%~dp0.. 6 | 7 | :: put GeoTools jars on the classpath 8 | setlocal enabledelayedexpansion 9 | echo. >NUL 2>tmp.txt 10 | for /R %GEOSCRIPT_HOME%\jars %%x in (*.jar) do echo %%x >> tmp.txt 11 | 12 | set CP= 13 | for /f %%a in (tmp.txt) do ( 14 | set CP=!CP!;%%a 15 | ) 16 | del /q tmp.txt 17 | set CP=.;..%CP% 18 | 19 | set CLASS=org.mozilla.javascript.tools.shell.Main 20 | 21 | :: Convert any backslashes in the command to forward slashes 22 | set CMD=java -cp "%CP%" %CLASS% -version 180 -modules file:///%GEOSCRIPT_HOME%\lib 23 | set CMD=%CMD:\=/% 24 | 25 | :: Execute 26 | %CMD% 27 | 28 | -------------------------------------------------------------------------------- /doc/api/feature.rst: -------------------------------------------------------------------------------- 1 | The feature module 2 | ================== 3 | 4 | The :doc:`feature ` module provides a provides constructors for 5 | features, feature collections, and feature schema. 6 | 7 | .. code-block:: javascript 8 | 9 | >> var feature = require("geoscript/feature"); 10 | 11 | 12 | Constructors 13 | ------------ 14 | 15 | .. toctree:: 16 | :glob: 17 | :maxdepth: 1 18 | 19 | feature/* 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /doc/api/feature/feature.rst: -------------------------------------------------------------------------------- 1 | :class:`feature.Feature` 2 | ======================== 3 | 4 | .. class:: feature.Feature(config) 5 | 6 | :arg Object config: Configuration object. 7 | 8 | Create a new feature. 9 | 10 | 11 | Example Use 12 | ----------- 13 | 14 | Sample code to create a new feature: 15 | 16 | .. code-block:: javascript 17 | 18 | >> var Feature = require("geoscript/feature").Feature; 19 | >> var Point = require("geoscript/geom").Point; 20 | >> var city = Feature({ 21 | .. properties: { 22 | .. location: Point([-110, 45]), 23 | .. name: "Metropolis" 24 | .. } 25 | .. }); 26 | 27 | >> city.get("name"); 28 | Metropolis 29 | >> city.get("location"); 30 | 31 | 32 | 33 | Config Properties 34 | ----------------- 35 | 36 | .. describe:: schema 37 | 38 | :class:`feature.Schema` 39 | The feature schema. If not provided, a schema will be derived from 40 | the provided ``properties`` in the configuration. 41 | 42 | .. describe:: properties 43 | 44 | ``Object`` 45 | An object with all the feature property names and values. 46 | 47 | 48 | 49 | Properties 50 | ---------- 51 | 52 | 53 | .. attribute:: Feature.bounds 54 | 55 | :class:`geom.Bounds` 56 | The bounds of the default geometry (if any) for this feature. Will be 57 | ``undefined`` if the feature has no geometry. 58 | 59 | .. attribute:: Feature.geometry 60 | 61 | :class:`geom.Geometry` 62 | The default geometry (if any) for the feature. Will be ``undefined`` 63 | if the feature does not have a geometry. 64 | 65 | .. attribute:: Feature.geometryName 66 | 67 | ``String`` 68 | Field name for the default geoemtry, or ``undefined`` if the feature 69 | has no geometry. 70 | 71 | .. attribute:: Feature.id 72 | 73 | ``String`` 74 | The feature identifier. Read only. 75 | 76 | .. attribute:: Feature.json 77 | 78 | ``String`` 79 | The JSON representation of the feature (see http://geojson.org). 80 | 81 | .. attribute:: Feature.projection 82 | 83 | :class:`proj.Projection` 84 | Optional projection for the feature. This corresponds to the projection 85 | of the default geometry for the feature. 86 | 87 | .. attribute:: Feature.schema 88 | 89 | :class:`feature.Schema` 90 | The feature schema (read-only). 91 | 92 | .. attribute:: Feature.properties 93 | 94 | ``Object`` 95 | An object with all the feature property names and values. Used for 96 | property access only. Use :func:`~Feature.set` to set property values. 97 | 98 | 99 | 100 | 101 | Methods 102 | ------- 103 | 104 | 105 | .. function:: Feature.clone 106 | 107 | :returns: :class:`feature.Feature` 108 | 109 | Create a clone of this feature. 110 | 111 | .. function:: Feature.get 112 | 113 | :arg name: ``String`` Attribute name. 114 | 115 | Get an attribute value. 116 | 117 | .. function:: Feature.set 118 | 119 | :arg name: ``String`` Attribute name. 120 | :arg value: ``String`` Attribute value. 121 | 122 | Set a feature attribute. 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /doc/api/feature/field.rst: -------------------------------------------------------------------------------- 1 | :class:`feature.Field` 2 | ====================== 3 | 4 | .. class:: feature.Field(config) 5 | 6 | :arg Object config: Configuration object. 7 | 8 | Create a new field. 9 | 10 | Example Use 11 | ----------- 12 | 13 | Sample code to create a new field: 14 | 15 | .. code-block:: javascript 16 | 17 | >> var Field = require("geoscript/feature").Field; 18 | >> var field = Field({ 19 | .. name: "age", 20 | .. type: "Double" 21 | .. }); 22 | 23 | >> var field = Field({ 24 | .. name: "location", 25 | .. type: "Point", 26 | .. projection: "EPSG:4326" 27 | .. }); 28 | 29 | For detail on the supported ``type`` values, see the section on 30 | :ref:`type_mapping`. 31 | 32 | Config Properties 33 | ----------------- 34 | 35 | .. describe:: description 36 | 37 | ``String`` 38 | The field description (optional). 39 | 40 | .. describe:: isNillable 41 | 42 | ``Boolean`` 43 | The field is nillable (optional). Default is ``true``. 44 | 45 | .. describe:: minOccurs 46 | 47 | ``Number`` 48 | The minimum occurences for field values (optional). Default is ``0``. 49 | 50 | .. describe:: name 51 | 52 | ``String`` 53 | The field name (required). 54 | 55 | .. describe:: projection 56 | 57 | :class:`proj.Projection` 58 | Geometry projection (optional). Relevant for geometry type fields only. 59 | 60 | .. describe:: title 61 | 62 | ``String`` 63 | The field title (optional). 64 | 65 | .. describe:: type 66 | 67 | ``String`` 68 | The field type (required). For detail on the supported ``type`` values, see 69 | the section on :ref:`type_mapping`. 70 | 71 | 72 | 73 | Properties 74 | ---------- 75 | 76 | .. attribute:: Field.description 77 | 78 | ``String`` 79 | The field description (read-only). 80 | 81 | .. attribute:: Field.isNillable 82 | 83 | ``Boolean`` 84 | The field is nillable (read-only). 85 | 86 | .. attribute:: Field.maxOccurs 87 | 88 | ``Number`` 89 | The maximum occurences for field values (read-only). 90 | 91 | .. attribute:: Field.minOccurs 92 | 93 | ``Number`` 94 | The minimum occurences for field values (read-only). 95 | 96 | .. attribute:: Field.name 97 | 98 | ``String`` 99 | The field name (read-only). 100 | 101 | .. attribute:: Field.projection 102 | 103 | :class:`proj.Projection` 104 | Geometry type fields can have an optional projection (read-only). 105 | 106 | .. attribute:: Field.title 107 | 108 | ``String`` 109 | The field title (read-only). 110 | 111 | .. attribute:: Field.type 112 | 113 | ``String`` 114 | The field type (read-only). For detail on the supported ``type`` values, 115 | see the section on :ref:`type_mapping`. 116 | 117 | 118 | 119 | Methods 120 | ------- 121 | 122 | .. function:: Field.equals 123 | 124 | :arg field: :class:`feature.Field` 125 | :returns: ``Boolean`` The two fields are equivalent. 126 | 127 | Determine if another field is equivalent to this one. 128 | 129 | -------------------------------------------------------------------------------- /doc/api/feature/schema.rst: -------------------------------------------------------------------------------- 1 | :class:`feature.Schema` 2 | ======================= 3 | 4 | .. class:: feature.Schema(config) 5 | 6 | :arg Object config: Configuration object. 7 | 8 | Create a new schema. 9 | 10 | 11 | Example Use 12 | ----------- 13 | 14 | Sample code to create a new schema: 15 | 16 | .. code-block:: javascript 17 | 18 | >> var Schema = require("geoscript/feature").Schema; 19 | >> var cities = Schema({ 20 | .. name: "cities", 21 | .. fields: [{ 22 | .. name: "the_geom", 23 | .. type: "Point", 24 | .. projection: "EPSG:4326" 25 | .. }, { 26 | .. name: "name", 27 | .. type: "String" 28 | .. }] 29 | .. }); 30 | 31 | >> cities.fields.length 32 | 2 33 | >> cities.geometry.name 34 | the_geom 35 | >> cities.get("the_geom").type 36 | Point 37 | >> cities.get("the_geom").projection 38 | 39 | 40 | Config Properties 41 | ----------------- 42 | 43 | .. describe:: fields 44 | 45 | ``Array`` 46 | Field definitions. Each item in the array must be a 47 | :class:`feature.Field` object or a valid field config. 48 | 49 | .. describe:: name 50 | 51 | ``String`` 52 | The schema name. Default is ``"feature"``. The schema name typically 53 | matches the layer name within a workspace. 54 | 55 | 56 | Properties 57 | ---------- 58 | 59 | 60 | .. attribute:: Schema.fieldNames 61 | 62 | ``Array`` 63 | Array of field names. 64 | 65 | .. attribute:: Schema.fields 66 | 67 | ``Array`` 68 | Field definitions. Field definitions are objects with at least ``name`` 69 | and ``type`` properties. Geometry field definitions may have a 70 | ``projection`` property. See the :class:`feature.Field` documentation 71 | for more detail. 72 | 73 | .. attribute:: Schema.geometry 74 | 75 | ``Object`` 76 | Default geometry field definition. Will be ``undefined`` if the schema 77 | doesn't include a geometry field. 78 | 79 | .. attribute:: Schema.name 80 | 81 | ``String`` 82 | The schema name. 83 | 84 | 85 | Methods 86 | ------- 87 | 88 | .. function:: Schema.clone 89 | 90 | :arg config: ``Object`` 91 | :returns: :class:`feature.Schema` 92 | 93 | Create a complete copy of this schema. 94 | 95 | .. function:: Schema.get 96 | 97 | :arg name: ``String`` A field name. 98 | :returns: :class:`feature.Field` A field definition. 99 | 100 | Get the definition for a named field. Field definitions have at least 101 | ``name`` and ``type`` properties. Geometry field definitions may have 102 | a ``projection`` property. Returns ``undefined`` if no field is found 103 | with the given name. 104 | 105 | 106 | -------------------------------------------------------------------------------- /doc/api/filter.rst: -------------------------------------------------------------------------------- 1 | The filter module 2 | ================= 3 | 4 | The :doc:`filter ` module provides a constructor for Filter objects. 5 | 6 | .. code-block:: javascript 7 | 8 | >> var filter = require("geoscript/filter"); 9 | 10 | 11 | Constructors 12 | ------------ 13 | 14 | .. toctree:: 15 | :glob: 16 | :maxdepth: 1 17 | 18 | filter/* 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /doc/api/filter/expression.rst: -------------------------------------------------------------------------------- 1 | :class:`filter.Expression` 2 | ========================== 3 | 4 | .. class:: filter.Expression(cql) 5 | 6 | :arg text: ``String`` The expression text. 7 | 8 | Expression class for generating values from features. 9 | 10 | 11 | Properties 12 | ---------- 13 | 14 | .. attribute:: Expression.literal 15 | 16 | ``Boolean`` 17 | This expression is just a literal value. 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /doc/api/filter/filter.rst: -------------------------------------------------------------------------------- 1 | :class:`filter.Filter` 2 | ====================== 3 | 4 | .. class:: filter.Filter 5 | 6 | :arg cql: `String` A CQL string representing filter constraints. 7 | 8 | Create a new filter to express constraints. Filters are typically 9 | used when querying features from a layer. A feature will be 10 | returned in a query if the filter's :func:`~Filter.evaluate` method returns 11 | `true` for the given feature. 12 | 13 | Filters are created using Common Query Language (CQL). 14 | 15 | Example Use 16 | ----------- 17 | 18 | Get the exported constructor: 19 | 20 | .. code-block:: javascript 21 | 22 | >> var Filter = require("geoscript/filter").Filter; 23 | 24 | Various simple constraints: 25 | 26 | .. code-block:: javascript 27 | 28 | >> var namedFoo = Filter("name = 'foo'"); 29 | >> var oneThing = Filter("thing = 1"); 30 | >> var few = Filter("count < 4"); 31 | >> var many = Filter("count > 36"); 32 | >> var teens = Filter("age BETWEEN 13 AND 19"); 33 | 34 | Spatial constraints: 35 | 36 | .. code-block:: javascript 37 | 38 | >> var box = Filter("BBOX(the_geom, -10, -10, 10, 10)"); 39 | >> var close = Filter("DWITHIN(the_geom, POINT(1 0), 3, kilometers)"); 40 | >> var has = Filter("CONTAINS(the_geom, POINT(1 0))"); 41 | >> var hit = Filter("INTERSECTS(the_geom, LINESTRING(0 0, 1 1))"); 42 | 43 | 44 | Properties 45 | ---------- 46 | 47 | 48 | .. attribute:: Filter.cql 49 | 50 | ``String`` 51 | The CQL string that represents constraints in this filter. 52 | 53 | .. attribute:: Filter.not 54 | 55 | :class:`filter.Filter` 56 | A filter that represents the negation of the constraints in this filter. 57 | 58 | 59 | 60 | Methods 61 | ------- 62 | 63 | .. function:: Filter.and 64 | 65 | :arg filter: :class:`filter.Filter` Input filter. 66 | :returns: :class:`filter.Filter` 67 | 68 | Returns a new filter that is the logical AND of this filter and the 69 | input filter. Provide multiple arguments to AND multiple filters. 70 | 71 | .. function:: Filter.evaluate 72 | 73 | :arg feature: :class:`feature.Feature` A feature. 74 | :returns: ``Boolean`` The feature matches the filter. 75 | 76 | Determine whether a feature matches the constraints of the filter. 77 | 78 | .. function:: Filter.or 79 | 80 | :arg filter: :class:`filter.Filter` Input filter. 81 | :returns: :class:`filter.Filter` 82 | 83 | Returns a new filter that is the logical OR of this filter and the 84 | input filter. Provide multiple arguments to OR multiple filters. 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /doc/api/geom.rst: -------------------------------------------------------------------------------- 1 | The geom module 2 | =============== 3 | 4 | 5 | The :doc:`geom ` module provides a provides constructors for point, line, 6 | polygon and multi-part geometries. 7 | 8 | .. code-block:: javascript 9 | 10 | >> var geom = require("geoscript/geom"); 11 | 12 | 13 | Constructors 14 | ------------ 15 | 16 | .. toctree:: 17 | :glob: 18 | :maxdepth: 1 19 | 20 | geom/point 21 | geom/linestring 22 | geom/polygon 23 | geom/multipoint 24 | geom/multilinestring 25 | geom/multipolygon 26 | geom/bounds 27 | geom/circularstring 28 | geom/compoundcurve 29 | 30 | 31 | Module Data 32 | ----------- 33 | 34 | The following constants are used in the :func:`Geometry.buffer` method to 35 | specify the buffer cap style. 36 | 37 | .. data:: geom.BUFFER_CAP_BUTT 38 | 39 | Used to calculate butt caps for buffer operations. 40 | 41 | .. data:: geom.BUFFER_CAP_ROUND 42 | 43 | Used to calculate round caps for buffer operations. 44 | 45 | .. data:: geom.BUFFER_CAP_SQUARE 46 | 47 | Used to calculate square caps for buffer operations. 48 | 49 | -------------------------------------------------------------------------------- /doc/api/geom/circularstring.rst: -------------------------------------------------------------------------------- 1 | :class:`geom.CircularString` 2 | ======================== 3 | 4 | .. class:: geom.CircularString(coords) 5 | 6 | :arg Array coords: Coordinates array. 7 | 8 | Create a new circularstring. 9 | 10 | 11 | Example Use 12 | ----------- 13 | 14 | Sample code to new circularstring: 15 | 16 | .. code-block:: javascript 17 | 18 | >> var CircularString = require("geoscript/geom").CircularString; 19 | >> var cs = new CircularString([[6.12, 10.0], [7.07, 7.07], [10.0, 0.0]]); 20 | >> cs.controlPoints.length 21 | 3 22 | >> cs.linear.getGeometryType() 23 | LineString 24 | >> cs.curvedWkt 25 | CIRCULARSTRING (6.12 10.0, 7.07 7.07, 10.0 0.0) 26 | 27 | 28 | 29 | Properties 30 | ---------- 31 | 32 | In addition to the properties common to :class:`geom.LineString` subclasses, 33 | circularstring geometries have the properties documented below. 34 | 35 | 36 | .. attribute:: CircularString.curvedWkt 37 | 38 | :class:`String` 39 | The curved WKT as a string. 40 | 41 | .. attribute:: CircularString.controlPoints 42 | 43 | ``Array`` 44 | An array of the original control Points. 45 | 46 | 47 | .. attribute:: CircularString.linear 48 | 49 | :class:`geom.LineString` 50 | A linearized LineString. 51 | 52 | 53 | 54 | Methods 55 | ------- 56 | 57 | CircularString geometries have the methods common to :class:`geom.LineString` 58 | subclasses. 59 | -------------------------------------------------------------------------------- /doc/api/geom/compoundcurve.rst: -------------------------------------------------------------------------------- 1 | :class:`geom.CompoundCurve` 2 | =========================== 3 | 4 | .. class:: geom.CompoundCurve(lineStrings) 5 | 6 | :arg Array lineStrings: An array of LineStrings or CircularStrings. 7 | 8 | Create a new CompoundCurve. 9 | 10 | 11 | Example Use 12 | ----------- 13 | 14 | Sample code to new compoundcurve: 15 | 16 | .. code-block:: javascript 17 | 18 | >> var GEOM = require("geoscript/geom"); 19 | >> var cs = new GEOM.CircularString([[10.0, 10.0], [0.0, 20.0], [-10.0, 10.0]]); 20 | >> var line = new GEOM.LineString([[-10.0, 10.0], [-10.0, 0.0], [10.0, 0.0], [5.0, 5.0]]) 21 | >> var cc = new GEOM.CompoundCurve([cs, line]); 22 | >> cc.components.length 23 | 2 24 | >> cc.linear.getGeometryType() 25 | LineString 26 | >> cc.curvedWkt 27 | COMPOUNDCURVE (CIRCULARSTRING (10.0 10.0, 0.0 20.0, -10.0 10.0), (-10.0 10.0, -10.0 0.0, 10.0 0.0, 5.0 5.0)) 28 | 29 | 30 | Properties 31 | ---------- 32 | 33 | In addition to the properties common to all :class:`geom.LineString` subclasses, 34 | compoundcurve geometries have the properties documented below. 35 | 36 | 37 | .. attribute:: CompoundCurve.components 38 | 39 | :class:`geom.LineString` 40 | The original LineString or CircularStrings. 41 | 42 | .. attribute:: CircularString.curvedWkt 43 | 44 | :class:`String` 45 | The curved WKT as a string. 46 | 47 | .. attribute:: CircularString.linear 48 | 49 | :class:`geom.LineString` 50 | A linearized LineString. 51 | 52 | Methods 53 | ------- 54 | 55 | CompoundCurve geometries have the methods common to all :class:`geom.LineString` 56 | subclasses. 57 | -------------------------------------------------------------------------------- /doc/api/geom/geometrycollection.rst: -------------------------------------------------------------------------------- 1 | :class:`geom.GeometryCollection` 2 | ================================ 3 | 4 | .. class:: geom.GeometryCollection(coords) 5 | 6 | :arg Array coords: Coordinates array. 7 | 8 | Create a multipart geometry with mixed geometry types. The items 9 | in the coords array may be geometry coordinates or :class:`geom.Geometry` 10 | objects. 11 | 12 | Properties 13 | ---------- 14 | 15 | In addition to the properties common to all :class:`geom.Geometry` subclasses, 16 | GeometryCollection geometries have the properties documented below. 17 | 18 | .. attribute:: GeometryCollection.components 19 | 20 | ``Array`` 21 | The component :class:`geom.Geometry` objects that make up this collection. 22 | 23 | 24 | Methods 25 | ------- 26 | 27 | GeometryCollection geometries have the methods common to all :class:`geom.Geometry` 28 | subclasses. 29 | -------------------------------------------------------------------------------- /doc/api/geom/linestring.rst: -------------------------------------------------------------------------------- 1 | :class:`geom.LineString` 2 | ======================== 3 | 4 | .. class:: geom.LineString(coords) 5 | 6 | :arg Array coords: Coordinates array. 7 | 8 | Create a new linestring. 9 | 10 | 11 | Example Use 12 | ----------- 13 | 14 | Sample code to new linestring: 15 | 16 | .. code-block:: javascript 17 | 18 | >> var LineString = require("geoscript/geom").LineString; 19 | >> var line = LineString([[-180, -90], [0, 0], [180, 90]]); 20 | >> line.coordinates.length 21 | 3 22 | >> line.length 23 | 402.49223594996215 24 | 25 | 26 | Properties 27 | ---------- 28 | 29 | In addition to the properties common to all :class:`geom.Geometry` subclasses, 30 | linestring geometries have the properties documented below. 31 | 32 | 33 | .. attribute:: LineString.endPoint 34 | 35 | :class:`geom.Point` 36 | The last point in the linestring. 37 | 38 | .. attribute:: LineString.endPoints 39 | 40 | ``Array`` 41 | List of start point and end point. 42 | 43 | 44 | .. attribute:: LineString.startPoint 45 | 46 | :class:`geom.Point` 47 | The first point in the linestring. 48 | 49 | 50 | 51 | Methods 52 | ------- 53 | 54 | Linestring geometries have the methods common to all :class:`geom.Geometry` 55 | subclasses. 56 | 57 | .. function:: LineString.interpolatePoint 58 | 59 | :arg position: ``Number`` The position between 0 and 1. 60 | :returns: :class:`geom.Point` 61 | 62 | Returns a Point placed on the LineString at the given percentage along 63 | the LineString. 64 | 65 | .. function:: LineString.locatePoint 66 | 67 | :arg point: :class:`geom.Point` The Point 68 | :returns: ``Number`` The position (0-1) or percentage of the Point along the LineString. 69 | 70 | Returns a position or percentage between 0 and 1 of the Point along the LineString. 71 | 72 | .. function:: LineString.placePoint 73 | 74 | :arg point: :class:`geom.Point` The Point. 75 | :returns: :class:`geom.Point` The Point on the LineString. 76 | 77 | Places or snaps the Point to the LineString. 78 | 79 | .. function:: LineString.subLine 80 | 81 | :arg start: ``Number`` The start position between 0 and 1. 82 | :arg end: ``Number`` The end position between 0 and 1. 83 | :returns: :class:`geom.LineString` The sub LineString 84 | 85 | Returns a position or percentage between 0 and 1 of the Point along the LineString. -------------------------------------------------------------------------------- /doc/api/geom/multilinestring.rst: -------------------------------------------------------------------------------- 1 | :class:`geom.MultiLineString` 2 | ============================= 3 | 4 | .. class:: geom.MultiLineString(coords) 5 | 6 | :arg Array coords: Coordinates array. 7 | 8 | Create a new multi-linestring geometry. The items in the coords array 9 | may be linestring coordinates or :class:`geom.LineString` objects. 10 | 11 | 12 | Example Use 13 | ----------- 14 | 15 | Sample code to new multi-linestring: 16 | 17 | .. code-block:: javascript 18 | 19 | >> var {MultiLineString, LineString} = require("geoscript/geom"); 20 | >> var l1 = LineString([[-180, -90], [0, 0], [180, 90]]); 21 | >> var l2 = LineString([[180, -90], [0, 0], [-180, 90]]); 22 | >> var ml = MultiLineString([l1, l2]); 23 | 24 | Alternate method to create the same geometry as above: 25 | 26 | .. code-block:: javascript 27 | 28 | >> var ml = MultiLineString([ 29 | .. [[-180, -90], [0, 0], [180, 90]], 30 | .. [[180, -90], [0, 0], [-180, 90]] 31 | .. ]); 32 | 33 | 34 | Properties 35 | ---------- 36 | 37 | Multi-polygon geometries have the properties common to all 38 | :class:`geom.GeometryCollection` subclasses. 39 | 40 | 41 | Methods 42 | ------- 43 | 44 | Multi-polygon geometries have the methods common to all 45 | :class:`geom.GeometryCollection` subclasses. 46 | 47 | 48 | -------------------------------------------------------------------------------- /doc/api/geom/multipoint.rst: -------------------------------------------------------------------------------- 1 | :class:`geom.MultiPoint` 2 | ======================== 3 | 4 | .. class:: geom.MultiPoint(coords) 5 | 6 | :arg Array coords: Coordinates array. 7 | 8 | Create a new multi-point geometry. The items in the coords array 9 | may be point coordinates or :class:`geom.Point` objects. 10 | 11 | 12 | 13 | Example Use 14 | ----------- 15 | 16 | Sample code to new multi-point: 17 | 18 | .. code-block:: javascript 19 | 20 | >> var {Point, MultiPoint} = require("geoscript/geom"); 21 | >> var p1 = Point([-180, 90]); 22 | >> var p2 = Point([-45, 45]); 23 | >> var mp = MultiPoint([p1, p2]); 24 | 25 | Alternate method to create the same geometry as above: 26 | 27 | .. code-block:: javascript 28 | 29 | >> var mp = MultiPoint([ 30 | .. [-180, 90], [-45, 45] 31 | .. ]); 32 | 33 | 34 | 35 | Properties 36 | ---------- 37 | 38 | Multi-polygon geometries have the properties common to all 39 | :class:`geom.GeometryCollection` subclasses. 40 | 41 | 42 | Methods 43 | ------- 44 | 45 | Multi-polygon geometries have the methods common to all 46 | :class:`geom.GeometryCollection` subclasses. 47 | 48 | -------------------------------------------------------------------------------- /doc/api/geom/multipolygon.rst: -------------------------------------------------------------------------------- 1 | :class:`geom.MultiPolygon` 2 | ========================== 3 | 4 | .. class:: geom.MultiPolygon(coords) 5 | 6 | :arg Array coords: Coordinates array. 7 | 8 | Create a new multipolygon geometry. The items in the coords array 9 | may be polygon coordinates or :class:`geom.Polygon` objects. 10 | 11 | 12 | Example Use 13 | ----------- 14 | 15 | Sample code to new multi-polygon: 16 | 17 | .. code-block:: javascript 18 | 19 | >> var {Polygon, MultiPolygon} = require("geoscript/geom"); 20 | >> var p1 = Polygon([ 21 | .. [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]], 22 | .. [[-90, -45], [-90, 45], [90, 45], [90, -45], [-90, -45]] 23 | .. ]); 24 | >> var p2 = Polygon([ 25 | .. [[-60, -30], [-60, 30], [60, 30], [60, -30], [-60, -30]] 26 | .. ]); 27 | >> var mp = MultiPolygon([p1, p2]); 28 | 29 | Alternate method to create the same geometry as above: 30 | 31 | .. code-block:: javascript 32 | 33 | >> var mp = MultiPolygon([ 34 | .. [ 35 | .. [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]], 36 | .. [[-90, -45], [-90, 45], [90, 45], [90, -45], [-90, -45]] 37 | .. ], [ 38 | .. [[-60, -30], [-60, 30], [60, 30], [60, -30], [-60, -30]] 39 | .. ] 40 | .. ]); 41 | 42 | 43 | Properties 44 | ---------- 45 | 46 | 47 | Multi-polygon geometries have the properties common to all 48 | :class:`geom.GeometryCollection` subclasses. 49 | 50 | 51 | Methods 52 | ------- 53 | 54 | Multi-polygon geometries have the methods common to all 55 | :class:`geom.GeometryCollection` subclasses. 56 | 57 | -------------------------------------------------------------------------------- /doc/api/geom/point.rst: -------------------------------------------------------------------------------- 1 | :class:`geom.Point` 2 | =================== 3 | 4 | .. class:: geom.Point(coords) 5 | 6 | :arg Array coords: Coordinates array. 7 | 8 | Create a new point. 9 | 10 | Example Use 11 | ----------- 12 | 13 | Sample code to create a new point: 14 | 15 | .. code-block:: javascript 16 | 17 | >> var Point = require("geoscript/geom").Point; 18 | >> var point = Point([-180, 90]); 19 | >> point.x; 20 | -180 21 | >> point.y; 22 | 90 23 | 24 | 25 | Properties 26 | ---------- 27 | 28 | In addition to the properties common to all :class:`geom.Geometry` subclasses, point 29 | geometries have the properties documented below. 30 | 31 | .. attribute:: Point.x 32 | 33 | ``Number`` 34 | The first coordinate value. 35 | 36 | .. attribute:: Point.y 37 | 38 | ``Number`` 39 | The second coordinate value. 40 | 41 | .. attribute:: Point.z 42 | 43 | ``Number`` 44 | The third coordinate value (or NaN if none). 45 | 46 | 47 | 48 | 49 | Methods 50 | ------- 51 | 52 | Point geometries have the methods common to all :class:`geom.Geometry` subclasses. 53 | 54 | -------------------------------------------------------------------------------- /doc/api/geom/polygon.rst: -------------------------------------------------------------------------------- 1 | :class:`geom.Polygon` 2 | ===================== 3 | 4 | .. class:: geom.Polygon(coords) 5 | 6 | :arg Array coords: Coordinates array. 7 | 8 | Create a new polygon. 9 | 10 | 11 | Example Use 12 | ----------- 13 | 14 | Sample code to new polygon: 15 | 16 | .. code-block:: javascript 17 | 18 | >> var Polygon = require("geoscript/geom").Polygon; 19 | >> var poly = Polygon([ 20 | .. [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]], 21 | .. [[-90, -45], [-90, 45], [90, 45], [90, -45], [-90, -45]] 22 | .. ]); 23 | 24 | 25 | Properties 26 | ---------- 27 | 28 | In addition to the properties common to all :class:`geom.Geometry` subclasses, 29 | polygon geometries have the properties documented below. 30 | 31 | .. attribute:: Polygon.rectangle 32 | 33 | ``Boolean`` 34 | This geometry is a rectangle. 35 | 36 | 37 | 38 | Methods 39 | ------- 40 | 41 | Polygon geometries have the methods common to all :class:`geom.Geometry` 42 | subclasses. 43 | -------------------------------------------------------------------------------- /doc/api/index.rst: -------------------------------------------------------------------------------- 1 | .. _api: 2 | 3 | API Reference 4 | ============= 5 | 6 | Examples and reference documents for geoscript.js. 7 | 8 | Modules 9 | ------- 10 | 11 | .. toctree:: 12 | :glob: 13 | :maxdepth: 1 14 | 15 | geom 16 | feature 17 | filter 18 | proj 19 | index/* 20 | layer 21 | workspace 22 | raster 23 | style 24 | map 25 | process 26 | io/* 27 | 28 | 29 | .. toctree:: 30 | :hidden: 31 | 32 | object 33 | types -------------------------------------------------------------------------------- /doc/api/index/quadtree.rst: -------------------------------------------------------------------------------- 1 | :class:`index.Quadtree` 2 | ========================== 3 | 4 | .. class:: index.Quadtree() 5 | 6 | Create a Quadtree Spatial Index. 7 | 8 | 9 | Properties 10 | ---------- 11 | 12 | .. attribute:: size 13 | 14 | ``Int`` 15 | The number of items in the spatial index. 16 | 17 | 18 | Methods 19 | ------- 20 | 21 | .. function:: Quadtree.query 22 | 23 | :arg bounds: :class:`geom.Bounds` The Bounds. 24 | :returns: :class:`Array` 25 | 26 | Query the spatial index by Bounds. 27 | 28 | .. function:: Quadtree.queryAll 29 | 30 | :returns: :class:`Array` 31 | 32 | Get all item in the spatial index. 33 | 34 | .. function:: Quadtree.insert 35 | 36 | :arg bounds: :class:`geom.Bounds` The Bounds. 37 | :arg item: :class:`Object` The value. 38 | :returns: :class:`boolean` Whether an item was removed or not 39 | 40 | Remove an item from the spatial index 41 | 42 | .. function:: Quadtree.remove 43 | 44 | :arg bounds: :class:`geom.Bounds` The Bounds. 45 | :arg item: :class:`Object` The value. 46 | :returns: :class:`boolean` Whether an item was removed or not 47 | 48 | Remove an item from the spatial index 49 | 50 | Get all item in the spatial index. 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /doc/api/index/strtree.rst: -------------------------------------------------------------------------------- 1 | :class:`index.STRtree` 2 | ========================== 3 | 4 | .. class:: index.STRtree() 5 | 6 | Create a STRtree Spatial Index. 7 | 8 | 9 | Properties 10 | ---------- 11 | 12 | .. attribute:: size 13 | 14 | ``Int`` 15 | The number of items in the spatial index. 16 | 17 | 18 | Methods 19 | ------- 20 | 21 | .. function:: STRtree.query 22 | 23 | :arg bounds: :class:`geom.Bounds` The Bounds. 24 | :returns: :class:`Array` 25 | 26 | Query the spatial index by Bounds. 27 | 28 | .. function:: STRtree.insert 29 | 30 | :arg bounds: :class:`geom.Bounds` The Bounds. 31 | :arg item: :class:`Object` The value. 32 | :returns: :class:`boolean` Whether an item was removed or not 33 | 34 | Remove an item from the spatial index 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /doc/api/io/json.rst: -------------------------------------------------------------------------------- 1 | The io/json module 2 | ================== 3 | 4 | .. code-block:: javascript 5 | 6 | >> var parser = require("geoscript/io/json"); 7 | 8 | Methods 9 | ------- 10 | 11 | 12 | .. function:: read 13 | 14 | :arg wkt: ``String`` The GeoJSON representation of a geometry or feature. 15 | :returns: :class:`Object` The deserialized version of the input string (one 16 | of :class:`geom.Geometry`, :class:`geom.GeometryCollection`, 17 | :class:`feature.Feature`, or :class:`feature.FeatureCollection`). 18 | 19 | Create a geometry, a feature, or a collection of either from a JSON string. 20 | 21 | Example of deserializing a geometry: 22 | 23 | .. code-block:: javascript 24 | 25 | >> var LineString = require("geoscript/geom").LineString; 26 | >> var line = parser.read('{"type": "LineString", "coordinates": [[1,2], [3,4]]}'); 27 | >> line instanceof LineString 28 | true 29 | >> line 30 | 31 | 32 | Example of deserializing a feature: 33 | 34 | .. code-block:: javascript 35 | 36 | >> var Feature = require("geoscript/feature").Feature; 37 | >> var str = '{"type": "Feature", "properties": {"foo": "bar"}, "geometry": {"type": "Point", "coordinates": [1, 2]}}' 38 | >> var feature = parser.read(str) 39 | >> feature instanceof Feature 40 | true 41 | >> feature 42 | > 43 | 44 | 45 | .. function:: write 46 | 47 | :arg obj: :class:`Object` Input object (one of :class:`geom.Geometry`, 48 | :class:`geom.GeometryCollection`, :class:`feature.Feature`, 49 | or :class:`feature.FeatureCollection`). 50 | :returns: ``String`` The GeoJSON representation of the input object. 51 | 52 | Generate a GeoJSON string from a geometry, a feature, or a collection of 53 | either. 54 | 55 | Example of serializing a geometry: 56 | 57 | .. code-block:: javascript 58 | 59 | >> var Point = require("geoscript/geom").Point; 60 | >> var str = parser.write(Point([1, 2])); 61 | >> str 62 | {"type":"Point","coordinates":[1,2]} 63 | 64 | -------------------------------------------------------------------------------- /doc/api/io/wkt.rst: -------------------------------------------------------------------------------- 1 | The io/wkt module 2 | ================= 3 | 4 | .. code-block:: javascript 5 | 6 | >> var parser = require("geoscript/io/wkt"); 7 | 8 | Methods 9 | ------- 10 | 11 | 12 | .. function:: read 13 | 14 | :arg wkt: ``String`` The Well-Known Text representation of a geometry. 15 | :returns: :class:`geom.Geometry` 16 | 17 | Create a geometry from WKT. The specific geometry type depends on the 18 | given WKT. 19 | 20 | Example use: 21 | 22 | .. code-block:: javascript 23 | 24 | >> var parser = require("geoscript/io/wkt"); 25 | >> var Point = require("geoscript/geom").Point; 26 | >> var point = parser.read("POINT(1 2)"); 27 | >> point instanceof Point 28 | true 29 | 30 | .. function:: write 31 | 32 | :arg geometry: :class:`geom.Geometry` A geometry. 33 | :returns: ``String`` The Well-Known Text representation of a geometry. 34 | 35 | Generate a Well-Known Text string from a geometry. 36 | 37 | Example use: 38 | 39 | .. code-block:: javascript 40 | 41 | >> var parser = require("geoscript/io/wkt"); 42 | >> var Point = require("geoscript/geom").Point; 43 | >> var str = parser.write(Point([1, 2])); 44 | >> str 45 | POINT (1 2) 46 | 47 | -------------------------------------------------------------------------------- /doc/api/map.rst: -------------------------------------------------------------------------------- 1 | The map module 2 | ~~~~~~~~~~~~~~ 3 | 4 | The :doc:`map ` module provides map rendering functionality. 5 | 6 | .. code-block:: javascript 7 | 8 | >> var Map = require("geoscript/map").Map; 9 | 10 | 11 | :class:`map.Map` 12 | ================ 13 | 14 | .. class:: map.Map(config) 15 | 16 | :arg config: ``Object`` Configuration object. 17 | 18 | Create a rule for rendering features. 19 | 20 | 21 | 22 | Config Properties 23 | ----------------- 24 | 25 | .. describe:: layers 26 | 27 | ``Array`` 28 | List of :class:`layer.Layer` objects making up this map. 29 | 30 | .. describe:: projection 31 | 32 | :class:`proj.Projection` 33 | Optional projection for the map. If set, calls to :func:`render` will 34 | result in a map image in this projection. If not set, the projection 35 | of the first layer will be used. 36 | 37 | 38 | Properties 39 | ---------- 40 | 41 | .. attribute:: Map.projection 42 | 43 | :class:`proj.Projection` 44 | The projection for rendering layers. 45 | 46 | 47 | Methods 48 | ------- 49 | 50 | .. function:: Map.add 51 | 52 | :arg layer: :class:`layer.Layer` 53 | 54 | Add a layer to the map. 55 | 56 | .. function:: Map.render 57 | 58 | Render the map's collection of layers as an image. 59 | 60 | TODO: document render options 61 | 62 | -------------------------------------------------------------------------------- /doc/api/object.rst: -------------------------------------------------------------------------------- 1 | :class:`GeoObject` 2 | ================== 3 | 4 | Properties 5 | ---------- 6 | 7 | .. attribute:: GeoObject.json 8 | 9 | ``String`` 10 | The JSON representation of the object. 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/api/proj.rst: -------------------------------------------------------------------------------- 1 | The proj module 2 | =============== 3 | 4 | The :doc:`proj ` module exports a Projection constructor and methods for 5 | transforming geometries between coordinate reference systems. 6 | 7 | .. code-block:: javascript 8 | 9 | >> var proj = require("geoscript/proj"); 10 | 11 | 12 | Constructors 13 | ------------ 14 | 15 | .. toctree:: 16 | :glob: 17 | :maxdepth: 1 18 | 19 | proj/* 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /doc/api/proj/projection.rst: -------------------------------------------------------------------------------- 1 | :class:`proj.Projection` 2 | ======================== 3 | 4 | .. class:: proj.Projection(id) 5 | 6 | :arg id: ``String`` Coordinate reference system identifier or 7 | well-known text for the projection. 8 | 9 | Create a new projection object. 10 | 11 | Example Use 12 | ----------- 13 | 14 | Sample code to create a new projection object: 15 | 16 | .. code-block:: javascript 17 | 18 | >> var Projection = require("geoscript/proj").Projection; 19 | >> var wgs84 = Projection("EPSG:4326") 20 | >> wgs84 21 | 22 | 23 | >> wgs84.wkt 24 | GEOGCS["WGS 84", 25 | DATUM["World Geodetic System 1984", 26 | SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], 27 | AUTHORITY["EPSG","6326"]], 28 | PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], 29 | UNIT["degree", 0.017453292519943295], 30 | AXIS["Geodetic longitude", EAST], 31 | AXIS["Geodetic latitude", NORTH], 32 | AUTHORITY["EPSG","4326"]] 33 | 34 | 35 | Properties 36 | ---------- 37 | 38 | .. attribute:: Projection.id 39 | 40 | ``String`` 41 | The coordinate reference system identifier. 42 | 43 | .. attribute:: Projection.wkt 44 | 45 | ``String`` 46 | The well-known text representation of the coordinate reference system. 47 | 48 | 49 | Methods 50 | ------- 51 | 52 | .. function:: Projection.equals 53 | 54 | :arg projection: :class:`proj.Projection` 55 | :returns: ``Boolean`` The two projections are equivalent. 56 | 57 | Determine if this projection is equivalent to the given projection. 58 | -------------------------------------------------------------------------------- /doc/api/style.rst: -------------------------------------------------------------------------------- 1 | The style module 2 | ================ 3 | 4 | The :doc:`style 14 | 15 | 16 |
17 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /lib/ringo-core.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geoscript/geoscript-js/baf658cb6880aa70e419a58e41824a2facdec294/lib/ringo-core.jar -------------------------------------------------------------------------------- /lib/ringo-modules.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geoscript/geoscript-js/baf658cb6880aa70e419a58e41824a2facdec294/lib/ringo-modules.jar -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | ## The MIT License (MIT) 2 | 3 | Copyright (c) 2009-2013 Tim Schaub 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "geoscript", 3 | "description": "Library for geospatial data access, manipulation, and rendering.", 4 | "author": "Tim Schaub", 5 | "dependencies": [], 6 | "contributors": [], 7 | "jars": "jars", 8 | "main": "lib/geoscript" 9 | } -------------------------------------------------------------------------------- /src/main/assembly/all.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | dist 4 | 5 | dir 6 | zip 7 | 8 | 9 | 10 | 11 | README* 12 | license* 13 | 14 | 15 | 16 | bin 17 | 0755 18 | 19 | geoscript-js-dev 20 | 21 | 22 | 23 | src/main/resources/org/geoscript/js/lib 24 | /lib 25 | 26 | 27 | ${project.build.directory}/jars 28 | /jars 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/GeoScriptModules.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js; 2 | 3 | import java.net.URISyntaxException; 4 | import java.net.URL; 5 | 6 | public class GeoScriptModules { 7 | 8 | public static String getModulePath() { 9 | String modulePath = System.getProperty("geoscript.modules"); 10 | if (modulePath == null) { 11 | URL moduleUrl = GeoScriptModules.class.getResource("lib"); 12 | try { 13 | modulePath = moduleUrl.toURI().toString(); 14 | } catch (URISyntaxException e) { 15 | throw new RuntimeException("Trouble evaluating GeoScript module path.", e); 16 | } 17 | } 18 | return modulePath; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/feature/Iterator.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js.feature; 2 | 3 | import org.geoscript.js.GeoObject; 4 | import org.geotools.data.simple.SimpleFeatureIterator; 5 | import org.mozilla.javascript.Context; 6 | import org.mozilla.javascript.Function; 7 | import org.mozilla.javascript.JavaScriptException; 8 | import org.mozilla.javascript.NativeIterator; 9 | import org.mozilla.javascript.ScriptRuntime; 10 | import org.mozilla.javascript.Scriptable; 11 | import org.mozilla.javascript.annotations.JSConstructor; 12 | import org.mozilla.javascript.annotations.JSFunction; 13 | import org.opengis.feature.simple.SimpleFeature; 14 | 15 | public class Iterator extends GeoObject { 16 | 17 | /** serialVersionUID */ 18 | private static final long serialVersionUID = 123388411616403866L; 19 | 20 | SimpleFeatureIterator iterator; 21 | Scriptable layer; 22 | 23 | /** 24 | * Prototype constructor. 25 | */ 26 | public Iterator() { 27 | } 28 | 29 | public Iterator(Scriptable scope, SimpleFeatureIterator iterator) { 30 | this.iterator = iterator; 31 | setParentScope(scope); 32 | this.setPrototype(Module.getClassPrototype(Iterator.class)); 33 | } 34 | 35 | @JSConstructor 36 | public static Object constructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) { 37 | throw ScriptRuntime.constructError("Error", "Iterators are for internal use only"); 38 | } 39 | 40 | public void setLayer(Scriptable layer) { 41 | this.layer = layer; 42 | } 43 | 44 | @JSFunction 45 | public Boolean hasNext() { 46 | boolean has = iterator.hasNext(); 47 | if (!has) { 48 | close(); 49 | } 50 | return has; 51 | } 52 | 53 | @JSFunction 54 | public Feature next() { 55 | Feature feature = null; 56 | if (hasNext()) { 57 | SimpleFeature simpleFeature = iterator.next(); 58 | feature = new Feature(getParentScope(), simpleFeature); 59 | if (layer != null) { 60 | feature.setLayer(layer); 61 | } 62 | } else { 63 | throw new JavaScriptException( 64 | NativeIterator.getStopIterationObject(getParentScope()), null, 0); 65 | } 66 | return feature; 67 | } 68 | 69 | public void close() { 70 | try { 71 | iterator.close(); 72 | } catch (Exception e) { 73 | // pass 74 | } 75 | } 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/feature/Module.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js.feature; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.util.Arrays; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | 8 | import org.geoscript.js.GeoObject; 9 | import org.mozilla.javascript.Scriptable; 10 | import org.mozilla.javascript.ScriptableObject; 11 | 12 | public class Module { 13 | 14 | static HashMap prototypes; 15 | 16 | /** 17 | * Define all feature related constructors in the given module scope. If 18 | * the provided scope is not a "top level" scope, constructors will be 19 | * defined in the top level scope for the given scope. 20 | * @param scope 21 | * @throws IllegalAccessException 22 | * @throws InstantiationException 23 | * @throws InvocationTargetException 24 | */ 25 | public static void init(Scriptable scope) throws IllegalAccessException, InstantiationException, InvocationTargetException { 26 | scope = ScriptableObject.getTopLevelScope(scope); 27 | 28 | @SuppressWarnings("unchecked") 29 | List> classes = Arrays.asList( 30 | Field.class, Schema.class, Feature.class, FeatureCollection.class, Iterator.class); 31 | 32 | prototypes = new HashMap(); 33 | for (Class cls : classes) { 34 | String name = ScriptableObject.defineClass(scope, cls, false, true); 35 | Scriptable prototype = ScriptableObject.getClassPrototype(scope, name); 36 | prototypes.put(name, prototype); 37 | } 38 | } 39 | 40 | protected static Scriptable getClassPrototype(Class cls) { 41 | String name = cls.getName(); 42 | if (prototypes == null || !prototypes.containsKey(name)) { 43 | throw new RuntimeException( 44 | "Attempt to access prototype before requiring module: " + name); 45 | } 46 | return prototypes.get(name); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/filter/Module.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js.filter; 2 | 3 | import org.geoscript.js.GeoObject; 4 | import org.mozilla.javascript.Scriptable; 5 | import org.mozilla.javascript.ScriptableObject; 6 | 7 | import java.lang.reflect.InvocationTargetException; 8 | import java.util.Arrays; 9 | import java.util.HashMap; 10 | import java.util.List; 11 | 12 | public class Module { 13 | 14 | static HashMap prototypes; 15 | 16 | /** 17 | * Define all filter constructors in the given module scope. If the 18 | * provided scope is not a "top level" scope, constructors will be defined 19 | * in the top level scope for the given scope. 20 | * @param scope 21 | * @throws IllegalAccessException 22 | * @throws InstantiationException 23 | * @throws java.lang.reflect.InvocationTargetException 24 | */ 25 | public static void init(Scriptable scope) throws IllegalAccessException, InstantiationException, InvocationTargetException { 26 | 27 | scope = ScriptableObject.getTopLevelScope(scope); 28 | 29 | @SuppressWarnings("unchecked") 30 | List> classes = Arrays.asList(Filter.class, Expression.class); 31 | 32 | prototypes = new HashMap(); 33 | for (Class cls : classes) { 34 | String name = ScriptableObject.defineClass(scope, cls, false, true); 35 | Scriptable prototype = ScriptableObject.getClassPrototype(scope, name); 36 | prototypes.put(name, prototype); 37 | } 38 | 39 | } 40 | 41 | protected static Scriptable getClassPrototype(Class cls) { 42 | String name = cls.getName(); 43 | if (prototypes == null || !prototypes.containsKey(name)) { 44 | throw new RuntimeException( 45 | "Attempt to access prototype before requiring module: " + name); 46 | } 47 | return prototypes.get(name); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/geom/GeometryWrapper.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js.geom; 2 | 3 | import org.mozilla.javascript.Scriptable; 4 | import org.mozilla.javascript.ScriptableObject; 5 | 6 | public class GeometryWrapper { 7 | 8 | public static ScriptableObject wrap(Scriptable scope, org.locationtech.jts.geom.Geometry geometry) { 9 | ScriptableObject wrapped = null; 10 | try { 11 | if (geometry instanceof org.locationtech.jts.geom.Point) { 12 | wrapped = new Point(scope, (org.locationtech.jts.geom.Point) geometry); 13 | } else if (geometry instanceof org.geotools.geometry.jts.CompoundCurve) { 14 | wrapped = new CompoundCurve(scope, (org.geotools.geometry.jts.CompoundCurve) geometry); 15 | } else if (geometry instanceof org.geotools.geometry.jts.CircularString) { 16 | wrapped = new CircularString(scope, (org.geotools.geometry.jts.CircularString) geometry); 17 | } else if (geometry instanceof org.locationtech.jts.geom.LineString) { 18 | wrapped = new LineString(scope, (org.locationtech.jts.geom.LineString) geometry); 19 | } else if (geometry instanceof org.locationtech.jts.geom.Polygon) { 20 | wrapped = new Polygon(scope, (org.locationtech.jts.geom.Polygon) geometry); 21 | } else if (geometry instanceof org.locationtech.jts.geom.MultiPoint) { 22 | wrapped = new MultiPoint(scope, (org.locationtech.jts.geom.MultiPoint) geometry); 23 | } else if (geometry instanceof org.locationtech.jts.geom.MultiLineString) { 24 | wrapped = new MultiLineString(scope, (org.locationtech.jts.geom.MultiLineString) geometry); 25 | } else if (geometry instanceof org.locationtech.jts.geom.MultiPolygon) { 26 | wrapped = new MultiPolygon(scope, (org.locationtech.jts.geom.MultiPolygon) geometry); 27 | } else if (geometry instanceof org.locationtech.jts.geom.GeometryCollection) { 28 | wrapped = new GeometryCollection(scope, (org.locationtech.jts.geom.GeometryCollection) geometry); 29 | } 30 | } catch (Exception e) { 31 | throw new RuntimeException("Trouble wrapping geometry", e); 32 | } 33 | return wrapped; 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/geom/Module.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js.geom; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.util.Arrays; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | 8 | import org.geoscript.js.GeoObject; 9 | import org.mozilla.javascript.Scriptable; 10 | import org.mozilla.javascript.ScriptableObject; 11 | 12 | public class Module { 13 | 14 | static HashMap prototypes; 15 | 16 | /** 17 | * Define all geometry constructors in the given module scope. If the 18 | * provided scope is not a "top level" scope, constructors will be defined 19 | * in the top level scope for the given scope. 20 | * @param scope 21 | * @throws IllegalAccessException 22 | * @throws InstantiationException 23 | * @throws InvocationTargetException 24 | */ 25 | public static void init(Scriptable scope) throws IllegalAccessException, InstantiationException, InvocationTargetException { 26 | 27 | scope = ScriptableObject.getTopLevelScope(scope); 28 | 29 | @SuppressWarnings("unchecked") 30 | List> classes = Arrays.asList( 31 | Geometry.class, Point.class, LineString.class, 32 | Polygon.class, GeometryCollection.class, MultiPoint.class, 33 | MultiLineString.class, MultiPolygon.class, Bounds.class, 34 | CircularString.class, CompoundCurve.class); 35 | 36 | prototypes = new HashMap(); 37 | for (Class cls : classes) { 38 | String name = ScriptableObject.defineClass(scope, cls, false, true); 39 | Scriptable prototype = ScriptableObject.getClassPrototype(scope, name); 40 | prototypes.put(name, prototype); 41 | } 42 | 43 | } 44 | 45 | protected static Scriptable getClassPrototype(Class cls) { 46 | String name = cls.getName(); 47 | if (prototypes == null || !prototypes.containsKey(name)) { 48 | throw new RuntimeException( 49 | "Attempt to access prototype before requiring module: " + name); 50 | } 51 | return prototypes.get(name); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/index/Module.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js.index; 2 | 3 | import org.geoscript.js.GeoObject; 4 | import org.geoscript.js.index.*; 5 | import org.mozilla.javascript.Scriptable; 6 | import org.mozilla.javascript.ScriptableObject; 7 | 8 | import java.lang.reflect.InvocationTargetException; 9 | import java.util.Arrays; 10 | import java.util.HashMap; 11 | import java.util.List; 12 | 13 | public class Module { 14 | 15 | static HashMap prototypes; 16 | 17 | /** 18 | * Define all geometry constructors in the given module scope. If the 19 | * provided scope is not a "top level" scope, constructors will be defined 20 | * in the top level scope for the given scope. 21 | * @param scope 22 | * @throws IllegalAccessException 23 | * @throws InstantiationException 24 | * @throws InvocationTargetException 25 | */ 26 | public static void init(Scriptable scope) throws IllegalAccessException, InstantiationException, InvocationTargetException { 27 | 28 | scope = ScriptableObject.getTopLevelScope(scope); 29 | 30 | @SuppressWarnings("unchecked") 31 | List> classes = Arrays.asList(Quadtree.class, STRtree.class); 32 | 33 | prototypes = new HashMap(); 34 | for (Class cls : classes) { 35 | String name = ScriptableObject.defineClass(scope, cls, false, true); 36 | Scriptable prototype = ScriptableObject.getClassPrototype(scope, name); 37 | prototypes.put(name, prototype); 38 | } 39 | 40 | } 41 | 42 | protected static Scriptable getClassPrototype(Class cls) { 43 | String name = cls.getName(); 44 | if (prototypes == null || !prototypes.containsKey(name)) { 45 | throw new RuntimeException( 46 | "Attempt to access prototype before requiring module: " + name); 47 | } 48 | return prototypes.get(name); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/index/Quadtree.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js.index; 2 | 3 | import org.geoscript.js.geom.Bounds; 4 | import org.mozilla.javascript.Context; 5 | import org.mozilla.javascript.Function; 6 | import org.mozilla.javascript.Scriptable; 7 | import org.mozilla.javascript.annotations.JSConstructor; 8 | import org.mozilla.javascript.annotations.JSFunction; 9 | import org.mozilla.javascript.annotations.JSGetter; 10 | 11 | public class Quadtree extends SpatialIndex { 12 | 13 | public Quadtree() { 14 | super(new org.locationtech.jts.index.quadtree.Quadtree()); 15 | } 16 | 17 | public Quadtree(Scriptable scope) { 18 | this(); 19 | this.setParentScope(scope); 20 | this.setPrototype(Module.getClassPrototype(Quadtree.class)); 21 | } 22 | 23 | 24 | @JSFunction 25 | public void insert(Bounds bounds, Object item) { 26 | this.index.insert(bounds.unwrap(), item); 27 | } 28 | 29 | @JSFunction 30 | public Object query(Bounds bounds) { 31 | return javaToJS(this.index.query(bounds.unwrap()), getParentScope()); 32 | } 33 | 34 | @JSGetter 35 | public int getSize() { 36 | return ((org.locationtech.jts.index.quadtree.Quadtree)this.index).size(); 37 | } 38 | 39 | @JSFunction 40 | public Object queryAll() { 41 | return javaToJS(((org.locationtech.jts.index.quadtree.Quadtree)this.index).queryAll(), getParentScope()); 42 | } 43 | 44 | @JSFunction 45 | public boolean remove(Bounds bounds, Object item) { 46 | return this.index.remove(bounds.unwrap(), item); 47 | } 48 | 49 | /** 50 | * JavaScript constructor. 51 | * @param cx 52 | * @param args 53 | * @param ctorObj 54 | * @param isNewExpr 55 | * @return 56 | */ 57 | @JSConstructor 58 | public static Object constructor(Context cx, Object[] args, Function ctorObj, boolean isNewExpr) { 59 | if (isNewExpr) { 60 | return new Quadtree(); 61 | } else { 62 | return new Quadtree(ctorObj.getParentScope()); 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/index/STRtree.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js.index; 2 | 3 | import org.geoscript.js.geom.Bounds; 4 | import org.mozilla.javascript.Context; 5 | import org.mozilla.javascript.Function; 6 | import org.mozilla.javascript.Scriptable; 7 | import org.mozilla.javascript.annotations.JSConstructor; 8 | import org.mozilla.javascript.annotations.JSFunction; 9 | import org.mozilla.javascript.annotations.JSGetter; 10 | 11 | import java.util.List; 12 | 13 | public class STRtree extends SpatialIndex { 14 | 15 | public STRtree() { 16 | super(new org.locationtech.jts.index.strtree.STRtree()); 17 | } 18 | 19 | public STRtree(Scriptable scope) { 20 | this(); 21 | this.setParentScope(scope); 22 | this.setPrototype(Module.getClassPrototype(STRtree.class)); 23 | } 24 | 25 | @JSFunction 26 | public void insert(Bounds bounds, Object item) { 27 | this.index.insert(bounds.unwrap(), item); 28 | } 29 | 30 | @JSFunction 31 | public List query(Bounds bounds) { 32 | return this.index.query(bounds.unwrap()); 33 | } 34 | 35 | @JSGetter 36 | public int getSize() { 37 | return ((org.locationtech.jts.index.strtree.STRtree)this.index).size(); 38 | } 39 | 40 | /** 41 | * JavaScript constructor. 42 | * @param cx 43 | * @param args 44 | * @param ctorObj 45 | * @param isNewExpr 46 | * @return 47 | */ 48 | @JSConstructor 49 | public static Object constructor(Context cx, Object[] args, Function ctorObj, boolean isNewExpr) { 50 | if (isNewExpr) { 51 | return new STRtree(); 52 | } else { 53 | return new STRtree(ctorObj.getParentScope()); 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/index/SpatialIndex.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js.index; 2 | 3 | import org.geoscript.js.GeoObject; 4 | import org.mozilla.javascript.Wrapper; 5 | 6 | public abstract class SpatialIndex extends GeoObject implements Wrapper { 7 | 8 | protected final org.locationtech.jts.index.SpatialIndex index; 9 | 10 | public SpatialIndex(org.locationtech.jts.index.SpatialIndex index) { 11 | this.index = index; 12 | } 13 | 14 | @Override 15 | public Object unwrap() { 16 | return index; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/process/MetaProcess.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js.process; 2 | 3 | import java.util.Map; 4 | 5 | import org.geotools.data.Parameter; 6 | import org.geotools.process.Process; 7 | import org.geotools.process.ProcessException; 8 | import org.opengis.util.ProgressListener; 9 | 10 | public class MetaProcess implements Process { 11 | 12 | private org.geotools.process.Process process; 13 | String title; 14 | String description; 15 | Map> inputs; 16 | Map> outputs; 17 | 18 | MetaProcess(org.geotools.process.Process process, String title, 19 | String description, Map> inputs, 20 | Map> outputs) { 21 | this.process = process; 22 | this.title = title; 23 | this.description = description; 24 | this.inputs = inputs; 25 | this.outputs = outputs; 26 | } 27 | 28 | public String getTitle() { 29 | return title; 30 | } 31 | 32 | public String getDescription() { 33 | return description; 34 | } 35 | 36 | public Map> getInputs() { 37 | return inputs; 38 | } 39 | 40 | public Map> getOutputs() { 41 | return outputs; 42 | } 43 | 44 | public Map execute(Map input, 45 | ProgressListener monitor) throws ProcessException { 46 | return process.execute(input, monitor); 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/process/Module.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js.process; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.util.HashMap; 5 | 6 | import org.geoscript.js.GeoObject; 7 | import org.mozilla.javascript.Scriptable; 8 | import org.mozilla.javascript.ScriptableObject; 9 | 10 | public class Module { 11 | 12 | static HashMap prototypes; 13 | 14 | /** 15 | * Define all feature related constructors in the given module scope. If 16 | * the provided scope is not a "top level" scope, constructors will be 17 | * defined in the top level scope for the given scope. 18 | * @param scope 19 | * @throws IllegalAccessException 20 | * @throws InstantiationException 21 | * @throws InvocationTargetException 22 | */ 23 | public static void init(Scriptable scope) throws IllegalAccessException, InstantiationException, InvocationTargetException { 24 | scope = ScriptableObject.getTopLevelScope(scope); 25 | 26 | String name = ScriptableObject.defineClass(scope, Process.class, false, true); 27 | prototypes = new HashMap(); 28 | prototypes.put(name, ScriptableObject.getClassPrototype(scope, name)); 29 | 30 | } 31 | 32 | protected static Scriptable getClassPrototype(Class cls) { 33 | String name = cls.getName(); 34 | if (prototypes == null || !prototypes.containsKey(name)) { 35 | throw new RuntimeException( 36 | "Attempt to access prototype before requiring module: " + name); 37 | } 38 | return prototypes.get(name); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/proj/Module.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js.proj; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.util.HashMap; 5 | 6 | import org.geoscript.js.GeoObject; 7 | import org.mozilla.javascript.Scriptable; 8 | import org.mozilla.javascript.ScriptableObject; 9 | 10 | public class Module { 11 | 12 | static HashMap prototypes; 13 | 14 | /** 15 | * Define all proj constructors in the given module scope. If the 16 | * provided scope is not a "top level" scope, constructors will be defined 17 | * in the top level scope for the given scope. 18 | * @param scope 19 | * @throws IllegalAccessException 20 | * @throws InstantiationException 21 | * @throws InvocationTargetException 22 | */ 23 | public static void init(Scriptable scope) throws IllegalAccessException, InstantiationException, InvocationTargetException { 24 | 25 | scope = ScriptableObject.getTopLevelScope(scope); 26 | 27 | String name = ScriptableObject.defineClass(scope, Projection.class, false, true); 28 | prototypes = new HashMap(); 29 | prototypes.put(name, ScriptableObject.getClassPrototype(scope, name)); 30 | } 31 | 32 | protected static Scriptable getClassPrototype(Class cls) { 33 | String name = cls.getName(); 34 | if (prototypes == null || !prototypes.containsKey(name)) { 35 | throw new RuntimeException( 36 | "Attempt to access prototype before requiring module: " + name); 37 | } 38 | return prototypes.get(name); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/geoscript/js/raster/Module.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js.raster; 2 | 3 | import org.geoscript.js.GeoObject; 4 | import org.mozilla.javascript.Scriptable; 5 | import org.mozilla.javascript.ScriptableObject; 6 | 7 | import java.lang.reflect.InvocationTargetException; 8 | import java.util.Arrays; 9 | import java.util.HashMap; 10 | import java.util.List; 11 | 12 | public class Module { 13 | 14 | static HashMap prototypes; 15 | 16 | /** 17 | * Define all geometry constructors in the given module scope. If the 18 | * provided scope is not a "top level" scope, constructors will be defined 19 | * in the top level scope for the given scope. 20 | * @param scope 21 | * @throws IllegalAccessException 22 | * @throws InstantiationException 23 | * @throws InvocationTargetException 24 | */ 25 | public static void init(Scriptable scope) throws IllegalAccessException, InstantiationException, InvocationTargetException { 26 | 27 | scope = ScriptableObject.getTopLevelScope(scope); 28 | 29 | @SuppressWarnings("unchecked") 30 | List> classes = Arrays.asList(Band.class, Raster.class, Format.class); 31 | 32 | prototypes = new HashMap(); 33 | for (Class cls : classes) { 34 | String name = ScriptableObject.defineClass(scope, cls, false, true); 35 | Scriptable prototype = ScriptableObject.getClassPrototype(scope, name); 36 | prototypes.put(name, prototype); 37 | } 38 | 39 | } 40 | 41 | protected static Scriptable getClassPrototype(Class cls) { 42 | String name = cls.getName(); 43 | if (prototypes == null || !prototypes.containsKey(name)) { 44 | throw new RuntimeException( 45 | "Attempt to access prototype before requiring module: " + name); 46 | } 47 | return prototypes.get(name); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/resources/Messages.properties: -------------------------------------------------------------------------------- 1 | fileNotFound = File not found: {0} 2 | troubleReadingFile = Unable to read file: {0} 3 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript.js: -------------------------------------------------------------------------------- 1 | exports.geom = require("./geoscript/geom"); 2 | exports.feature = require("./geoscript/feature"); 3 | exports.filter = require("./geoscript/filter"); 4 | exports.proj = require("./geoscript/proj"); 5 | exports.layer = require("./geoscript/layer"); 6 | exports.workspace = require("./geoscript/workspace"); 7 | exports.viewer = require("./geoscript/viewer"); 8 | exports.style = require("./geoscript/style"); 9 | exports.map = require("./geoscript/map"); 10 | exports.index = require("./geoscript/index"); 11 | exports.raster = require("./geoscript/raster"); 12 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/factory.js: -------------------------------------------------------------------------------- 1 | var UTIL = require("./util"); 2 | 3 | var Factory = UTIL.extend(Object, { 4 | 5 | constructor: function Factory(Type, config) { 6 | UTIL.apply(this, config); 7 | this.Type = Type; 8 | this.type = Type.prototype.constructor.name; 9 | }, 10 | 11 | handles: function(config) { 12 | return false; 13 | }, 14 | 15 | create: function(config) { 16 | return new this.Type(config); 17 | }, 18 | 19 | wraps: function(_obj) { 20 | return false; 21 | }, 22 | 23 | from_: function(_obj) { 24 | return this.Type.from_(_obj); 25 | } 26 | 27 | }); 28 | 29 | exports.Factory = Factory; 30 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/filter.js: -------------------------------------------------------------------------------- 1 | var FILTER_UTIL = require("./filter/util"); 2 | 3 | /** api: module = filter */ 4 | 5 | /** api: synopsis 6 | * Filter related functionality. 7 | */ 8 | 9 | /** api: summary 10 | * The :mod:`filter` module provides a constructor for Filter objects. 11 | * 12 | * .. code-block:: javascript 13 | * 14 | * js> var FILTER = require("geoscript/filter"); 15 | */ 16 | 17 | /** api: classes[] = filter */ 18 | var Filter = exports.Filter = require("./filter/filter").Filter; 19 | /** api: classes[] = expression */ 20 | exports.Expression = require("./filter/expression").Expression; 21 | exports.and = Filter.and; 22 | exports.or = Filter.or; 23 | exports.not = Filter.not; 24 | exports.fids = Filter.fids; 25 | 26 | /** private: method[where] 27 | * Convenience method for creating filters. May be called in one of three 28 | * forms: 29 | * 30 | * 1. where(cql) - This is equivalent to new Filter(cql). 31 | * 32 | * 2. where(fn, arg1, arg2, ...) - Constructs cql from string arguments 33 | * assuming the first argument is a function name. E.g. 34 | * where("WITHIN", "the_geom", "POINT(1 1)"). 35 | * 36 | * 3. where(args) - Constructs a cql string from an array of strings assuming 37 | * the first item in the array is a function name. E.g. 38 | * where(["WITHIN", "the_geom", "POINT(1 1)"]). 39 | */ 40 | var where = exports.where = function() { 41 | var cql; 42 | if (arguments.length === 1 && typeof arguments[0] === "string") { 43 | cql = arguments[0]; 44 | } else { 45 | var args; 46 | if (arguments.length > 1) { 47 | args = Array.slice(arguments); 48 | } else { 49 | // assume an array is given for first arg 50 | args = arguments[0]; 51 | } 52 | cql = args[0] + "(" + args.slice(1).join(",") + ")"; 53 | } 54 | return new Filter(cql); 55 | }; 56 | 57 | /** private: method[create] 58 | * :arg config: ``Object`` Configuration object. 59 | * :returns: :class:`filter.Filter` 60 | * 61 | * Create a filter given a configuration object. 62 | */ 63 | exports.create = FILTER_UTIL.create; 64 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/filter/expression.js: -------------------------------------------------------------------------------- 1 | /** api: (define) 2 | * module = filter 3 | * class = Expression 4 | */ 5 | Packages.org.geoscript.js.filter.Module.init(this); 6 | var Expression = exports.Expression = this["org.geoscript.js.filter.Expression"]; 7 | 8 | /** api: constructor 9 | * .. class:: Expression 10 | * 11 | * :arg text: ``String`` The expression text. 12 | * 13 | * Expression class for generating values from features. 14 | */ 15 | 16 | 17 | /** api: property[literal] 18 | * ``Boolean`` 19 | * This expression is just a literal value. 20 | */ -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/filter/util.js: -------------------------------------------------------------------------------- 1 | var Registry = require("../registry").Registry; 2 | 3 | var registry = new Registry(); 4 | 5 | /** private: method[create] 6 | * :arg config: ``Object`` Configuration object. 7 | * :returns: :class:`filter.Filter` 8 | * 9 | * Create a filter given a configuration object. 10 | */ 11 | exports.create = registry.create; 12 | 13 | /** private: method[register] */ 14 | exports.register = registry.register; 15 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/geom/io/json.js: -------------------------------------------------------------------------------- 1 | /** api: module = geom/io/json */ 2 | 3 | /** api: synopsis 4 | * Reading and writing JSON. 5 | */ 6 | 7 | /** api: summary 8 | * The :mod:`geom/io/json` module exports functions to read and write 9 | * geometries. 10 | * 11 | * .. code-block:: javascript 12 | * 13 | * js> var json = require("geoscript/geom/io/json"); 14 | */ 15 | 16 | var UTIL = require("../../util"); 17 | var GEOM = require("../../geom"); 18 | 19 | /** api: method[read] 20 | * :arg str: ``String`` 21 | * :returns: :class:`geom.Geometry` 22 | * 23 | * Creates a geometry from a JSON string. See http://geojson.org/ for details 24 | * on the format. 25 | * 26 | * Example use: 27 | * 28 | * .. code-block:: javascript 29 | * 30 | * js> var json = require("geoscript/geom/io/json"); 31 | * js> var str = '{"type": "Point", "coordinates": [0, 1]}'; 32 | * js> var point = json.read(str); 33 | * js> point.x 34 | * 0 35 | * js> point.y 36 | * 1 37 | */ 38 | var read = function(str) { 39 | 40 | var obj = JSON.parse(str); 41 | if (!obj.type) { 42 | throw new Error("Invalid GeoJSON, no type member."); 43 | } 44 | 45 | var collection = obj.type === "GeometryCollection"; 46 | var configs; 47 | if (collection) { 48 | configs = obj.geometries; 49 | // TODO: deal with crs 50 | } else { 51 | configs = [obj]; 52 | } 53 | 54 | var num = configs.length; 55 | var geometries = new Array(num); 56 | for (var i=0; i var json = require("geoscript/geom/io/json"); 75 | * js> var Point = require("geoscript/geom").Point; 76 | * js> var point = new Point([0, 1]); 77 | * js> var str = json.write(point); 78 | * js> str 79 | * {"type": "Point", "coordinates": [0, 1]} 80 | */ 81 | var write = function(geometries) { 82 | 83 | var collection = true; 84 | if (!(UTIL.isArray(config))) { 85 | collection = false; 86 | geometries = [geometries]; 87 | } 88 | 89 | var num = geometries.length; 90 | var configs = new Array(num); 91 | for (var i=0; i 60) { 44 | str = str.substring(0, 60) + "..."; 45 | } 46 | if (draw !== false) { 47 | try { 48 | require("./viewer").drawIfBound(this); 49 | } catch (err) { 50 | // pass 51 | } 52 | } 53 | return "<" + this.constructor.name + (str ? " " + str : "") + ">"; 54 | } 55 | 56 | }); 57 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/process.js: -------------------------------------------------------------------------------- 1 | require("./feature"); // initialize all modules for values that may be wrapped 2 | 3 | Packages.org.geoscript.js.process.Module.init(this); 4 | 5 | /** api: module = process */ 6 | 7 | /** api: synopsis 8 | * Process related functionality. 9 | */ 10 | 11 | /** api: summary 12 | * The :mod:`process` module provides a constructor for Process objects. 13 | * 14 | * .. code-block:: javascript 15 | * 16 | * js> var PROCESS = require("geoscript/process"); 17 | */ 18 | 19 | 20 | /** api: class = Process */ 21 | var Process = exports.Process = this["org.geoscript.js.process.Process"]; 22 | 23 | 24 | /** api: config[title] 25 | * ``String`` 26 | * Title for the process. 27 | */ 28 | /** api: property[title] 29 | * ``String`` 30 | * Title for the process. 31 | */ 32 | 33 | /** api: config[description] 34 | * ``String`` 35 | * Full description of the process, including all input and output fields. 36 | */ 37 | /** api: property[description] 38 | * ``String`` 39 | * Full description of the process, including all input and output fields. 40 | */ 41 | 42 | 43 | /** api: config[inputs] 44 | * ``Object`` 45 | * Proces inputs. 46 | */ 47 | /** api: property[inputs] 48 | * ``Object`` 49 | * Proces inputs. 50 | */ 51 | 52 | 53 | /** api: config[outputs] 54 | * ``Object`` 55 | * Proces outputs. 56 | */ 57 | /** api: property[outputs] 58 | * ``Object`` 59 | * Proces outputs. 60 | */ 61 | 62 | /** api: config[run] 63 | * ``Function`` 64 | * The function to be executed when running the process. 65 | */ 66 | 67 | /** api: constructor 68 | * .. class:: Process 69 | * 70 | * :arg config: `Object` Process configuration. 71 | * 72 | */ 73 | 74 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/proj.js: -------------------------------------------------------------------------------- 1 | /** api: module = proj */ 2 | 3 | /** api: synopsis 4 | * Projection related functionality. 5 | */ 6 | 7 | /** api: summary 8 | * The :mod:`proj` module exports a Projection constructor and methods for 9 | * transforming geometries between coordinate reference systems. 10 | * 11 | * .. code-block:: javascript 12 | * 13 | * js> var PROJ = require("geoscript/proj"); 14 | */ 15 | 16 | /** api: classes[] = projection */ 17 | Packages.org.geoscript.js.proj.Module.init(this); 18 | var Projection = this["org.geoscript.js.proj.Projection"]; 19 | 20 | /** api: method[transform] 21 | * :arg geometry: :class:`geom.Geometry` 22 | * :arg from: :class:`proj.Projection` or ``String`` 23 | * :arg to: :class:`proj.Projection` or ``String`` 24 | * :returns: :class:`geom.Geometry` 25 | * 26 | * Tranform a geometry from one coordinate reference system to another. 27 | * Returns a new geometry. The ``from`` and ``to`` arguments can be 28 | * :class:`proj.Projection` instances or the string values used to construct 29 | * them. 30 | * 31 | * Example use: 32 | * 33 | * .. code-block:: javascript 34 | * 35 | * js> var GEOM = require("geoscript/geom"); 36 | * js> var p1 = new GEOM.Point([-111.0, 45.7]); 37 | * js> var p2 = PROJ.transform(p1, "epsg:4326", "epsg:26912"); 38 | * js> Math.floor(p2.x) 39 | * 499999 40 | * js> Math.floor(p2.y) 41 | * 5060716 42 | */ 43 | var transform = function(geometry, from, to) { 44 | if (!(from instanceof Projection)) { 45 | from = new Projection(from); 46 | } 47 | geometry.projection = from; 48 | return geometry.transform(to); 49 | }; 50 | 51 | exports.transform = transform; 52 | exports.Projection = Projection; 53 | 54 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/raster.js: -------------------------------------------------------------------------------- 1 | var Util = require("./util"); 2 | var Registry = require("./registry").Registry; 3 | var Factory = require("./factory").Factory; 4 | 5 | Packages.org.geoscript.js.raster.Module.init(this); 6 | exports.Band = this["org.geoscript.js.raster.Band"]; 7 | exports.Raster = this["org.geoscript.js.raster.Raster"]; 8 | exports.Format = this["org.geoscript.js.raster.Format"]; 9 | 10 | var registry = new Registry(); 11 | exports.create = registry.create; 12 | 13 | registry.register(new Factory(exports.Format, { 14 | handles: function(config) { 15 | return true; 16 | } 17 | })); 18 | 19 | registry.register(new Factory(exports.Raster, { 20 | handles: function(config) { 21 | return true; 22 | } 23 | })); 24 | 25 | registry.register(new Factory(exports.Band, { 26 | handles: function(config) { 27 | return true; 28 | } 29 | })); -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/registry.js: -------------------------------------------------------------------------------- 1 | var UTIL = require("./util"); 2 | 3 | var Registry = UTIL.extend(Object, { 4 | 5 | constructor: function Registry() { 6 | 7 | var factories = []; 8 | 9 | this.register = function(factory) { 10 | factories.push(factory); 11 | }; 12 | 13 | this.create = function(config) { 14 | if (!config) { 15 | config = {}; 16 | } 17 | var candidate, factory; 18 | for (var i=0, ii=factories.length; i var WORKSPACE = require("geoscript/workspace"); 14 | */ 15 | 16 | /** private: method[create] 17 | * :arg config: ``Object`` Configuration object. 18 | * :returns: :class:`Workspace` 19 | * 20 | * Create a workspace given a configuration object. 21 | */ 22 | exports.create = require("./workspace/util").create; 23 | 24 | /** private: classes[] = workspace */ 25 | exports.Workspace = require("./workspace/workspace").Workspace; 26 | 27 | /** api: classes[] = memory */ 28 | exports.Memory = require("./workspace/memory").Memory; 29 | 30 | /** api: classes[] = directory */ 31 | exports.Directory = require("./workspace/directory").Directory; 32 | 33 | /** api: classes[] = postgis */ 34 | exports.PostGIS = require("./workspace/postgis").PostGIS; 35 | 36 | /** api: classes[] = h2 */ 37 | exports.H2 = require("./workspace/h2").H2; 38 | 39 | /** api: classes[] = mysql */ 40 | exports.MySQL = require("./workspace/mysql").MySQL; 41 | 42 | /** api: classes[] = geopackage */ 43 | exports.GeoPackage = require("./workspace/geopackage").GeoPackage; 44 | 45 | /** api: classes[] = geobuf */ 46 | exports.Geobuf = require("./workspace/geobuf").Geobuf; 47 | 48 | /** api: classes[] = flatgeobuf */ 49 | exports.Flatgeobuf = require("./workspace/flatgeobuf").Flatgeobuf; 50 | 51 | /** private: classes[] = spatialite */ 52 | exports.SpatiaLite = require("./workspace/spatialite").SpatiaLite; 53 | 54 | /** api: property[memory] 55 | * :class:`Memory` 56 | * A memory workspace that will be used to collect all temporary layers 57 | * created without a specific workspace. 58 | */ 59 | exports.memory = new exports.Memory(); 60 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/workspace/flatgeobuf.js: -------------------------------------------------------------------------------- 1 | var register = require("./util").register; 2 | var Factory = require("../factory").Factory; 3 | var Workspace = require("./workspace").Workspace; 4 | var UTIL = require("../util"); 5 | 6 | var URLs = Packages.org.geotools.util.URLs; 7 | var FlatGeobufDataStoreFactory = Packages.org.geotools.data.flatgeobuf.FlatGeobufDataStoreFactory; 8 | 9 | /** private: (define) 10 | * module = workspace 11 | * class = Flatgeobuf 12 | */ 13 | 14 | var prepConfig = function(config) { 15 | if (config) { 16 | if (typeof config === "string") { 17 | config = {'url': config}; 18 | } 19 | if (!(typeof config.file === "string")) { 20 | throw "Flatgeobuf config must include file path."; 21 | } 22 | config = { 23 | 'url': String(URLs.fileToUrl(UTIL.toFile(config.file))) 24 | }; 25 | } 26 | return config; 27 | }; 28 | 29 | /** private: (extends) 30 | * workspace/workspace.js 31 | */ 32 | var Flatgeobuf = UTIL.extend(Workspace, { 33 | 34 | /** private: config[file] 35 | * ``String`` 36 | * Path to the file (required). 37 | */ 38 | 39 | /** private: constructor 40 | * .. class:: Flatgeobuf 41 | * 42 | * :arg config: ``Object`` Configuration object. 43 | * 44 | * Create a workspace from a Flatgeobuf directory. 45 | */ 46 | constructor: function Flatgeobuf(config) { 47 | Workspace.prototype.constructor.apply(this, [prepConfig(config)]); 48 | }, 49 | 50 | /** private: method[_create] 51 | * :arg config: ``Object`` 52 | * :returns: ``org.geotools.data.flatgeobuf.FlatgeobufDataStore`` 53 | * 54 | * Create the underlying store for the workspace. 55 | */ 56 | _create: function(config) { 57 | var factory = new FlatGeobufDataStoreFactory(); 58 | return factory.createDataStore(config); 59 | }, 60 | 61 | /** private: property[config] 62 | */ 63 | get config() { 64 | return { 65 | type: this.constructor.name, 66 | file: this.file 67 | }; 68 | } 69 | 70 | }); 71 | 72 | exports.Flatgeobuf = Flatgeobuf; 73 | 74 | // register a Flatgeobuf factory for the module 75 | register(new Factory(Flatgeobuf, { 76 | handles: function(config) { 77 | var capable = false; 78 | if (typeof config.type === "string" && config.type.toLowerCase() === "Flatgeobuf") { 79 | try { 80 | config = prepConfig(config); 81 | capable = true; 82 | } catch (err) { 83 | // pass 84 | } 85 | } 86 | return capable; 87 | } 88 | })); 89 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/workspace/geobuf.js: -------------------------------------------------------------------------------- 1 | var register = require("./util").register; 2 | var Factory = require("../factory").Factory; 3 | var Workspace = require("./workspace").Workspace; 4 | var UTIL = require("../util"); 5 | 6 | var GeobufDataStoreFactory = Packages.org.geotools.data.geobuf.GeobufDataStoreFactory; 7 | 8 | /** private: (define) 9 | * module = workspace 10 | * class = Geobuf 11 | */ 12 | 13 | var prepConfig = function(config) { 14 | if (config) { 15 | if (typeof config === "string") { 16 | config = {file: config}; 17 | } 18 | if (!(typeof config.file === "string")) { 19 | throw "Geobuf config must include file path."; 20 | } 21 | config = { 22 | file: String(config.file) 23 | }; 24 | } 25 | return config; 26 | }; 27 | 28 | /** private: (extends) 29 | * workspace/workspace.js 30 | */ 31 | var Geobuf = UTIL.extend(Workspace, { 32 | 33 | /** private: config[file] 34 | * ``String`` 35 | * Path to the directory (required). 36 | */ 37 | 38 | /** private: constructor 39 | * .. class:: Geobuf 40 | * 41 | * :arg config: ``Object`` Configuration object. 42 | * 43 | * Create a workspace from a Geobuf directory. 44 | */ 45 | constructor: function Geobuf(config) { 46 | Workspace.prototype.constructor.apply(this, [prepConfig(config)]); 47 | }, 48 | 49 | /** private: method[_create] 50 | * :arg config: ``Object`` 51 | * :returns: ``org.geotools.data.geobuf.GeobufDataStore`` 52 | * 53 | * Create the underlying store for the workspace. 54 | */ 55 | _create: function(config) { 56 | var factory = new GeobufDataStoreFactory(); 57 | return factory.createDataStore(config); 58 | }, 59 | 60 | /** private: property[config] 61 | */ 62 | get config() { 63 | return { 64 | type: this.constructor.name, 65 | file: this.file 66 | }; 67 | } 68 | 69 | }); 70 | 71 | exports.Geobuf = Geobuf; 72 | 73 | // register a Geobuf factory for the module 74 | register(new Factory(Geobuf, { 75 | handles: function(config) { 76 | var capable = false; 77 | if (typeof config.type === "string" && config.type.toLowerCase() === "Geobuf") { 78 | try { 79 | config = prepConfig(config); 80 | capable = true; 81 | } catch (err) { 82 | // pass 83 | } 84 | } 85 | return capable; 86 | } 87 | })); 88 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/workspace/geopackage.js: -------------------------------------------------------------------------------- 1 | var register = require("./util").register; 2 | var Factory = require("../factory").Factory; 3 | var Workspace = require("./workspace").Workspace; 4 | var UTIL = require("../util"); 5 | 6 | var GeoPkgDataStoreFactory = Packages.org.geotools.geopkg.GeoPkgDataStoreFactory; 7 | 8 | /** private: (define) 9 | * module = workspace 10 | * class = GeoPackage 11 | */ 12 | 13 | var prepConfig = function(config) { 14 | if (config) { 15 | if (typeof config === "string") { 16 | config = {database: config}; 17 | } 18 | if (!(typeof config.database === "string" || config.database instanceof file.Path)) { 19 | throw "GeoPackage config must include database path."; 20 | } 21 | config = { 22 | database: String(config.database) 23 | }; 24 | } 25 | return config; 26 | }; 27 | 28 | /** private: (extends) 29 | * workspace/workspace.js 30 | */ 31 | var GeoPackage = UTIL.extend(Workspace, { 32 | 33 | /** private: config[database] 34 | * ``String`` 35 | * Path to the database (required). 36 | */ 37 | 38 | /** private: constructor 39 | * .. class:: GeoPackage 40 | * 41 | * :arg config: ``Object`` Configuration object. 42 | * 43 | * Create a workspace from a GeoPackage enabled database. 44 | */ 45 | constructor: function GeoPackage(config) { 46 | Workspace.prototype.constructor.apply(this, [prepConfig(config)]); 47 | }, 48 | 49 | /** private: method[_create] 50 | * :arg config: ``Object`` 51 | * :returns: ``org.geotools.jdbc.JDBCDataStore`` 52 | * 53 | * Create the underlying store for the workspace. 54 | */ 55 | _create: function(config) { 56 | config.dbtype = "geopkg"; 57 | var factory = new GeoPkgDataStoreFactory(); 58 | return factory.createDataStore(config); 59 | }, 60 | 61 | /** private: property[config] 62 | */ 63 | get config() { 64 | return { 65 | type: this.constructor.name, 66 | database: this.database 67 | }; 68 | } 69 | 70 | }); 71 | 72 | exports.GeoPackage = GeoPackage; 73 | 74 | // register a geopackage factory for the module 75 | register(new Factory(GeoPackage, { 76 | handles: function(config) { 77 | var capable = false; 78 | if (typeof config.type === "string" && config.type.toLowerCase() === "geopackage") { 79 | try { 80 | config = prepConfig(config); 81 | capable = true; 82 | } catch (err) { 83 | // pass 84 | } 85 | } 86 | return capable; 87 | } 88 | })); 89 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/workspace/h2.js: -------------------------------------------------------------------------------- 1 | var register = require("./util").register; 2 | var Factory = require("../factory").Factory; 3 | var Workspace = require("./workspace").Workspace; 4 | var UTIL = require("../util"); 5 | var H2DataStoreFactory = Packages.org.geotools.data.h2.H2DataStoreFactory; 6 | 7 | /** api: (define) 8 | * module = workspace 9 | * class = H2 10 | */ 11 | 12 | var prepConfig = function(config) { 13 | if (config) { 14 | if (typeof config === "string") { 15 | config = {database: config}; 16 | } 17 | if (typeof config.database !== "string") { 18 | throw "H2 config must include database path."; 19 | } 20 | config = {database: String(config.database)}; 21 | } 22 | return config; 23 | }; 24 | 25 | /** api: (extends) 26 | * workspace/workspace.js 27 | */ 28 | var H2 = UTIL.extend(Workspace, { 29 | 30 | /** api: config[database] 31 | * ``String`` 32 | * Path to the database (required). 33 | */ 34 | 35 | /** api: constructor 36 | * .. class:: H2 37 | * 38 | * :arg config: ``Object`` Configuration object. 39 | * 40 | * Create a workspace from an H2 database. 41 | */ 42 | constructor: function H2(config) { 43 | Workspace.prototype.constructor.apply(this, [prepConfig(config)]); 44 | }, 45 | 46 | /** private: method[_create] 47 | * :arg config: ``Object`` 48 | * :returns: ``org.geotools.jdbc.JDBCDataStore`` 49 | * 50 | * Create the underlying store for the workspace. 51 | */ 52 | _create: function(config) { 53 | config.dbtype = "h2"; 54 | var factory = new H2DataStoreFactory(); 55 | return factory.createDataStore(config); 56 | }, 57 | 58 | /** private: property[config] 59 | */ 60 | get config() { 61 | return { 62 | type: this.constructor.name, 63 | database: this.database 64 | }; 65 | } 66 | 67 | }); 68 | 69 | /** api: example 70 | * Sample code create a new workspace for accessing data in a H2 database: 71 | * 72 | * .. code-block:: javascript 73 | * 74 | * js> var h2 = new WORKSPACE.H2({database: "data/h2/geoscript"}); 75 | * js> h2 76 | *

77 | * js> var states = h2.get("states"); 78 | * js> states 79 | * 80 | */ 81 | 82 | exports.H2 = H2; 83 | 84 | // register an H2 factory for the module 85 | register(new Factory(H2, { 86 | handles: function(config) { 87 | var capable = false; 88 | if (config && typeof config.type === "string" && config.type.toLowerCase() === "h2") { 89 | try { 90 | config = prepConfig(config); 91 | capable = true; 92 | } catch (err) { 93 | // pass 94 | } 95 | } 96 | return capable; 97 | } 98 | })); 99 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/workspace/memory.js: -------------------------------------------------------------------------------- 1 | var register = require("./util").register; 2 | var Factory = require("../factory").Factory; 3 | var Workspace = require("./workspace").Workspace; 4 | var UTIL = require("../util"); 5 | 6 | var MemoryDataStore = Packages.org.geotools.data.memory.MemoryDataStore; 7 | 8 | var prepConfig = function(config) { 9 | if (config === undefined) { 10 | config = {}; 11 | } 12 | return config; 13 | }; 14 | 15 | /** api: (define) 16 | * module = workspace 17 | * class = Memory 18 | */ 19 | 20 | /** api: (extends) 21 | * workspace/workspace.js 22 | */ 23 | var Memory = UTIL.extend(Workspace, { 24 | 25 | /** api: constructor 26 | * .. class:: Memory 27 | * 28 | * Create a memory based workspace. 29 | */ 30 | constructor: function Memory(config) { 31 | Workspace.prototype.constructor.apply(this, [prepConfig(config)]); 32 | }, 33 | 34 | /** private: method[_create] 35 | * :arg config: ``Object`` 36 | * :returns: ``org.geotools.data.memory.MemoryDataStore`` 37 | * 38 | * Create the underlying store for the workspace. 39 | */ 40 | _create: function(config) { 41 | return java.lang.Class.forName("org.geotools.data.memory.MemoryDataStore").newInstance(); 42 | } 43 | 44 | }); 45 | 46 | exports.Memory = Memory; 47 | 48 | // register a memory factory for the module 49 | register(new Factory(Memory, { 50 | handles: function(config) { 51 | config = prepConfig(config); 52 | var capable = false; 53 | if (typeof config === "object") { 54 | if (config.type) { 55 | if (config.type.toLowerCase() === "memory") { 56 | capable = true; 57 | } 58 | } else if (Object.keys(config).length === 0) { 59 | capable = true; 60 | } 61 | } 62 | return capable; 63 | } 64 | })); 65 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/workspace/spatialite.js: -------------------------------------------------------------------------------- 1 | var register = require("./util").register; 2 | var Factory = require("../factory").Factory; 3 | var Workspace = require("./workspace").Workspace; 4 | var UTIL = require("../util"); 5 | 6 | var SpatiaLiteDataStoreFactory = Packages.org.geotools.data.spatialite.SpatiaLiteDataStoreFactory; 7 | 8 | /** private: (define) 9 | * module = workspace 10 | * class = SpatiaLite 11 | */ 12 | 13 | var prepConfig = function(config) { 14 | if (config) { 15 | if (typeof config === "string") { 16 | config = {database: config}; 17 | } 18 | if (!(typeof config.database === "string" || config.database instanceof file.Path)) { 19 | throw "SpatiaLite config must include database path."; 20 | } 21 | config = { 22 | database: String(config.database) 23 | }; 24 | } 25 | return config; 26 | }; 27 | 28 | /** private: (extends) 29 | * workspace/workspace.js 30 | */ 31 | var SpatiaLite = UTIL.extend(Workspace, { 32 | 33 | /** private: config[database] 34 | * ``String`` 35 | * Path to the database (required). 36 | */ 37 | 38 | /** private: constructor 39 | * .. class:: SpatiaLite 40 | * 41 | * :arg config: ``Object`` Configuration object. 42 | * 43 | * Create a workspace from a SpatiaLite enabled database. 44 | */ 45 | constructor: function SpatiaLite(config) { 46 | Workspace.prototype.constructor.apply(this, [prepConfig(config)]); 47 | }, 48 | 49 | /** private: method[_create] 50 | * :arg config: ``Object`` 51 | * :returns: ``org.geotools.jdbc.JDBCDataStore`` 52 | * 53 | * Create the underlying store for the workspace. 54 | */ 55 | _create: function(config) { 56 | config.dbtype = "spatialite"; 57 | var factory = new SpatiaLiteDataStoreFactory(); 58 | return factory.createDataStore(config); 59 | }, 60 | 61 | /** private: property[config] 62 | */ 63 | get config() { 64 | return { 65 | type: this.constructor.name, 66 | database: this.database 67 | }; 68 | } 69 | 70 | }); 71 | 72 | exports.SpatiaLite = SpatiaLite; 73 | 74 | // register a spatialite factory for the module 75 | register(new Factory(SpatiaLite, { 76 | handles: function(config) { 77 | var capable = false; 78 | if (typeof config.type === "string" && config.type.toLowerCase() === "spatialite") { 79 | try { 80 | config = prepConfig(config); 81 | capable = true; 82 | } catch (err) { 83 | // pass 84 | } 85 | } 86 | return capable; 87 | } 88 | })); 89 | -------------------------------------------------------------------------------- /src/main/resources/org/geoscript/js/lib/geoscript/workspace/util.js: -------------------------------------------------------------------------------- 1 | var Registry = require("../registry").Registry; 2 | 3 | var registry = new Registry(); 4 | 5 | /** private: method[create] 6 | * :arg config: ``Object`` Configuration object. 7 | * :returns: :class:`Workspace` 8 | * 9 | * Create a workspace given a configuration object. 10 | */ 11 | exports.create = registry.create; 12 | 13 | /** private: method[from_] */ 14 | exports.from_ = registry.from_; 15 | 16 | /** private: method[register] */ 17 | exports.register = registry.register; 18 | -------------------------------------------------------------------------------- /src/test/java/org/geoscript/js/RingoTest.java: -------------------------------------------------------------------------------- 1 | package org.geoscript.js; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | 5 | import java.net.URI; 6 | 7 | import org.junit.Test; 8 | import org.ringojs.tools.launcher.Main; 9 | 10 | public class RingoTest { 11 | 12 | @Test 13 | public void runRingoTests() throws Exception { 14 | String gsModulePath = new URI(GeoScriptModules.getModulePath()).getPath(); 15 | String testModulePath = RingoTest.class.getResource("tests/all.js").getFile(); 16 | String[] args = new String[] { testModulePath }; 17 | String ringoHome = Main.class.getResource("/").getFile(); 18 | System.setProperty("ringo.home", ringoHome); 19 | System.setProperty("ringo.classpath", ""); 20 | System.setProperty("ringo.modulepath", gsModulePath); 21 | Main.main(args); 22 | assertTrue("all tests passed", true); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/resources/org/geoscript/js/tests/admin.js: -------------------------------------------------------------------------------- 1 | var ZIP = require("ringo/zip"); 2 | var FS = require("fs"); 3 | 4 | var unzip = function(source, dest) { 5 | var zip = new ZIP.ZipFile(source); 6 | for (var i=0, ii=zip.entries.length; i -1) { 20 | FS.touch(path, entry.time); 21 | } 22 | } 23 | } 24 | 25 | var path = function(rel) { 26 | return FS.absolute(FS.resolve(module.path, rel)); 27 | } 28 | 29 | var meta = { 30 | shp: { 31 | source: path("data/states.shp.zip"), 32 | dest: path("tmp"), 33 | setUp: function() { 34 | meta.shp.tearDown(); 35 | unzip(meta.shp.source, meta.shp.dest); 36 | }, 37 | tearDown: function() { 38 | if (FS.exists(meta.shp.dest)) { 39 | FS.removeTree(meta.shp.dest); 40 | } 41 | } 42 | }, 43 | h2: { 44 | source: path("data/h2.zip"), 45 | dest: path("tmp"), 46 | setUp: function() { 47 | meta.h2.tearDown(); 48 | unzip(meta.h2.source, meta.h2.dest); 49 | }, 50 | tearDown: function() { 51 | if (FS.exists(meta.h2.dest)) { 52 | Packages.org.h2.tools.DeleteDbFiles.execute(meta.h2.dest, "geoscript", true); 53 | FS.removeTree(meta.h2.dest); 54 | } 55 | } 56 | }, 57 | geopkg: { 58 | source: path("data/geopkg.zip"), 59 | dest: path("tmp"), 60 | setUp: function() { 61 | meta.geopkg.tearDown(); 62 | unzip(meta.geopkg.source, meta.geopkg.dest); 63 | }, 64 | tearDown: function() { 65 | if (FS.exists(meta.geopkg.dest)) { 66 | FS.removeTree(meta.geopkg.dest); 67 | } 68 | } 69 | }, 70 | pg: { 71 | driver: new Packages.org.postgresql.Driver, 72 | setUp: function() { 73 | var uri = "jdbc:postgresql:geoscript"; 74 | var params = new java.util.Properties(); 75 | params.setProperty("user", "postgres"); 76 | params.setProperty("password", "postgres"); 77 | var connection = meta.pg.driver.getConnection(uri, params); 78 | } 79 | }, 80 | raster: { 81 | source: path("data/raster.tif"), 82 | writePng: path("raster.png") 83 | } 84 | }; 85 | 86 | for (var key in meta) { 87 | exports[key] = meta[key]; 88 | } 89 | -------------------------------------------------------------------------------- /src/test/resources/org/geoscript/js/tests/all.js: -------------------------------------------------------------------------------- 1 | var system = require("system"); 2 | exports["test: geoscript"] = require("./test_geoscript"); 3 | 4 | if (require.main == module || require.main == module.id) { 5 | system.exit(require("test").run(exports)); 6 | } -------------------------------------------------------------------------------- /src/test/resources/org/geoscript/js/tests/data/geopkg.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geoscript/geoscript-js/baf658cb6880aa70e419a58e41824a2facdec294/src/test/resources/org/geoscript/js/tests/data/geopkg.zip -------------------------------------------------------------------------------- /src/test/resources/org/geoscript/js/tests/data/h2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geoscript/geoscript-js/baf658cb6880aa70e419a58e41824a2facdec294/src/test/resources/org/geoscript/js/tests/data/h2.zip -------------------------------------------------------------------------------- /src/test/resources/org/geoscript/js/tests/data/raster.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geoscript/geoscript-js/baf658cb6880aa70e419a58e41824a2facdec294/src/test/resources/org/geoscript/js/tests/data/raster.tif -------------------------------------------------------------------------------- /src/test/resources/org/geoscript/js/tests/data/states.shp.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geoscript/geoscript-js/baf658cb6880aa70e419a58e41824a2facdec294/src/test/resources/org/geoscript/js/tests/data/states.shp.zip -------------------------------------------------------------------------------- /src/test/resources/org/geoscript/js/tests/geoscript/filter/test_expression.js: -------------------------------------------------------------------------------- 1 | var ASSERT = require("assert"); 2 | var FILTER = require("geoscript/filter"); 3 | 4 | exports["test constructor"] = function() { 5 | 6 | var e = new FILTER.Expression(); 7 | ASSERT.ok(e instanceof FILTER.Expression, "constructor returns instance"); 8 | 9 | }; 10 | 11 | exports["test literal"] = function() { 12 | 13 | var cases = [{ 14 | config: "'foo'", literal: true, 15 | config: 2, literal: true, 16 | config: "foo", literal: false, 17 | config: {text: "foo"}, literal: false, 18 | config: {text: "'foo'"}, literal: true, 19 | config: {text: 2.234}, literal: true 20 | }]; 21 | 22 | var e, c; 23 | for (var i=0, ii=cases.length; i -1, "geopkg.names includes 'states'"); 27 | 28 | geopkg.close(); 29 | 30 | }; 31 | 32 | exports["test: get"] = function() { 33 | 34 | var geopkg = new WORKSPACE.GeoPackage({database: database}); 35 | 36 | var states = geopkg.get("states"); 37 | ASSERT.ok(states instanceof LAYER.Layer, "get returns a layer instance"); 38 | 39 | geopkg.close(); 40 | 41 | }; 42 | 43 | if (require.main == module.id) { 44 | system.exit(require("test").run(exports)); 45 | } 46 | -------------------------------------------------------------------------------- /src/test/resources/org/geoscript/js/tests/geoscript/workspace/test_h2.js: -------------------------------------------------------------------------------- 1 | var ASSERT = require("assert"); 2 | var WORKSPACE = require("geoscript/workspace"); 3 | var LAYER = require("geoscript/layer"); 4 | var FS = require("fs"); 5 | var admin = require("../../admin"); 6 | 7 | var database = FS.join(admin.h2.dest, "geoscript"); 8 | exports.setUp = admin.h2.setUp; 9 | exports.tearDown = admin.h2.tearDown; 10 | 11 | exports["test: constructor"] = function() { 12 | 13 | var h2 = new WORKSPACE.H2(); 14 | 15 | ASSERT.ok(h2 instanceof WORKSPACE.Workspace, "instanceof Workspace"); 16 | ASSERT.ok(h2 instanceof WORKSPACE.H2, "instanceof H2"); 17 | 18 | h2.close(); 19 | 20 | }; 21 | 22 | exports["test: names"] = function() { 23 | 24 | var h2 = new WORKSPACE.H2({database: database}); 25 | // TODO: change this when "_GEOH2" is filtered from layer names 26 | ASSERT.ok(h2.names.indexOf("states") > -1, "h2.names includes 'states'"); 27 | 28 | h2.close(); 29 | 30 | }; 31 | 32 | exports["test: get"] = function() { 33 | 34 | var h2 = new WORKSPACE.H2({database: database}); 35 | 36 | var states = h2.get("states"); 37 | ASSERT.ok(states instanceof LAYER.Layer, "get returns a layer instance"); 38 | 39 | h2.close(); 40 | 41 | }; 42 | 43 | if (require.main == module.id) { 44 | system.exit(require("test").run(exports)); 45 | } 46 | -------------------------------------------------------------------------------- /src/test/resources/org/geoscript/js/tests/geoscript/workspace/test_memory.js: -------------------------------------------------------------------------------- 1 | var ASSERT = require("assert"); 2 | var WORKSPACE = require("geoscript/workspace"); 3 | 4 | exports["test: constructor"] = function() { 5 | 6 | var mem = new WORKSPACE.Memory(); 7 | 8 | ASSERT.ok(mem instanceof WORKSPACE.Workspace, "instanceof Workspace"); 9 | ASSERT.ok(mem instanceof WORKSPACE.Memory, "instanceof Memory"); 10 | 11 | mem.close(); 12 | 13 | }; 14 | 15 | if (require.main == module.id) { 16 | system.exit(require("test").run(exports)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/test/resources/org/geoscript/js/tests/geoscript/workspace/test_postgis.js: -------------------------------------------------------------------------------- 1 | var ASSERT = require("assert"); 2 | var WORKSPACE = require("geoscript/workspace"); 3 | var LAYER = require("geoscript/layer"); 4 | 5 | var database = "geoscript"; 6 | 7 | exports["test: constructor"] = function() { 8 | 9 | var ws = new WORKSPACE.PostGIS(); 10 | 11 | ASSERT.ok(ws instanceof WORKSPACE.Workspace, "instanceof Workspace"); 12 | ASSERT.ok(ws instanceof WORKSPACE.PostGIS, "instanceof PostGIS"); 13 | 14 | ws.close(); 15 | 16 | }; 17 | 18 | exports["test: names"] = function() { 19 | 20 | var ws = new WORKSPACE.PostGIS({database: database}); 21 | ASSERT.ok(ws.names.indexOf("states") > -1, "ws.names includes 'states'"); 22 | 23 | ws.close(); 24 | 25 | }; 26 | 27 | exports["test: get"] = function() { 28 | 29 | var ws = new WORKSPACE.PostGIS({database: database}); 30 | 31 | var states = ws.get("states"); 32 | ASSERT.ok(states instanceof LAYER.Layer, "get returns a layer instance"); 33 | 34 | ws.close(); 35 | 36 | }; 37 | 38 | if (require.main == module.id) { 39 | system.exit(require("test").run(exports)); 40 | } 41 | -------------------------------------------------------------------------------- /src/test/resources/org/geoscript/js/tests/test_geoscript.js: -------------------------------------------------------------------------------- 1 | exports["test: geom"] = require("./geoscript/test_geom"); 2 | exports["test: proj"] = require("./geoscript/test_proj"); 3 | exports["test: feature"] = require("./geoscript/test_feature"); 4 | exports["test: filter"] = require("./geoscript/test_filter"); 5 | exports["test: layer"] = require("./geoscript/test_layer"); 6 | exports["test: process"] = require("./geoscript/test_process"); 7 | exports["test: workspace"] = require("./geoscript/test_workspace"); 8 | exports["test: style"] = require("./geoscript/test_style"); 9 | exports["test: map"] = require("./geoscript/test_map"); 10 | exports["test: util"] = require("./geoscript/test_util"); 11 | exports["test: index"] = require("./geoscript/test_index"); 12 | exports["test: raster"] = require("./geoscript/test_raster"); 13 | 14 | if (require.main == module.id) { 15 | system.exit(require("test").run(exports)); 16 | } 17 | --------------------------------------------------------------------------------