Skip to content

Commit 1886a50

Browse files
authored
Add Raster Module (#73)
1 parent 2a58914 commit 1886a50

File tree

15 files changed

+866
-0
lines changed

15 files changed

+866
-0
lines changed

doc/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Modules
1919
index/*
2020
layer
2121
workspace
22+
raster
2223
style
2324
map
2425
process

doc/api/raster.rst

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
The raster module
2+
~~~~~~~~~~~~~~~~
3+
4+
The :doc:`raster <Format>` module can read and write Rasters.
5+
6+
.. code-block:: javascript
7+
8+
>> var Format = require("geoscript/raster").Format;
9+
10+
:class:`raster.Format`
11+
====================
12+
13+
.. class:: raster.Format(config)
14+
15+
Create a new Format. The config must contain a source representing the file or URL.
16+
17+
Properties
18+
----------
19+
20+
.. attribute:: Format.name
21+
22+
``String``
23+
The type of Format (GeoTIFF, WorldImage).
24+
25+
.. attribute:: Format.names
26+
27+
``Array``
28+
Array of Raster names. Most Formats will only contain one Raster.
29+
30+
Methods
31+
-------
32+
33+
.. function:: Format.read(config)
34+
35+
:arg config: ``Object`` An object literal with parameters
36+
37+
name: The name of the Raster (optional). Required if there are more than one Raster in the Format.
38+
39+
proj: The Projection of the Raster (optional).
40+
41+
bounds: The Bounds to read a subset of the entire Raster. Optional, but if included size must also be included.
42+
43+
size: An array of width and height of the Raster. Optional, buf if included bound must also be included.
44+
45+
.. function:: Format.write(raster, config)
46+
47+
:arg raster: :class:`raster.Raster` The Raster to write to this Format.
48+
49+
:arg config: ``Object`` An object literal of write parameters.
50+
51+
:class:`raster.Raster`
52+
====================
53+
54+
.. class:: raster.Raster
55+
56+
A Raster is a spatial data set represented by a grid of cells organized in one or more bands.
57+
58+
Properties
59+
----------
60+
61+
.. attribute:: Raster.name
62+
63+
``String``
64+
Get the name of the Raster.
65+
66+
.. attribute:: Raster.proj
67+
68+
:class:`proj.Projection`
69+
Get the Projection.
70+
71+
72+
.. attribute:: Raster.bounds
73+
74+
:class:`geom.Bounds`
75+
Get the Bounds.
76+
77+
.. attribute:: Raster.size
78+
79+
`Array`
80+
Get the size of the Raster as an Array of two numbers: width and height
81+
82+
.. attribute:: Raster.cols
83+
84+
`Number`
85+
Get the number of columns or the width or the Raster
86+
87+
.. attribute:: Raster.rows
88+
89+
`Number`
90+
Get the number of row or the height or the Raster
91+
92+
.. attribute:: Raster.bands
93+
94+
`Array` of :class:`raster.Bands`
95+
Get an array of Bands
96+
97+
Methods
98+
-------
99+
100+
.. function:: Raster.getPoint(x,y)
101+
102+
:arg x: ``Number`` The pixel's x position
103+
104+
:arg y: ``Number`` The pixel's y position
105+
106+
Get a :class:`geom.Point` for the pixel.
107+
108+
.. function:: Raster.getValue(pointOrPixel)
109+
110+
:arg pointOrPixel: ``Object`` The pixel or :class:`geom.Point`
111+
112+
:arg type: ``String`` The type of value to return (double, int, float, byte, boolean)
113+
114+
Get a value for each band from the Raster.
115+
116+
117+
:class:`raster.Band`
118+
====================
119+
120+
.. class:: raster.Band
121+
122+
An individual layer from a Raster.
123+
124+
Properties
125+
----------
126+
127+
.. attribute:: Band.min
128+
129+
``Number``
130+
Get the minimum value from this Band.
131+
132+
.. attribute:: Band.max
133+
134+
``Number``
135+
Get the maximum value from this Band.
136+
137+
.. attribute:: Band.noData
138+
139+
``Array``
140+
Get the array of no data values.
141+
142+
143+
144+
.. attribute:: Band.scale
145+
146+
``Number``
147+
Get the scale.
148+
149+
.. attribute:: Band.scale
150+
151+
``Number``
152+
Get the scale.
153+
154+
.. attribute:: Band.type
155+
156+
``Number``
157+
Get the Raster type.
158+
159+
.. attribute:: Band.description
160+
161+
``Number``
162+
Get the Raster description.
163+
164+
Methods
165+
-------
166+
167+
.. function:: Band.isNoData(value)
168+
169+
:arg value: ``Object`` The value to check
170+
171+
Determine whether the value is a no data value.

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@
156156
<artifactId>gt-flatgeobuf</artifactId>
157157
<version>${gt.version}</version>
158158
</dependency>
159+
<dependency>
160+
<groupId>org.geotools</groupId>
161+
<artifactId>gt-geotiff</artifactId>
162+
<version>${gt.version}</version>
163+
</dependency>
164+
<dependency>
165+
<groupId>org.geotools</groupId>
166+
<artifactId>gt-image</artifactId>
167+
<version>${gt.version}</version>
168+
</dependency>
159169
</dependencies>
160170
<build>
161171
<plugins>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package org.geoscript.js.raster;
2+
3+
import org.geoscript.js.GeoObject;
4+
import org.geotools.coverage.TypeMap;
5+
import org.mozilla.javascript.Context;
6+
import org.mozilla.javascript.Function;
7+
import org.mozilla.javascript.Scriptable;
8+
import org.mozilla.javascript.Wrapper;
9+
import org.mozilla.javascript.annotations.JSConstructor;
10+
import org.mozilla.javascript.annotations.JSFunction;
11+
import org.mozilla.javascript.annotations.JSGetter;
12+
import org.opengis.coverage.SampleDimension;
13+
14+
import javax.measure.Unit;
15+
import java.awt.image.DataBuffer;
16+
import java.util.Arrays;
17+
18+
public class Band extends GeoObject implements Wrapper {
19+
20+
private SampleDimension sampleDimension;
21+
22+
public Band() {
23+
}
24+
25+
public Band(SampleDimension sampleDimension) {
26+
this.sampleDimension = sampleDimension;
27+
}
28+
29+
public Band(Scriptable scope, SampleDimension sampleDimension) {
30+
this(sampleDimension);
31+
this.setParentScope(scope);
32+
this.setPrototype(Module.getClassPrototype(Band.class));
33+
}
34+
35+
@JSGetter
36+
public double getMin() {
37+
return this.sampleDimension.getMinimumValue();
38+
}
39+
40+
@JSGetter
41+
public double getMax() {
42+
return this.sampleDimension.getMaximumValue();
43+
}
44+
45+
@JSGetter
46+
public Object getNoData() {
47+
return javaToJS(this.sampleDimension.getNoDataValues(), this.getParentScope());
48+
}
49+
50+
@JSFunction
51+
public boolean isNoData(double value) {
52+
double[] values = this.sampleDimension.getNoDataValues();
53+
return Arrays.asList(values).contains(value);
54+
}
55+
56+
@JSGetter
57+
public double getScale() {
58+
return this.sampleDimension.getScale();
59+
}
60+
61+
@JSGetter
62+
public double getOffset() {
63+
return this.sampleDimension.getOffset();
64+
}
65+
66+
@JSGetter
67+
public String getType() {
68+
int type = TypeMap.getDataBufferType(this.sampleDimension.getSampleDimensionType());
69+
if (type == DataBuffer.TYPE_BYTE) {
70+
return "byte";
71+
} else if (type == DataBuffer.TYPE_DOUBLE) {
72+
return "double";
73+
} else if (type == DataBuffer.TYPE_FLOAT) {
74+
return "float";
75+
} else if (type == DataBuffer.TYPE_INT) {
76+
return "int";
77+
} else if (type == DataBuffer.TYPE_SHORT) {
78+
return "short";
79+
} else if (type == DataBuffer.TYPE_USHORT) {
80+
return "short";
81+
} else {
82+
return "undefined";
83+
}
84+
}
85+
86+
@JSGetter
87+
public String getDescription() {
88+
return this.sampleDimension.getDescription().toString();
89+
}
90+
91+
@Override
92+
public Object unwrap() {
93+
return this.sampleDimension;
94+
}
95+
96+
@Override
97+
public String toString() {
98+
return getDescription();
99+
}
100+
101+
@JSConstructor
102+
public static Object constructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) {
103+
if (inNewExpr) {
104+
return new Band(null);
105+
} else {
106+
return new Band(ctorObj.getParentScope(), null);
107+
}
108+
}
109+
110+
}

0 commit comments

Comments
 (0)