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
public class MultiFetchServerObjectReader extends OsmServerReader
Retrieves a set ofOsmPrimitives 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 Classes Modifier and Type Class Description protected classMultiFetchServerObjectReader.FetcherThe class that actually download data from OSM API.protected static classMultiFetchServerObjectReader.FetchResultThe 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
Fields Modifier and Type Field Description private java.util.concurrent.ExecutorServiceexecprivate static intMAX_IDS_PER_REQUESTthe max.private java.util.Set<PrimitiveId>missingPrimitivesprivate java.util.Set<java.lang.Long>nodesprivate DataSetoutputDataSetprotected java.util.Map<OsmPrimitiveType,java.util.Set<java.lang.Long>>primitivesMapprivate booleanrecurseDownAppendedprotected booleanrecurseDownRelationsprivate java.util.Set<java.lang.Long>relationsprivate java.util.Set<java.lang.Long>ways-
Fields inherited from class org.openstreetmap.josm.io.OsmServerReader
contentType, gpxParsedProperly
-
Fields inherited from class org.openstreetmap.josm.io.OsmConnection
activeConnection, cancel, fetcher, oAuth20Parameters
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMultiFetchServerObjectReader()Constructs aMultiFetchServerObjectReader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MultiFetchServerObjectReaderappend(java.util.Collection<? extends OsmPrimitive> primitives)appends a list ofOsmPrimitiveto the list of ids which will be fetched from the server.MultiFetchServerObjectReaderappend(DataSet ds, long id, OsmPrimitiveType type)appends aOsmPrimitiveid to the list of ids which will be fetched from the server.MultiFetchServerObjectReaderappend(OsmPrimitive primitive)appends anOsmPrimitiveto the list of ids which will be fetched from the server.voidappend(PrimitiveId id)Remembers anOsmPrimitive's id.MultiFetchServerObjectReaderappendNode(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.MultiFetchServerObjectReaderappendWay(Way way)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 java.lang.StringbuildRequestString(OsmPrimitiveType type, java.util.Set<java.lang.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.protected java.util.Set<java.lang.Long>extractIdPackage(java.util.Set<java.lang.Long> ids)extracts a subset of maxMAX_IDS_PER_REQUESTids fromidsand replies the subset.protected voidfetchPrimitives(java.util.Set<java.lang.Long> ids, OsmPrimitiveType type, ProgressMonitor progressMonitor)fetches a set of ids of a givenOsmPrimitiveTypefrom the serverjava.util.Set<PrimitiveId>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)protected voidmerge(DataSet from)merges the datasetfromtooutputDataSet.DataSetparseOsm(ProgressMonitor progressMonitor)invokes one or more Multi Gets to fetch theOsmPrimitives and replies the dataset of retrieved primitives.protected voidrememberNodesOfIncompleteWaysToLoad(DataSet from)MultiFetchServerObjectReadersetRecurseDownAppended(boolean recurseAppended)Determine how appended objects are treated.MultiFetchServerObjectReadersetRecurseDownRelations(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, setDoAuthenticate
-
Methods inherited from class org.openstreetmap.josm.io.OsmConnection
addAuth, addBasicAuthorizationHeader, addOAuth20AuthorizationHeader, isCanceled, retrieveBasicAuthorizationLogin, setOAuthAccessTokenFetcher
-
-
-
-
Field Detail
-
MAX_IDS_PER_REQUEST
private static final int 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:
- Constant Field Values
-
nodes
private final java.util.Set<java.lang.Long> nodes
-
ways
private final java.util.Set<java.lang.Long> ways
-
relations
private final java.util.Set<java.lang.Long> relations
-
missingPrimitives
private final java.util.Set<PrimitiveId> missingPrimitives
-
outputDataSet
private final DataSet outputDataSet
-
primitivesMap
protected final java.util.Map<OsmPrimitiveType,java.util.Set<java.lang.Long>> primitivesMap
-
recurseDownRelations
protected boolean recurseDownRelations
-
recurseDownAppended
private boolean recurseDownAppended
-
exec
private java.util.concurrent.ExecutorService exec
-
-
Constructor Detail
-
MultiFetchServerObjectReader
protected MultiFetchServerObjectReader()
Constructs aMultiFetchServerObjectReader.
-
-
Method Detail
-
create
public static MultiFetchServerObjectReader create()
Creates a new instance ofMultiFetchServerObjectReaderorMultiFetchOverpassObjectReaderdepending on thepreference.- Returns:
- a new instance
- Since:
- 9241
-
create
public static MultiFetchServerObjectReader create(boolean fromMirror)
Creates a new instance ofMultiFetchServerObjectReaderorMultiFetchOverpassObjectReaderdepending on thefromMirrorparameter.- Parameters:
fromMirror-falseforMultiFetchServerObjectReader,trueforMultiFetchOverpassObjectReader- Returns:
- a new instance
- Since:
- 15520 (changed visibility)
-
append
public void append(PrimitiveId id)
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
public MultiFetchServerObjectReader append(DataSet ds, long id, OsmPrimitiveType type)
appends aOsmPrimitiveid to the list of ids which will be fetched from the server.
-
appendNode
public MultiFetchServerObjectReader appendNode(Node node)
appends aNodeid to the list of ids which will be fetched from the server.- Parameters:
node- the node (ignored, if null)- Returns:
- this
-
appendWay
public MultiFetchServerObjectReader appendWay(Way way)
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
protected MultiFetchServerObjectReader appendRelation(Relation relation)
appends aRelationid to the list of ids which will be fetched from the server.- Parameters:
relation- the relation (ignored, if null)- Returns:
- this
-
append
public MultiFetchServerObjectReader append(OsmPrimitive primitive)
appends anOsmPrimitiveto the list of ids which will be fetched from the server.- Parameters:
primitive- the primitive- Returns:
- this
-
append
public MultiFetchServerObjectReader append(java.util.Collection<? extends OsmPrimitive> primitives)
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:
append(OsmPrimitive)
-
extractIdPackage
protected java.util.Set<java.lang.Long> extractIdPackage(java.util.Set<java.lang.Long> ids)
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
protected java.lang.String buildRequestString(OsmPrimitiveType type, java.util.Set<java.lang.Long> idPackage)
builds the Multi Get request string for a set of ids and a givenOsmPrimitiveType.
-
rememberNodesOfIncompleteWaysToLoad
protected void rememberNodesOfIncompleteWaysToLoad(DataSet from)
-
merge
protected void merge(DataSet from)
merges the datasetfromtooutputDataSet.- Parameters:
from- the other dataset
-
fetchPrimitives
protected void fetchPrimitives(java.util.Set<java.lang.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
public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException
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:
getMissingPrimitives()
-
checkMissing
private void checkMissing(DataSet ds, ProgressMonitor progressMonitor) throws OsmTransferException
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
private void downloadRelations(ProgressMonitor progressMonitor) throws OsmTransferException
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()
-
getMissingPrimitives
public java.util.Set<PrimitiveId> 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
public MultiFetchServerObjectReader setRecurseDownRelations(boolean recurseDownRelations)
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
public MultiFetchServerObjectReader setRecurseDownAppended(boolean recurseAppended)
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
public void cancel()
Description copied from class:OsmConnectionCancels the connection.- Overrides:
cancelin classOsmConnection
-
-