From b39f9ca00327499152280b027083c29d328747f3 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Sun, 30 Mar 2014 03:53:07 +0200 Subject: [PATCH] add geojson example tile sources - add OsmLanduseJsonTileSource - add layers for buildings and water areas --- .../source/geojson/GeoJsonTileSource.java | 5 + .../geojson/HighroadJsonTileSource.java | 98 ++++++++++++++ .../geojson/OsmBuildingJsonTileSource.java | 38 ++++++ .../geojson/OsmLanduseJsonTileSource.java | 127 ++++++++++++++++++ .../geojson/OsmWaterJsonTileSource.java | 38 ++++++ .../source/geojson/RiverJsonTileSource.java | 22 +++ 6 files changed, 328 insertions(+) create mode 100644 vtm-extras/src/org/oscim/tiling/source/geojson/HighroadJsonTileSource.java create mode 100644 vtm-extras/src/org/oscim/tiling/source/geojson/OsmBuildingJsonTileSource.java create mode 100644 vtm-extras/src/org/oscim/tiling/source/geojson/OsmLanduseJsonTileSource.java create mode 100644 vtm-extras/src/org/oscim/tiling/source/geojson/OsmWaterJsonTileSource.java create mode 100644 vtm-extras/src/org/oscim/tiling/source/geojson/RiverJsonTileSource.java diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileSource.java b/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileSource.java index e76d63a8..e381f6a1 100644 --- a/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileSource.java +++ b/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileSource.java @@ -33,6 +33,11 @@ public abstract class GeoJsonTileSource extends UrlTileSource { setExtension(".json"); } + public GeoJsonTileSource(String url, int zoomMin, int zoomMax) { + super(url, zoomMin, zoomMax); + setExtension(".json"); + } + @Override public ITileDataSource getDataSource() { Map opt = new HashMap(); diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/HighroadJsonTileSource.java b/vtm-extras/src/org/oscim/tiling/source/geojson/HighroadJsonTileSource.java new file mode 100644 index 00000000..4d00d2fe --- /dev/null +++ b/vtm-extras/src/org/oscim/tiling/source/geojson/HighroadJsonTileSource.java @@ -0,0 +1,98 @@ +/* + * Copyright 2014 Hannes Janetzek + * + * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). + * + * 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.tiling.source.geojson; + +import java.util.Map; + +import org.oscim.core.MapElement; +import org.oscim.core.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class HighroadJsonTileSource extends GeoJsonTileSource { + + static final Logger log = LoggerFactory.getLogger(HighroadJsonTileSource.class); + + Tag mTagTunnel = new Tag("tunnel", "yes"); + Tag mTagBridge = new Tag("bridge", "yes"); + + public HighroadJsonTileSource() { + super("http://tile.openstreetmap.us/vectiles-highroad"); + } + + @Override + public void decodeTags(MapElement mapElement, Map properties) { + String highway = null; + boolean isLink = false; + + mapElement.layer = 5; + + for (Map.Entry entry : properties.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + //log.debug(key + " : " + String.valueOf(value)); + + if (value == null) + continue; + + if ("no".equals(value)) + continue; + + if ("highway".equals(key) && value instanceof String) { + highway = (String) entry.getValue(); + } + else if ("is_link".equals(key)) { + isLink = "yes".equals(value); + } + else if ("is_tunnel".equals(key)) { + mapElement.tags.add(mTagTunnel); + } + else if ("is_bridge".equals(key)) { + mapElement.tags.add(mTagBridge); + } + else if ("sort_key".equals(key)) { + if (value instanceof Integer) + mapElement.layer = 5 + (Integer) value; + } + else if ("railway".equals(key) && value instanceof String) { + mapElement.tags.add(new Tag("railway", (String) value)); + } + } + + if (highway == null) + return; + + if (isLink) + highway += "_link"; + + mapElement.tags.add(new Tag("highway", highway)); + + } + + @Override + public Tag rewriteTag(String key, Object value) { + if ("kind".equals(key)) + return null; + + if (value == null) + return null; + + String val = (value instanceof String) ? (String) value : String.valueOf(value); + + return new Tag(key, val); + } +} diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/OsmBuildingJsonTileSource.java b/vtm-extras/src/org/oscim/tiling/source/geojson/OsmBuildingJsonTileSource.java new file mode 100644 index 00000000..9ad02bac --- /dev/null +++ b/vtm-extras/src/org/oscim/tiling/source/geojson/OsmBuildingJsonTileSource.java @@ -0,0 +1,38 @@ +/* + * Copyright 2014 Hannes Janetzek + * + * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). + * + * 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.tiling.source.geojson; + +import java.util.Map; + +import org.oscim.core.MapElement; +import org.oscim.core.Tag; + +public class OsmBuildingJsonTileSource extends GeoJsonTileSource { + + public OsmBuildingJsonTileSource() { + super("http://tile.openstreetmap.us/vectiles-buildings"); + } + + Tag mTagBuilding = new Tag("building", "yes"); + + @Override + public void decodeTags(MapElement mapElement, Map properties) { + + mapElement.tags.add(mTagBuilding); + + } +} diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/OsmLanduseJsonTileSource.java b/vtm-extras/src/org/oscim/tiling/source/geojson/OsmLanduseJsonTileSource.java new file mode 100644 index 00000000..fb8d7049 --- /dev/null +++ b/vtm-extras/src/org/oscim/tiling/source/geojson/OsmLanduseJsonTileSource.java @@ -0,0 +1,127 @@ +/* + * Copyright 2014 Hannes Janetzek + * + * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). + * + * 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.tiling.source.geojson; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.oscim.core.GeometryBuffer.GeometryType; +import org.oscim.core.MapElement; +import org.oscim.core.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class OsmLanduseJsonTileSource extends GeoJsonTileSource { + static final Logger log = LoggerFactory.getLogger(OsmLanduseJsonTileSource.class); + + public OsmLanduseJsonTileSource() { + super("http://tile.openstreetmap.us/vectiles-land-usages"); + } + + private static LinkedHashMap mappings = + new LinkedHashMap(); + + static void addMapping(String key, String val) { + mappings.put(val, new Tag(key, val)); + } + + static { + addMapping("landuse", "residential"); + addMapping("landuse", "commercial"); + addMapping("landuse", "retail"); + addMapping("landuse", "railway"); + addMapping("landuse", "grass"); + addMapping("landuse", "meadow"); + addMapping("landuse", "forest"); + addMapping("landuse", "farm"); + addMapping("landuse", "allotments"); + addMapping("landuse", "cemetery"); + addMapping("landuse", "farmyard"); + addMapping("landuse", "farmland"); + addMapping("landuse", "quarry"); + addMapping("landuse", "military"); + addMapping("landuse", "industrial"); + addMapping("landuse", "greenfield"); + addMapping("landuse", "village_green"); + addMapping("landuse", "recreation_ground"); + addMapping("landuse", "conservation"); + addMapping("landuse", "landfill"); + addMapping("landuse", "construction"); + + addMapping("leisure", "common"); + addMapping("leisure", "park"); + addMapping("leisure", "pitch"); + addMapping("leisure", "garden"); + addMapping("leisure", "sports_centre"); + addMapping("leisure", "playground"); + addMapping("leisure", "nature_reserve"); + addMapping("leisure", "golf_course"); + addMapping("leisure", "stadium"); + + addMapping("amenity", "hospital"); + addMapping("amenity", "cinema"); + addMapping("amenity", "school"); + addMapping("amenity", "college"); + addMapping("amenity", "university"); + addMapping("amenity", "theatre"); + addMapping("amenity", "library"); + addMapping("amenity", "parking"); + addMapping("amenity", "place_of_worship"); + + addMapping("highway", "pedestrian"); + addMapping("highway", "footway"); + addMapping("highway", "service"); + addMapping("highway", "street"); + + addMapping("natural", "scrub"); + addMapping("natural", "wood"); + + mappings.put("urban area", new Tag("landuse", "urban")); + mappings.put("park or protected land", new Tag("leisure", "park")); + } + + private final static Tag mTagArea = new Tag("area", "yes"); + + @Override + public void decodeTags(MapElement mapElement, Map properties) { + + for (Map.Entry entry : properties.entrySet()) { + String key = entry.getKey(); + + if (!"kind".equals(key)) + continue; + + String value = (String) entry.getValue(); + + Tag tag = mappings.get(value); + if (tag == null) { + System.out.println("unmatched " + value); + } else { + mapElement.tags.add(tag); + } + break; + } + } + + @Override + public void postGeomHook(MapElement mapElement) { + //if (mapElement.type != GeometryType.POLY) { + mapElement.type = GeometryType.POLY; + mapElement.tags.add(mTagArea); + //} + } +} diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/OsmWaterJsonTileSource.java b/vtm-extras/src/org/oscim/tiling/source/geojson/OsmWaterJsonTileSource.java new file mode 100644 index 00000000..70a087f9 --- /dev/null +++ b/vtm-extras/src/org/oscim/tiling/source/geojson/OsmWaterJsonTileSource.java @@ -0,0 +1,38 @@ +/* + * Copyright 2014 Hannes Janetzek + * + * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). + * + * 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.tiling.source.geojson; + +import java.util.Map; + +import org.oscim.core.MapElement; +import org.oscim.core.Tag; + +public class OsmWaterJsonTileSource extends GeoJsonTileSource { + + public OsmWaterJsonTileSource() { + super("http://tile.openstreetmap.us/vectiles-water-areas"); + } + + Tag mTagWater = new Tag("natural", "water"); + + @Override + public void decodeTags(MapElement mapElement, Map properties) { + + mapElement.tags.add(mTagWater); + + } +} diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/RiverJsonTileSource.java b/vtm-extras/src/org/oscim/tiling/source/geojson/RiverJsonTileSource.java new file mode 100644 index 00000000..7db9cc6c --- /dev/null +++ b/vtm-extras/src/org/oscim/tiling/source/geojson/RiverJsonTileSource.java @@ -0,0 +1,22 @@ +package org.oscim.tiling.source.geojson; + +import java.util.Map; + +import org.oscim.core.MapElement; +import org.oscim.core.Tag; + +public class RiverJsonTileSource extends GeoJsonTileSource { + + public RiverJsonTileSource() { + super("http://www.somebits.com:8001/rivers"); + } + + Tag mTagWater = new Tag("waterway", "river"); + + @Override + public void decodeTags(MapElement mapElement, Map properties) { + + mapElement.tags.add(mTagWater); + + } +}