start OsmVectorLayer
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.oscim.utils.osm;
|
package org.oscim.core.osm;
|
||||||
|
|
||||||
public class Bound {
|
public class Bound {
|
||||||
|
|
||||||
@@ -14,22 +14,22 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.oscim.utils.osm;
|
package org.oscim.core.osm;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OSM dataset containing nodes, areas and relations
|
* Osm dataset containing nodes, areas and relations
|
||||||
*/
|
*/
|
||||||
public class OSMData {
|
public class OsmData {
|
||||||
|
|
||||||
private final Collection<Bound> bounds;
|
private final Collection<Bound> bounds;
|
||||||
private final Collection<OSMNode> nodes;
|
private final Collection<OsmNode> nodes;
|
||||||
private final Collection<OSMWay> ways;
|
private final Collection<OsmWay> ways;
|
||||||
private final Collection<OSMRelation> relations;
|
private final Collection<OsmRelation> relations;
|
||||||
|
|
||||||
public OSMData(Collection<Bound> bounds, Collection<OSMNode> nodes,
|
public OsmData(Collection<Bound> bounds, Collection<OsmNode> nodes,
|
||||||
Collection<OSMWay> ways, Collection<OSMRelation> relations) {
|
Collection<OsmWay> ways, Collection<OsmRelation> relations) {
|
||||||
|
|
||||||
this.bounds = bounds;
|
this.bounds = bounds;
|
||||||
this.nodes = nodes;
|
this.nodes = nodes;
|
||||||
@@ -38,15 +38,15 @@ public class OSMData {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<OSMNode> getNodes() {
|
public Collection<OsmNode> getNodes() {
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<OSMWay> getWays() {
|
public Collection<OsmWay> getWays() {
|
||||||
return ways;
|
return ways;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<OSMRelation> getRelations() {
|
public Collection<OsmRelation> getRelations() {
|
||||||
return relations;
|
return relations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14,18 +14,18 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.oscim.utils.osm;
|
package org.oscim.core.osm;
|
||||||
|
|
||||||
import org.oscim.core.TagSet;
|
import org.oscim.core.TagSet;
|
||||||
|
|
||||||
import com.vividsolutions.jts.geom.Geometry;
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
|
||||||
public abstract class OSMElement {
|
public abstract class OsmElement {
|
||||||
|
|
||||||
public final TagSet tags;
|
public final TagSet tags;
|
||||||
public final long id;
|
public final long id;
|
||||||
|
|
||||||
public OSMElement(TagSet tags, long id) {
|
public OsmElement(TagSet tags, long id) {
|
||||||
assert tags != null;
|
assert tags != null;
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@@ -47,7 +47,7 @@ public abstract class OSMElement {
|
|||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
OSMElement other = (OSMElement) obj;
|
OsmElement other = (OsmElement) obj;
|
||||||
if (id != other.id)
|
if (id != other.id)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
@@ -14,9 +14,9 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.oscim.utils.osm;
|
package org.oscim.core.osm;
|
||||||
|
|
||||||
public class OSMMember {
|
public class OsmMember {
|
||||||
public enum MemberType {
|
public enum MemberType {
|
||||||
NODE,
|
NODE,
|
||||||
WAY,
|
WAY,
|
||||||
@@ -24,9 +24,9 @@ public class OSMMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final String role;
|
public final String role;
|
||||||
public final OSMElement member;
|
public final OsmElement member;
|
||||||
|
|
||||||
public OSMMember(String role, OSMElement member) {
|
public OsmMember(String role, OsmElement member) {
|
||||||
assert role != null && member != null;
|
assert role != null && member != null;
|
||||||
this.role = role;
|
this.role = role;
|
||||||
this.member = member;
|
this.member = member;
|
||||||
@@ -14,18 +14,18 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.oscim.utils.osm;
|
package org.oscim.core.osm;
|
||||||
|
|
||||||
import org.oscim.core.TagSet;
|
import org.oscim.core.TagSet;
|
||||||
|
|
||||||
import com.vividsolutions.jts.geom.Geometry;
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
|
||||||
public class OSMNode extends OSMElement {
|
public class OsmNode extends OsmElement {
|
||||||
|
|
||||||
public final double lat;
|
public final double lat;
|
||||||
public final double lon;
|
public final double lon;
|
||||||
|
|
||||||
public OSMNode(double lat, double lon, TagSet tags, long id) {
|
public OsmNode(double lat, double lon, TagSet tags, long id) {
|
||||||
super(tags, id);
|
super(tags, id);
|
||||||
this.lat = lat;
|
this.lat = lat;
|
||||||
this.lon = lon;
|
this.lon = lon;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.oscim.utils.osm;
|
package org.oscim.core.osm;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -23,16 +23,16 @@ import org.oscim.core.TagSet;
|
|||||||
|
|
||||||
import com.vividsolutions.jts.geom.Geometry;
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
|
||||||
public class OSMRelation extends OSMElement {
|
public class OsmRelation extends OsmElement {
|
||||||
|
|
||||||
public final List<OSMMember> relationMembers;
|
public final List<OsmMember> relationMembers;
|
||||||
|
|
||||||
// content added after constructor call
|
// content added after constructor call
|
||||||
|
|
||||||
public OSMRelation(TagSet tags, long id, int initialMemberSize) {
|
public OsmRelation(TagSet tags, long id, int initialMemberSize) {
|
||||||
super(tags, id);
|
super(tags, id);
|
||||||
this.relationMembers =
|
this.relationMembers =
|
||||||
new ArrayList<OSMMember>(initialMemberSize);
|
new ArrayList<OsmMember>(initialMemberSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.oscim.utils.osm;
|
package org.oscim.core.osm;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -25,11 +25,11 @@ import com.vividsolutions.jts.geom.Geometry;
|
|||||||
import com.vividsolutions.jts.geom.LineString;
|
import com.vividsolutions.jts.geom.LineString;
|
||||||
import com.vividsolutions.jts.geom.impl.PackedCoordinateSequenceFactory;
|
import com.vividsolutions.jts.geom.impl.PackedCoordinateSequenceFactory;
|
||||||
|
|
||||||
public class OSMWay extends OSMElement {
|
public class OsmWay extends OsmElement {
|
||||||
|
|
||||||
public final List<OSMNode> nodes;
|
public final List<OsmNode> nodes;
|
||||||
|
|
||||||
public OSMWay(TagSet tags, long id, List<OSMNode> nodes) {
|
public OsmWay(TagSet tags, long id, List<OsmNode> nodes) {
|
||||||
super(tags, id);
|
super(tags, id);
|
||||||
this.nodes = nodes;
|
this.nodes = nodes;
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ public class OSMWay extends OSMElement {
|
|||||||
public Geometry toJts() {
|
public Geometry toJts() {
|
||||||
double[] coords = new double[nodes.size() * 2];
|
double[] coords = new double[nodes.size() * 2];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (OSMNode n : nodes) {
|
for (OsmNode n : nodes) {
|
||||||
coords[i++] = n.lon;
|
coords[i++] = n.lon;
|
||||||
coords[i++] = n.lat;
|
coords[i++] = n.lat;
|
||||||
}
|
}
|
||||||
19
vtm-extras/src/org/oscim/layers/OsmVectorLayer.java
Normal file
19
vtm-extras/src/org/oscim/layers/OsmVectorLayer.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package org.oscim.layers;
|
||||||
|
|
||||||
|
import org.oscim.core.BoundingBox;
|
||||||
|
import org.oscim.core.osm.OsmElement;
|
||||||
|
import org.oscim.layers.vector.AbstractVectorLayer;
|
||||||
|
import org.oscim.map.Map;
|
||||||
|
|
||||||
|
public class OsmVectorLayer extends AbstractVectorLayer<OsmElement> {
|
||||||
|
|
||||||
|
public OsmVectorLayer(Map map) {
|
||||||
|
super(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void processFeatures(Task t, BoundingBox b) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -25,11 +25,11 @@ import org.openstreetmap.osmosis.osmbinary.BinaryParser;
|
|||||||
import org.openstreetmap.osmosis.osmbinary.Osmformat;
|
import org.openstreetmap.osmosis.osmbinary.Osmformat;
|
||||||
import org.oscim.core.Tag;
|
import org.oscim.core.Tag;
|
||||||
import org.oscim.core.TagSet;
|
import org.oscim.core.TagSet;
|
||||||
import org.oscim.utils.osm.OSMData;
|
import org.oscim.core.osm.OsmData;
|
||||||
import org.oscim.utils.osm.OSMMember;
|
import org.oscim.core.osm.OsmMember;
|
||||||
import org.oscim.utils.osm.OSMNode;
|
import org.oscim.core.osm.OsmNode;
|
||||||
import org.oscim.utils.osm.OSMRelation;
|
import org.oscim.core.osm.OsmRelation;
|
||||||
import org.oscim.utils.osm.OSMWay;
|
import org.oscim.core.osm.OsmWay;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that reads and parses binary files and sends the contained entities to
|
* Class that reads and parses binary files and sends the contained entities to
|
||||||
@@ -65,8 +65,8 @@ public class OsmPbfParser extends BinaryParser {
|
|||||||
/** The magic number used to indicate no changeset metadata for this entity. */
|
/** The magic number used to indicate no changeset metadata for this entity. */
|
||||||
static final int NOCHANGESET = -1;
|
static final int NOCHANGESET = -1;
|
||||||
|
|
||||||
HashMap<Long, OSMNode> mNodeMap = new HashMap<Long, OSMNode>();
|
HashMap<Long, OsmNode> mNodeMap = new HashMap<Long, OsmNode>();
|
||||||
HashMap<Long, OSMWay> mWayMap = new HashMap<Long, OSMWay>();
|
HashMap<Long, OsmWay> mWayMap = new HashMap<Long, OsmWay>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void parseNodes(List<Osmformat.Node> nodes) {
|
protected void parseNodes(List<Osmformat.Node> nodes) {
|
||||||
@@ -82,16 +82,16 @@ public class OsmPbfParser extends BinaryParser {
|
|||||||
// long id, int version, Date timestamp, OsmUser user,
|
// long id, int version, Date timestamp, OsmUser user,
|
||||||
// long changesetId, Collection<Tag> tags,
|
// long changesetId, Collection<Tag> tags,
|
||||||
// double latitude, double longitude
|
// double latitude, double longitude
|
||||||
OSMNode tmp;
|
OsmNode tmp;
|
||||||
long id = i.getId();
|
long id = i.getId();
|
||||||
double latf = parseLat(i.getLat()), lonf = parseLon(i.getLon());
|
double latf = parseLat(i.getLat()), lonf = parseLon(i.getLon());
|
||||||
|
|
||||||
// if (i.hasInfo()) {
|
// if (i.hasInfo()) {
|
||||||
// Osmformat.Info info = i.getInfo();
|
// Osmformat.Info info = i.getInfo();
|
||||||
// tmp = new OSMNode(new CommonEntityData(id, info.getVersion(), getDate(info),
|
// tmp = new OsmNode(new CommonEntityData(id, info.getVersion(), getDate(info),
|
||||||
// getUser(info), info.getChangeset(), tags), latf, lonf);
|
// getUser(info), info.getChangeset(), tags), latf, lonf);
|
||||||
// } else {
|
// } else {
|
||||||
tmp = new OSMNode(latf, lonf, tags, id);
|
tmp = new OsmNode(latf, lonf, tags, id);
|
||||||
// tmp = new Node(new CommonEntityData(id, NOVERSION, NODATE, OsmUser.NONE,
|
// tmp = new Node(new CommonEntityData(id, NOVERSION, NODATE, OsmUser.NONE,
|
||||||
// NOCHANGESET, tags), latf, lonf);
|
// NOCHANGESET, tags), latf, lonf);
|
||||||
// }
|
// }
|
||||||
@@ -115,7 +115,7 @@ public class OsmPbfParser extends BinaryParser {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
for (int i = 0; i < nodes.getIdCount(); i++) {
|
for (int i = 0; i < nodes.getIdCount(); i++) {
|
||||||
OSMNode tmp;
|
OsmNode tmp;
|
||||||
TagSet tags = new TagSet(4);
|
TagSet tags = new TagSet(4);
|
||||||
long lat = nodes.getLat(i) + lastLat;
|
long lat = nodes.getLat(i) + lastLat;
|
||||||
lastLat = lat;
|
lastLat = lat;
|
||||||
@@ -150,9 +150,9 @@ public class OsmPbfParser extends BinaryParser {
|
|||||||
// user = new OsmUser(uid, getStringById(userSid));
|
// user = new OsmUser(uid, getStringById(userSid));
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// tmp = new OSMNode(id, tags, latf, lonf);
|
// tmp = new OsmNode(id, tags, latf, lonf);
|
||||||
// } else {
|
// } else {
|
||||||
tmp = new OSMNode(latf, lonf, tags, id);
|
tmp = new OsmNode(latf, lonf, tags, id);
|
||||||
|
|
||||||
mNodeMap.put(Long.valueOf(id), tmp);
|
mNodeMap.put(Long.valueOf(id), tmp);
|
||||||
|
|
||||||
@@ -178,11 +178,11 @@ public class OsmPbfParser extends BinaryParser {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
long lastId = 0;
|
long lastId = 0;
|
||||||
List<OSMNode> nodes = new ArrayList<OSMNode>();
|
List<OsmNode> nodes = new ArrayList<OsmNode>();
|
||||||
for (long j : i.getRefsList()) {
|
for (long j : i.getRefsList()) {
|
||||||
OSMNode n = mNodeMap.get(Long.valueOf(j + lastId));
|
OsmNode n = mNodeMap.get(Long.valueOf(j + lastId));
|
||||||
if (n == null)
|
if (n == null)
|
||||||
n = new OSMNode(Double.NaN, Double.NaN, null, j + lastId);
|
n = new OsmNode(Double.NaN, Double.NaN, null, j + lastId);
|
||||||
|
|
||||||
nodes.add(n);
|
nodes.add(n);
|
||||||
lastId = j + lastId;
|
lastId = j + lastId;
|
||||||
@@ -193,13 +193,13 @@ public class OsmPbfParser extends BinaryParser {
|
|||||||
// long id, int version, Date timestamp, OsmUser user,
|
// long id, int version, Date timestamp, OsmUser user,
|
||||||
// long changesetId, Collection<Tag> tags,
|
// long changesetId, Collection<Tag> tags,
|
||||||
// List<WayNode> wayNodes
|
// List<WayNode> wayNodes
|
||||||
OSMWay tmp;
|
OsmWay tmp;
|
||||||
// if (i.hasInfo()) {
|
// if (i.hasInfo()) {
|
||||||
// Osmformat.Info info = i.getInfo();
|
// Osmformat.Info info = i.getInfo();
|
||||||
// tmp = new Way(new CommonEntityData(id, info.getVersion(), getDate(info),
|
// tmp = new Way(new CommonEntityData(id, info.getVersion(), getDate(info),
|
||||||
// getUser(info), info.getChangeset(), tags), nodes);
|
// getUser(info), info.getChangeset(), tags), nodes);
|
||||||
// } else {
|
// } else {
|
||||||
tmp = new OSMWay(tags, id, nodes);
|
tmp = new OsmWay(tags, id, nodes);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
mWayMap.put(Long.valueOf(id), tmp);
|
mWayMap.put(Long.valueOf(id), tmp);
|
||||||
@@ -220,7 +220,7 @@ public class OsmPbfParser extends BinaryParser {
|
|||||||
long id = i.getId();
|
long id = i.getId();
|
||||||
|
|
||||||
long lastMid = 0;
|
long lastMid = 0;
|
||||||
List<OSMMember> nodes = new ArrayList<OSMMember>();
|
List<OsmMember> nodes = new ArrayList<OsmMember>();
|
||||||
int memberCnt = i.getMemidsCount();
|
int memberCnt = i.getMemidsCount();
|
||||||
|
|
||||||
// for (int j = 0; j < memberCnt; j++) {
|
// for (int j = 0; j < memberCnt; j++) {
|
||||||
@@ -240,14 +240,14 @@ public class OsmPbfParser extends BinaryParser {
|
|||||||
// assert false; // TODO; Illegal file?
|
// assert false; // TODO; Illegal file?
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// nodes.add(new OSMMember(mid, etype, role));
|
// nodes.add(new OsmMember(mid, etype, role));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// long id, int version, TimestampContainer timestampContainer,
|
// long id, int version, TimestampContainer timestampContainer,
|
||||||
// OsmUser user,
|
// OsmUser user,
|
||||||
// long changesetId, Collection<Tag> tags,
|
// long changesetId, Collection<Tag> tags,
|
||||||
// List<RelationMember> members
|
// List<RelationMember> members
|
||||||
OSMRelation tmp = new OSMRelation(tags, id, memberCnt);
|
OsmRelation tmp = new OsmRelation(tags, id, memberCnt);
|
||||||
|
|
||||||
// if (i.hasInfo()) {
|
// if (i.hasInfo()) {
|
||||||
// Osmformat.Info info = i.getInfo();
|
// Osmformat.Info info = i.getInfo();
|
||||||
@@ -290,16 +290,16 @@ public class OsmPbfParser extends BinaryParser {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public OSMData getData() {
|
public OsmData getData() {
|
||||||
|
|
||||||
// for (Entry<OSMRelation, List<TmpRelation>> entry : relationMembersForRelation
|
// for (Entry<OsmRelation, List<TmpRelation>> entry : relationMembersForRelation
|
||||||
// .entrySet()) {
|
// .entrySet()) {
|
||||||
//
|
//
|
||||||
// OSMRelation relation = entry.getKey();
|
// OsmRelation relation = entry.getKey();
|
||||||
//
|
//
|
||||||
// for (TmpRelation member : entry.getValue()) {
|
// for (TmpRelation member : entry.getValue()) {
|
||||||
//
|
//
|
||||||
// OSMElement memberObject = null;
|
// OsmElement memberObject = null;
|
||||||
//
|
//
|
||||||
// if ("node".equals(member)) {
|
// if ("node".equals(member)) {
|
||||||
// memberObject = nodesById.get(member.id);
|
// memberObject = nodesById.get(member.id);
|
||||||
@@ -313,7 +313,7 @@ public class OsmPbfParser extends BinaryParser {
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// if (memberObject != null) {
|
// if (memberObject != null) {
|
||||||
// OSMMember ownMember = new OSMMember(member.role,
|
// OsmMember ownMember = new OsmMember(member.role,
|
||||||
// memberObject);
|
// memberObject);
|
||||||
//
|
//
|
||||||
// relation.relationMembers.add(ownMember);
|
// relation.relationMembers.add(ownMember);
|
||||||
@@ -323,11 +323,11 @@ public class OsmPbfParser extends BinaryParser {
|
|||||||
|
|
||||||
// give up references to original collections
|
// give up references to original collections
|
||||||
|
|
||||||
ArrayList<OSMWay> ways = new ArrayList<OSMWay>(mWayMap.values());
|
ArrayList<OsmWay> ways = new ArrayList<OsmWay>(mWayMap.values());
|
||||||
ArrayList<OSMNode> nodes = new ArrayList<OSMNode>(mNodeMap.values());
|
ArrayList<OsmNode> nodes = new ArrayList<OsmNode>(mNodeMap.values());
|
||||||
|
|
||||||
//log.debug("nodes: " + nodes.size() + " ways: " + ways.size());
|
//log.debug("nodes: " + nodes.size() + " ways: " + ways.size());
|
||||||
|
|
||||||
return new OSMData(null, nodes, ways, null);
|
return new OsmData(null, nodes, ways, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.openstreetmap.osmosis.osmbinary.file.BlockInputStream;
|
import org.openstreetmap.osmosis.osmbinary.file.BlockInputStream;
|
||||||
import org.oscim.utils.osm.OSMData;
|
import org.oscim.core.osm.OsmData;
|
||||||
|
|
||||||
public class OsmPbfReader {
|
public class OsmPbfReader {
|
||||||
|
|
||||||
public static OSMData process(InputStream is) {
|
public static OsmData process(InputStream is) {
|
||||||
OsmPbfParser parser = new OsmPbfParser();
|
OsmPbfParser parser = new OsmPbfParser();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -35,13 +35,13 @@ import java.util.zip.InflaterInputStream;
|
|||||||
|
|
||||||
import org.oscim.core.Tag;
|
import org.oscim.core.Tag;
|
||||||
import org.oscim.core.TagSet;
|
import org.oscim.core.TagSet;
|
||||||
import org.oscim.utils.osm.Bound;
|
import org.oscim.core.osm.Bound;
|
||||||
import org.oscim.utils.osm.OSMData;
|
import org.oscim.core.osm.OsmData;
|
||||||
import org.oscim.utils.osm.OSMElement;
|
import org.oscim.core.osm.OsmElement;
|
||||||
import org.oscim.utils.osm.OSMMember;
|
import org.oscim.core.osm.OsmMember;
|
||||||
import org.oscim.utils.osm.OSMNode;
|
import org.oscim.core.osm.OsmNode;
|
||||||
import org.oscim.utils.osm.OSMRelation;
|
import org.oscim.core.osm.OsmRelation;
|
||||||
import org.oscim.utils.osm.OSMWay;
|
import org.oscim.core.osm.OsmWay;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonFactory;
|
import com.fasterxml.jackson.core.JsonFactory;
|
||||||
import com.fasterxml.jackson.core.JsonParseException;
|
import com.fasterxml.jackson.core.JsonParseException;
|
||||||
@@ -166,15 +166,15 @@ public class OverpassAPIReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final List<Bound> bounds = new ArrayList<Bound>();
|
private final List<Bound> bounds = new ArrayList<Bound>();
|
||||||
private Map<Long, OSMNode> nodesById = new HashMap<Long, OSMNode>();
|
private Map<Long, OsmNode> nodesById = new HashMap<Long, OsmNode>();
|
||||||
private Map<Long, OSMWay> waysById = new HashMap<Long, OSMWay>();
|
private Map<Long, OsmWay> waysById = new HashMap<Long, OsmWay>();
|
||||||
private Map<Long, OSMRelation> relationsById = new HashMap<Long, OSMRelation>();
|
private Map<Long, OsmRelation> relationsById = new HashMap<Long, OsmRelation>();
|
||||||
private Map<OSMRelation, List<TmpRelation>> relationMembersForRelation =
|
private Map<OsmRelation, List<TmpRelation>> relationMembersForRelation =
|
||||||
new HashMap<OSMRelation, List<TmpRelation>>();
|
new HashMap<OsmRelation, List<TmpRelation>>();
|
||||||
|
|
||||||
private final Collection<OSMNode> ownNodes = new ArrayList<OSMNode>(10000);
|
private final Collection<OsmNode> ownNodes = new ArrayList<OsmNode>(10000);
|
||||||
private final Collection<OSMWay> ownWays = new ArrayList<OSMWay>(1000);
|
private final Collection<OsmWay> ownWays = new ArrayList<OsmWay>(1000);
|
||||||
private final Collection<OSMRelation> ownRelations = new ArrayList<OSMRelation>(
|
private final Collection<OsmRelation> ownRelations = new ArrayList<OsmRelation>(
|
||||||
100);
|
100);
|
||||||
|
|
||||||
public void parse(InputStream in) throws IOException {
|
public void parse(InputStream in) throws IOException {
|
||||||
@@ -236,7 +236,7 @@ public class OverpassAPIReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log("node: "+id + " "+ lat + " " + lon);
|
// log("node: "+id + " "+ lat + " " + lon);
|
||||||
OSMNode node = new OSMNode(lat, lon, tags, id);
|
OsmNode node = new OsmNode(lat, lon, tags, id);
|
||||||
ownNodes.add(node);
|
ownNodes.add(node);
|
||||||
nodesById.put(Long.valueOf(id), node);
|
nodesById.put(Long.valueOf(id), node);
|
||||||
}
|
}
|
||||||
@@ -245,7 +245,7 @@ public class OverpassAPIReader {
|
|||||||
|
|
||||||
long id = 0;
|
long id = 0;
|
||||||
TagSet tags = null;
|
TagSet tags = null;
|
||||||
ArrayList<OSMNode> wayNodes = new ArrayList<OSMNode>();
|
ArrayList<OsmNode> wayNodes = new ArrayList<OsmNode>();
|
||||||
|
|
||||||
while (jp.nextToken() != JsonToken.END_OBJECT) {
|
while (jp.nextToken() != JsonToken.END_OBJECT) {
|
||||||
|
|
||||||
@@ -259,7 +259,7 @@ public class OverpassAPIReader {
|
|||||||
while (jp.nextToken() != JsonToken.END_ARRAY) {
|
while (jp.nextToken() != JsonToken.END_ARRAY) {
|
||||||
Long nodeId = Long.valueOf(jp.getLongValue());
|
Long nodeId = Long.valueOf(jp.getLongValue());
|
||||||
|
|
||||||
OSMNode node = nodesById.get(nodeId);
|
OsmNode node = nodesById.get(nodeId);
|
||||||
if (node != null)
|
if (node != null)
|
||||||
// log("missing node " + nodeId);
|
// log("missing node " + nodeId);
|
||||||
// else
|
// else
|
||||||
@@ -270,7 +270,7 @@ public class OverpassAPIReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log("way: "+ id + " " + wayNodes.size());
|
// log("way: "+ id + " " + wayNodes.size());
|
||||||
OSMWay way = new OSMWay(tags, id, wayNodes);
|
OsmWay way = new OsmWay(tags, id, wayNodes);
|
||||||
ownWays.add(way);
|
ownWays.add(way);
|
||||||
waysById.put(Long.valueOf(id), way);
|
waysById.put(Long.valueOf(id), way);
|
||||||
}
|
}
|
||||||
@@ -313,7 +313,7 @@ public class OverpassAPIReader {
|
|||||||
tags = parseTags(jp);
|
tags = parseTags(jp);
|
||||||
}
|
}
|
||||||
|
|
||||||
OSMRelation relation = new OSMRelation(tags, id, members.size());
|
OsmRelation relation = new OsmRelation(tags, id, members.size());
|
||||||
ownRelations.add(relation);
|
ownRelations.add(relation);
|
||||||
relationsById.put(Long.valueOf(id), relation);
|
relationsById.put(Long.valueOf(id), relation);
|
||||||
relationMembersForRelation.put(relation, members);
|
relationMembersForRelation.put(relation, members);
|
||||||
@@ -342,7 +342,7 @@ public class OverpassAPIReader {
|
|||||||
System.out.println(msg);
|
System.out.println(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OSMData getData() {
|
public OsmData getData() {
|
||||||
|
|
||||||
String encoded;
|
String encoded;
|
||||||
try {
|
try {
|
||||||
@@ -371,14 +371,14 @@ public class OverpassAPIReader {
|
|||||||
inputStream = null;
|
inputStream = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Entry<OSMRelation, List<TmpRelation>> entry : relationMembersForRelation
|
for (Entry<OsmRelation, List<TmpRelation>> entry : relationMembersForRelation
|
||||||
.entrySet()) {
|
.entrySet()) {
|
||||||
|
|
||||||
OSMRelation relation = entry.getKey();
|
OsmRelation relation = entry.getKey();
|
||||||
|
|
||||||
for (TmpRelation member : entry.getValue()) {
|
for (TmpRelation member : entry.getValue()) {
|
||||||
|
|
||||||
OSMElement memberObject = null;
|
OsmElement memberObject = null;
|
||||||
|
|
||||||
if ("node".equals(member)) {
|
if ("node".equals(member)) {
|
||||||
memberObject = nodesById.get(member.id);
|
memberObject = nodesById.get(member.id);
|
||||||
@@ -392,7 +392,7 @@ public class OverpassAPIReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (memberObject != null) {
|
if (memberObject != null) {
|
||||||
OSMMember ownMember = new OSMMember(member.role,
|
OsmMember ownMember = new OsmMember(member.role,
|
||||||
memberObject);
|
memberObject);
|
||||||
|
|
||||||
relation.relationMembers.add(ownMember);
|
relation.relationMembers.add(ownMember);
|
||||||
@@ -408,6 +408,6 @@ public class OverpassAPIReader {
|
|||||||
relationsById = null;
|
relationsById = null;
|
||||||
relationMembersForRelation = null;
|
relationMembersForRelation = null;
|
||||||
|
|
||||||
return new OSMData(bounds, ownNodes, ownWays, ownRelations);
|
return new OsmData(bounds, ownNodes, ownWays, ownRelations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user