Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Modules
index/*
layer
workspace
raster
style
map
process
Expand Down
171 changes: 171 additions & 0 deletions doc/api/raster.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
The raster module
~~~~~~~~~~~~~~~~

The :doc:`raster <Format>` module can read and write Rasters.

.. code-block:: javascript

>> var Format = require("geoscript/raster").Format;

:class:`raster.Format`
====================

.. class:: raster.Format(config)

Create a new Format. The config must contain a source representing the file or URL.

Properties
----------

.. attribute:: Format.name

``String``
The type of Format (GeoTIFF, WorldImage).

.. attribute:: Format.names

``Array``
Array of Raster names. Most Formats will only contain one Raster.

Methods
-------

.. function:: Format.read(config)

:arg config: ``Object`` An object literal with parameters

name: The name of the Raster (optional). Required if there are more than one Raster in the Format.

proj: The Projection of the Raster (optional).

bounds: The Bounds to read a subset of the entire Raster. Optional, but if included size must also be included.

size: An array of width and height of the Raster. Optional, buf if included bound must also be included.

.. function:: Format.write(raster, config)

:arg raster: :class:`raster.Raster` The Raster to write to this Format.

:arg config: ``Object`` An object literal of write parameters.

:class:`raster.Raster`
====================

.. class:: raster.Raster

A Raster is a spatial data set represented by a grid of cells organized in one or more bands.

Properties
----------

.. attribute:: Raster.name

``String``
Get the name of the Raster.

.. attribute:: Raster.proj

:class:`proj.Projection`
Get the Projection.


.. attribute:: Raster.bounds

:class:`geom.Bounds`
Get the Bounds.

.. attribute:: Raster.size

`Array`
Get the size of the Raster as an Array of two numbers: width and height

.. attribute:: Raster.cols

`Number`
Get the number of columns or the width or the Raster

.. attribute:: Raster.rows

`Number`
Get the number of row or the height or the Raster

.. attribute:: Raster.bands

`Array` of :class:`raster.Bands`
Get an array of Bands

Methods
-------

.. function:: Raster.getPoint(x,y)

:arg x: ``Number`` The pixel's x position

:arg y: ``Number`` The pixel's y position

Get a :class:`geom.Point` for the pixel.

.. function:: Raster.getValue(pointOrPixel)

:arg pointOrPixel: ``Object`` The pixel or :class:`geom.Point`

:arg type: ``String`` The type of value to return (double, int, float, byte, boolean)

Get a value for each band from the Raster.


:class:`raster.Band`
====================

.. class:: raster.Band

An individual layer from a Raster.

Properties
----------

.. attribute:: Band.min

``Number``
Get the minimum value from this Band.

.. attribute:: Band.max

``Number``
Get the maximum value from this Band.

.. attribute:: Band.noData

``Array``
Get the array of no data values.



.. attribute:: Band.scale

``Number``
Get the scale.

.. attribute:: Band.scale

``Number``
Get the scale.

.. attribute:: Band.type

``Number``
Get the Raster type.

.. attribute:: Band.description

``Number``
Get the Raster description.

Methods
-------

.. function:: Band.isNoData(value)

:arg value: ``Object`` The value to check

Determine whether the value is a no data value.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@
<artifactId>gt-flatgeobuf</artifactId>
<version>${gt.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-geotiff</artifactId>
<version>${gt.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-image</artifactId>
<version>${gt.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
110 changes: 110 additions & 0 deletions src/main/java/org/geoscript/js/raster/Band.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package org.geoscript.js.raster;

import org.geoscript.js.GeoObject;
import org.geotools.coverage.TypeMap;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Wrapper;
import org.mozilla.javascript.annotations.JSConstructor;
import org.mozilla.javascript.annotations.JSFunction;
import org.mozilla.javascript.annotations.JSGetter;
import org.opengis.coverage.SampleDimension;

import javax.measure.Unit;
import java.awt.image.DataBuffer;
import java.util.Arrays;

public class Band extends GeoObject implements Wrapper {

private SampleDimension sampleDimension;

public Band() {
}

public Band(SampleDimension sampleDimension) {
this.sampleDimension = sampleDimension;
}

public Band(Scriptable scope, SampleDimension sampleDimension) {
this(sampleDimension);
this.setParentScope(scope);
this.setPrototype(Module.getClassPrototype(Band.class));
}

@JSGetter
public double getMin() {
return this.sampleDimension.getMinimumValue();
}

@JSGetter
public double getMax() {
return this.sampleDimension.getMaximumValue();
}

@JSGetter
public Object getNoData() {
return javaToJS(this.sampleDimension.getNoDataValues(), this.getParentScope());
}

@JSFunction
public boolean isNoData(double value) {
double[] values = this.sampleDimension.getNoDataValues();
return Arrays.asList(values).contains(value);
}

@JSGetter
public double getScale() {
return this.sampleDimension.getScale();
}

@JSGetter
public double getOffset() {
return this.sampleDimension.getOffset();
}

@JSGetter
public String getType() {
int type = TypeMap.getDataBufferType(this.sampleDimension.getSampleDimensionType());
if (type == DataBuffer.TYPE_BYTE) {
return "byte";
} else if (type == DataBuffer.TYPE_DOUBLE) {
return "double";
} else if (type == DataBuffer.TYPE_FLOAT) {
return "float";
} else if (type == DataBuffer.TYPE_INT) {
return "int";
} else if (type == DataBuffer.TYPE_SHORT) {
return "short";
} else if (type == DataBuffer.TYPE_USHORT) {
return "short";
} else {
return "undefined";
}
}

@JSGetter
public String getDescription() {
return this.sampleDimension.getDescription().toString();
}

@Override
public Object unwrap() {
return this.sampleDimension;
}

@Override
public String toString() {
return getDescription();
}

@JSConstructor
public static Object constructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) {
if (inNewExpr) {
return new Band(null);
} else {
return new Band(ctorObj.getParentScope(), null);
}
}

}
Loading