From da53b02e8a929e2877acf41fcbc42210151870fc Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Sun, 28 Apr 2013 04:41:50 +0200 Subject: [PATCH] add OSM datatypes --- src/org/oscim/core/osm/Bound.java | 19 ++++++++ src/org/oscim/core/osm/OSMData.java | 55 +++++++++++++++++++++++ src/org/oscim/core/osm/OSMElement.java | 58 +++++++++++++++++++++++++ src/org/oscim/core/osm/OSMMember.java | 35 +++++++++++++++ src/org/oscim/core/osm/OSMNode.java | 32 ++++++++++++++ src/org/oscim/core/osm/OSMRelation.java | 37 ++++++++++++++++ src/org/oscim/core/osm/OSMWay.java | 40 +++++++++++++++++ src/org/oscim/core/osm/TagGroup.java | 31 +++++++++++++ 8 files changed, 307 insertions(+) create mode 100644 src/org/oscim/core/osm/Bound.java create mode 100644 src/org/oscim/core/osm/OSMData.java create mode 100644 src/org/oscim/core/osm/OSMElement.java create mode 100644 src/org/oscim/core/osm/OSMMember.java create mode 100644 src/org/oscim/core/osm/OSMNode.java create mode 100644 src/org/oscim/core/osm/OSMRelation.java create mode 100644 src/org/oscim/core/osm/OSMWay.java create mode 100644 src/org/oscim/core/osm/TagGroup.java diff --git a/src/org/oscim/core/osm/Bound.java b/src/org/oscim/core/osm/Bound.java new file mode 100644 index 00000000..9f92a885 --- /dev/null +++ b/src/org/oscim/core/osm/Bound.java @@ -0,0 +1,19 @@ +/* + * Copyright 2013 Hannes Janetzek + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package org.oscim.core.osm; + +public class Bound { + +} diff --git a/src/org/oscim/core/osm/OSMData.java b/src/org/oscim/core/osm/OSMData.java new file mode 100644 index 00000000..6d9d10ec --- /dev/null +++ b/src/org/oscim/core/osm/OSMData.java @@ -0,0 +1,55 @@ +/* + * Copyright 2013 Tobias Knerr + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package org.oscim.core.osm; + +import java.util.Collection; + +/** + * OSM dataset containing nodes, areas and relations + */ +public class OSMData { + + private final Collection bounds; + private final Collection nodes; + private final Collection ways; + private final Collection relations; + + public OSMData(Collection bounds, Collection nodes, + Collection ways, Collection relations) { + + this.bounds = bounds; + this.nodes = nodes; + this.ways = ways; + this.relations = relations; + + } + + public Collection getNodes() { + return nodes; + } + + public Collection getWays() { + return ways; + } + + public Collection getRelations() { + return relations; + } + + public Collection getBounds() { + return bounds; + } + +} diff --git a/src/org/oscim/core/osm/OSMElement.java b/src/org/oscim/core/osm/OSMElement.java new file mode 100644 index 00000000..666281c3 --- /dev/null +++ b/src/org/oscim/core/osm/OSMElement.java @@ -0,0 +1,58 @@ +/* + * Copyright 2013 Tobias Knerr + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package org.oscim.core.osm; + +public abstract class OSMElement { + + public final TagGroup tags; + public final long id; + + public OSMElement(TagGroup tags, long id) { + assert tags != null; + this.tags = tags; + this.id = id; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (id ^ (id >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + OSMElement other = (OSMElement) obj; + if (id != other.id) + return false; + return true; + } + + /** + * returns the id, plus an one-letter prefix for the element type + */ + @Override + public String toString() { + return "?" + id; + } + +} diff --git a/src/org/oscim/core/osm/OSMMember.java b/src/org/oscim/core/osm/OSMMember.java new file mode 100644 index 00000000..7e1fc6d1 --- /dev/null +++ b/src/org/oscim/core/osm/OSMMember.java @@ -0,0 +1,35 @@ +/* + * Copyright 2013 Tobias Knerr + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package org.oscim.core.osm; + +public class OSMMember { + + static final boolean useDebugLabels = true; + + public final String role; + public final OSMElement member; + + public OSMMember(String role, OSMElement member) { + assert role != null && member != null; + this.role = role; + this.member = member; + } + + @Override + public String toString() { + return role + ":" + member; + } + +} diff --git a/src/org/oscim/core/osm/OSMNode.java b/src/org/oscim/core/osm/OSMNode.java new file mode 100644 index 00000000..7eae59c9 --- /dev/null +++ b/src/org/oscim/core/osm/OSMNode.java @@ -0,0 +1,32 @@ +/* + * Copyright 2013 Tobias Knerr + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package org.oscim.core.osm; + +public class OSMNode extends OSMElement { + public final double lat; + public final double lon; + + public OSMNode(double lat, double lon, TagGroup tags, long id) { + super(tags, id); + this.lat = lat; + this.lon = lon; + } + + @Override + public String toString() { + return "n" + id; + } + +} diff --git a/src/org/oscim/core/osm/OSMRelation.java b/src/org/oscim/core/osm/OSMRelation.java new file mode 100644 index 00000000..fb75cb52 --- /dev/null +++ b/src/org/oscim/core/osm/OSMRelation.java @@ -0,0 +1,37 @@ +/* + * Copyright 2013 Tobias Knerr + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package org.oscim.core.osm; + +import java.util.ArrayList; +import java.util.List; + +public class OSMRelation extends OSMElement { + + public final List relationMembers; + + // content added after constructor call + + public OSMRelation(TagGroup tags, long id, int initialMemberSize) { + super(tags, id); + this.relationMembers = + new ArrayList(initialMemberSize); + } + + @Override + public String toString() { + return "r" + id; + } + +} diff --git a/src/org/oscim/core/osm/OSMWay.java b/src/org/oscim/core/osm/OSMWay.java new file mode 100644 index 00000000..e15be68d --- /dev/null +++ b/src/org/oscim/core/osm/OSMWay.java @@ -0,0 +1,40 @@ +/* + * Copyright 2013 Tobias Knerr + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package org.oscim.core.osm; + +import java.util.List; + +public class OSMWay extends OSMElement { + + public final List nodes; + + public OSMWay(TagGroup tags, long id, List nodes) { + super(tags, id); + for (OSMNode node : nodes) + assert node != null; + this.nodes = nodes; + } + + public boolean isClosed() { + return nodes.size() > 0 && + nodes.get(0).equals(nodes.get(nodes.size() - 1)); + } + + @Override + public String toString() { + return "w" + id; + } + +} diff --git a/src/org/oscim/core/osm/TagGroup.java b/src/org/oscim/core/osm/TagGroup.java new file mode 100644 index 00000000..24090f0d --- /dev/null +++ b/src/org/oscim/core/osm/TagGroup.java @@ -0,0 +1,31 @@ +/* + * Copyright 2013 Hannes Janetzek + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package org.oscim.core.osm; + +import java.util.Map; + +public class TagGroup { + public final static TagGroup EMPTY_TAG_GROUP = new TagGroup(); + + public final Map tags; + + public TagGroup(Map tags) { + this.tags = tags; + } + + private TagGroup(){ + this.tags = null; + } +}