Package org.openstreetmap.josm.io
Class MultiFetchServerObjectReader
java.lang.Object
org.openstreetmap.josm.io.OsmConnection
org.openstreetmap.josm.io.OsmServerReader
org.openstreetmap.josm.io.MultiFetchServerObjectReader
- Direct Known Subclasses:
MultiFetchOverpassObjectReader
Retrieves a set of
OsmPrimitives from an OSM server using the so called
Multi Fetch API.
Usage:
MultiFetchServerObjectReader reader = MultiFetchServerObjectReader()
.append(new Node(72343));
reader.parseOsm();
if (!reader.getMissingPrimitives().isEmpty()) {
Logging.info("There are missing primitives: " + reader.getMissingPrimitives());
}
if (!reader.getSkippedWays().isEmpty()) {
Logging.info("There are skipped ways: " + reader.getMissingPrimitives());
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThe class that actually download data from OSM API.protected static classThe class holding the results given byMultiFetchServerObjectReader.Fetcher.Nested classes/interfaces inherited from class org.openstreetmap.josm.io.OsmServerReader
OsmServerReader.DomParser<R>Nested classes/interfaces inherited from class org.openstreetmap.josm.io.OsmConnection
OsmConnection.OAuthAccessTokenFetcher -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ExecutorServiceprivate static final intthe max.private final Set<PrimitiveId>private final DataSetprotected final Map<OsmPrimitiveType,Set<Long>> private booleanprotected booleanFields inherited from class org.openstreetmap.josm.io.OsmServerReader
contentType, gpxParsedProperlyFields inherited from class org.openstreetmap.josm.io.OsmConnection
activeConnection, cancel, fetcher, oAuth20Parameters -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs aMultiFetchServerObjectReader. -
Method Summary
Modifier and TypeMethodDescriptionappend(Collection<? extends OsmPrimitive> primitives) appends a list ofOsmPrimitiveto the list of ids which will be fetched from the server.append(DataSet ds, long id, OsmPrimitiveType type) appends aOsmPrimitiveid to the list of ids which will be fetched from the server.append(OsmPrimitive primitive) appends anOsmPrimitiveto the list of ids which will be fetched from the server.voidappend(PrimitiveId id) Remembers anOsmPrimitive's id.appendNode(Node node) appends aNodeid to the list of ids which will be fetched from the server.protected MultiFetchServerObjectReaderappendRelation(Relation relation) appends aRelationid to the list of ids which will be fetched from the server.appends aWayid and the list of ids of nodes the way refers to the list of ids which will be fetched from the server.protected StringbuildRequestString(OsmPrimitiveType type, Set<Long> idPackage) builds the Multi Get request string for a set of ids and a givenOsmPrimitiveType.voidcancel()Cancels the connection.private voidcheckMissing(DataSet ds, ProgressMonitor progressMonitor) Workaround for difference in Overpass API.static MultiFetchServerObjectReadercreate()Creates a new instance ofMultiFetchServerObjectReaderorMultiFetchOverpassObjectReaderdepending on thepreference.static MultiFetchServerObjectReadercreate(boolean fromMirror) Creates a new instance ofMultiFetchServerObjectReaderorMultiFetchOverpassObjectReaderdepending on thefromMirrorparameter.private voiddownloadRelations(ProgressMonitor progressMonitor) Finds best way to download a set of relations.extractIdPackage(Set<Long> ids) extracts a subset of maxMAX_IDS_PER_REQUESTids fromidsand replies the subset.protected voidfetchPrimitives(Set<Long> ids, OsmPrimitiveType type, ProgressMonitor progressMonitor) fetches a set of ids of a givenOsmPrimitiveTypefrom the serverreplies the set of ids of all primitives for which a fetch request to the server was submitted but which are not available from the server (the server replied a return code of 404)protected voidmerges the datasetfromtooutputDataSet.parseOsm(ProgressMonitor progressMonitor) invokes one or more Multi Gets to fetch theOsmPrimitives and replies the dataset of retrieved primitives.protected voidsetRecurseDownAppended(boolean recurseAppended) Determine how appended objects are treated.setRecurseDownRelations(boolean recurseDownRelations) Should downloaded relations be complete?Methods inherited from class org.openstreetmap.josm.io.OsmServerReader
adaptRequest, fetchData, getAttribute, getBaseUrl, getInputStream, getInputStream, getInputStreamRaw, getInputStreamRaw, getInputStreamRaw, getInputStreamRaw, isDoAuthenticate, isGpxParsedProperly, parseNotes, parseOsm, parseOsmChange, parseOsmChange, parseRawGps, parseRawGps, parseRawNotes, parseRawNotes, setDoAuthenticateMethods inherited from class org.openstreetmap.josm.io.OsmConnection
addAuth, addBasicAuthorizationHeader, addOAuth20AuthorizationHeader, isCanceled, retrieveBasicAuthorizationLogin, setOAuthAccessTokenFetcher
-
Field Details
-
MAX_IDS_PER_REQUEST
the max. number of primitives retrieved in one step. Assuming IDs with 10 digits, this leads to a max. request URL of ~ 1900 Bytes ((10 digits + 1 Separator) * 170), which should be safe according to the WWW FAQ.- See Also:
-
nodes
-
ways
-
relations
-
missingPrimitives
-
outputDataSet
-
primitivesMap
-
recurseDownRelations
-
recurseDownAppended
-
exec
-
-
Constructor Details
-
MultiFetchServerObjectReader
protected MultiFetchServerObjectReader()Constructs aMultiFetchServerObjectReader.
-
-
Method Details
-
create
Creates a new instance ofMultiFetchServerObjectReaderorMultiFetchOverpassObjectReaderdepending on thepreference.- Returns:
- a new instance
- Since:
- 9241
-
create
Creates a new instance ofMultiFetchServerObjectReaderorMultiFetchOverpassObjectReaderdepending on thefromMirrorparameter.- Parameters:
fromMirror-falseforMultiFetchServerObjectReader,trueforMultiFetchOverpassObjectReader- Returns:
- a new instance
- Since:
- 15520 (changed visibility)
-
append
Remembers anOsmPrimitive's id. The id will later be fetched as part of a Multi Get request.Ignore the id if it represents a new primitives.
- Parameters:
id- the id
-
append
appends aOsmPrimitiveid to the list of ids which will be fetched from the server. -
appendNode
appends aNodeid to the list of ids which will be fetched from the server.- Parameters:
node- the node (ignored, if null)- Returns:
- this
-
appendWay
appends aWayid and the list of ids of nodes the way refers to the list of ids which will be fetched from the server.- Parameters:
way- the way (ignored, if null)- Returns:
- this
-
appendRelation
appends aRelationid to the list of ids which will be fetched from the server.- Parameters:
relation- the relation (ignored, if null)- Returns:
- this
-
append
appends anOsmPrimitiveto the list of ids which will be fetched from the server.- Parameters:
primitive- the primitive- Returns:
- this
-
append
appends a list ofOsmPrimitiveto the list of ids which will be fetched from the server.- Parameters:
primitives- the list of primitives (ignored, if null)- Returns:
- this
- See Also:
-
extractIdPackage
extracts a subset of maxMAX_IDS_PER_REQUESTids fromidsand replies the subset. The extracted subset is removed fromids.- Parameters:
ids- a set of ids- Returns:
- the subset of ids
-
buildRequestString
builds the Multi Get request string for a set of ids and a givenOsmPrimitiveType. -
rememberNodesOfIncompleteWaysToLoad
-
merge
merges the datasetfromtooutputDataSet.- Parameters:
from- the other dataset
-
fetchPrimitives
protected void fetchPrimitives(Set<Long> ids, OsmPrimitiveType type, ProgressMonitor progressMonitor) throws OsmTransferException fetches a set of ids of a givenOsmPrimitiveTypefrom the server- Parameters:
ids- the set of idstype- The primitive type. Must be one ofNODE,WAY,RELATIONprogressMonitor- progress monitor- Throws:
OsmTransferException- if an error occurs while communicating with the API server
-
parseOsm
invokes one or more Multi Gets to fetch theOsmPrimitives and replies the dataset of retrieved primitives. Note that the dataset includes non visible primitives too! In contrast to a simple Get for a node, a way, or a relation, a Multi Get always replies the latest version of the primitive (if any), even if the primitive is not visible (i.e. if visible==false).Invoke
getMissingPrimitives()to get a list of primitives which have not been found on the server (the server response code was 404)- Specified by:
parseOsmin classOsmServerReader- Parameters:
progressMonitor- progress monitor- Returns:
- the parsed data
- Throws:
OsmTransferException- if an error occurs while communicating with the API server- See Also:
-
checkMissing
Workaround for difference in Overpass API. As of now (version 7.55) Overpass api doesn't return invisible objects. Check if we have objects which do not appear in the dataset and fetch them from OSM instead.- Parameters:
ds- the datasetprogressMonitor- progress monitor- Throws:
OsmTransferException- if an error occurs while communicating with the API server
-
downloadRelations
Finds best way to download a set of relations.- Parameters:
progressMonitor- progress monitor- Throws:
OsmTransferException- if an error occurs while communicating with the API server- See Also:
-
getMissingPrimitives
replies the set of ids of all primitives for which a fetch request to the server was submitted but which are not available from the server (the server replied a return code of 404)- Returns:
- the set of ids of missing primitives
-
setRecurseDownRelations
Should downloaded relations be complete?- Parameters:
recurseDownRelations- true: yes, recurse down to retrieve the members of the relation This will download sub relations, complete way members and nodes. Members of sub relations are not retrieved unless they are also members of the relations. See #18835.- Returns:
- this
- Since:
- 15811
-
setRecurseDownAppended
Determine how appended objects are treated. By default, all children of an appended object are also appended.- Parameters:
recurseAppended- false: do not append known children of appended objects, i.e. all nodes of way and all members of a relation- Returns:
- this
- Since:
- 15811
-
cancel
Description copied from class:OsmConnectionCancels the connection.- Overrides:
cancelin classOsmConnection
-