start OsmVectorLayer

This commit is contained in:
Hannes Janetzek 2014-02-18 21:31:00 +01:00
parent 6a40c3c375
commit 8428f438db
11 changed files with 110 additions and 91 deletions

View File

@ -14,7 +14,7 @@
* 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/>.
*/
package org.oscim.utils.osm;
package org.oscim.core.osm;
public class Bound {

View File

@ -14,22 +14,22 @@
* 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/>.
*/
package org.oscim.utils.osm;
package org.oscim.core.osm;
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<OSMNode> nodes;
private final Collection<OSMWay> ways;
private final Collection<OSMRelation> relations;
private final Collection<OsmNode> nodes;
private final Collection<OsmWay> ways;
private final Collection<OsmRelation> relations;
public OSMData(Collection<Bound> bounds, Collection<OSMNode> nodes,
Collection<OSMWay> ways, Collection<OSMRelation> relations) {
public OsmData(Collection<Bound> bounds, Collection<OsmNode> nodes,
Collection<OsmWay> ways, Collection<OsmRelation> relations) {
this.bounds = bounds;
this.nodes = nodes;
@ -38,15 +38,15 @@ public class OSMData {
}
public Collection<OSMNode> getNodes() {
public Collection<OsmNode> getNodes() {
return nodes;
}
public Collection<OSMWay> getWays() {
public Collection<OsmWay> getWays() {
return ways;
}
public Collection<OSMRelation> getRelations() {
public Collection<OsmRelation> getRelations() {
return relations;
}

View File

@ -14,18 +14,18 @@
* 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/>.
*/
package org.oscim.utils.osm;
package org.oscim.core.osm;
import org.oscim.core.TagSet;
import com.vividsolutions.jts.geom.Geometry;
public abstract class OSMElement {
public abstract class OsmElement {
public final TagSet tags;
public final long id;
public OSMElement(TagSet tags, long id) {
public OsmElement(TagSet tags, long id) {
assert tags != null;
this.tags = tags;
this.id = id;
@ -47,7 +47,7 @@ public abstract class OSMElement {
return false;
if (getClass() != obj.getClass())
return false;
OSMElement other = (OSMElement) obj;
OsmElement other = (OsmElement) obj;
if (id != other.id)
return false;
return true;

View File

@ -14,9 +14,9 @@
* 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/>.
*/
package org.oscim.utils.osm;
package org.oscim.core.osm;
public class OSMMember {
public class OsmMember {
public enum MemberType {
NODE,
WAY,
@ -24,9 +24,9 @@ public class OSMMember {
}
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;
this.role = role;
this.member = member;

View File

@ -14,18 +14,18 @@
* 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/>.
*/
package org.oscim.utils.osm;
package org.oscim.core.osm;
import org.oscim.core.TagSet;
import com.vividsolutions.jts.geom.Geometry;
public class OSMNode extends OSMElement {
public class OsmNode extends OsmElement {
public final double lat;
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);
this.lat = lat;
this.lon = lon;

View File

@ -14,7 +14,7 @@
* 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/>.
*/
package org.oscim.utils.osm;
package org.oscim.core.osm;
import java.util.ArrayList;
import java.util.List;
@ -23,16 +23,16 @@ import org.oscim.core.TagSet;
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
public OSMRelation(TagSet tags, long id, int initialMemberSize) {
public OsmRelation(TagSet tags, long id, int initialMemberSize) {
super(tags, id);
this.relationMembers =
new ArrayList<OSMMember>(initialMemberSize);
new ArrayList<OsmMember>(initialMemberSize);
}
@Override

View File

@ -14,7 +14,7 @@
* 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/>.
*/
package org.oscim.utils.osm;
package org.oscim.core.osm;
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.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);
this.nodes = nodes;
}
@ -47,7 +47,7 @@ public class OSMWay extends OSMElement {
public Geometry toJts() {
double[] coords = new double[nodes.size() * 2];
int i = 0;
for (OSMNode n : nodes) {
for (OsmNode n : nodes) {
coords[i++] = n.lon;
coords[i++] = n.lat;
}

View 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) {
}
}

View File

@ -25,11 +25,11 @@ import org.openstreetmap.osmosis.osmbinary.BinaryParser;
import org.openstreetmap.osmosis.osmbinary.Osmformat;
import org.oscim.core.Tag;
import org.oscim.core.TagSet;
import org.oscim.utils.osm.OSMData;
import org.oscim.utils.osm.OSMMember;
import org.oscim.utils.osm.OSMNode;
import org.oscim.utils.osm.OSMRelation;
import org.oscim.utils.osm.OSMWay;
import org.oscim.core.osm.OsmData;
import org.oscim.core.osm.OsmMember;
import org.oscim.core.osm.OsmNode;
import org.oscim.core.osm.OsmRelation;
import org.oscim.core.osm.OsmWay;
/**
* 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. */
static final int NOCHANGESET = -1;
HashMap<Long, OSMNode> mNodeMap = new HashMap<Long, OSMNode>();
HashMap<Long, OSMWay> mWayMap = new HashMap<Long, OSMWay>();
HashMap<Long, OsmNode> mNodeMap = new HashMap<Long, OsmNode>();
HashMap<Long, OsmWay> mWayMap = new HashMap<Long, OsmWay>();
@Override
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 changesetId, Collection<Tag> tags,
// double latitude, double longitude
OSMNode tmp;
OsmNode tmp;
long id = i.getId();
double latf = parseLat(i.getLat()), lonf = parseLon(i.getLon());
// if (i.hasInfo()) {
// 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);
// } 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,
// NOCHANGESET, tags), latf, lonf);
// }
@ -115,7 +115,7 @@ public class OsmPbfParser extends BinaryParser {
// }
for (int i = 0; i < nodes.getIdCount(); i++) {
OSMNode tmp;
OsmNode tmp;
TagSet tags = new TagSet(4);
long lat = nodes.getLat(i) + lastLat;
lastLat = lat;
@ -150,9 +150,9 @@ public class OsmPbfParser extends BinaryParser {
// user = new OsmUser(uid, getStringById(userSid));
// }
//
// tmp = new OSMNode(id, tags, latf, lonf);
// tmp = new OsmNode(id, tags, latf, lonf);
// } else {
tmp = new OSMNode(latf, lonf, tags, id);
tmp = new OsmNode(latf, lonf, tags, id);
mNodeMap.put(Long.valueOf(id), tmp);
@ -178,11 +178,11 @@ public class OsmPbfParser extends BinaryParser {
// }
long lastId = 0;
List<OSMNode> nodes = new ArrayList<OSMNode>();
List<OsmNode> nodes = new ArrayList<OsmNode>();
for (long j : i.getRefsList()) {
OSMNode n = mNodeMap.get(Long.valueOf(j + lastId));
OsmNode n = mNodeMap.get(Long.valueOf(j + lastId));
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);
lastId = j + lastId;
@ -193,13 +193,13 @@ public class OsmPbfParser extends BinaryParser {
// long id, int version, Date timestamp, OsmUser user,
// long changesetId, Collection<Tag> tags,
// List<WayNode> wayNodes
OSMWay tmp;
OsmWay tmp;
// if (i.hasInfo()) {
// Osmformat.Info info = i.getInfo();
// tmp = new Way(new CommonEntityData(id, info.getVersion(), getDate(info),
// getUser(info), info.getChangeset(), tags), nodes);
// } else {
tmp = new OSMWay(tags, id, nodes);
tmp = new OsmWay(tags, id, nodes);
// }
mWayMap.put(Long.valueOf(id), tmp);
@ -220,7 +220,7 @@ public class OsmPbfParser extends BinaryParser {
long id = i.getId();
long lastMid = 0;
List<OSMMember> nodes = new ArrayList<OSMMember>();
List<OsmMember> nodes = new ArrayList<OsmMember>();
int memberCnt = i.getMemidsCount();
// for (int j = 0; j < memberCnt; j++) {
@ -240,14 +240,14 @@ public class OsmPbfParser extends BinaryParser {
// 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,
// OsmUser user,
// long changesetId, Collection<Tag> tags,
// List<RelationMember> members
OSMRelation tmp = new OSMRelation(tags, id, memberCnt);
OsmRelation tmp = new OsmRelation(tags, id, memberCnt);
// if (i.hasInfo()) {
// 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()) {
//
// OSMRelation relation = entry.getKey();
// OsmRelation relation = entry.getKey();
//
// for (TmpRelation member : entry.getValue()) {
//
// OSMElement memberObject = null;
// OsmElement memberObject = null;
//
// if ("node".equals(member)) {
// memberObject = nodesById.get(member.id);
@ -313,7 +313,7 @@ public class OsmPbfParser extends BinaryParser {
// }
//
// if (memberObject != null) {
// OSMMember ownMember = new OSMMember(member.role,
// OsmMember ownMember = new OsmMember(member.role,
// memberObject);
//
// relation.relationMembers.add(ownMember);
@ -323,11 +323,11 @@ public class OsmPbfParser extends BinaryParser {
// give up references to original collections
ArrayList<OSMWay> ways = new ArrayList<OSMWay>(mWayMap.values());
ArrayList<OSMNode> nodes = new ArrayList<OSMNode>(mNodeMap.values());
ArrayList<OsmWay> ways = new ArrayList<OsmWay>(mWayMap.values());
ArrayList<OsmNode> nodes = new ArrayList<OsmNode>(mNodeMap.values());
//log.debug("nodes: " + nodes.size() + " ways: " + ways.size());
return new OSMData(null, nodes, ways, null);
return new OsmData(null, nodes, ways, null);
}
}

View File

@ -20,11 +20,11 @@ import java.io.IOException;
import java.io.InputStream;
import org.openstreetmap.osmosis.osmbinary.file.BlockInputStream;
import org.oscim.utils.osm.OSMData;
import org.oscim.core.osm.OsmData;
public class OsmPbfReader {
public static OSMData process(InputStream is) {
public static OsmData process(InputStream is) {
OsmPbfParser parser = new OsmPbfParser();
try {

View File

@ -35,13 +35,13 @@ import java.util.zip.InflaterInputStream;
import org.oscim.core.Tag;
import org.oscim.core.TagSet;
import org.oscim.utils.osm.Bound;
import org.oscim.utils.osm.OSMData;
import org.oscim.utils.osm.OSMElement;
import org.oscim.utils.osm.OSMMember;
import org.oscim.utils.osm.OSMNode;
import org.oscim.utils.osm.OSMRelation;
import org.oscim.utils.osm.OSMWay;
import org.oscim.core.osm.Bound;
import org.oscim.core.osm.OsmData;
import org.oscim.core.osm.OsmElement;
import org.oscim.core.osm.OsmMember;
import org.oscim.core.osm.OsmNode;
import org.oscim.core.osm.OsmRelation;
import org.oscim.core.osm.OsmWay;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
@ -166,15 +166,15 @@ public class OverpassAPIReader {
}
private final List<Bound> bounds = new ArrayList<Bound>();
private Map<Long, OSMNode> nodesById = new HashMap<Long, OSMNode>();
private Map<Long, OSMWay> waysById = new HashMap<Long, OSMWay>();
private Map<Long, OSMRelation> relationsById = new HashMap<Long, OSMRelation>();
private Map<OSMRelation, List<TmpRelation>> relationMembersForRelation =
new HashMap<OSMRelation, List<TmpRelation>>();
private Map<Long, OsmNode> nodesById = new HashMap<Long, OsmNode>();
private Map<Long, OsmWay> waysById = new HashMap<Long, OsmWay>();
private Map<Long, OsmRelation> relationsById = new HashMap<Long, OsmRelation>();
private Map<OsmRelation, List<TmpRelation>> relationMembersForRelation =
new HashMap<OsmRelation, List<TmpRelation>>();
private final Collection<OSMNode> ownNodes = new ArrayList<OSMNode>(10000);
private final Collection<OSMWay> ownWays = new ArrayList<OSMWay>(1000);
private final Collection<OSMRelation> ownRelations = new ArrayList<OSMRelation>(
private final Collection<OsmNode> ownNodes = new ArrayList<OsmNode>(10000);
private final Collection<OsmWay> ownWays = new ArrayList<OsmWay>(1000);
private final Collection<OsmRelation> ownRelations = new ArrayList<OsmRelation>(
100);
public void parse(InputStream in) throws IOException {
@ -214,7 +214,7 @@ public class OverpassAPIReader {
long id = 0;
double lat = 0, lon = 0;
TagSet tags = null;
TagSet tags = null;
while (jp.nextToken() != JsonToken.END_OBJECT) {
@ -236,7 +236,7 @@ public class OverpassAPIReader {
}
// log("node: "+id + " "+ lat + " " + lon);
OSMNode node = new OSMNode(lat, lon, tags, id);
OsmNode node = new OsmNode(lat, lon, tags, id);
ownNodes.add(node);
nodesById.put(Long.valueOf(id), node);
}
@ -245,7 +245,7 @@ public class OverpassAPIReader {
long id = 0;
TagSet tags = null;
ArrayList<OSMNode> wayNodes = new ArrayList<OSMNode>();
ArrayList<OsmNode> wayNodes = new ArrayList<OsmNode>();
while (jp.nextToken() != JsonToken.END_OBJECT) {
@ -259,7 +259,7 @@ public class OverpassAPIReader {
while (jp.nextToken() != JsonToken.END_ARRAY) {
Long nodeId = Long.valueOf(jp.getLongValue());
OSMNode node = nodesById.get(nodeId);
OsmNode node = nodesById.get(nodeId);
if (node != null)
// log("missing node " + nodeId);
// else
@ -270,7 +270,7 @@ public class OverpassAPIReader {
}
// log("way: "+ id + " " + wayNodes.size());
OSMWay way = new OSMWay(tags, id, wayNodes);
OsmWay way = new OsmWay(tags, id, wayNodes);
ownWays.add(way);
waysById.put(Long.valueOf(id), way);
}
@ -313,7 +313,7 @@ public class OverpassAPIReader {
tags = parseTags(jp);
}
OSMRelation relation = new OSMRelation(tags, id, members.size());
OsmRelation relation = new OsmRelation(tags, id, members.size());
ownRelations.add(relation);
relationsById.put(Long.valueOf(id), relation);
relationMembersForRelation.put(relation, members);
@ -342,7 +342,7 @@ public class OverpassAPIReader {
System.out.println(msg);
}
public OSMData getData() {
public OsmData getData() {
String encoded;
try {
@ -371,14 +371,14 @@ public class OverpassAPIReader {
inputStream = null;
}
for (Entry<OSMRelation, List<TmpRelation>> entry : relationMembersForRelation
for (Entry<OsmRelation, List<TmpRelation>> entry : relationMembersForRelation
.entrySet()) {
OSMRelation relation = entry.getKey();
OsmRelation relation = entry.getKey();
for (TmpRelation member : entry.getValue()) {
OSMElement memberObject = null;
OsmElement memberObject = null;
if ("node".equals(member)) {
memberObject = nodesById.get(member.id);
@ -392,7 +392,7 @@ public class OverpassAPIReader {
}
if (memberObject != null) {
OSMMember ownMember = new OSMMember(member.role,
OsmMember ownMember = new OsmMember(member.role,
memberObject);
relation.relationMembers.add(ownMember);
@ -408,6 +408,6 @@ public class OverpassAPIReader {
relationsById = null;
relationMembersForRelation = null;
return new OSMData(bounds, ownNodes, ownWays, ownRelations);
return new OsmData(bounds, ownNodes, ownWays, ownRelations);
}
}