- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 GeoTools 从启用了 PostGIS 的数据库中的要素表中过滤要素。
我的配置:
设置
我通过按顺序执行这些 sql 脚本来设置支持 postgis 的数据库:
然后我使用 OSMembrane 导入我从 europe.osm 中提取的一些 .osm 数据。
到目前为止,一切都很好。所有表都包含一些数据。然后我尝试阅读功能表,例如看起来像这样的“方式”:
CREATE TABLE ways
(
id bigint NOT NULL,
"version" integer NOT NULL,
user_id integer NOT NULL,
tstamp timestamp without time zone NOT NULL,
changeset_id bigint NOT NULL,
tags hstore,
nodes bigint[],
CONSTRAINT pk_ways PRIMARY KEY (id)
)
特别是“标签”列包含我想用于过滤的键/值对。当尝试在 SQL 中按“natural = coaSTLine”过滤行时,我得到约 550 个结果行。
SELECT tags FROM ways where tags @> 'natural => coastline'
Example result: '"source"=>"PGS", "natural"=>"coastline", "created_by"=>"almien_coastlines"'
使用 GeoTools 尝试此操作并没有像预期的那样工作,因为这个例子将有希望向您展示。
package getfeaturesapplication;
import java.util.HashMap;
import java.util.Map;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.postgis.PostgisNGDataStoreFactory;
import org.geotools.data.simple.SimpleFeatureSource;
public class GetFeaturesApplication {
public static void main(String[] args) {
try {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put(PostgisNGDataStoreFactory.DBTYPE.key, "postgis");
parameters.put(PostgisNGDataStoreFactory.HOST.key, "localhost");
parameters.put(PostgisNGDataStoreFactory.PORT.key, new Integer(5432));
parameters.put(PostgisNGDataStoreFactory.DATABASE.key, "postgis");
parameters.put(PostgisNGDataStoreFactory.SCHEMA.key, "public");
parameters.put(PostgisNGDataStoreFactory.USER.key, "osm");
parameters.put(PostgisNGDataStoreFactory.PASSWD.key, "osm");
DataStore dataStore = DataStoreFinder.getDataStore(parameters);
String featureName = "ways";
SimpleFeatureSource featureSource = dataStore.getFeatureSource(featureName); //=> WARNINGS
SimpleFeatureCollection features1 = featureSource.getFeatures();
System.out.println("Feature count: " + features1.size()); //406391
FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2(null);
Filter filter = filterFactory.equals(filterFactory.literal("natural"), filterFactory.literal("coastline"));
SimpleFeatureCollection features2 = featureSource.getFeatures(filter);
System.out.println("Features found after filtering: " + !features2.isEmpty()); //SEEMS TO BE ALWAYS EMPTY
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
运行此应用程序时我得到:
31.01.2012 15:27:49 org.geotools.jdbc.JDBCFeatureSource buildFeatureType
WARNING: Could not find mapping for 'tags', ignoring the column and setting the feature type read only
31.01.2012 15:27:49 org.geotools.jdbc.JDBCFeatureSource buildFeatureType
WARNING: Could not find mapping for 'nodes', ignoring the column and setting the feature type read only
Feature count: 406391
Features found after filtering: false
hstore 和 bigint[] 列有问题还是我误用了 GeoTools?也许,你可以给我一些提示。
最佳答案
虽然我无法让 geoServer 直接使用 hstore(在基于 SQL View 的层中),但我能够向数据库添加一个辅助函数,这允许显示内容。函数是
CREATE OR REPLACE FUNCTION hstore_to_text(h hstore)
RETURNS text AS
$BODY$
DECLARE
txt text;
BEGIN
txt := cast(h as text);
return txt;
END $BODY$
LANGUAGE 'plpgsql' volatile
COST 1;
ALTER FUNCTION hstore_to_text(hstore)
OWNER TO postgres;
然后你可以使用类似的东西在查询中转换 hstore
从 mytable 中选择 id、hstore_to_text(hst_var)、mygeom
并且 FWIW - 执行转换(或直接在查询中的任何其他变体 - 而不是通过函数)不起作用。
关于postgresql - 如何使用 GeoTools 从 hstore 列中过滤数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9081946/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 4 年前。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 4 年前。
我也是 Geotools 和 Maven 的新手。我尝试了快速入门来开始使用地理工具,一切都运行良好,直到我尝试创建示例应用程序。所有以 org.geotools 开头的导入都被标记为不存在。查找依赖
我目前正在使用 GeoTools 工具包对海洋船只数据进行计算,例如计算两个经/纬度点之间的大圆距离。我还有两个需要满足的其他要求,但我不确定在 GeoTools 中的什么地方可以找到执行此类计算的类
我正在研究一个Java项目,该项目需要将WGS84转换为UMT。我使用geotools v20.5通过以下代码创建了一个转换: transform = CRS.findMathTransform(
有人可以告诉我如何通过 java geotools api 获取特征的顶点吗? 就我而言,我在postgis中有一个多边形层,我可以查询该层的所有特征,并且我需要知道每个特征的顶点。
我正在使用 geotools.js 将操作系统网格引用转换为纬度和经度。不幸的是,默认情况下(我相信)输出限制为小数点后两位。为了更准确的读数,我需要它是小数点后 5 位。 我尝试在自己的代码中删除对
我正在使用 geotools 库。我的目标是输入一个坐标,然后获取包含它的要素信息。 Geotools Quickstart 教程的 map 完全按照我想要的方式使用我在下面用红色圈出的按钮。但是,我
我正在使用 GeoTools Java 库进行一些几何计算。就我而言,我使用的是一个形状文件,其中包含某个城市的所有邻域多面体。我想知道那个城市的每一个可能的坐标,它对应于哪个街区。所以我的方法是简单
我正在使用 Java Geotools 库来检查 POINT(...) 是否包含在 POLYGON(...) 中。 我已经完成了: Geometry sPG = reader.read(wktStar
本文整理了Java中org.geotools.util.WeakCollectionCleaner类的一些代码示例,展示了WeakCollectionCleaner类的具体用法。这些代码示例主要来源于
本文整理了Java中org.geotools.resources.XArray类的一些代码示例,展示了XArray类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Mave
本文整理了Java中org.geotools.resources.XMath类的一些代码示例,展示了XMath类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等
本文整理了Java中org.geotools.xs.XSSchema类的一些代码示例,展示了XSSchema类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平
本文整理了Java中org.geotools.ysld.Ysld类的一些代码示例,展示了Ysld类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些
本文整理了Java中org.geotools.ysld.YamlSeq类的一些代码示例,展示了YamlSeq类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平
本文整理了Java中org.geotools.ysld.YamlUtil类的一些代码示例,展示了YamlUtil类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 6 个月前关闭。 Improve
我正在实现轨迹点的插值。所以,基本上,我需要沿着从起点到终点的方位角创建几个点。问题是,我无法将创建的点添加到集合中: SimpleFeatureType featureType = featureS
我有很多点导致 getOrthodromicDistance 方法在 geotools lib 中失败并出现异常,而这些点是有效的经纬度点: 抛出异常的点(纬度,经度): val p1= (5.318
我是一名优秀的程序员,十分优秀!