![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
ol-elevation-parser
Advanced tools
Sample geometries and retrieve parsed elevation data from Open Layers sources
Tiny module to retrieve and parse data to create elevation profiles and/or volume calculations from raster sources. This will sample the provided geometries and then parse the elevation data from differents Open Layers sources, using raster grayscale or color processed rgbs as source.
Tested with OpenLayers version 6, 7 and 8.
getFeatureInfo
function (very slow to calculate LineStrings and Polygons, but useful in some specific cases).Supports calculations from Points, LineStrings and Polygons. Each of these geometries is processed diferently:
Points
: in this case, there is no further processing, the coordinates of each point are consulted according to the configured method (see calculateZMethod) and the same supplied coordinates are returned with the z value embedded.LineStrings
: here it's necessary to resample the geometry to assemble the profile, and make requests only of those sampled points. The greater the number of samples (see samples), the longer it will take, but the better the quality of the profile will be. In the the sampling, the length of that line is divided into x number of parts to obtain the coordinates of each of the extremes. Then, the vertices of the geometry are also added to those sampled coordinates.Polygons
: two different samples are made:
import ElevationParser from 'ol-elevation-parser';
import TileWMS from 'ol/source/TileWMS.js';
import LineString from 'ol/geom/LineString.js';
import Feature from 'ol/Feature.js';
var elevationLayer = new TileWMS({
url: 'http://localhost:8080/geoserver/dipsohdev/ows',
serverType: 'geoserver',
crossOrigin: null,
interpolate: false,
params: {
SERVICE: 'wms',
LAYERS: 'mdeIgnRgb'
}
});
var options = {
source: elevationLayer,
calculateZMethod: 'getFeatureInfo',
tilesResolution: 'current',
samples: 50, // For LineStrings and Polygons contour
sampleSizeArea: 'auto', // For Polygons area
noDataValue: -10000,
smooth: 0
};
var elevationParser = new ElevationParser(options);
// Add control the the Open Layers map instance
map.addControl(elevationParser);
var lineStringFeature = new Feature(new LineString(/*...*/));
const data = await elevationParser.getElevationValues(feature);
See CHANGELOG for details of changes in each release.
Load ol-elevation-parser.js
after OpenLayers. Elevation Parser is available as ElevationParser
.
<script src="https://unpkg.com/ol-elevation-parser@1.3.18"></script>
NPM package: ol-elevation-parser.
Install the package via npm
npm install ol-elevation-parser
import ElevationParser from 'ol-elevation-parser';
TypeScript types are shipped with the project in the dist directory and should be automatically used in a TypeScript project. Interfaces are provided for the Options.
Extends ol/control/Control~Control
options
Options Get Feature's elevation values. Use custom options to overwrite the general ones for specific cases
feature
Feature<(LineString | Point | Polygon)> customOptions
ElevationValuesIndividualOptions (optional, default null
)Returns Promise<(IGetElevationValues | Error)>
Returns any
source
any silent
(optional, default false
)Returns void
Returns any
samples
any silent
(optional, default false
)Returns void
Returns any
sampleSizeArea
any silent
boolean Returns void
Returns any
calculateZMethod
any silent
(optional, default false
)Returns void
Returns any
smooth
any silent
(optional, default false
)Returns void
Returns any
noDataValue
any silent
(optional, default false
)Returns void
Returns any
tilesResolution
any silent
(optional, default false
)Returns void
Returns any
bands
any silent
(optional, default false
)Returns void
Returns any
timeout
any silent
(optional, default false
)Returns void
Maximum tile resolution of the image source Only if the source is a raster
Returns number
Current view resolution Unsupported if the view of a GeoTIFF is used in the map
Returns number
map
Map Returns void
Sampled coordinates from LineStrings, Point coordinates, or sampled coordinates from Polygons, obtained by subdividing the area in multiples squares and getting each center point.
Type: Array<CoordinatesXY>
Contour coordinates from Polygons features.
Type: Array<CoordinatesXY>
[type]
Type: ("change:samples"
| "change:sampleSizeArea"
| "change:source"
| "change:calculateZMethod"
| "change:noDataValue"
| "change:smooth"
| "change:bands"
| "change:tilesResolution"
| "change:timeout"
)
Extends IElevationCoords
[interface]
Sampled Polygons Useful to to calculate fill and cut values on ovolume measurements
Type: Array<Feature<Polygon>>
[type]
Type: [number, number, number]
[type]
[interface]
Sampled coordinates from LineStrings, Point coordinates, or sampled coordinates from Polygons, obtained by subdividing the area in multiples squares and getting each center point.
Type: Array<CoordinatesXYZ>
Contour coordinates from Polygons features.
Type: Array<CoordinatesXYZ>
[type]
Type: (TileWMS | TileImage | XYZ | GeoTIFF)
[type]
Type: function (originalFeature: Feature<(LineString | Point | Polygon)>, sampledCoords: any): Promise<IElevationCoords>
[interface]
Extends Omit<ControlOptions, 'target'>
[interface]
Source from which it is obtained the elevation values. If not provided, the zGraph would be not displayed.
If a Raster source is used and the option resolution
is set to max
, provide the maxZoom
attribute
to allow download the data in the higher resolution available.
Also, you can provide a custom function to call an API or other methods to obtain the data.
Type: (RasterSources | CustomSourceFn)
To obtain the elevation values from the diferrents sources, you can:
Calculate the zValues from the rgb pixel data (TileImage
and XYZ
source formats need this):
Mapbox
preset: (r * 256 * 256 + g * 256 + b) * 0.1 - 10000Terrarium
preset: (r * 256 + g + b / 256) - 32768Making requests to the geoserver (TileWMS
source)
getFeatureInfo
: make requests to the source url using service getFeatureInfo
By default:
TileWMS
format use 'getFeatureInfo'
requests to the source_url to obtain the values.TileImage
and XYZ
formats are calculated from the pixel data using 'Mapbox'
preset.Type: ("getFeatureInfo"
| "Mapbox"
| "Terrarium"
| function (r: number, g: number, b: number): number)
Only used if calculateZMethod
is not getFeatureInfo
.
This sets the resolution in wich the tiles are downloaded to calculate the z values.
If max
, the tiles will be downloaded using the maximum quality possible, but you
have to configure the maxZoom
attribute of the source to prevent requesting inexisting tiles.
Using max
provides the maximum quality, but the requests are gonna be in higher number and would be slower.
Use the method getMaxTilesResolution
to get the max resolution in a number number.
´current´ uses the current view resolution of the map. If the source is visible in the map,
the already downloaded tiles would be used to the calculations so is it's the faster method.
Use the method getCurrentViewResolution
to get the curent view resolution number.
Doesn't work if the source is GeoTIFF and the map use its view
´current´ is the default
Type: (number | "max"
| "current"
)
Only used if calculateZMethod
is not getFeatureInfo
.
Default is 4
Type: number
To obtain the elevation values on each distance measurement, multiples samples are taken across the line. This number is used as equally percentage steps across the geom, plus all the vertices positions.
getFeatureInfo
on TileWMS sources will make one request per sampleTileImage
and XYZ
are calculated across each pixel after downloading the required tiles.
The bigger the number, the greater the quality of the elevation data, but slower response times and
bigger overhead (principally on getFeatureInfo
method).
This value is used to sample LinesStrings and Polygons contour
50
is the defaultType: (number | function (length: number): number)
To obtain the elevation values on a volume measurement, multiples samples are taken across the polygon.
The value provided must be in meters. The bigger the number, the greater the quality of the measurement,
but slower response times and bigger overhead (principally on getFeatureInfo
method).
'auto'
is the default
Type: (number | "auto"
| function (area: number): number)
Smooth result values on LineStrings measurements
0
is the default (no smoothing)
Type: number
When calculating the zGraph statistics from the raster dataset, you can choose to ignore specific values with the NoDataValue parameter. These values are considerated as transparency, so probably you want these replaced by 0.
-10000
is the default
false
to disable
Type: (number | false
)
Timeout in ms to wait before close the requests
5000
ms is the default
Type: number
console.log to help debug the code
false
is the default
Type: boolean
FAQs
Sample geometries and retrieve parsed elevation data from Open Layers sources
We found that ol-elevation-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.