diff --git a/build.gradle b/build.gradle index dcf7061b4..d68c0119d 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,7 @@ def versionName() { return version } subprojects { repositories { google() - //maven { url 'https://repo.boundlessgeo.com/main/' } + maven { url 'https://repo.osgeo.org/repository/release/' } jcenter() maven { url 'https://jitpack.io' } } diff --git a/settings.gradle b/settings.gradle index 814da9475..ddc74185f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,7 +14,7 @@ include ':vtm-gdx-poi3d' include ':vtm-http' include ':vtm-ios' include ':vtm-ios-example' -//include ':vtm-jeo' +include ':vtm-jeo' include ':vtm-json' include ':vtm-jts' include ':vtm-models' diff --git a/vtm-jeo/build.gradle b/vtm-jeo/build.gradle index 40044a22f..1c76e835f 100644 --- a/vtm-jeo/build.gradle +++ b/vtm-jeo/build.gradle @@ -3,10 +3,8 @@ apply plugin: 'maven' dependencies { api project(':vtm') - api('org.jeo:jeo:0-SNAPSHOT') { - exclude group: 'org.slf4j', module: 'slf4j-jdk14' - } - api('org.jeo:jeo-carto:0-SNAPSHOT') { + + api('com.github.jeo.jeo:jeo-carto:master-SNAPSHOT') { exclude group: 'org.slf4j', module: 'slf4j-jdk14' } } diff --git a/vtm-jeo/src/org/oscim/jeo/JeoUtils.java b/vtm-jeo/src/org/oscim/jeo/JeoUtils.java index def14a68a..ce6c804a7 100644 --- a/vtm-jeo/src/org/oscim/jeo/JeoUtils.java +++ b/vtm-jeo/src/org/oscim/jeo/JeoUtils.java @@ -1,6 +1,6 @@ package org.oscim.jeo; -import org.jeo.map.RGB; +import io.jeo.map.RGB; public class JeoUtils { public static int color(RGB rgb) { diff --git a/vtm-jeo/src/org/oscim/layers/JeoTileSource.java b/vtm-jeo/src/org/oscim/layers/JeoTileSource.java index 9cade8190..8133c41b0 100644 --- a/vtm-jeo/src/org/oscim/layers/JeoTileSource.java +++ b/vtm-jeo/src/org/oscim/layers/JeoTileSource.java @@ -16,8 +16,6 @@ */ package org.oscim.layers; -import org.jeo.tile.Tile; -import org.jeo.tile.TileDataset; import org.oscim.backend.CanvasAdapter; import org.oscim.backend.canvas.Bitmap; import org.oscim.layers.tile.MapTile; @@ -30,6 +28,9 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import io.jeo.tile.Tile; +import io.jeo.tile.TileDataset; + import static org.oscim.tiling.QueryResult.FAILED; import static org.oscim.tiling.QueryResult.SUCCESS; import static org.oscim.tiling.QueryResult.TILE_NOT_FOUND; diff --git a/vtm-jeo/src/org/oscim/layers/JeoVectorLayer.java b/vtm-jeo/src/org/oscim/layers/JeoVectorLayer.java index 4a6339fa9..7788814bd 100644 --- a/vtm-jeo/src/org/oscim/layers/JeoVectorLayer.java +++ b/vtm-jeo/src/org/oscim/layers/JeoVectorLayer.java @@ -20,15 +20,6 @@ import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.LineString; -import org.jeo.geom.Geom; -import org.jeo.map.CartoCSS; -import org.jeo.map.RGB; -import org.jeo.map.Rule; -import org.jeo.map.RuleList; -import org.jeo.map.Style; -import org.jeo.vector.Feature; -import org.jeo.vector.VectorDataset; -import org.jeo.vector.VectorQuery; import org.oscim.jeo.JeoUtils; import org.oscim.map.Map; import org.oscim.renderer.bucket.LineBucket; @@ -40,6 +31,16 @@ import java.io.IOException; +import io.jeo.geom.Geom; +import io.jeo.map.CartoCSS; +import io.jeo.map.RGB; +import io.jeo.map.Rule; +import io.jeo.map.RuleList; +import io.jeo.map.Style; +import io.jeo.vector.Feature; +import io.jeo.vector.VectorDataset; +import io.jeo.vector.VectorQuery; + public class JeoVectorLayer extends JtsLayer { public static final Logger log = LoggerFactory.getLogger(JeoVectorLayer.class); @@ -77,7 +78,7 @@ protected void processFeatures(Task t, Envelope b) { VectorQuery q = new VectorQuery().bounds(b); if (dbg) log.debug("query {}", b); - for (Feature f : mDataset.cursor(q)) { + for (Feature f : mDataset.read(q)) { if (dbg) log.debug("feature {}", f); diff --git a/vtm-jeo/src/org/oscim/layers/JtsLayer.java b/vtm-jeo/src/org/oscim/layers/JtsLayer.java index 68d5b9509..0bedb8b22 100644 --- a/vtm-jeo/src/org/oscim/layers/JtsLayer.java +++ b/vtm-jeo/src/org/oscim/layers/JtsLayer.java @@ -22,7 +22,6 @@ import com.vividsolutions.jts.geom.Envelope; import com.vividsolutions.jts.geom.Geometry; -import org.jeo.geom.CoordinatePath; import org.oscim.core.Box; import org.oscim.core.GeometryBuffer; import org.oscim.core.MapPosition; @@ -35,6 +34,8 @@ import org.oscim.utils.geom.SimplifyDP; import org.oscim.utils.geom.SimplifyVW; +import io.jeo.geom.CoordinatePath; + public abstract class JtsLayer extends AbstractVectorLayer { private double mMinX; diff --git a/vtm-jeo/src/org/oscim/layers/OSMIndoorLayer.java b/vtm-jeo/src/org/oscim/layers/OSMIndoorLayer.java index 2c88dd4e6..d15247f89 100644 --- a/vtm-jeo/src/org/oscim/layers/OSMIndoorLayer.java +++ b/vtm-jeo/src/org/oscim/layers/OSMIndoorLayer.java @@ -22,12 +22,6 @@ import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.LineString; -import org.jeo.map.CartoCSS; -import org.jeo.map.RGB; -import org.jeo.map.Rule; -import org.jeo.map.Style; -import org.jeo.vector.Feature; -import org.jeo.vector.VectorDataset; import org.oscim.backend.canvas.Color; import org.oscim.jeo.JeoUtils; import org.oscim.map.Map; @@ -41,6 +35,13 @@ import java.util.HashMap; +import io.jeo.map.CartoCSS; +import io.jeo.map.RGB; +import io.jeo.map.Rule; +import io.jeo.map.Style; +import io.jeo.vector.Feature; +import io.jeo.vector.VectorDataset; + public class OSMIndoorLayer extends JeoVectorLayer { protected TextBucket mTextLayer; diff --git a/vtm-jeo/src/org/oscim/test/JeoTest.java b/vtm-jeo/src/org/oscim/test/JeoTest.java index 3f46e5291..28dffc3bd 100644 --- a/vtm-jeo/src/org/oscim/test/JeoTest.java +++ b/vtm-jeo/src/org/oscim/test/JeoTest.java @@ -19,20 +19,6 @@ import com.vividsolutions.jts.geom.Geometry; -import org.jeo.carto.Carto; -import org.jeo.data.Dataset; -import org.jeo.data.mem.MemVector; -import org.jeo.data.mem.MemWorkspace; -import org.jeo.geojson.GeoJSONDataset; -import org.jeo.geojson.GeoJSONReader; -import org.jeo.geom.GeomBuilder; -import org.jeo.map.Style; -import org.jeo.vector.Feature; -import org.jeo.vector.Features; -import org.jeo.vector.Schema; -import org.jeo.vector.SchemaBuilder; -import org.jeo.vector.VectorDataset; -import org.jeo.vector.VectorQuery; import org.oscim.backend.canvas.Color; import org.oscim.layers.OSMIndoorLayer; import org.oscim.layers.tile.buildings.BuildingLayer; @@ -48,6 +34,22 @@ import java.io.IOException; import java.io.InputStream; +import io.jeo.carto.Carto; +import io.jeo.data.Dataset; +import io.jeo.data.mem.MemVectorDataset; +import io.jeo.data.mem.MemWorkspace; +import io.jeo.geojson.GeoJSONDataset; +import io.jeo.geojson.GeoJSONReader; +import io.jeo.geom.GeomBuilder; +import io.jeo.map.Style; +import io.jeo.vector.Feature; +import io.jeo.vector.Features; +import io.jeo.vector.ListFeature; +import io.jeo.vector.Schema; +import io.jeo.vector.SchemaBuilder; +import io.jeo.vector.VectorDataset; +import io.jeo.vector.VectorQuery; + public class JeoTest { public static void indoorSketch(Map map, String file) { @@ -101,13 +103,13 @@ public static VectorDataset readGeoJson(InputStream is) { GeoJSONReader r = new GeoJSONReader(); @SuppressWarnings("resource") - MemWorkspace mem = new MemWorkspace(); + MemWorkspace mem = new MemWorkspace(""); //mem.put("layer", data); try { Schema s = new SchemaBuilder("way").schema(); - MemVector memData = mem.create(s); + MemVectorDataset memData = mem.create(s); for (Feature f : r.features(is)) { //System.out.println("loaded: " + f); @@ -133,7 +135,7 @@ public static Dataset getJsonData(String file, boolean memory) { if (memory) { @SuppressWarnings("resource") - MemWorkspace mem = new MemWorkspace(); + MemWorkspace mem = new MemWorkspace(""); //mem.put("layer", data); try { @@ -141,9 +143,9 @@ public static Dataset getJsonData(String file, boolean memory) { Schema s = data.schema(); VectorQuery q = new VectorQuery(); - MemVector memData = mem.create(s); + MemVectorDataset memData = mem.create(s); - for (Feature f : data.cursor(q)) { + for (Feature f : data.read(q)) { memData.add(f); } @@ -160,14 +162,14 @@ public static Dataset getMemWorkspace(String layer) { GeomBuilder gb = new GeomBuilder(4326); @SuppressWarnings("resource") - MemWorkspace mem = new MemWorkspace(); + MemWorkspace mem = new MemWorkspace(""); Schema schema = new SchemaBuilder(layer) .field("geometry", Geometry.class) .field("id", Integer.class) .field("name", String.class) .field("cost", Double.class).schema(); - MemVector data; + MemVectorDataset data; try { data = mem.create(schema); } catch (UnsupportedOperationException e) { @@ -181,15 +183,16 @@ public static Dataset getMemWorkspace(String layer) { Geometry g = gb.point(0, 0).toPoint(); //g.setSRID(4326); - data.add(Features.create(null, data.schema(), + + data.add(new ListFeature(data.schema(), g, 1, "anvil", 10.99)); - data.add(Features.create(null, data.schema(), + data.add(new ListFeature(data.schema(), gb.points(10, 10, 20, 20).toLineString(), 2, "bomb", 11.99)); - data.add(Features.create(null, data.schema(), + data.add(new ListFeature(data.schema(), gb.point(100, 10).toPoint().buffer(10), 3, "dynamite", 12.99)); diff --git a/vtm-jeo/src/org/oscim/theme/carto/BasicFeature.java b/vtm-jeo/src/org/oscim/theme/carto/BasicFeature.java new file mode 100644 index 000000000..8dfe7aa4f --- /dev/null +++ b/vtm-jeo/src/org/oscim/theme/carto/BasicFeature.java @@ -0,0 +1,462 @@ +package org.oscim.theme.carto; + +/* Copyright 2013 The jeo project. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import io.jeo.util.Util; +import io.jeo.vector.Feature; +import io.jeo.vector.Field; +import io.jeo.vector.Schema; +import io.jeo.vector.SchemaBuilder; + +import org.osgeo.proj4j.CoordinateReferenceSystem; + +import com.vividsolutions.jts.geom.Geometry; + +/** + * Basic feature implementation. + * + * @author Justin Deoliveira, Boundless + * + * Adapted by Jan Lippert to the changes made in https://github.com/jeo/jeo/commit/e28695ccc8530ae6d1a2dff1fbd1e11449ef949f + */ +public class BasicFeature implements Feature { + + /** + * feature identifier + */ + protected String id; + + /** + * Underlying feature storage. + */ + protected Storage storage; + + /** + * Constructor taking a feature identifier. + * + * @param id The feature id, if null an identifier will be generated. + */ + public BasicFeature(String id) { + this(id, (Schema) null); + } + + /** + * Constructor taking a feature identifier and an explicit schema object. + * + * @param id The feature id, if null an identifier will be generated. + * @param schema The feature schema, if null the schema will be always be derived + */ + public BasicFeature(String id, Schema schema) { + this(id, (Storage) + (schema != null ? new ListStorage(null, schema) : new MapStorage(null, schema))); + } + + /** + * Constructs a feature from an identifier and a list of values. + * + * @param id The feature id, if null an identifier will be generated. + * @param values The feature values. + */ + public BasicFeature(String id, List values) { + this(id, values, null); + } + + /** + * Constructs a feature from an identifier, a list of values, and a schema. + * + * @param id The feature id, if null an identifier will be generated. + * @param values The feature values. + * @param schema The feature schema, if null the schema will be always be derived + */ + public BasicFeature(String id, List values, Schema schema) { + this(id, new ListStorage(values, schema)); + } + + /** + * Constructs a feature from an identifier and a map of values. + * + * @param id The feature id, if null an identifier will be generated. + * @param values The feature values. + */ + public BasicFeature(String id, Map values) { + this(id, values, null); + } + + /** + * Constructs a feature from an identifier, a map of values, and a schema. + * + * @param id The feature id, if null an identifier will be generated. + * @param values The feature values. + * @param schema The feature schema, if null the schema will be always be derived + */ + public BasicFeature(String id, Map values, Schema schema) { + this(id, new MapStorage(values, schema)); + } + + /** + * Constructor taking an identifier and feature storage object directly. + *

+ * This constructor is typically only used for subclasses that need to implement custom feature + * storage. + *

+ */ + protected BasicFeature(String id, Storage storage) { + this.id = id != null ? id : Util.uuid(); + this.storage = storage; + } + + @Override + public String id() { + return id; + } + + // @Override +// public CoordinateReferenceSystem getCRS() { +// return crs; +// } +// + public BasicFeature crs(CoordinateReferenceSystem crs) { + storage.crs(crs); + return this; + } + + @Override + public boolean has(String key) { + return storage.has(key); + } + + @Override + public Object get(String key) { + return storage.get(key); + } + + @Override + public BasicFeature put(String key, Object val) { + storage.put(key, val); + return this; + } + + @Override + public BasicFeature put(Geometry g) { + //TODO:optimize before triggering schema creation + Field gf = storage.schema(true).geometry(); + if (gf == null) { + throw new IllegalArgumentException("Feature schema has no geometry"); + } + + return put(gf.name(), g); + } + + + @Override + public Geometry geometry() { + return storage.geometry(); + } + + @Override + public Map map() { + return storage.map(); + } + + @Override + public String toString() { + return new StringBuilder(id).append(map()).toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((storage == null) ? 0 : storage.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BasicFeature other = (BasicFeature) obj; + if (id == null) { + return other.id == null; + } + + return id.equals(other.id); + } + + + + protected static abstract class Storage { + Schema schema; + CoordinateReferenceSystem crs; + + protected Storage(Schema schema) { + this.schema = schema; + } + + protected Storage crs(CoordinateReferenceSystem crs) { + this.crs = crs; + return this; + } + + protected Schema schema() { + return schema(true); + } + + protected Schema schema(boolean derive) { + if (schema == null && derive) { + schema = buildSchema(); + + // hack to apply crs override + if (crs != null && schema.crs() == null) { + schema = SchemaBuilder.crs(schema, crs); + } + } + return schema; + } + + protected Geometry geometry() { + if (schema != null) { + Field f = schema.geometry(); + if (f != null) { + return (Geometry) get(f.name()); + } + } + + return findGeometry(); + } + + protected CoordinateReferenceSystem crs() { + if (crs != null) { + return crs; + } + + if (schema != null) { + return schema.crs(); + } + return null; + } + + /** + * Method for subclasses to implement to build a schema for the feature from its underlying + * attributes. + */ + protected abstract Schema buildSchema(); + + /** + * Method for subclasses to implement in order to find a geometry object when no schema + * information is available. + */ + protected abstract Geometry findGeometry(); + + protected abstract Object get(String key); + + protected abstract Object get(int index); + + protected abstract void put(String key, Object value); + + protected abstract void set(int index, Object value); + + protected abstract List list(); + + protected abstract Map map(); + + protected abstract boolean has(String key); + } + + static class ListStorage extends Storage { + + List list; + + ListStorage(List values, Schema schema) { + super(schema); + this.list = pad(values, schema); + } + + List pad(List values, Schema schema) { + //copy list passed in + values = values != null ? new ArrayList(values) : new ArrayList(); + + //expand up to size of schema if necessary + if (schema != null) { + while(values.size() < schema.size()) { + values.add(null); + } + } + return values; + } + + @Override + protected Geometry findGeometry() { + for (Object o : list) { + if (o instanceof Geometry) { + return (Geometry) o; + } + } + + return null; + } + + @Override + protected Schema buildSchema() { + List fields = new ArrayList(); + int i = 0; + boolean g = false; + for (Object o : list) { + if (o instanceof Geometry && !g) { + //first geometry + fields.add(new Field("geometry", o.getClass())); + g = true; + } + else { + //regular field + fields.add(new Field(String.format(Locale.ROOT,"field%d", i++), o != null ? o.getClass():null)); + } + } + return new Schema("feature", fields); + } + + @Override + protected boolean has(String key) { + return schema().indexOf(key) >= 0; + } + + @Override + protected Object get(int i) { + return list.get(i); + } + + @Override + protected void set(int i, Object value) { + list.set(i, value); + } + + @Override + protected Object get(String key) { + int i = schema().indexOf(key); + return i != -1 ? get(i) : null; + } + + @Override + protected void put(String key, Object val) { + int i = schema().indexOf(key); + if (i == -1) { + throw new IllegalArgumentException("No such key " + key); + } + set(i, val); + } + + @Override + protected List list() { + return Collections.unmodifiableList(list); + } + + @Override + protected Map map() { + LinkedHashMap map = new LinkedHashMap(); + for (Field f : schema()) { + map.put(f.name(), get(f.name())); + } + return map; + } + } + + static class MapStorage extends Storage { + + Map map; + + MapStorage(Map values, Schema schema) { + super(schema); + this.map = values != null ? + new LinkedHashMap(values) : new LinkedHashMap(); + } + + @Override + protected Schema buildSchema() { + List fields = new ArrayList(); + for (Map.Entry e : map.entrySet()) { + fields.add(new Field(e.getKey(), e.getValue() != null ? e.getValue().getClass() : null)); + } + + return new Schema("feature", fields); + } + + @Override + protected Geometry findGeometry() { + for (Object obj : map.values()) { + if (obj instanceof Geometry) { + return (Geometry) obj; + } + } + + return null; + } + + @Override + protected boolean has(String key) { + return map.containsKey(key); + } + + @Override + protected Object get(String key) { + return map.get(key); + } + + @Override + protected void put(String key, Object val) { + if (!map.containsKey(key)) { + //new field, clear cached schema + schema = null; + } + map.put(key, val); + } + + @Override + protected Object get(int index) { + return Util.get(map, index); + } + + @Override + protected void set(int index, Object value) { + Util.set(map, index, value); + } + + @Override + protected List list() { + List list = new ArrayList(); + for (Field f : schema()) { + list.add(get(f.name())); + } + return list; + } + + @Override + protected Map map() { + return Collections.unmodifiableMap(map); + } + } +} diff --git a/vtm-jeo/src/org/oscim/theme/carto/MatcherFeature.java b/vtm-jeo/src/org/oscim/theme/carto/MatcherFeature.java index 1c68832d6..c8b4c2cd6 100644 --- a/vtm-jeo/src/org/oscim/theme/carto/MatcherFeature.java +++ b/vtm-jeo/src/org/oscim/theme/carto/MatcherFeature.java @@ -16,13 +16,13 @@ */ package org.oscim.theme.carto; -import org.jeo.vector.BasicFeature; import org.oscim.core.Tag; import org.oscim.core.TagSet; import java.util.List; import java.util.Map; + import static java.lang.System.out; //imitate Feature behaviour for tags and zoom-level @@ -64,27 +64,10 @@ public BasicFeature put(String key, Object val) { return null; } - @Override - public List list() { - out.println("EEEK list()"); - return null; - } @Override public Map map() { out.println("EEEK map()"); return null; } - - @Override - public Object get(int arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public BasicFeature set(int arg0, Object arg1) { - // TODO Auto-generated method stub - return null; - } } diff --git a/vtm-jeo/src/org/oscim/theme/carto/RenderTheme.java b/vtm-jeo/src/org/oscim/theme/carto/RenderTheme.java index 47424ce52..c515f2e65 100644 --- a/vtm-jeo/src/org/oscim/theme/carto/RenderTheme.java +++ b/vtm-jeo/src/org/oscim/theme/carto/RenderTheme.java @@ -1,11 +1,5 @@ package org.oscim.theme.carto; -import org.jeo.carto.Carto; -import org.jeo.map.CartoCSS; -import org.jeo.map.RGB; -import org.jeo.map.Rule; -import org.jeo.map.RuleList; -import org.jeo.map.Style; import org.oscim.core.GeometryBuffer.GeometryType; import org.oscim.core.MapElement; import org.oscim.core.Tag; @@ -19,9 +13,16 @@ import java.util.HashMap; import java.util.Map; +import io.jeo.carto.Carto; +import io.jeo.map.CartoCSS; +import io.jeo.map.RGB; +import io.jeo.map.Rule; +import io.jeo.map.RuleList; +import io.jeo.map.Style; + +import static io.jeo.map.CartoCSS.BACKGROUND_COLOR; +import static io.jeo.map.CartoCSS.OPACITY; import static java.lang.System.out; -import static org.jeo.map.CartoCSS.BACKGROUND_COLOR; -import static org.jeo.map.CartoCSS.OPACITY; public class RenderTheme implements IRenderTheme {