Mixin DataSetMixin

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 $.

Properties

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

Functions

add

Adds one or more primitives to the dataset.

Signatures
add(o1,o2, ...)
Adds a variable number of objects. null or undefined are ignored. An object is either an instance of Node, Way, or Relation.
add(array|collection)
Adds an javascript array or a java collection of objects. null or undefined are ignored. A list element is an instance of Node, a Way, or Relation. null and undefined are ignored.

Examples

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.

Parameters

Name Type Description
delegate function the function implementing the batch processes. Ignored if null or undefined.

Examples

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.

Signatures
each(delegate,?options)
Iterates over the objects in the dataset and invokes 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.
The parameter options consists of the following (optional) named parameters:
all : boolean
If true, searches all objects in the dataset. If false, ignores incomplete or deleted objects. Default: false.

Parameters

Name 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.

Signatures
get(id, type)
Replies an object given by its unique numeric id and a type. The type is either a string "node", "way", or "relation", or one of the symbols OsmPrimitiveType.NODE, OsmPrimitiveType.WAY, or OsmPrimitiveType.RELATION.
get(id)
Replies an object given an ID. id is either an instance of PrimitiveId or an object with the properties id and type, i.e. {id: 1234, type: "node"}.

Examples

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.

Signatures
has(id, type)
Replies true, if an object given by its unique numeric ID and a type is in the dataset. The type is either a string "node", "way", or "relation", or one of the symbols OsmPrimitiveType.NODE, OsmPrimitiveType.WAY, or OsmPrimitiveType.RELATION.
has(id)
Replies true, if an object with the 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"}.

Examples

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
one of the strings "osm" (Open Street Map XML data), "osc" (Open Street Map change format), "osm.bz2" (Open Street Map XML data, compressed with bzip2), or "osm.gz" (Open Street Map XML data, compressed with gzip). Value is normalized by removing leading and trailing whitespace and conversion to lower case.

Parameters

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

Examples

// 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.

Parameters

Name Type Description
id number the unique numeric id. Must not be 0.

query

Queries the dataset

Signatures
query(josmSearchExpression,?options)
Queries the dataset using the JOSM search expression 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)
Queries the dataset using a javascript predicate function 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.
The parameter options consist of the following (optional) named parameters:
allElements : boolean (Deprecated parameter names: all)
If true, searches all objects in the dataset. If false, ignores incomplete or deleted objects. Default: false.
caseSensitive : boolean
Only applicable for searches with a JOSM search expression. If true, searches case sensitive. If false, searches case insensitive. Default: false.
regexSearch : boolean (Deprecated parameter names: withRegexp, regexpSearch)
Only applicable for searches with a JOSM search expression. If true, the search expression contains regular expressions. If false, it includes only plain strings for searching. Default: false.
mapCSSSearch
Only applies for searches with a JOSM search expression. Default: false.

Parameters

Name Type Description
expression string the match expression
options object (optional) additional named parameters

relation

Replies the relation with id id.

Parameters

Name Type Description
id number the unique numeric id. Must not be 0.

remove

Removes objects from the dataset.

Signatures
remove(id, type)
Removes a single object given by its unique numeric ID (nid) and a type. The type is either a string "node", "way", or "relation", or one of the symbols OsmPrimitiveType.NODE, OsmPrimitiveType.WAY, or OsmPrimitiveType.RELATION.
remove(id, id, ...)
Removes a collection of objects given by the ids. 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)
Removes a collection of objects given by the an array ora java.util.Collection of ids. The collection elemeents are either instances of PrimitiveId or an object with the properties id and type, i.e. {id: 1234, type: "node"}. null or undefined elements are ignored.

Examples

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: string
the value of the attribute version in the OSM file header. Default: "0.6"
changeset: Changeset
the changeset whose id is included in the attribute changeset on every OSM object. If undefined, includes the individual changeset attribute of the OSM object. Default: undefined

Parameters

Name Type Description
target string the target file. Either a file name as string or a java.io.File
options object (optional) optional named parameters

Examples

var ds = ....; // create and populate a dataset
// save the data 
ds.save("/tmp/data.osm");  
 

way

Replies the way with id id.

Parameters

Name Type Description
id number the unique numeric id. Must not be 0.