This mixin provides additional properties and methods which you can invoke on an instance of DataSet.
var ds = new org.openstreetmap.josm.data.osm.DataSet();
// create objects
var n1 = ds.nodeBuilder.create();
var n2 = ds.nodeBuilder.create();
var w1 = ds.wbuilder.create(1234, {nodes: [n1,n2]});
// access and manipulate the objects in the dataset
ds.add(w1);
ds.has(w1); // -> true
ds.has(n1); // -> true
// access and manipulate the selected objects
ds.selection.add(n2);
ds.selection.isSelected(n2); // -> true
ds.selection.toogle(n2);
Name | Description |
---|---|
Properties | |
nodeBuilder | the builder for creating Nodes |
relationBuilder | the builder for creating Relations |
selection | to manipulate the selected objects in the dataset |
wayBuilder | the builder for creating Ways |
Methods | |
add | Adds one or more objects to the dataset. |
batch | Run a sequence of command without notifying listeners. |
each | Iterates over the dataset. |
get | Get an object from the dataset. |
has | Check whether an object is in the dataset. |
load | Loads a dataset from a file. |
node | Get a specific Node from the dataset. |
query | Queries the dataset. |
relation | Get a specific Relation from the dataset. |
remove | Remove one or more objects from the dataset. |
save | Saves a dataset to a file. |
way | Get a specific Way from the dataset. |
This mixin provides additional properties and methods for the native Java class
DataSet, whose native public methods are available
for scripting, too. If a native method name is hidden by a property name in the mixin,
then prefix the native name with $
.
nodeBuilder:NodeBuilder
Replies a node builder to create nodes in this dataset.
var ds = new DataSet();
var n = ds.nodeBuilder.withId(1234).withTags({amenity: "restaurant"}).create();
ds.has(n); // --> true
relationBuilder:RelationBuilder
Replies a relation builder to create relations in this dataset.
var ds = new DataSet();
var r = ds.relationBuilder.withId(8765).create({tags: {type: "network"}});
ds.has(r); // --> true
selection:DataSetSelectionFacade
Replies the dataset selection object.
wayBuilder:WayBuilder
Replies a way builder to create ways in this dataset.
var ds = new DataSet();
var w = ds.wayBuilder.create(1234, {tags: {highway: "residential"}});
ds.has(w); // --> true
add
Adds one or more primitives to the dataset.
Signaturesadd(o1,o2, ...)
add(array|collection)
var DataSet = org.openstreetmap.josm.data.osm.DataSet;
var rbuilder = require("josm/builder").RelationBuilder;
var nbuilder = require("josm/builder").NodeBuilder;
var wbuilder = require("josm/builder").WayBuilder;
// add two nodes and a way to the dataset
ds.add(
var n1 = nb.create(),
var n2 = nb.create(),
wb.withNodes(n1,n2).create()
);
// add a array of objects to the dataset
var l = [nb.create(1), nb.create(2), wb.create()];
relation.add(l);
batch
Run a sequence of operations against the dataset in "batch mode". Listeners to data set events are only notified at the end of the batch.
Name | Type | Description |
---|---|---|
delegate | function | the function implementing the batch processes. Ignored if null or undefined. |
var DataSet = org.openstreetmap.josm.data.osm.DataSet;
var ds = new DataSet();
ds.batch(function() {
var n1 = ds.nodeBuilder.create();
var n2 = ds.nodeBuilder.create();
ds.wayBuilder.withNodes(n1,n2).create();
});
each
Iterates over the objects in the dataset.
Signatureseach(delegate,?options)
delegate
for each object.
If null or undefined, the iteration is skipped. Expects a function with the following signature:
function(obj) {} // when invoked, obj is a node, a way, or a relation
options
is an (optional) object with named parameters, see below.
options
consists of the following (optional) named parameters:
all
: booleanName | Type | Description |
---|---|---|
delegate | function | the function invoked on every element |
options | object | (optional) additional named parameters |
get
Replies an OSM object from the dataset, or undefined, if no such object exists.
Signaturesget(id, type)
get(id)
id
is either an instance of
PrimitiveId or an object with
the properties id
and type
, i.e. {id: 1234, type: "node"}
.var DataSet = org.openstreetmap.josm.data.osm.DataSet;
var SimplePrimitiveId = org.openstreetmap.josm.data.osm.SimplePrimitiveId;
var OsmPrimitiveType = org.openstreetmap.josm.data.osm.OsmPrimitiveType;
var rbuilder = require("josm/builder").RelationBuilder;
var nbuilder = require("josm/builder").NodeBuilder;
var wbuilder = require("josm/builder").WayBuilder;
// get a node with a global id
var o1 = ds.get(1234, "node");
// get a way with a global id
var o2 = ds.get(3333, OsmPrimitiveType.WAY);
// get a relation with an id object
var o3 = ds.get({id: 5423, type: "relation"});
// pass in a SimplePrimitiveId
var id = new SimplePrimitiveId(-5, OsmPrimitiveType.NODE);
var o4 = ds.get(id);
// pass in a primitive to get it
var way = wbuilder.create(987);
var o5 = ds.get(way);
has
Replies true, if the dataset contains an object.
Signatureshas(id, type)
has(id)
id
exists in the dataset. id
is either
an instance of PrimitiveId or an object with
the properties id
and type
, i.e. {id: 1234, type: "node"}
.var DataSet = org.openstreetmap.josm.data.osm.DataSet;
var SimplePrimitiveId = org.openstreetmap.josm.data.osm.SimplePrimitiveId;
var OsmPrimitiveType = org.openstreetmap.josm.data.osm.OsmPrimitiveType;
var rbuilder = require("josm/builder").RelationBuilder;
var nbuilder = require("josm/builder").NodeBuilder;
var wbuilder = require("josm/builder").WayBuilder;
// is there a node with id 1234 ?
var ret = ds.has(1234, "node");
// is there a way with id 3333 ?
ret = ds.has(3333, OsmPrimitiveType.WAY);
// is there a relation with id 5433 ?
ret = ds.has({id: 5423, type: "relation"});
// is there a node with id -5 ?
var id = new SimplePrimitiveId(-5, OsmPrimitiveType.NODE);
ret = ds.has(id);
// does it contain the way w?
var way = wbuilder.create(987);
ret = ds.has(way);
load
Loads a dataset from a file.
Derives the format of the file from the file suffix, unless the named option options.format
is set.
options
can contain the following named options:
format
Name | Type | Description |
---|---|---|
source | string | the data source. Either a file name as string or a java.io.File |
options | object | (optional) optional named parameters |
// loads OSM data from a data file
var ds1 = DataSet.load("/tmp/my-data.osm");
// loads OSM data from a data file, the format is compressed OSM xml
var ds2 = DataSet.load("/tmp/my-data.ogz", {format: "osm.gz"});
node
Replies the node with id id
.
Name | Type | Description |
---|---|---|
id | number | the unique numeric id. Must not be 0. |
query
Queries the dataset
Signaturesquery(josmSearchExpression,?options)
josmSearchExpression
.
josmSearchExpression
is a string as you would enter it in the JOSM search
dialog. options
is an (optional) object with named parameters, see below.query(predicate,?options)
predicate
.
predicate
is a javascript function which accepts a object as parameter and replies
true, when it matches for the object ans false otherwise.
options
is an (optional) object with named parameters, see below.options
consist of the following (optional) named parameters:
allElements
: boolean (Deprecated parameter names:
all
)caseSensitive
: booleanregexSearch
: boolean (Deprecated parameter names:
withRegexp
,
regexpSearch
)mapCSSSearch
Name | Type | Description |
---|---|---|
expression | string | the match expression |
options | object | (optional) additional named parameters |
relation
Replies the relation with id id
.
Name | Type | Description |
---|---|---|
id | number | the unique numeric id. Must not be 0. |
remove
Removes objects from the dataset.
Signaturesremove(id, type)
remove(id, id, ...)
id
is either an instance of
PrimitiveId or an object with
the properties id
and type
, i.e. {id: 1234, type: "node"}
.
null and undefined are ignored.remove(array|collection)
id
and type
, i.e. {id: 1234, type: "node"}
.
null or undefined elements are ignored.
var DataSet = org.openstreetmap.josm.data.osm.DataSet;
var SimplePrimitiveId = org.openstreetmap.josm.data.osm.SimplePrimitiveId;
var OsmPrimitiveType = org.openstreetmap.josm.data.osm.OsmPrimitiveType;
var rbuilder = require("josm/builder").RelationBuilder;
var nbuilder = require("josm/builder").NodeBuilder;
var wbuilder = require("josm/builder").WayBuilder;
// get a node with a global id
ds.remove(1234, "node");
// remove a node and a way
var id1 = new SimplePrimitiveId(1234, "node")
var id2 = new SimplePrimitiveId(3333, OsmPrimitiveType.WAY)
ds.remove(id1, id2);
// remove a relation and a node
ds.remove({id: 1234, type: "relation"}, id1);
// remove an array of nodes
ds.remove([id1,id2]);
// remove a set of objects
var ids = new HashSet();
ids.add(id1); ids.add(id1);
ds.remove(ids);
save
Saves the dataset to a file (in OSM XML format).
options
can contain the following named options:
version
: stringversion
in the OSM file header. Default: "0.6"changeset
on every
OSM object. If undefined, includes the individual changeset
attribute of the OSM object. Default: undefinedName | Type | Description |
---|---|---|
target | string | the target file. Either a file name as string or a java.io.File |
options | object | (optional) optional named parameters |
var ds = ....; // create and populate a dataset
// save the data
ds.save("/tmp/data.osm");
way
Replies the way with id id
.
Name | Type | Description |
---|---|---|
id | number | the unique numeric id. Must not be 0. |