public class MultiFetchServerObjectReader extends OsmServerReader
OsmPrimitive
s from an OSM server using the so called
Multi Fetch API.
Usage:
MultiFetchServerObjectReader reader = MultiFetchServerObjectReader() .append(2345,2334,4444) .append(new Node(72343)); reader.parseOsm(); if (!reader.getMissingPrimitives().isEmpty()) { Main.info("There are missing primitives: " + reader.getMissingPrimitives()); } if (!reader.getSkippedWays().isEmpty()) { Main.info("There are skipped ways: " + reader.getMissingPrimitives()); }
Modifier and Type | Class and Description |
---|---|
protected static class |
MultiFetchServerObjectReader.Fetcher
The class that actually download data from OSM API.
|
protected static class |
MultiFetchServerObjectReader.FetchResult
The class holding the results given by
MultiFetchServerObjectReader.Fetcher . |
OsmServerReader.Compression
Modifier and Type | Field and Description |
---|---|
private static int |
MAX_IDS_PER_REQUEST
the max. number of primitives retrieved in one step.
|
private Set<PrimitiveId> |
missingPrimitives |
private Set<Long> |
nodes |
private DataSet |
outputDataSet |
private Set<Long> |
relations |
private Set<Long> |
ways |
gpxParsedProperly
activeConnection, cancel, oauthParameters
Constructor and Description |
---|
MultiFetchServerObjectReader()
Constructs a
MultiFetchServerObjectReader . |
Modifier and Type | Method and Description |
---|---|
MultiFetchServerObjectReader |
append(Collection<? extends OsmPrimitive> primitives)
appends a list of
OsmPrimitive to the list of ids which will be fetched from the server. |
MultiFetchServerObjectReader |
append(DataSet ds,
long id,
OsmPrimitiveType type)
appends a
OsmPrimitive id to the list of ids which will be fetched from the server. |
MultiFetchServerObjectReader |
append(OsmPrimitive primitive)
appends an
OsmPrimitive to the list of ids which will be fetched from the server. |
MultiFetchServerObjectReader |
appendNode(Node node)
appends a
Node id to the list of ids which will be fetched from the server. |
protected MultiFetchServerObjectReader |
appendRelation(Relation relation)
appends a
Relation id to the list of ids which will be fetched from the server. |
MultiFetchServerObjectReader |
appendWay(Way way)
appends a
Way id and the list of ids of nodes the way refers to the list of ids which will be fetched from the server. |
protected static String |
buildRequestString(OsmPrimitiveType type,
long id)
builds the Multi Get request string for a single id and a given
OsmPrimitiveType . |
protected static String |
buildRequestString(OsmPrimitiveType type,
Set<Long> idPackage)
builds the Multi Get request string for a set of ids and a given
OsmPrimitiveType . |
protected Set<Long> |
extractIdPackage(Set<Long> ids)
extracts a subset of max
MAX_IDS_PER_REQUEST ids from ids and
replies the subset. |
protected void |
fetchPrimitives(Set<Long> ids,
OsmPrimitiveType type,
ProgressMonitor progressMonitor)
fetches a set of ids of a given
OsmPrimitiveType from the server |
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 void |
merge(DataSet from)
merges the dataset
from to outputDataSet . |
DataSet |
parseOsm(ProgressMonitor progressMonitor)
invokes one or more Multi Gets to fetch the
OsmPrimitive s and replies
the dataset of retrieved primitives. |
protected void |
remember(DataSet ds,
long id,
OsmPrimitiveType type)
remembers an
OsmPrimitive 's id. |
protected void |
remember(PrimitiveId id)
Remembers an
OsmPrimitive 's id. |
protected void |
rememberNodesOfIncompleteWaysToLoad(DataSet from) |
getBaseUrl, getInputStream, getInputStreamRaw, isDoAuthenticate, isGpxParsedProperly, parseOsmBzip2, parseOsmChange, parseOsmChangeBzip2, parseOsmChangeGzip, parseOsmGzip, parseRawGps, parseRawGpsBzip2, setDoAuthenticate
addAuth, addBasicAuthorizationHeader, addOAuthAuthorizationHeader, cancel, isCanceled
private static int MAX_IDS_PER_REQUEST
private Set<PrimitiveId> missingPrimitives
private DataSet outputDataSet
public MultiFetchServerObjectReader()
MultiFetchServerObjectReader
.protected void remember(PrimitiveId id)
OsmPrimitive
's id. The id will
later be fetched as part of a Multi Get request.
Ignore the id if it represents a new primitives.id
- the idprotected void remember(DataSet ds, long id, OsmPrimitiveType type) throws IllegalArgumentException, NoSuchElementException
OsmPrimitive
's id. ds
must include
an OsmPrimitive
with id=id
. The id will
later we fetched as part of a Multi Get request.
Ignore the id if it id <= 0.ds
- the dataset (must not be null)id
- the primitive idtype
- The primitive type. Must be one of NODE
, WAY
, RELATION
IllegalArgumentException
- if ds is nullNoSuchElementException
- if ds does not include an OsmPrimitive
with id=id
public MultiFetchServerObjectReader append(DataSet ds, long id, OsmPrimitiveType type)
OsmPrimitive
id to the list of ids which will be fetched from the server.public MultiFetchServerObjectReader appendNode(Node node)
Node
id to the list of ids which will be fetched from the server.node
- the node (ignored, if null)public MultiFetchServerObjectReader appendWay(Way way)
Way
id and the list of ids of nodes the way refers to the list of ids which will be fetched from the server.way
- the way (ignored, if null)protected MultiFetchServerObjectReader appendRelation(Relation relation)
Relation
id to the list of ids which will be fetched from the server.relation
- the relation (ignored, if null)public MultiFetchServerObjectReader append(OsmPrimitive primitive)
OsmPrimitive
to the list of ids which will be fetched from the server.primitive
- the primitivepublic MultiFetchServerObjectReader append(Collection<? extends OsmPrimitive> primitives)
OsmPrimitive
to the list of ids which will be fetched from the server.primitives
- the list of primitives (ignored, if null)append(OsmPrimitive)
protected Set<Long> extractIdPackage(Set<Long> ids)
MAX_IDS_PER_REQUEST
ids from ids
and
replies the subset. The extracted subset is removed from ids
.ids
- a set of idsprotected static String buildRequestString(OsmPrimitiveType type, Set<Long> idPackage)
OsmPrimitiveType
.protected static String buildRequestString(OsmPrimitiveType type, long id)
OsmPrimitiveType
.protected void rememberNodesOfIncompleteWaysToLoad(DataSet from)
protected void merge(DataSet from)
from
to outputDataSet
.from
- the other datasetprotected void fetchPrimitives(Set<Long> ids, OsmPrimitiveType type, ProgressMonitor progressMonitor) throws OsmTransferException
OsmPrimitiveType
from the serverids
- the set of idstype
- The primitive type. Must be one of NODE
, WAY
, RELATION
OsmTransferException
- if an error occurs while communicating with the API serverpublic DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException
OsmPrimitive
s 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)parseOsm
in class OsmServerReader
progressMonitor
- The progress monitorOsmTransferException
- if an error occurs while communicating with the API servergetMissingPrimitives()
public Set<PrimitiveId> getMissingPrimitives()